1- use crate :: { cache:: StateSource , CacheError , SimItemValidity } ;
1+ use crate :: {
2+ cache:: { check_bundle_tx_list, StateSource } ,
3+ CacheError , SimItemValidity ,
4+ } ;
25use alloy:: {
36 consensus:: {
47 transaction:: { Recovered , SignerRecoverable } ,
58 Transaction , TxEnvelope ,
69 } ,
7- primitives:: { Address , TxHash , U256 } ,
10+ primitives:: { TxHash , U256 } ,
811} ;
912use signet_bundle:: { RecoveredBundle , SignetEthBundle , TxRequirement } ;
1013use std:: {
1114 borrow:: { Borrow , Cow } ,
12- collections:: BTreeMap ,
1315 hash:: Hash ,
1416 sync:: Arc ,
1517} ;
@@ -168,7 +170,7 @@ impl SimItem {
168170 where
169171 S : StateSource ,
170172 {
171- Self :: check_bundle_tx_list ( items, source) . await
173+ check_bundle_tx_list ( items, source) . await
172174 }
173175
174176 #[ instrument( level = "trace" , skip_all) ]
@@ -179,79 +181,7 @@ impl SimItem {
179181 where
180182 S : StateSource ,
181183 {
182- Self :: check_bundle_tx_list ( items, source) . await
183- }
184-
185- async fn check_bundle_tx_list < S > (
186- items : impl Iterator < Item = TxRequirement > ,
187- source : & S ,
188- ) -> Result < SimItemValidity , S :: Error >
189- where
190- S : StateSource ,
191- {
192- // For bundles, we want to check the nonce of each transaction. To do
193- // this, we build a small in memory cache so that if the same signer
194- // appears, we can reuse the nonce info. We do not check balances after
195- // the first tx, as they may have changed due to prior txs in the
196- // bundle.
197-
198- let mut nonce_cache: BTreeMap < Address , u64 > = BTreeMap :: new ( ) ;
199- let mut items = items. peekable ( ) ;
200-
201- // Peek to perform the balance check for the first tx
202- if let Some ( first) = items. peek ( ) {
203- let info = source. account_details ( & first. signer ) . await ?;
204-
205- // check balance for the first tx is sufficient
206- if first. balance > info. balance {
207- trace ! (
208- required = %first. balance,
209- available = %info. balance,
210- signer = %first. signer,
211- "insufficient balance" ,
212- ) ;
213- return Ok ( SimItemValidity :: Future ) ;
214- }
215-
216- // Cache the nonce. This will be used for the first tx.
217- nonce_cache. insert ( first. signer , info. nonce ) ;
218- }
219-
220- for requirement in items {
221- let state_nonce = match nonce_cache. get ( & requirement. signer ) {
222- Some ( cached_nonce) => * cached_nonce,
223- None => {
224- let nonce = source. nonce ( & requirement. signer ) . await ?;
225- nonce_cache. insert ( requirement. signer , nonce) ;
226- nonce
227- }
228- } ;
229-
230- let _guard = trace_span ! (
231- "check_bundle_tx" ,
232- signer = %requirement. signer,
233- item_nonce = requirement. nonce,
234- expected_nonce = state_nonce,
235- )
236- . entered ( ) ;
237-
238- if requirement. nonce < state_nonce {
239- trace ! ( "nonce too low" ) ;
240- return Ok ( SimItemValidity :: Never ) ;
241- }
242- if requirement. nonce > state_nonce {
243- trace ! ( "nonce too high" ) ;
244- return Ok ( SimItemValidity :: Future ) ;
245- }
246-
247- // Increment the cached nonce for the next transaction from this
248- // signer. Map _must_ have the entry as we just either loaded or
249- // stored it above
250- nonce_cache. entry ( requirement. signer ) . and_modify ( |n| * n += 1 ) ;
251- }
252-
253- // All transactions passed
254- Ok ( SimItemValidity :: Now )
184+ check_bundle_tx_list ( items, source) . await
255185 }
256186
257187 async fn check_bundle < S , S2 > (
0 commit comments