Skip to content

Commit

Permalink
Careful with weak reference aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed May 17, 2024
1 parent ecedb76 commit aeb9f6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
19 changes: 9 additions & 10 deletions include/bitcoin/node/impl/chasers/chaser_organize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
BC_ASSERT(stranded());

using namespace system;
const auto& block = *block_ptr;
const auto hash = block.hash();
const auto header = get_header(block);
const auto hash = block_ptr->hash();
const auto header = get_header(*block_ptr);
auto& query = archive();

// Skip existing/orphan, get state.
Expand Down Expand Up @@ -217,14 +216,14 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
return;
};

if (const auto ec = validate(block, *state))
if (const auto ec = validate(*block_ptr, *state))
{
handler(ec, height);
return;
}

// Store with checkpoint, milestone, or currency with sufficient work.
if (!is_storable(block, *state))
if (!is_storable(*block_ptr, *state))
{
log_state_change(*parent, *state);
cache(block_ptr, state);
Expand Down Expand Up @@ -321,7 +320,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,

// Push new header as top of candidate chain.
{
if (push(block, state->context()).is_terminal())
if (push(*block_ptr, state->context()).is_terminal())
{
handler(fault(error::node_push), height);
return;
Expand Down Expand Up @@ -408,16 +407,16 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
const auto top_candidate = state_->height();
for (auto index = add1(fork_point); index <= top_candidate; ++index)
{
typename Block::cptr block{};
if (!get_block(block, index))
typename Block::cptr block_ptr{};
if (!get_block(block_ptr, index))
{
fault(error::get_block);
return;
}

const auto& header = get_header(*block);
const auto& header = get_header(*block_ptr);
state.reset(new chain::chain_state{ *state, header, settings_ });
cache(block, state);
cache(block_ptr, state);
}

// Pop candidates from top down to above fork point.
Expand Down
16 changes: 8 additions & 8 deletions src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,8 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
// ........................................................................

auto& query = archive();
const auto& block = *message->block_ptr;
const auto hash = block.hash();
const auto& block_ptr = message->block_ptr;
const auto hash = block_ptr->hash();
const auto it = map_->find(hash);

if (it == map_->end())
Expand All @@ -289,7 +289,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
return true;
}

if (query.is_malleated(block))
if (query.is_malleated(*block_ptr))
{
// Disallow known block malleation, drop peer and keep trying.
LOGR("Malleated block [" << encode_hash(hash) << "] from ["
Expand All @@ -304,11 +304,11 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
// Check block.
// ........................................................................

if (const auto code = check(block, ctx))
if (const auto code = check(*block_ptr, ctx))
{
// Both forms of malleabilty are possible here.
// Malleable has not been associated, so just drop peer and continue.
if (!block.is_malleable())
if (!block_ptr->is_malleable())
{
if (!query.set_block_unconfirmable(link))
{
Expand All @@ -334,10 +334,10 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
// Commit block.txs.
// ........................................................................

const auto size = block.serialized_size(true);
const auto& txs = *block.transactions_ptr();
const auto size = block_ptr->serialized_size(true);
const auto& txs_ptr = block_ptr->transactions_ptr();

if (const auto code = query.set_code(txs, link, size))
if (const auto code = query.set_code(*txs_ptr, link, size))
{
LOGF("Failure storing block [" << encode_hash(hash) << ":"
<< ctx.height << "] from [" << authority() << "] "
Expand Down

0 comments on commit aeb9f6f

Please sign in to comment.