mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
kernel: improve BlockChecked ownership semantics
Subscribers to the BlockChecked validation interface event may need access to the block outside of the callback scope. Currently, this is only possible by copying the block, which makes exposing this validation interface event publicly either cumbersome or with significant copy overhead. By using shared_ptr, we make the shared ownership explicit and allow users to safely use the block outside of the callback scope.
This commit is contained in:
@@ -513,7 +513,7 @@ public:
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
|
||||
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
void BlockChecked(const CBlock& block, const BlockValidationState& state) override
|
||||
void BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& state) override
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
|
||||
void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) override
|
||||
EXCLUSIVE_LOCKS_REQUIRED(!m_most_recent_block_mutex);
|
||||
@@ -2103,11 +2103,11 @@ void PeerManagerImpl::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlock
|
||||
* Handle invalid block rejection and consequent peer discouragement, maintain which
|
||||
* peers announce compact blocks.
|
||||
*/
|
||||
void PeerManagerImpl::BlockChecked(const CBlock& block, const BlockValidationState& state)
|
||||
void PeerManagerImpl::BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& state)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
const uint256 hash(block.GetHash());
|
||||
const uint256 hash(block->GetHash());
|
||||
std::map<uint256, std::pair<NodeId, bool>>::iterator it = mapBlockSource.find(hash);
|
||||
|
||||
// If the block failed validation, we know where it came from and we're still connected
|
||||
|
||||
Reference in New Issue
Block a user