1
1
use crate :: {
2
+ building:: cached_reads:: CachedDB ,
2
3
live_builder:: {
3
4
block_list_provider:: BlockList , order_input:: mempool_txs_detector:: MempoolTxsDetector ,
4
5
payload_events:: InternalPayloadId ,
@@ -39,6 +40,7 @@ use reth::{
39
40
payload:: PayloadId ,
40
41
primitives:: { Block , SealedBlock } ,
41
42
providers:: ExecutionOutcome ,
43
+ revm:: database:: StateProviderDatabase ,
42
44
} ;
43
45
use reth_chainspec:: { ChainSpec , EthChainSpec , EthereumHardforks } ;
44
46
use reth_errors:: { BlockExecutionError , BlockValidationError , ProviderError } ;
@@ -48,15 +50,17 @@ use reth_node_api::{EngineApiMessageVersion, PayloadBuilderAttributes};
48
50
use reth_payload_builder:: EthPayloadBuilderAttributes ;
49
51
use reth_primitives:: BlockBody ;
50
52
use reth_primitives_traits:: { proofs, Block as _} ;
53
+ use reth_provider:: StateProvider ;
51
54
use revm:: {
52
55
context:: BlockEnv ,
53
56
context_interface:: { block:: BlobExcessGasAndPrice , result:: InvalidTransaction } ,
54
- database:: states:: bundle_state:: BundleRetention ,
57
+ database:: { states:: bundle_state:: BundleRetention , BundleAccount } ,
55
58
primitives:: hardfork:: SpecId ,
59
+ Database as _,
56
60
} ;
57
61
use serde:: Deserialize ;
58
62
use std:: {
59
- collections:: { HashMap , HashSet } ,
63
+ collections:: { hash_map , HashMap , HashSet } ,
60
64
hash:: Hash ,
61
65
ops:: { Add , AddAssign } ,
62
66
str:: FromStr ,
@@ -1028,9 +1032,10 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
1028
1032
let step_start = Instant :: now ( ) ;
1029
1033
1030
1034
// calculate the state root
1031
- let ( bundle, _ ) = state. into_parts ( ) ;
1035
+ let ( bundle, state_provider ) = state. into_parts ( ) ;
1032
1036
// we use execution outcome here only for interface compatibility, its just a wrapper around bundle
1033
- let execution_outcome = ExecutionOutcome :: new ( bundle, Vec :: new ( ) , block_number, Vec :: new ( ) ) ;
1037
+ let mut execution_outcome =
1038
+ ExecutionOutcome :: new ( bundle, Vec :: new ( ) , block_number, Vec :: new ( ) ) ;
1034
1039
let state_root = ctx. root_hasher . state_root ( & execution_outcome, local_ctx) ?;
1035
1040
let root_hash_time = step_start. elapsed ( ) ;
1036
1041
@@ -1138,7 +1143,8 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
1138
1143
1139
1144
let bid_adjustments = Self :: generate_bid_adjustments (
1140
1145
& block. header ,
1141
- & execution_outcome,
1146
+ & state_provider,
1147
+ & mut execution_outcome,
1142
1148
ctx,
1143
1149
local_ctx,
1144
1150
placeholder_transaction_proof,
@@ -1180,7 +1186,8 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
1180
1186
1181
1187
fn generate_bid_adjustments (
1182
1188
header : & Header ,
1183
- outcome : & ExecutionOutcome ,
1189
+ state_provider : & impl StateProvider ,
1190
+ outcome : & mut ExecutionOutcome ,
1184
1191
ctx : & BlockBuildingContext ,
1185
1192
local_ctx : & mut ThreadBlockBuildingContext ,
1186
1193
placeholder_transaction_proof : Vec < Bytes > ,
@@ -1209,6 +1216,28 @@ impl<Tracer: SimulationTracer, PartialBlockExecutionTracerType: PartialBlockExec
1209
1216
. into_iter ( )
1210
1217
. chain ( ctx. adjustment_fee_payers . clone ( ) ) ,
1211
1218
) ;
1219
+
1220
+ // Pre-load all proof targets that are missing from the bundle state.
1221
+ // This is a requirement for accounts to become a part of the trie and be able to generate proofs for them.
1222
+ let mut cachedb = CachedDB :: new (
1223
+ StateProviderDatabase :: new ( state_provider) ,
1224
+ & mut local_ctx. cached_reads ,
1225
+ & ctx. shared_cached_reads ,
1226
+ ) ;
1227
+ for fee_payer in & ctx. adjustment_fee_payers {
1228
+ if let hash_map:: Entry :: Vacant ( entry) = outcome. bundle . state . entry ( * fee_payer) {
1229
+ let account_info = cachedb
1230
+ . basic ( * fee_payer)
1231
+ . map_err ( |error| FinalizeError :: Other ( error. into ( ) ) ) ?;
1232
+ entry. insert ( BundleAccount {
1233
+ original_info : account_info. clone ( ) ,
1234
+ info : account_info,
1235
+ status : revm:: database:: AccountStatus :: Loaded ,
1236
+ storage : Default :: default ( ) ,
1237
+ } ) ;
1238
+ }
1239
+ }
1240
+
1212
1241
let mut account_proofs =
1213
1242
ctx. root_hasher
1214
1243
. account_proofs ( outcome, & proof_targets, local_ctx) ?;
0 commit comments