Skip to content

Commit

Permalink
Merged from pktd-v1.5.1 --ignoremined flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdelisle committed Jan 4, 2024
2 parents dfce82c + 90603ac commit 3cf9ca9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 2 additions & 0 deletions chaincfg/globalcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,5 @@ func AmountUnits() []CoinAmount {
checkRegistered()
return gConf.Amounts
}

var IgnoreMined bool
9 changes: 8 additions & 1 deletion pktwallet/chain/block_filterer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type BlockFilterer struct {
// that contained matches from an address in either ExReverseFilter or
// InReverseFilter.
RelevantTxns []*wire.MsgTx

// If true, do not include coinbase transactions
IgnoreCoinbase bool
}

// NewBlockFilterer constructs the reverse indexes for the current set of
Expand Down Expand Up @@ -107,6 +110,7 @@ func NewBlockFilterer(params *chaincfg.Params,
FoundExternal: foundExternal,
FoundInternal: foundInternal,
FoundOutPoints: foundOutPoints,
IgnoreCoinbase: req.IgnoreCoinbase,
}
}

Expand All @@ -117,7 +121,10 @@ func NewBlockFilterer(params *chaincfg.Params,
// controlled by the wallet.
func (bf *BlockFilterer) FilterBlock(block *wire.MsgBlock) bool {
var hasRelevantTxns bool
for _, tx := range block.Transactions {
for i, tx := range block.Transactions {
if bf.IgnoreCoinbase && i == 0 {
continue
}
if bf.FilterTx(tx) {
bf.RelevantTxns = append(bf.RelevantTxns, tx)
hasRelevantTxns = true
Expand Down
1 change: 1 addition & 0 deletions pktwallet/chain/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type (
InternalAddrs map[waddrmgr.ScopedIndex]btcutil.Address
ImportedAddrs []btcutil.Address
WatchedOutPoints map[wire.OutPoint]btcutil.Address
IgnoreCoinbase bool
}

// FilterBlocksResponse reports the set of all internal and external
Expand Down
2 changes: 2 additions & 0 deletions pktwallet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type config struct {
LogDir string `long:"logdir" description:"Directory to log output."`
StatsViz string `long:"statsviz" description:"Enable StatsViz runtime visualization on given port -- NOTE port must be between 1024 and 65535"`
Profile string `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"`
IgnoreMined bool `long:"ignoremined" description:"Ignore payments from coinbases (newly mined coins)"`

// Wallet options
WalletPass string `long:"walletpass" default-mask:"-" description:"The public wallet password -- Only required if the wallet was created with one"`
Expand Down Expand Up @@ -365,6 +366,7 @@ func loadConfig() (*config, []string, er.R) {
activeNet.PowLimit = blockchain.CompactToBig(activeNet.PowLimitBits)

globalcfg.SelectConfig(activeNet.GlobalConf)
globalcfg.IgnoreMined = cfg.IgnoreMined

// Append the network type to the log directory so it is "namespaced"
// per network.
Expand Down
5 changes: 3 additions & 2 deletions pktwallet/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pkt-cash/pktd/btcutil/hdkeychain"
"github.com/pkt-cash/pktd/chaincfg"
"github.com/pkt-cash/pktd/chaincfg/chainhash"
"github.com/pkt-cash/pktd/chaincfg/globalcfg"
"github.com/pkt-cash/pktd/pktwallet/chain"
"github.com/pkt-cash/pktd/pktwallet/waddrmgr"
"github.com/pkt-cash/pktd/pktwallet/wallet/seedwords"
Expand Down Expand Up @@ -2878,7 +2879,7 @@ func existsTxEntry(
}

func mkFilterReq(w *watcher.Watcher, header *wire.BlockHeader, height int32) *chain.FilterBlocksRequest {
filterReq := w.FilterReq(height)
filterReq := w.FilterReq(height, globalcfg.IgnoreMined)
filterReq.Blocks = []wtxmgr.BlockMeta{
{
Block: wtxmgr.Block{
Expand Down Expand Up @@ -3165,7 +3166,7 @@ func (w *Wallet) block(bm wtxmgr.Block) er.R {
}
if bm.Height == st.Height+1 && header.PrevBlock.IsEqual(&st.Hash) {
// Easy case, the new block is one more block than the one we have
filterReq := w.watch.FilterReq(bm.Height)
filterReq := w.watch.FilterReq(bm.Height, globalcfg.IgnoreMined)
filterReq.Blocks = []wtxmgr.BlockMeta{
{
Block: wtxmgr.Block{
Expand Down
3 changes: 2 additions & 1 deletion pktwallet/wallet/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (w *Watcher) WatchAddr(addr btcutil.Address) {
w.watchStuff([]btcutil.Address{addr}, nil)
}

func (w *Watcher) FilterReq(height int32) *chain.FilterBlocksRequest {
func (w *Watcher) FilterReq(height int32, ignoreCoinbase bool) *chain.FilterBlocksRequest {
w.watchAddrsLock.RLock()
defer w.watchAddrsLock.RUnlock()
filterReq := chain.FilterBlocksRequest{
Expand All @@ -79,6 +79,7 @@ func (w *Watcher) FilterReq(height int32) *chain.FilterBlocksRequest {
InternalAddrs: make(map[waddrmgr.ScopedIndex]btcutil.Address),
ImportedAddrs: make([]btcutil.Address, 0, len(w.watchAddrs)),
WatchedOutPoints: make(map[wire.OutPoint]btcutil.Address),
IgnoreCoinbase: ignoreCoinbase,
}
for wa := range w.watchAddrs {
filterReq.ImportedAddrs = append(filterReq.ImportedAddrs, wa)
Expand Down

0 comments on commit 3cf9ca9

Please sign in to comment.