Skip to content

Commit

Permalink
const auto txs_ptr = block->transactions_ptr();
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Dec 11, 2024
1 parent 0750adf commit a818a3c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/bitcoin/node/impl/chasers/chaser_organize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ void CLASS::do_organize(typename Block::cptr block,
using namespace system;
BC_ASSERT(stranded());

// shared_ptr copy keeps block ref in scope until completion of set_code.
const auto& hash = block->get_hash();
const auto& header = get_header(*block);
auto& query = archive();
Expand Down Expand Up @@ -564,6 +565,7 @@ code CLASS::push_block(const system::hash_digest& key) NOEXCEPT
if (!handle)
return error::organize15;

// handle keeps the block reference in scope until completion of set_code.
const auto& value = handle.mapped();
return push_block(*value.block, value.state->context());
}
Expand Down
5 changes: 4 additions & 1 deletion src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,11 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
// Commit block.txs.
// ........................................................................

// This must not be a reference to the shared pointer, as otherwise the
// shared_ptr may be taken out of scope before the tx write completes.
// set_code() uses weak references to many elements of the transaction ref.
const auto txs_ptr = block->transactions_ptr();
const auto size = block->serialized_size(true);
const auto& txs_ptr = block->transactions_ptr();

// This invokes set_strong when checked.
if (const auto code = query.set_code(*txs_ptr, link, size, checked))
Expand Down

0 comments on commit a818a3c

Please sign in to comment.