Skip to content

Commit

Permalink
No longer consider malleable64 when setting strong.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jun 16, 2024
1 parent e2af0f4 commit 3ccd966
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
28 changes: 11 additions & 17 deletions include/bitcoin/node/impl/chasers/chaser_organize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
auto index = top_candidate;
while (index > branch_point)
{
// TODO: if milestone set_unstrong.
if (!query.pop_candidate())
{
handler(fault(error::pop_candidate), height);
Expand All @@ -291,6 +292,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
// Push stored strong headers to candidate chain.
for (const auto& link: views_reverse(store_branch))
{
// TODO: if milestone set_strong.
if (!query.push_candidate(link))
{
handler(fault(error::push_candidate), height);
Expand All @@ -304,6 +306,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,
// Store strong tree headers and push to candidate chain.
for (const auto& key: views_reverse(tree_branch))
{
// TODO: if milestone set_strong.
if ((ec = push_block(key)))
{
handler(fault(ec), height);
Expand All @@ -317,6 +320,7 @@ void CLASS::do_organize(typename Block::cptr& block_ptr,

// Push new header as top of candidate chain.
{
// TODO: if milestone set_strong.
if ((ec = push_block(*block_ptr, state->context())))
{
handler(fault(ec), height);
Expand Down Expand Up @@ -423,6 +427,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
const auto top_candidate = state_->height();
for (auto index = top_candidate; index > fork_point; --index)
{
// TODO: if !milestone set_unstrong.
if (!query.pop_candidate())
{
fault(error::pop_candidate);
Expand All @@ -442,6 +447,7 @@ void CLASS::do_disorganize(header_t link) NOEXCEPT
const auto top_confirmed = query.get_top_confirmed();
for (auto index = add1(fork_point); index <= top_confirmed; ++index)
{
// TODO: if milestone set_strong.
const auto confirmed = query.to_confirmed(index);
if (!query.push_candidate(confirmed))
{
Expand Down Expand Up @@ -568,26 +574,14 @@ TEMPLATE
code CLASS::push_block(const Block& block,
const system::chain::context& context) const NOEXCEPT
{
auto& query = archive();
// set milestone and sets strong if milestone or checkpoint.
const auto checkpoint = is_under_checkpoint(context.height);
const auto milestone = is_under_milestone(context.height);
const auto strong = is_block() && (checkpoint || milestone);

// headers-first sets milestone and set_strong ms or cp and not mealleable.
// blocks-first does not set milestone and set_strong cp not malleable.
const auto strong = [&]() NOEXCEPT
{
if constexpr (is_block())
{
return is_under_checkpoint(context.height) &&
!block.is_malleable64();
}
else
{
return false;
}
};

auto& query = archive();
database::header_link link{};
const auto ec = query.set_code(link, block, context, milestone, strong());
const auto ec = query.set_code(link, block, context, milestone, strong);
if (ec)
return ec;

Expand Down
17 changes: 9 additions & 8 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,23 +196,24 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT
}

// Can get malleable64 from block if we have it.
const auto malleable64 = query.is_malleable64(link);
const auto checkpoint = is_under_checkpoint(index);
const auto always_strong = checkpoint && !malleable64;
const auto strong = is_under_checkpoint(index) ||
query.is_milestone(link);

const auto confirmed = [&]() NOEXCEPT
{
return !malleable64 && (checkpoint || query.is_milestone(link));
return strong && !query.is_malleable64(link);
};

// Required for block_confirmable and all confirmed blocks.
// Only checkpoint && !malleable64 guarantees set_strong is always set.
if (!always_strong && !query.is_strong(link) && !query.set_strong(link))
// Checkpoint and milestone guarantee set_strong is always set.
if (!strong && !query.is_strong(link) && !query.set_strong(link))
{
fault(error::set_confirmed);
return;
}

if (ec == database::error::block_confirmable || confirmed())
if (ec == database::error::block_confirmable ||
confirmed())
{
// TODO: compute fees from validation records.
if ((ec != database::error::block_confirmable) &&
Expand Down Expand Up @@ -243,7 +244,7 @@ void chaser_confirm::do_validated(height_t height) NOEXCEPT

if (ec)
{
if (malleable64)
if (query.is_malleable64(link))
{
LOGR("Malleated64 block [" << index << "] " << ec.message());
notify(ec, chase::malleated, link);
Expand Down
3 changes: 1 addition & 2 deletions src/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void chaser_header::do_malleated(header_t link) NOEXCEPT

bool chaser_header::is_storable(const chain_state& state) const NOEXCEPT
{
return is_checkpoint(state)
|| is_milestone(state)
return is_checkpoint(state) || is_milestone(state)
|| (is_current(state) && is_hard(state));
}

Expand Down
6 changes: 4 additions & 2 deletions src/chasers/chaser_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ void chaser_validate::do_bump(height_t) NOEXCEPT
const auto valid = [&]() NOEXCEPT
{
// Can get malleable64 from block if we have it.
return (is_under_checkpoint(height) || query.is_milestone(link)) &&
!query.is_malleable64(link);
const auto strong = is_under_checkpoint(height) ||
query.is_milestone(link);

return strong && !query.is_malleable64(link);
};

if ((ec == database::error::block_valid) ||
Expand Down
10 changes: 6 additions & 4 deletions src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
// ........................................................................

// Header state checked by organize (neither associated nor unconfirmable).
const auto checked = !malleable64 && (is_under_checkpoint(ctx.height) ||
query.is_milestone(link));
const auto strong = is_under_checkpoint(ctx.height) ||
query.is_milestone(link);

const auto checked = strong && !malleable64;

if (const auto code = check(*block_ptr, ctx, checked))
{
Expand Down Expand Up @@ -373,8 +375,8 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
const auto size = block_ptr->serialized_size(true);
const chain::transactions_cptr txs_ptr{ block_ptr->transactions_ptr() };

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

0 comments on commit 3ccd966

Please sign in to comment.