diff --git a/category/execution/monad/chain/monad_chain.hpp b/category/execution/monad/chain/monad_chain.hpp index cd924ce8d..56b4fd27d 100644 --- a/category/execution/monad/chain/monad_chain.hpp +++ b/category/execution/monad/chain/monad_chain.hpp @@ -49,6 +49,9 @@ struct MonadChainContext std::vector>> const &authorities; }; +static_assert(sizeof(MonadChainContext) == 40); +static_assert(alignof(MonadChainContext) == 8); + struct MonadChain : Chain { virtual evmc_revision diff --git a/cmd/monad/runloop_ethereum.cpp b/cmd/monad/runloop_ethereum.cpp index 92564d4d6..166be6db3 100644 --- a/cmd/monad/runloop_ethereum.cpp +++ b/cmd/monad/runloop_ethereum.cpp @@ -79,9 +79,8 @@ void log_tps( // Process a single historical Ethereum block template -Result process_ethereum_block( - Chain const &chain, Db &db, vm::VM &vm, - BlockHashBufferFinalized &block_hash_buffer, +Result process_ethereum_block( + Chain const &chain, Db &db, vm::VM &vm, BlockHashBuffer &block_hash_buffer, fiber::PriorityPool &priority_pool, Block &block, bytes32_t const &block_id, bytes32_t const &parent_block_id, bool const enable_tracing) { @@ -151,7 +150,7 @@ Result process_ethereum_block( block_state.log_debug(); auto const commit_begin = std::chrono::steady_clock::now(); block_state.commit( - bytes32_t{block.header.number}, + block_id, block.header, receipts, call_frames, @@ -164,7 +163,7 @@ Result process_ethereum_block( std::chrono::steady_clock::now() - commit_begin); // Post-commit validation of header, with Merkle root fields filled in - auto const output_header = db.read_eth_header(); + BlockHeader const output_header = db.read_eth_header(); BOOST_OUTCOME_TRY( chain.validate_output_header(block.header, output_header)); @@ -172,9 +171,6 @@ Result process_ethereum_block( // block hash to append to the circular hash buffer db.finalize(block.header.number, block_id); db.update_verified_block(block.header.number); - auto const eth_block_hash = - to_bytes(keccak256(rlp::encode_block_header(output_header))); - block_hash_buffer.set(block.header.number, eth_block_hash); // Emit the block metrics log line [[maybe_unused]] auto const block_time = @@ -209,7 +205,7 @@ Result process_ethereum_block( vm.print_and_reset_block_counts(), vm.print_compiler_stats()); - return outcome_e::success(); + return output_header; } MONAD_ANONYMOUS_NAMESPACE_END @@ -245,7 +241,7 @@ Result> runloop_ethereum( evmc_revision const rev = chain.get_revision(block.header.number, block.header.timestamp); - BOOST_OUTCOME_TRY([&] { + BOOST_OUTCOME_TRY(BlockHeader const output_header, [&] { SWITCH_EVM_TRAITS( process_ethereum_block, chain, @@ -260,6 +256,10 @@ Result> runloop_ethereum( MONAD_ABORT_PRINTF("unhandled rev switch case: %d", rev); }()); + bytes32_t const eth_block_hash = + to_bytes(keccak256(rlp::encode_block_header(output_header))); + block_hash_buffer.set(block.header.number, eth_block_hash); + ntxs += block.transactions.size(); batch_num_txs += block.transactions.size(); total_gas += block.header.gas_used; diff --git a/cmd/monad/runloop_monad.cpp b/cmd/monad/runloop_monad.cpp index aeda83b76..2f844cfea 100644 --- a/cmd/monad/runloop_monad.cpp +++ b/cmd/monad/runloop_monad.cpp @@ -183,28 +183,26 @@ Result propose_block( return TransactionError::MissingSender; } } - ankerl::unordered_dense::segmented_set
senders_and_authorities; + + BOOST_OUTCOME_TRY(static_validate_monad_senders(senders)); + auto [entry, success] = block_cache.emplace( + block_id, + BlockCacheEntry{ + .block_number = block.header.number, + .parent_id = consensus_header.parent_id(), + .senders_and_authorities = {}}); + MONAD_ASSERT(success, "should never be processing duplicate block"); for (Address const &sender : senders) { - senders_and_authorities.insert(sender); + entry->second.senders_and_authorities.insert(sender); } for (std::vector> const &authorities : recovered_authorities) { for (std::optional
const &authority : authorities) { if (authority.has_value()) { - senders_and_authorities.insert(authority.value()); + entry->second.senders_and_authorities.insert(authority.value()); } } } - MONAD_ASSERT(block_cache - .emplace( - block_id, - BlockCacheEntry{ - .block_number = block.header.number, - .parent_id = consensus_header.parent_id(), - .senders_and_authorities = - std::move(senders_and_authorities)}) - .second); - BOOST_OUTCOME_TRY(static_validate_monad_senders(senders)); // Create call frames vectors for tracers std::vector> call_frames{block.transactions.size()};