Skip to content

Commit

Permalink
Handle malleability ICO bypass confirmations.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Jun 2, 2024
1 parent 4e4da01 commit cc29182
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
return true;
}

if (query.is_malleated(*block_ptr))
const auto malleable = block_ptr->is_malleable();
if (malleable && query.is_malleated(*block_ptr))
{
// Disallow known block malleation, drop peer and keep trying.
LOGR("Malleated block [" << encode_hash(hash) << "] from ["
Expand All @@ -307,11 +308,13 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
// Hack to measure performance with cached bypass point.
constexpr auto bypass = true;

if (const auto code = check(*block_ptr, ctx, bypass))
// Perform full check if block is malleable.
// mally32 is caught here, mally64 may pass.
if (const auto code = check(*block_ptr, ctx, bypass && !malleable))
{
// Both forms of malleabilty are possible here.
// Malleable has not been associated, so just drop peer and continue.
if (!block_ptr->is_malleable())
if (!malleable)
{
if (!query.set_block_unconfirmable(link))
{
Expand All @@ -337,11 +340,17 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
// Commit block.txs.
// ........................................................................

const auto txs_ptr = block_ptr->transactions_ptr();
const auto block_size = block_ptr->serialized_size(true);

// block_ptr goes out of scope here, even if a reference is held to its
// transactions_ptr, so txs_ptr must be a pointer copy.
chain::transactions_cptr txs_ptr{ block_ptr->transactions_ptr() };
const auto block_size = block_ptr->serialized_size(true);

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
// TODO: ensure that when a mally64 is caught under bypass that tx
// confirmations are reverted when the block is sequentially invalidated.
// Query: A strong_tx may be in a not-yet-confirmed block.
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

if (const auto code = query.set_code(*txs_ptr, link, block_size, bypass))
{
LOGF("Failure storing block [" << encode_hash(hash) << ":"
Expand Down

0 comments on commit cc29182

Please sign in to comment.