diff --git a/blockchain/chain.go b/blockchain/chain.go index f32301c4..224009e7 100644 --- a/blockchain/chain.go +++ b/blockchain/chain.go @@ -747,18 +747,6 @@ func (b *BlockChain) connectBlock(node *blockNode, block, parent *dcrutil.Block, return err } - // Notify subscribed indexes of the connected block. - if b.indexSubscriber != nil { - b.indexSubscriber.Notify(&indexers.IndexNtfn{ - NtfnType: indexers.ConnectNtfn, - Block: block, - Parent: parent, - PrevScripts: prevScripter, - IsTreasuryEnabled: isTreasuryEnabled, - Done: make(chan bool), - }) - } - // This node is now the end of the best chain. b.bestChain.SetTip(node) b.index.MaybePruneCachedTips(node) @@ -796,6 +784,7 @@ func (b *BlockChain) connectBlock(node *blockNode, block, parent *dcrutil.Block, Block: block, ParentBlock: parent, CheckTxFlags: checkTxFlags, + PrevScripts: prevScripter, }) b.chainLock.Lock() @@ -958,18 +947,6 @@ func (b *BlockChain) disconnectBlock(node *blockNode, block, parent *dcrutil.Blo return err } - // Notify subscribed indexes of the disconnected block. - if b.indexSubscriber != nil { - b.indexSubscriber.Notify(&indexers.IndexNtfn{ - NtfnType: indexers.DisconnectNtfn, - Block: block, - Parent: parent, - PrevScripts: prevScripter, - IsTreasuryEnabled: isTreasuryEnabled, - Done: make(chan bool), - }) - } - // This node's parent is now the end of the best chain. b.bestChain.SetTip(node.parent) @@ -990,6 +967,7 @@ func (b *BlockChain) disconnectBlock(node *blockNode, block, parent *dcrutil.Blo Block: block, ParentBlock: parent, CheckTxFlags: checkTxFlags, + PrevScripts: prevScripter, }) b.chainLock.Lock() diff --git a/blockchain/indexers/common.go b/blockchain/indexers/common.go index b04b548a..83f28229 100644 --- a/blockchain/indexers/common.go +++ b/blockchain/indexers/common.go @@ -532,12 +532,18 @@ func recover(ctx context.Context, idx Indexer) error { return err } + isTreasuryEnabled, err := queryer.IsTreasuryAgendaActive(parentHash) + if err != nil { + return err + } + ntfn := &IndexNtfn{ - NtfnType: DisconnectNtfn, - Block: block, - Parent: parent, - PrevScripts: prevScripts, - Done: make(chan bool), + NtfnType: DisconnectNtfn, + Block: block, + Parent: parent, + IsTreasuryEnabled: isTreasuryEnabled, + PrevScripts: prevScripts, + Done: make(chan bool), } err = updateIndex(ctx, idx, ntfn) diff --git a/blockchain/indexers/indexsubscriber.go b/blockchain/indexers/indexsubscriber.go index bedd9d27..62a264d3 100644 --- a/blockchain/indexers/indexsubscriber.go +++ b/blockchain/indexers/indexsubscriber.go @@ -359,7 +359,9 @@ func (s *IndexSubscriber) Run(ctx context.Context) { } } - close(ntfn.Done) + if ntfn.Done != nil { + close(ntfn.Done) + } case <-ctx.Done(): log.Infof("Index subscriber shutting down") diff --git a/blockchain/notifications.go b/blockchain/notifications.go index ecf64428..6182bd39 100644 --- a/blockchain/notifications.go +++ b/blockchain/notifications.go @@ -8,6 +8,7 @@ package blockchain import ( "fmt" + "github.com/decred/dcrd/blockchain/v4/indexers" "github.com/decred/dcrd/chaincfg/chainhash" "github.com/decred/dcrd/dcrutil/v4" ) @@ -131,6 +132,10 @@ type BlockConnectedNtfnsData struct { // CheckTxFlags represents the agendas to consider as active when checking // transactions for the block that was connected. CheckTxFlags AgendaFlags + + // PrevScripts provides access to previous transaction scripts and their + // associated versions spent by the connected block. + PrevScripts indexers.PrevScripter } // BlockDisconnectedNtfnsData is the structure for data indicating information @@ -146,6 +151,10 @@ type BlockDisconnectedNtfnsData struct { // CheckTxFlags represents the agendas to consider as active when checking // transactions for the block that was **disconnected**. CheckTxFlags AgendaFlags + + // PrevScripts provides access to previous transaction scripts and their + // associated versions spent by the disconnected block. + PrevScripts indexers.PrevScripter } // ReorganizationNtfnsData is the structure for data indicating information diff --git a/server.go b/server.go index 1b76513b..461907e2 100644 --- a/server.go +++ b/server.go @@ -2750,6 +2750,17 @@ func (s *server) handleBlockchainNotification(notification *blockchain.Notificat s.bg.BlockConnected(block) } + // Notify subscribed indexes of connected block. + if s.indexSubscriber != nil { + s.indexSubscriber.Notify(&indexers.IndexNtfn{ + NtfnType: indexers.ConnectNtfn, + Block: block, + Parent: parentBlock, + IsTreasuryEnabled: isTreasuryEnabled, + PrevScripts: ntfn.PrevScripts, + }) + } + // Proactively evict signature cache entries that are virtually // guaranteed to no longer be useful. s.proactivelyEvictSigCacheEntries(block.Height()) @@ -2865,6 +2876,17 @@ func (s *server) handleBlockchainNotification(notification *blockchain.Notificat s.bg.BlockDisconnected(block) } + // Notify subscribed indexes of disconnected block. + if s.indexSubscriber != nil { + s.indexSubscriber.Notify(&indexers.IndexNtfn{ + NtfnType: indexers.DisconnectNtfn, + Block: block, + Parent: parentBlock, + IsTreasuryEnabled: isTreasuryEnabled, + PrevScripts: ntfn.PrevScripts, + }) + } + // Notify registered websocket clients. if r := s.rpcServer; r != nil { // Filter and update the rebroadcast inventory.