Skip to content

Commit

Permalink
Merge pull request #1476 from evoskuil/master
Browse files Browse the repository at this point in the history
Rename error::merkle_mismatch to invalid_transaction_commitment.
  • Loading branch information
evoskuil authored Jun 4, 2024
2 parents d22356a + af02dae commit aafc22f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 30 deletions.
2 changes: 1 addition & 1 deletion include/bitcoin/system/error/block_error_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum block_error_t : uint8_t
internal_duplicate,
block_internal_double_spend,
forward_reference,
merkle_mismatch,
invalid_transaction_commitment,
block_legacy_sigop_limit,
type32_malleated,

Expand Down
37 changes: 12 additions & 25 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,21 +727,16 @@ code block::confirm_transactions(const context& ctx) const NOEXCEPT
// TODO: use of get_hash() in is_forward_reference makes this thread unsafe.
code block::check(bool bypass) const NOEXCEPT
{
if (bypass)
{
// Transaction commitment is required under checkpoint.
if (is_invalid_merkle_root())
return error::merkle_mismatch;

// type32_malleated is subset of is_internal_double_spend, assuming
// otherwise valid txs, as that will catch any duplicated transaction.
if (is_malleated32())
return error::type32_malleated;
if (is_invalid_merkle_root())
return error::invalid_transaction_commitment;

// type32_malleated is subset of is_internal_double_spend
if (bypass && is_malleated32())
return error::type32_malleated;
if (bypass)
return error::block_success;
}

// empty_block is redundant with first_not_coinbase.
// empty_block is subset of first_not_coinbase.
//if (is_empty())
// return error::empty_block;
if (is_oversized())
Expand All @@ -754,8 +749,6 @@ code block::check(bool bypass) const NOEXCEPT
return error::forward_reference;
if (is_internal_double_spend())
return error::block_internal_double_spend;
if (is_invalid_merkle_root())
return error::merkle_mismatch;

return check_transactions();
}
Expand All @@ -769,29 +762,23 @@ code block::check(bool bypass) const NOEXCEPT
// TODO: use of get_hash() in is_hash_limit_exceeded makes this thread unsafe.
code block::check(const context& ctx, bool bypass) const NOEXCEPT
{
if (bypass)
{
const auto bip141 = ctx.is_enabled(bip141_rule);
const auto bip141 = ctx.is_enabled(bip141_rule);

if (bip141 && is_invalid_witness_commitment())
return error::invalid_witness_commitment;

// Wintness commitment is required under checkpoint.
if (bip141 && is_invalid_witness_commitment())
return error::invalid_witness_commitment;

if (bypass)
return error::block_success;
}

const auto bip34 = ctx.is_enabled(bip34_rule);
const auto bip50 = ctx.is_enabled(bip50_rule);
const auto bip141 = ctx.is_enabled(bip141_rule);

if (bip141 && is_overweight())
return error::block_weight_limit;
if (bip34 && is_invalid_coinbase_script(ctx.height))
return error::coinbase_height_mismatch;
if (bip50 && is_hash_limit_exceeded())
return error::temporary_hash_limit;
if (bip141 && is_invalid_witness_commitment())
return error::invalid_witness_commitment;

return check_transactions(ctx);
}
Expand Down
2 changes: 1 addition & 1 deletion src/error/block_error_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DEFINE_ERROR_T_MESSAGE_MAP(block_error)
{ internal_duplicate, "matching transaction hashes in block" },
{ block_internal_double_spend, "double spend internal to block" },
{ forward_reference, "transactions out of order" },
{ merkle_mismatch, "merkle root mismatch" },
{ invalid_transaction_commitment, "invalid transaction commitment" },
{ block_legacy_sigop_limit, "too many block legacy signature operations" },
{ type32_malleated, "block is type32 malleated" },

Expand Down
6 changes: 3 additions & 3 deletions test/error/block_error_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ BOOST_AUTO_TEST_CASE(block_error_t__code__forward_reference__true_exected_messag
BOOST_REQUIRE_EQUAL(ec.message(), "transactions out of order");
}

BOOST_AUTO_TEST_CASE(block_error_t__code__merkle_mismatch__true_exected_message)
BOOST_AUTO_TEST_CASE(block_error_t__code__invalid_transaction_commitment__true_exected_message)
{
constexpr auto value = error::merkle_mismatch;
constexpr auto value = error::invalid_transaction_commitment;
const auto ec = code(value);
BOOST_REQUIRE(ec);
BOOST_REQUIRE(ec == value);
BOOST_REQUIRE_EQUAL(ec.message(), "merkle root mismatch");
BOOST_REQUIRE_EQUAL(ec.message(), "invalid transaction commitment");
}

BOOST_AUTO_TEST_CASE(block_error_t__code__block_legacy_sigop_limit__true_exected_message)
Expand Down

0 comments on commit aafc22f

Please sign in to comment.