|  | 
| 36 | 36 | #include <category/execution/ethereum/trace/call_tracer.hpp> | 
| 37 | 37 | #include <category/execution/ethereum/validate_block.hpp> | 
| 38 | 38 | #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> | 
| 39 | 41 | #include <category/vm/evm/explicit_traits.hpp> | 
| 40 | 42 | #include <category/vm/evm/switch_traits.hpp> | 
| 41 | 43 | #include <category/vm/evm/traits.hpp> | 
| @@ -91,8 +93,7 @@ Result<BlockHeader> process_ethereum_block( | 
| 91 | 93 |     BlockHashBuffer const &block_hash_buffer, | 
| 92 | 94 |     fiber::PriorityPool &priority_pool, Block const &block, | 
| 93 | 95 |     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) | 
| 96 | 97 | { | 
| 97 | 98 |     [[maybe_unused]] auto const block_start = std::chrono::system_clock::now(); | 
| 98 | 99 |     auto const block_begin = std::chrono::steady_clock::now(); | 
| @@ -142,9 +143,88 @@ Result<BlockHeader> process_ethereum_block( | 
| 142 | 143 |     db.set_block_and_prefix(block.header.number - 1, parent_block_id); | 
| 143 | 144 |     BlockMetrics block_metrics; | 
| 144 | 145 |     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 | + | 
| 148 | 228 |     record_block_marker_event(MONAD_EXEC_BLOCK_PERF_EVM_ENTER); | 
| 149 | 229 |     BOOST_OUTCOME_TRY( | 
| 150 | 230 |         auto const receipts, | 
|  | 
0 commit comments