33use std:: future:: IntoFuture ;
44use std:: sync:: Arc ;
55
6+ use alloy_provider:: RootProvider ;
67use anyhow:: Result ;
78use http:: header:: CONTENT_TYPE ;
89use http:: Method ;
910use jsonrpsee:: RpcModule ;
1011use katana_chain_spec:: ChainSpec ;
1112use katana_executor:: ExecutionFlags ;
13+ use katana_gas_price_oracle:: GasPriceOracle ;
1214use katana_gateway_client:: Client as SequencerGateway ;
1315use katana_metrics:: exporters:: prometheus:: PrometheusRecorder ;
1416use katana_metrics:: { Report , Server as MetricsServer } ;
@@ -27,6 +29,7 @@ use tracing::{error, info};
2729
2830use crate :: config:: db:: DbConfig ;
2931use crate :: config:: metrics:: MetricsConfig ;
32+ use crate :: full:: pending:: PreconfStateFactory ;
3033
3134mod exit;
3235mod pending;
@@ -75,6 +78,7 @@ pub struct Node {
7578 pub pipeline : Pipeline < DbProvider > ,
7679 pub rpc_server : RpcServer ,
7780 pub gateway_client : SequencerGateway ,
81+ pub chain_tip_watcher : ChainTipWatcher < RootProvider > ,
7882}
7983
8084impl Node {
@@ -114,12 +118,32 @@ impl Node {
114118
115119 // --- build pipeline
116120
117- let ( mut pipeline, _ ) = Pipeline :: new ( provider. clone ( ) , 50 ) ;
121+ let ( mut pipeline, pipeline_handle ) = Pipeline :: new ( provider. clone ( ) , 50 ) ;
118122 let block_downloader = BatchBlockDownloader :: new_gateway ( gateway_client. clone ( ) , 8 ) ;
119123 pipeline. add_stage ( Blocks :: new ( provider. clone ( ) , block_downloader) ) ;
120124 pipeline. add_stage ( Classes :: new ( provider. clone ( ) , gateway_client. clone ( ) , 8 ) ) ;
121125 pipeline. add_stage ( StateTrie :: new ( provider. clone ( ) ) ) ;
122126
127+ // --
128+
129+ let core_contract = match config. network {
130+ Network :: Mainnet => {
131+ katana_starknet:: StarknetCore :: new_http_mainnet ( & config. eth_rpc_url ) ?
132+ }
133+ Network :: Sepolia => {
134+ katana_starknet:: StarknetCore :: new_http_sepolia ( & config. eth_rpc_url ) ?
135+ }
136+ } ;
137+
138+ let chain_tip_watcher = ChainTipWatcher :: new ( core_contract) ;
139+
140+ let preconf_factory = PreconfStateFactory :: new (
141+ provider. clone ( ) ,
142+ gateway_client. clone ( ) ,
143+ pipeline_handle. subscribe_blocks ( ) ,
144+ chain_tip_watcher. subscribe ( ) ,
145+ ) ;
146+
123147 // --- build rpc server
124148
125149 let mut rpc_modules = RpcModule :: new ( ( ) ) ;
@@ -148,6 +172,8 @@ impl Node {
148172 pool. clone ( ) ,
149173 task_spawner. clone ( ) ,
150174 starknet_api_cfg,
175+ Box :: new ( preconf_factory) ,
176+ GasPriceOracle :: create_for_testing ( ) ,
151177 ) ;
152178
153179 if config. rpc . apis . contains ( & RpcModuleKind :: Starknet ) {
@@ -194,6 +220,7 @@ impl Node {
194220 rpc_server,
195221 task_manager,
196222 gateway_client,
223+ chain_tip_watcher,
197224 config : Arc :: new ( config) ,
198225 } )
199226 }
@@ -212,18 +239,7 @@ impl Node {
212239
213240 let pipeline_handle = self . pipeline . handle ( ) ;
214241
215- let core_contract = match self . config . network {
216- Network :: Mainnet => {
217- katana_starknet:: StarknetCore :: new_http_mainnet ( & self . config . eth_rpc_url ) . await ?
218- }
219- Network :: Sepolia => {
220- katana_starknet:: StarknetCore :: new_http_sepolia ( & self . config . eth_rpc_url ) . await ?
221- }
222- } ;
223-
224- let tip_watcher = ChainTipWatcher :: new ( core_contract) ;
225-
226- let mut tip_subscription = tip_watcher. subscribe ( ) ;
242+ let mut tip_subscription = self . chain_tip_watcher . subscribe ( ) ;
227243 let pipeline_handle_clone = pipeline_handle. clone ( ) ;
228244
229245 self . task_manager
@@ -237,7 +253,7 @@ impl Node {
237253 . build_task ( )
238254 . graceful_shutdown ( )
239255 . name ( "Chain tip watcher" )
240- . spawn ( tip_watcher . into_future ( ) ) ;
256+ . spawn ( self . chain_tip_watcher . into_future ( ) ) ;
241257
242258 // spawn a task for updating the pipeline's tip based on chain tip changes
243259 self . task_manager . task_spawner ( ) . spawn ( async move {
0 commit comments