@@ -18,9 +18,11 @@ use aws_sdk_kms::config::BehaviorVersion;
18
18
use reth_chainspec:: EthChainSpec ;
19
19
use reth_network:: NetworkProtocols ;
20
20
use reth_network_api:: FullNetwork ;
21
- use reth_node_builder:: rpc:: RethRpcServerHandles ;
21
+ use reth_node_builder:: { rpc:: RethRpcServerHandles , NodeConfig as RethNodeConfig } ;
22
22
use reth_node_core:: primitives:: BlockHeader ;
23
- use reth_scroll_chainspec:: { ChainConfig , ScrollChainConfig , SCROLL_FEE_VAULT_ADDRESS } ;
23
+ use reth_scroll_chainspec:: {
24
+ ChainConfig , ScrollChainConfig , ScrollChainSpec , SCROLL_FEE_VAULT_ADDRESS ,
25
+ } ;
24
26
use reth_scroll_node:: ScrollNetworkPrimitives ;
25
27
use rollup_node_chain_orchestrator:: ChainOrchestrator ;
26
28
use rollup_node_manager:: {
@@ -79,6 +81,9 @@ pub struct ScrollRollupNodeConfig {
79
81
/// The gas price oracle args
80
82
#[ command( flatten) ]
81
83
pub gas_price_oracle_args : GasPriceOracleArgs ,
84
+ /// The database connection (not parsed via CLI but hydrated after validation).
85
+ #[ arg( skip) ]
86
+ pub database : Option < Arc < Database > > ,
82
87
}
83
88
84
89
impl ScrollRollupNodeConfig {
@@ -112,6 +117,26 @@ impl ScrollRollupNodeConfig {
112
117
113
118
Ok ( ( ) )
114
119
}
120
+
121
+ /// Hydrate the config by initializing the database connection.
122
+ pub async fn hydrate (
123
+ & mut self ,
124
+ node_config : RethNodeConfig < ScrollChainSpec > ,
125
+ ) -> eyre:: Result < ( ) > {
126
+ // Instantiate the database
127
+ let db_path = node_config. datadir ( ) . db ( ) ;
128
+ let database_path = if let Some ( database_path) = & self . database_args . path {
129
+ database_path. to_string_lossy ( ) . to_string ( )
130
+ } else {
131
+ // append the path using strings as using `join(...)` overwrites "sqlite://"
132
+ // if the path is absolute.
133
+ let path = db_path. join ( "scroll.db?mode=rwc" ) ;
134
+ "sqlite://" . to_string ( ) + & * path. to_string_lossy ( )
135
+ } ;
136
+ let db = Database :: new ( & database_path) . await ?;
137
+ self . database = Some ( Arc :: new ( db) ) ;
138
+ Ok ( ( ) )
139
+ }
115
140
}
116
141
117
142
impl ScrollRollupNodeConfig {
@@ -175,17 +200,8 @@ impl ScrollRollupNodeConfig {
175
200
. expect ( "failed to create payload provider" ) ;
176
201
let l2_provider = Arc :: new ( l2_provider) ;
177
202
178
- // Instantiate the database
179
- let db_path = ctx. datadir ;
180
- let database_path = if let Some ( database_path) = self . database_args . path {
181
- database_path. to_string_lossy ( ) . to_string ( )
182
- } else {
183
- // append the path using strings as using `join(...)` overwrites "sqlite://"
184
- // if the path is absolute.
185
- let path = db_path. join ( "scroll.db?mode=rwc" ) ;
186
- "sqlite://" . to_string ( ) + & * path. to_string_lossy ( )
187
- } ;
188
- let db = Database :: new ( & database_path) . await ?;
203
+ // Fetch the database from the hydrated config.
204
+ let db = self . database . clone ( ) . expect ( "should hydrate config before build" ) ;
189
205
190
206
// Run the database migrations
191
207
if let Some ( named) = chain_spec. chain ( ) . named ( ) {
@@ -215,9 +231,6 @@ impl ScrollRollupNodeConfig {
215
231
tracing:: info!( target: "scroll::node::args" , ?genesis_hash, "Overwriting genesis hash for custom chain" ) ;
216
232
}
217
233
218
- // Wrap the database in an Arc
219
- let db = Arc :: new ( db) ;
220
-
221
234
let chain_spec_fcs = || {
222
235
ForkchoiceState :: head_from_chain_spec ( chain_spec. clone ( ) )
223
236
. expect ( "failed to derive forkchoice state from chain spec" )
@@ -787,6 +800,7 @@ mod tests {
787
800
algorithm : ConsensusAlgorithm :: SystemContract ,
788
801
authorized_signer : None ,
789
802
} ,
803
+ database : None ,
790
804
} ;
791
805
792
806
let result = config. validate ( ) ;
@@ -817,6 +831,7 @@ mod tests {
817
831
algorithm : ConsensusAlgorithm :: SystemContract ,
818
832
authorized_signer : None ,
819
833
} ,
834
+ database : None ,
820
835
} ;
821
836
822
837
let result = config. validate ( ) ;
@@ -842,6 +857,7 @@ mod tests {
842
857
network_args : NetworkArgs :: default ( ) ,
843
858
gas_price_oracle_args : GasPriceOracleArgs :: default ( ) ,
844
859
consensus_args : ConsensusArgs :: noop ( ) ,
860
+ database : None ,
845
861
} ;
846
862
847
863
assert ! ( config. validate( ) . is_ok( ) ) ;
@@ -865,6 +881,7 @@ mod tests {
865
881
network_args : NetworkArgs :: default ( ) ,
866
882
gas_price_oracle_args : GasPriceOracleArgs :: default ( ) ,
867
883
consensus_args : ConsensusArgs :: noop ( ) ,
884
+ database : None ,
868
885
} ;
869
886
870
887
assert ! ( config. validate( ) . is_ok( ) ) ;
@@ -884,6 +901,7 @@ mod tests {
884
901
network_args : NetworkArgs :: default ( ) ,
885
902
gas_price_oracle_args : GasPriceOracleArgs :: default ( ) ,
886
903
consensus_args : ConsensusArgs :: noop ( ) ,
904
+ database : None ,
887
905
} ;
888
906
889
907
assert ! ( config. validate( ) . is_ok( ) ) ;
0 commit comments