Skip to content

Commit 5a82b0d

Browse files
committed
inline the revert transaction logic
1 parent e83b231 commit 5a82b0d

File tree

6 files changed

+100
-185
lines changed

6 files changed

+100
-185
lines changed

cmd/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ add_executable(
2424
monad/event.hpp
2525
monad/file_io.hpp
2626
monad/file_io.cpp
27-
monad/revert_transaction_generator.cpp
28-
monad/revert_transaction_generator.hpp
2927
monad/runloop_ethereum.cpp
3028
monad/runloop_ethereum.hpp
3129
monad/runloop_monad.cpp

cmd/monad/revert_transaction_generator.cpp

Lines changed: 0 additions & 109 deletions
This file was deleted.

cmd/monad/revert_transaction_generator.hpp

Lines changed: 0 additions & 50 deletions
This file was deleted.

cmd/monad/runloop_ethereum.cpp

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <category/execution/ethereum/trace/call_tracer.hpp>
3737
#include <category/execution/ethereum/validate_block.hpp>
3838
#include <category/execution/ethereum/validate_transaction.hpp>
39+
#include <category/execution/monad/chain/monad_chain.hpp>
40+
#include <category/execution/monad/validate_monad_block.hpp>
3941
#include <category/vm/evm/explicit_traits.hpp>
4042
#include <category/vm/evm/switch_traits.hpp>
4143
#include <category/vm/evm/traits.hpp>
@@ -91,8 +93,7 @@ Result<BlockHeader> process_ethereum_block(
9193
BlockHashBuffer const &block_hash_buffer,
9294
fiber::PriorityPool &priority_pool, Block const &block,
9395
bytes32_t const &block_id, bytes32_t const &parent_block_id,
94-
bool const enable_tracing,
95-
RevertTransactionGeneratorFn const &make_revert_transaction)
96+
bool const enable_tracing, BlockCache *const block_cache)
9697
{
9798
[[maybe_unused]] auto const block_start = std::chrono::system_clock::now();
9899
auto const block_begin = std::chrono::steady_clock::now();
@@ -142,9 +143,88 @@ Result<BlockHeader> process_ethereum_block(
142143
db.set_block_and_prefix(block.header.number - 1, parent_block_id);
143144
BlockMetrics block_metrics;
144145
BlockState block_state(db, vm);
145-
BOOST_OUTCOME_TRY(
146-
RevertTransactionFn const revert_transaction,
147-
make_revert_transaction(senders, recovered_authorities));
146+
147+
// Build the revert transaction function
148+
RevertTransactionFn revert_transaction =
149+
[](Address const &, Transaction const &, uint64_t, State &) {
150+
return false;
151+
};
152+
if constexpr (is_monad_trait_v<traits>) {
153+
// Monad-specific revert transaction logic
154+
BOOST_OUTCOME_TRY(static_validate_monad_senders<traits>(senders));
155+
156+
// Update the BlockCache with this block's senders and authorities
157+
MONAD_ASSERT(block_cache, "block_cache required for Monad traits");
158+
auto [entry, success] = block_cache->emplace(
159+
block_id,
160+
BlockCacheEntry{
161+
.block_number = block.header.number,
162+
.parent_id = parent_block_id,
163+
.senders_and_authorities = {}});
164+
MONAD_ASSERT(success, "should never be processing duplicate block");
165+
for (Address const &sender : senders) {
166+
entry->second.senders_and_authorities.insert(sender);
167+
}
168+
for (std::vector<std::optional<Address>> const &authorities :
169+
recovered_authorities) {
170+
for (std::optional<Address> const &authority : authorities) {
171+
if (authority.has_value()) {
172+
entry->second.senders_and_authorities.insert(
173+
authority.value());
174+
}
175+
}
176+
}
177+
178+
// Make the chain context, providing the parent and grandparent
179+
MonadChainContext chain_context{
180+
.grandparent_senders_and_authorities = nullptr,
181+
.parent_senders_and_authorities = nullptr,
182+
.senders_and_authorities =
183+
block_cache->at(block_id).senders_and_authorities,
184+
.senders = senders,
185+
.authorities = recovered_authorities};
186+
187+
if (block.header.number > 1) {
188+
MONAD_ASSERT(
189+
block_cache->contains(parent_block_id),
190+
"block cache must contain parent");
191+
BlockCacheEntry const &parent_entry =
192+
block_cache->at(parent_block_id);
193+
chain_context.parent_senders_and_authorities =
194+
&parent_entry.senders_and_authorities;
195+
if (block.header.number > 2) {
196+
bytes32_t const &grandparent_id = parent_entry.parent_id;
197+
MONAD_ASSERT(
198+
block_cache->contains(grandparent_id),
199+
"block cache must contain grandparent");
200+
BlockCacheEntry const &grandparent_entry =
201+
block_cache->at(grandparent_id);
202+
chain_context.grandparent_senders_and_authorities =
203+
&grandparent_entry.senders_and_authorities;
204+
}
205+
}
206+
207+
// Capture chain reference for the revert transaction function
208+
MonadChain const *const monad_chain =
209+
dynamic_cast<MonadChain const *>(&chain);
210+
MONAD_ASSERT(monad_chain, "chain must be a MonadChain");
211+
revert_transaction = [monad_chain, &block, chain_context](
212+
Address const &sender,
213+
Transaction const &tx,
214+
uint64_t const i,
215+
State &state) {
216+
return monad_chain->revert_transaction(
217+
block.header.number,
218+
block.header.timestamp,
219+
sender,
220+
tx,
221+
block.header.base_fee_per_gas.value_or(0),
222+
i,
223+
state,
224+
chain_context);
225+
};
226+
}
227+
148228
record_block_marker_event(MONAD_EXEC_BLOCK_PERF_EVM_ENTER);
149229
BOOST_OUTCOME_TRY(
150230
auto const receipts,

cmd/monad/runloop_ethereum.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515

1616
#pragma once
1717

18-
#include "revert_transaction_generator.hpp"
19-
2018
#include <category/core/bytes.hpp>
2119
#include <category/core/config.hpp>
2220
#include <category/core/result.hpp>
21+
#include <category/execution/ethereum/core/address.hpp>
2322
#include <category/vm/evm/traits.hpp>
2423
#include <category/vm/vm.hpp>
2524

25+
#include <ankerl/unordered_dense.h>
26+
2627
#include <cstdint>
2728
#include <filesystem>
2829
#include <utility>
@@ -43,21 +44,23 @@ namespace fiber
4344
class PriorityPool;
4445
}
4546

47+
struct BlockCacheEntry
48+
{
49+
uint64_t block_number;
50+
bytes32_t parent_id;
51+
ankerl::unordered_dense::segmented_set<Address> senders_and_authorities;
52+
};
53+
54+
using BlockCache =
55+
ankerl::unordered_dense::segmented_map<bytes32_t, BlockCacheEntry>;
56+
4657
template <Traits traits>
4758
Result<BlockHeader> process_ethereum_block(
4859
Chain const &chain, Db &db, vm::VM &vm,
4960
BlockHashBuffer const &block_hash_buffer,
5061
fiber::PriorityPool &priority_pool, Block const &block,
5162
bytes32_t const &block_id, bytes32_t const &parent_block_id,
52-
bool const enable_tracing,
53-
RevertTransactionGeneratorFn const & =
54-
[](std::vector<Address> const &,
55-
std::vector<std::vector<std::optional<Address>>> const &)
56-
-> Result<RevertTransactionFn> {
57-
return [](Address const &, Transaction const &, uint64_t, State &) {
58-
return false;
59-
};
60-
});
63+
bool const enable_tracing, BlockCache * = nullptr);
6164

6265
Result<std::pair<uint64_t, uint64_t>> runloop_ethereum(
6366
Chain const &, std::filesystem::path const &, Db &, vm::VM &,

cmd/monad/runloop_monad.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "runloop_monad.hpp"
1717
#include "file_io.hpp"
18-
#include "revert_transaction_generator.hpp"
1918
#include "runloop_ethereum.hpp"
2019

2120
#include <category/core/assert.h>
@@ -150,12 +149,6 @@ Result<BlockExecOutput> propose_block(
150149
BlockHashBuffer const &block_hash_buffer =
151150
block_hash_chain.find_chain(consensus_header.parent_id());
152151

153-
// make a generator which is able to return the revert function based on
154-
// purely ethereum concepts
155-
RevertTransactionGeneratorFn const make_revert_transaction =
156-
revert_transaction_generator<traits>(
157-
block_id, consensus_header.parent_id(), block, chain, block_cache);
158-
159152
// Block input validation
160153
BOOST_OUTCOME_TRY(static_validate_consensus_header(consensus_header));
161154

@@ -173,7 +166,7 @@ Result<BlockExecOutput> propose_block(
173166
block_id,
174167
is_first_block ? bytes32_t{} : consensus_header.parent_id(),
175168
enable_tracing,
176-
make_revert_transaction));
169+
&block_cache));
177170

178171
// Commit prologue: computation of the Ethereum block hash to append to
179172
// the circular hash buffer

0 commit comments

Comments
 (0)