chainntnfs/bitcoindnotify: always populate block headers for block epochs

This commit is contained in:
Olaoluwa Osuntokun 2021-08-11 16:04:56 -07:00
parent b2cc4cf088
commit 67aa7a0df7
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306

View file

@ -157,6 +157,10 @@ func (b *BitcoindNotifier) startNotifier() error {
if err != nil { if err != nil {
return err return err
} }
blockHeader, err := b.chainConn.GetBlockHeader(currentHash)
if err != nil {
return err
}
b.txNotifier = chainntnfs.NewTxNotifier( b.txNotifier = chainntnfs.NewTxNotifier(
uint32(currentHeight), chainntnfs.ReorgSafetyLimit, uint32(currentHeight), chainntnfs.ReorgSafetyLimit,
@ -164,8 +168,9 @@ func (b *BitcoindNotifier) startNotifier() error {
) )
b.bestBlock = chainntnfs.BlockEpoch{ b.bestBlock = chainntnfs.BlockEpoch{
Height: currentHeight, Height: currentHeight,
Hash: currentHash, Hash: currentHash,
BlockHeader: blockHeader,
} }
b.wg.Add(1) b.wg.Add(1)
@ -322,6 +327,7 @@ out:
b.notifyBlockEpochClient( b.notifyBlockEpochClient(
msg, b.bestBlock.Height, msg, b.bestBlock.Height,
b.bestBlock.Hash, b.bestBlock.Hash,
b.bestBlock.BlockHeader,
) )
msg.errorChan <- nil msg.errorChan <- nil
@ -343,6 +349,7 @@ out:
for _, block := range missedBlocks { for _, block := range missedBlocks {
b.notifyBlockEpochClient( b.notifyBlockEpochClient(
msg, block.Height, block.Hash, msg, block.Height, block.Hash,
block.BlockHeader,
) )
} }
@ -392,8 +399,9 @@ out:
} }
newBlock := chainntnfs.BlockEpoch{ newBlock := chainntnfs.BlockEpoch{
Height: item.Height, Height: item.Height,
Hash: &item.Hash, Hash: &item.Hash,
BlockHeader: blockHeader,
} }
if err := b.handleBlockConnected(newBlock); err != nil { if err := b.handleBlockConnected(newBlock); err != nil {
chainntnfs.Log.Error(err) chainntnfs.Log.Error(err)
@ -589,26 +597,29 @@ func (b *BitcoindNotifier) handleBlockConnected(block chainntnfs.BlockEpoch) err
// satisfy any client requests based upon the new block. // satisfy any client requests based upon the new block.
b.bestBlock = block b.bestBlock = block
b.notifyBlockEpochs(block.Height, block.Hash) b.notifyBlockEpochs(block.Height, block.Hash, block.BlockHeader)
return b.txNotifier.NotifyHeight(uint32(block.Height)) return b.txNotifier.NotifyHeight(uint32(block.Height))
} }
// notifyBlockEpochs notifies all registered block epoch clients of the newly // notifyBlockEpochs notifies all registered block epoch clients of the newly
// connected block to the main chain. // connected block to the main chain.
func (b *BitcoindNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash) { func (b *BitcoindNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash,
blockHeader *wire.BlockHeader) {
for _, client := range b.blockEpochClients { for _, client := range b.blockEpochClients {
b.notifyBlockEpochClient(client, newHeight, newSha) b.notifyBlockEpochClient(client, newHeight, newSha, blockHeader)
} }
} }
// notifyBlockEpochClient sends a registered block epoch client a notification // notifyBlockEpochClient sends a registered block epoch client a notification
// about a specific block. // about a specific block.
func (b *BitcoindNotifier) notifyBlockEpochClient(epochClient *blockEpochRegistration, func (b *BitcoindNotifier) notifyBlockEpochClient(epochClient *blockEpochRegistration,
height int32, sha *chainhash.Hash) { height int32, sha *chainhash.Hash, header *wire.BlockHeader) {
epoch := &chainntnfs.BlockEpoch{ epoch := &chainntnfs.BlockEpoch{
Height: height, Height: height,
Hash: sha, Hash: sha,
BlockHeader: header,
} }
select { select {