mirror of
https://github.com/btcsuite/btcd.git
synced 2025-02-23 14:40:44 +01:00
Merge pull request #2128 from kcalvinalvin/2024-02-27-no-panic-for-subscription-callback-errors
blockchain: always relock chainLock for subscription callbacks
This commit is contained in:
commit
f0ec9fbcce
2 changed files with 15 additions and 9 deletions
|
@ -84,9 +84,11 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, flags BehaviorFlags)
|
||||||
// Notify the caller that the new block was accepted into the block
|
// Notify the caller that the new block was accepted into the block
|
||||||
// chain. The caller would typically want to react by relaying the
|
// chain. The caller would typically want to react by relaying the
|
||||||
// inventory to other peers.
|
// inventory to other peers.
|
||||||
|
func() {
|
||||||
b.chainLock.Unlock()
|
b.chainLock.Unlock()
|
||||||
|
defer b.chainLock.Lock()
|
||||||
b.sendNotification(NTBlockAccepted, block)
|
b.sendNotification(NTBlockAccepted, block)
|
||||||
b.chainLock.Lock()
|
}()
|
||||||
|
|
||||||
return isMainChain, nil
|
return isMainChain, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -702,9 +702,11 @@ func (b *BlockChain) connectBlock(node *blockNode, block *btcutil.Block,
|
||||||
// Notify the caller that the block was connected to the main chain.
|
// Notify the caller that the block was connected to the main chain.
|
||||||
// The caller would typically want to react with actions such as
|
// The caller would typically want to react with actions such as
|
||||||
// updating wallets.
|
// updating wallets.
|
||||||
|
func() {
|
||||||
b.chainLock.Unlock()
|
b.chainLock.Unlock()
|
||||||
|
defer b.chainLock.Lock()
|
||||||
b.sendNotification(NTBlockConnected, block)
|
b.sendNotification(NTBlockConnected, block)
|
||||||
b.chainLock.Lock()
|
}()
|
||||||
|
|
||||||
// Since we may have changed the UTXO cache, we make sure it didn't exceed its
|
// Since we may have changed the UTXO cache, we make sure it didn't exceed its
|
||||||
// maximum size. If we're pruned and have flushed already, this will be a no-op.
|
// maximum size. If we're pruned and have flushed already, this will be a no-op.
|
||||||
|
@ -834,9 +836,11 @@ func (b *BlockChain) disconnectBlock(node *blockNode, block *btcutil.Block, view
|
||||||
// Notify the caller that the block was disconnected from the main
|
// Notify the caller that the block was disconnected from the main
|
||||||
// chain. The caller would typically want to react with actions such as
|
// chain. The caller would typically want to react with actions such as
|
||||||
// updating wallets.
|
// updating wallets.
|
||||||
|
func() {
|
||||||
b.chainLock.Unlock()
|
b.chainLock.Unlock()
|
||||||
|
defer b.chainLock.Lock()
|
||||||
b.sendNotification(NTBlockDisconnected, block)
|
b.sendNotification(NTBlockDisconnected, block)
|
||||||
b.chainLock.Lock()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue