Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IF: use the same way to determine if instant finality is active #2043

Merged
merged 4 commits into from
Jan 6, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2796,19 +2796,16 @@ struct controller_impl {

// thread safe, expected to be called from thread other than the main thread
block_state_legacy_ptr create_block_state_i( const block_id_type& id, const signed_block_ptr& b, const block_header_state_legacy& prev ) {
bool hs_active = false;
if (!b->header_extensions.empty()) {
std::optional<block_header_extension> instant_finality_ext = b->extract_header_extension(instant_finality_extension::extension_id());
#warning change to use instant_finality_ext https://github.com/AntelopeIO/leap/issues/1508
if (instant_finality_ext) {
const auto& ext = std::get<instant_finality_extension>(*instant_finality_ext);
hs_active = !!ext.new_proposer_policy;
}
}

uint32_t hs_lib = hs_irreversible_block_num.load();
heifner marked this conversation as resolved.
Show resolved Hide resolved
const bool hs_active = hs_lib > 0;
auto trx_mroot = calculate_trx_merkle( b->transactions, hs_active );
EOS_ASSERT( b->transaction_mroot == trx_mroot, block_validate_exception,
"invalid block transaction merkle root ${b} != ${c}", ("b", b->transaction_mroot)("c", trx_mroot) );
if( b->transaction_mroot != trx_mroot ) {
// Call of create_block_state_i can happen right before hs_irreversible_block_num
// is set. Fall back to verify in the other way.
trx_mroot = calculate_trx_merkle( b->transactions, !hs_active );
EOS_ASSERT( b->transaction_mroot == trx_mroot, block_validate_exception,
"invalid block transaction merkle root ${b} != ${c}", ("b", b->transaction_mroot)("c", trx_mroot) );
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This opens up an attack vector as you can create a block with invalid mroot that will pass this validation. I think we can go with your first implementation. There is a small race condition at time of activation, but even if that is tripped and the block is considered invalid, the node will attempt to sync the block in the future and succeed; that is what I meant by re-try.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your insight!


const bool skip_validate_signee = false;
auto bsp = std::make_shared<block_state_legacy>(
Expand Down