multi: source index notif. from block notif.
This updates the index subscriber to use block notifications as the source of index notifications.
This commit is contained in:
parent
5c74266e3b
commit
cdf881d9ce
@ -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()
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -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
|
||||
|
||||
22
server.go
22
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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user