1+ use std:: sync:: Arc ;
2+
13use apollo_gateway_config:: config:: StatefulTransactionValidatorConfig ;
24use apollo_gateway_types:: deprecated_gateway_error:: {
35 KnownStarknetErrorCode ,
@@ -7,6 +9,7 @@ use apollo_gateway_types::deprecated_gateway_error::{
79use apollo_gateway_types:: errors:: GatewaySpecError ;
810use apollo_mempool_types:: communication:: SharedMempoolClient ;
911use apollo_proc_macros:: sequencer_latency_histogram;
12+ use async_trait:: async_trait;
1013use blockifier:: blockifier:: stateful_validator:: {
1114 StatefulValidator ,
1215 StatefulValidatorTrait as BlockifierStatefulValidatorTrait ,
@@ -38,29 +41,31 @@ mod stateful_transaction_validator_test;
3841
3942type BlockifierStatefulValidator = StatefulValidator < Box < dyn MempoolStateReader > > ;
4043
44+ #[ async_trait]
4145#[ cfg_attr( test, mockall:: automock) ]
4246pub trait StatefulTransactionValidatorFactoryTrait : Send + Sync {
43- fn instantiate_validator (
47+ async fn instantiate_validator (
4448 & self ,
45- state_reader_factory : & dyn StateReaderFactory ,
49+ state_reader_factory : Arc < dyn StateReaderFactory > ,
4650 ) -> StatefulTransactionValidatorResult < Box < dyn StatefulTransactionValidatorTrait > > ;
4751}
4852pub struct StatefulTransactionValidatorFactory {
4953 pub config : StatefulTransactionValidatorConfig ,
5054 pub chain_info : ChainInfo ,
5155}
5256
57+ #[ async_trait]
5358impl StatefulTransactionValidatorFactoryTrait for StatefulTransactionValidatorFactory {
5459 // TODO(Ayelet): Move state_reader_factory and chain_info to the struct.
55- fn instantiate_validator (
60+ async fn instantiate_validator (
5661 & self ,
57- state_reader_factory : & dyn StateReaderFactory ,
62+ state_reader_factory : Arc < dyn StateReaderFactory > ,
5863 ) -> StatefulTransactionValidatorResult < Box < dyn StatefulTransactionValidatorTrait > > {
5964 // TODO(yael 6/5/2024): consider storing the block_info as part of the
6065 // StatefulTransactionValidator and update it only once a new block is created.
61- let current_runtime = tokio :: runtime :: Handle :: current ( ) ;
62- let state_reader = current_runtime
63- . block_on ( state_reader_factory . get_state_reader_from_latest_block ( ) )
66+ let state_reader = state_reader_factory
67+ . get_state_reader_from_latest_block ( )
68+ . await
6469 . map_err ( |err| GatewaySpecError :: UnexpectedError {
6570 data : format ! ( "Internal server error: {err}" ) ,
6671 } )
@@ -70,7 +75,7 @@ impl StatefulTransactionValidatorFactoryTrait for StatefulTransactionValidatorFa
7075 e,
7176 )
7277 } ) ?;
73- let latest_block_info = current_runtime . block_on ( get_latest_block_info ( & state_reader) ) ?;
78+ let latest_block_info = get_latest_block_info ( & state_reader) . await ?;
7479
7580 let state = CachedState :: new ( state_reader) ;
7681 let mut versioned_constants = VersionedConstants :: get_versioned_constants (
0 commit comments