Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions category/execution/monad/chain/monad_chain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ struct MonadChainContext
std::vector<std::vector<std::optional<Address>>> const &authorities;
};

static_assert(sizeof(MonadChainContext) == 40);
static_assert(alignof(MonadChainContext) == 8);

struct MonadChain : Chain
{
virtual evmc_revision
Expand Down
20 changes: 10 additions & 10 deletions cmd/monad/runloop_ethereum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ void log_tps(

// Process a single historical Ethereum block
template <Traits traits>
Result<void> process_ethereum_block(
Chain const &chain, Db &db, vm::VM &vm,
BlockHashBufferFinalized &block_hash_buffer,
Result<BlockHeader> 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)
{
Expand Down Expand Up @@ -151,7 +150,7 @@ Result<void> 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,
Expand All @@ -164,17 +163,14 @@ Result<void> 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));

// Commit prologue: database finalization, computation of the Ethereum
// 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 =
Expand Down Expand Up @@ -209,7 +205,7 @@ Result<void> process_ethereum_block(
vm.print_and_reset_block_counts(),
vm.print_compiler_stats());

return outcome_e::success();
return output_header;
}

MONAD_ANONYMOUS_NAMESPACE_END
Expand Down Expand Up @@ -245,7 +241,7 @@ Result<std::pair<uint64_t, uint64_t>> 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,
Expand All @@ -260,6 +256,10 @@ Result<std::pair<uint64_t, uint64_t>> 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;
Expand Down
24 changes: 11 additions & 13 deletions cmd/monad/runloop_monad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,26 @@ Result<BlockExecOutput> propose_block(
return TransactionError::MissingSender;
}
}
ankerl::unordered_dense::segmented_set<Address> senders_and_authorities;

BOOST_OUTCOME_TRY(static_validate_monad_senders<traits>(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<std::optional<Address>> const &authorities :
recovered_authorities) {
for (std::optional<Address> 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<traits>(senders));

// Create call frames vectors for tracers
std::vector<std::vector<CallFrame>> call_frames{block.transactions.size()};
Expand Down
Loading