@@ -212,11 +212,11 @@ impl SequencerNodeArgs {
212212 // Launch the node
213213 let handle = node. launch ( ) . await . context ( "failed to launch forked node" ) ?;
214214
215- // Start sidecars if needed (sidecar processes are managed by CLI)
215+ // Bootstrap and start sidecars if needed
216216 #[ cfg( feature = "paymaster" ) ]
217- let mut sidecars = start_sidecars_if_needed (
217+ let mut sidecars = bootstrap_and_start_sidecars (
218218 self ,
219- handle. sidecar_bootstrap ( ) ,
219+ handle. node ( ) ,
220220 handle. rpc ( ) . addr ( ) ,
221221 paymaster_sidecar. as_ref ( ) ,
222222 #[ cfg( feature = "vrf" ) ]
@@ -249,11 +249,11 @@ impl SequencerNodeArgs {
249249 // Launch the node
250250 let handle = node. launch ( ) . await . context ( "failed to launch node" ) ?;
251251
252- // Start sidecars if needed (sidecar processes are managed by CLI)
252+ // Bootstrap and start sidecars if needed
253253 #[ cfg( feature = "paymaster" ) ]
254- let mut sidecars = start_sidecars_if_needed (
254+ let mut sidecars = bootstrap_and_start_sidecars (
255255 self ,
256- handle. sidecar_bootstrap ( ) ,
256+ handle. node ( ) ,
257257 handle. rpc ( ) . addr ( ) ,
258258 paymaster_sidecar. as_ref ( ) ,
259259 #[ cfg( feature = "vrf" ) ]
@@ -775,51 +775,89 @@ impl SequencerNodeArgs {
775775 }
776776}
777777
778- /// Start sidecar processes if needed based on the configuration .
778+ /// Bootstrap contracts and start sidecar processes if needed.
779779///
780- /// This function is called after the node is launched to start any sidecar processes
781- /// that are configured in sidecar mode (not external mode).
780+ /// This function is called after the node is launched to:
781+ /// 1. Bootstrap necessary contracts (forwarder, VRF accounts)
782+ /// 2. Start sidecar processes in sidecar mode
782783#[ cfg( feature = "paymaster" ) ]
783- async fn start_sidecars_if_needed (
784+ async fn bootstrap_and_start_sidecars < P > (
784785 args : & SequencerNodeArgs ,
785- bootstrap : & katana_node:: sidecar :: BootstrapResult ,
786+ node : & katana_node:: Node < P > ,
786787 rpc_addr : & std:: net:: SocketAddr ,
787788 paymaster_sidecar : Option < & PaymasterSidecarInfo > ,
788789 #[ cfg( feature = "vrf" ) ] vrf_sidecar : Option < & VrfSidecarInfo > ,
789- ) -> Result < Option < crate :: sidecar:: SidecarProcesses > > {
790+ ) -> Result < Option < crate :: sidecar:: SidecarProcesses > >
791+ where
792+ P : katana_provider:: ProviderFactory + Clone ,
793+ <P as katana_provider:: ProviderFactory >:: Provider :
794+ katana_core:: backend:: storage:: ProviderRO ,
795+ <P as katana_provider:: ProviderFactory >:: ProviderMut :
796+ katana_core:: backend:: storage:: ProviderRW ,
797+ {
790798 #[ cfg( feature = "vrf" ) ]
791- use crate :: sidecar:: VrfSidecarConfig ;
792- use crate :: sidecar:: { start_sidecars, PaymasterSidecarConfig , SidecarStartConfig } ;
799+ use crate :: sidecar:: { VrfBootstrapConfig , VrfKeySource , VrfSidecarConfig } ;
800+ use crate :: sidecar:: {
801+ bootstrap_sidecars, start_sidecars, BootstrapConfig , PaymasterSidecarConfig ,
802+ SidecarStartConfig ,
803+ } ;
804+
805+ // If no sidecars need to be started, return None
806+ #[ cfg( feature = "vrf" ) ]
807+ let has_sidecars = paymaster_sidecar. is_some ( ) || vrf_sidecar. is_some ( ) ;
808+ #[ cfg( not( feature = "vrf" ) ) ]
809+ let has_sidecars = paymaster_sidecar. is_some ( ) ;
810+
811+ if !has_sidecars {
812+ return Ok ( None ) ;
813+ }
793814
794- // Build paymaster sidecar config if needed
815+ // Build bootstrap config
816+ let bootstrap_config = BootstrapConfig {
817+ paymaster_prefunded_index : paymaster_sidecar. map ( |_| args. paymaster . prefunded_index ) ,
818+ #[ cfg( feature = "vrf" ) ]
819+ vrf : vrf_sidecar. map ( |_| {
820+ let key_source = match args. vrf . key_source {
821+ crate :: options:: VrfKeySource :: Prefunded => VrfKeySource :: Prefunded ,
822+ crate :: options:: VrfKeySource :: Sequencer => VrfKeySource :: Sequencer ,
823+ } ;
824+ VrfBootstrapConfig {
825+ key_source,
826+ prefunded_index : args. vrf . prefunded_index ,
827+ sequencer_address : node. config ( ) . chain . genesis ( ) . sequencer_address ,
828+ }
829+ } ) ,
830+ fee_enabled : node. config ( ) . dev . fee ,
831+ } ;
832+
833+ // Bootstrap contracts
834+ let bootstrap = bootstrap_sidecars (
835+ & bootstrap_config,
836+ node. backend ( ) ,
837+ node. block_producer ( ) ,
838+ node. pool ( ) ,
839+ )
840+ . await ?;
841+
842+ // Build sidecar start config
795843 let paymaster_config = paymaster_sidecar. map ( |info| PaymasterSidecarConfig {
796844 options : & args. paymaster ,
797845 port : info. port ,
798846 api_key : info. api_key . clone ( ) ,
799847 } ) ;
800848
801- // Build VRF sidecar config if needed
802849 #[ cfg( feature = "vrf" ) ]
803850 let vrf_config =
804851 vrf_sidecar. map ( |info| VrfSidecarConfig { options : & args. vrf , port : info. port } ) ;
805852
806- // If no sidecars need to be started, return None
807- #[ cfg( feature = "vrf" ) ]
808- let has_sidecars = paymaster_config. is_some ( ) || vrf_config. is_some ( ) ;
809- #[ cfg( not( feature = "vrf" ) ) ]
810- let has_sidecars = paymaster_config. is_some ( ) ;
811-
812- if !has_sidecars {
813- return Ok ( None ) ;
814- }
815-
816- let config = SidecarStartConfig {
853+ let start_config = SidecarStartConfig {
817854 paymaster : paymaster_config,
818855 #[ cfg( feature = "vrf" ) ]
819856 vrf : vrf_config,
820857 } ;
821858
822- let processes = start_sidecars ( & config, bootstrap, rpc_addr) . await ?;
859+ // Start sidecar processes
860+ let processes = start_sidecars ( & start_config, & bootstrap, rpc_addr) . await ?;
823861 Ok ( Some ( processes) )
824862}
825863
0 commit comments