@@ -149,17 +149,8 @@ pub struct Client<Env: Environment> {
149149 /// Local node to manage the execution state and the local storage of the chains that we are
150150 /// tracking.
151151 local_node : LocalNodeClient < Env :: Storage > ,
152- /// Maximum number of pending message bundles processed at a time in a block.
153- max_pending_message_bundles : usize ,
154- /// The policy for automatically handling incoming messages.
155- message_policy : MessagePolicy ,
156152 /// The admin chain ID.
157153 admin_id : ChainId ,
158- /// Whether to block on cross-chain message delivery.
159- cross_chain_message_delivery : CrossChainMessageDelivery ,
160- /// An additional delay, after reaching a quorum, to wait for additional validator signatures,
161- /// as a fraction of time taken to reach quorum.
162- grace_period : f64 ,
163154 /// Chains that should be tracked by the client.
164155 // TODO(#2412): Merge with set of chains the client is receiving notifications from validators
165156 tracked_chains : Arc < RwLock < HashSet < ChainId > > > ,
@@ -169,26 +160,21 @@ pub struct Client<Env: Environment> {
169160 chains : DashMap < ChainId , ChainClientState > ,
170161 /// The maximum active chain workers.
171162 max_loaded_chains : NonZeroUsize ,
172- /// The delay when downloading a blob, after which we try a second validator .
173- blob_download_timeout : Duration ,
163+ /// Configuration options .
164+ options : ChainClientOptions ,
174165}
175166
176167impl < Env : Environment > Client < Env > {
177168 /// Creates a new `Client` with a new cache and notifiers.
178- #[ expect( clippy:: too_many_arguments) ]
179169 #[ instrument( level = "trace" , skip_all) ]
180170 pub fn new (
181171 environment : Env ,
182- max_pending_message_bundles : usize ,
183172 admin_id : ChainId ,
184- message_policy : MessagePolicy ,
185- cross_chain_message_delivery : CrossChainMessageDelivery ,
186173 long_lived_services : bool ,
187174 tracked_chains : impl IntoIterator < Item = ChainId > ,
188175 name : impl Into < String > ,
189176 max_loaded_chains : NonZeroUsize ,
190- grace_period : f64 ,
191- blob_download_timeout : Duration ,
177+ options : ChainClientOptions ,
192178 ) -> Self {
193179 let tracked_chains = Arc :: new ( RwLock :: new ( tracked_chains. into_iter ( ) . collect ( ) ) ) ;
194180 let state = WorkerState :: new_for_client (
@@ -206,15 +192,11 @@ impl<Env: Environment> Client<Env> {
206192 environment,
207193 local_node,
208194 chains : DashMap :: new ( ) ,
209- max_pending_message_bundles,
210195 admin_id,
211- message_policy,
212- cross_chain_message_delivery,
213- grace_period,
214196 tracked_chains,
215197 notifier : Arc :: new ( ChannelNotifier :: default ( ) ) ,
216198 max_loaded_chains,
217- blob_download_timeout ,
199+ options ,
218200 }
219201 }
220202
@@ -267,13 +249,7 @@ impl<Env: Environment> Client<Env> {
267249 ChainClient {
268250 client : self . clone ( ) ,
269251 chain_id,
270- options : ChainClientOptions {
271- max_pending_message_bundles : self . max_pending_message_bundles ,
272- message_policy : self . message_policy . clone ( ) ,
273- cross_chain_message_delivery : self . cross_chain_message_delivery ,
274- grace_period : self . grace_period ,
275- blob_download_timeout : self . blob_download_timeout ,
276- } ,
252+ options : self . options . clone ( ) ,
277253 preferred_owner,
278254 initial_block_hash : block_hash,
279255 initial_next_block_height : next_block_height,
@@ -292,10 +268,13 @@ impl<Env: Environment> Client<Env> {
292268 // If the chain is missing then the error is a WorkerError
293269 // and so a BlobsNotFound
294270 // TODO(#2351): make sure the blobs are legitimate!
295- let blobs =
296- RemoteNode :: download_blobs ( & blob_ids, validators, self . blob_download_timeout )
297- . await
298- . ok_or ( LocalNodeError :: BlobsNotFound ( blob_ids) ) ?;
271+ let blobs = RemoteNode :: download_blobs (
272+ & blob_ids,
273+ validators,
274+ self . options . blob_download_timeout ,
275+ )
276+ . await
277+ . ok_or ( LocalNodeError :: BlobsNotFound ( blob_ids) ) ?;
299278 self . local_node . storage_client ( ) . write_blobs ( & blobs) . await ?;
300279 self . local_node . chain_info ( chain_id) . await
301280 }
@@ -484,9 +463,10 @@ impl<Env: Environment> Client<Env> {
484463 // Recover history from the current validators, according to the admin chain.
485464 // TODO(#2351): make sure that the blob is legitimately created!
486465 let nodes = self . validator_nodes ( ) . await ?;
487- let blob = RemoteNode :: download_blob ( & nodes, chain_desc_id, self . blob_download_timeout )
488- . await
489- . ok_or ( LocalNodeError :: BlobsNotFound ( vec ! [ chain_desc_id] ) ) ?;
466+ let blob =
467+ RemoteNode :: download_blob ( & nodes, chain_desc_id, self . options . blob_download_timeout )
468+ . await
469+ . ok_or ( LocalNodeError :: BlobsNotFound ( vec ! [ chain_desc_id] ) ) ?;
490470 self . local_node . storage_client ( ) . write_blob ( & blob) . await ?;
491471 Ok ( blob)
492472 }
@@ -521,7 +501,7 @@ impl<Env: Environment> Client<Env> {
521501 let hashed_value = ConfirmedBlock :: new ( certificate. inner ( ) . block ( ) . clone ( ) ) ;
522502 let finalize_action = CommunicateAction :: FinalizeBlock {
523503 certificate : Box :: new ( certificate) ,
524- delivery : self . cross_chain_message_delivery ,
504+ delivery : self . options . cross_chain_message_delivery ,
525505 } ;
526506 let certificate = self
527507 . communicate_chain_action ( committee, finalize_action, hashed_value)
@@ -587,7 +567,7 @@ impl<Env: Environment> Client<Env> {
587567 . await
588568 } )
589569 } ,
590- self . grace_period ,
570+ self . options . grace_period ,
591571 )
592572 . await ?;
593573 Ok ( ( ) )
@@ -622,7 +602,7 @@ impl<Env: Environment> Client<Env> {
622602 let action = action. clone ( ) ;
623603 Box :: pin ( async move { updater. send_chain_update ( action) . await } )
624604 } ,
625- self . grace_period ,
605+ self . options . grace_period ,
626606 )
627607 . await ?;
628608 ensure ! (
@@ -715,10 +695,13 @@ impl<Env: Environment> Client<Env> {
715695 if let Err ( err) = self . process_certificate ( certificate. clone ( ) ) . await {
716696 match & err {
717697 LocalNodeError :: BlobsNotFound ( blob_ids) => {
718- let blobs =
719- RemoteNode :: download_blobs ( blob_ids, & nodes, self . blob_download_timeout )
720- . await
721- . ok_or ( err) ?;
698+ let blobs = RemoteNode :: download_blobs (
699+ blob_ids,
700+ & nodes,
701+ self . options . blob_download_timeout ,
702+ )
703+ . await
704+ . ok_or ( err) ?;
722705 self . local_node . store_blobs ( & blobs) . await ?;
723706 self . process_certificate ( certificate) . await ?;
724707 }
@@ -933,7 +916,7 @@ impl<Env: Environment> Client<Env> {
933916 self . try_synchronize_chain_state_from ( & remote_node, chain_id)
934917 . await
935918 } ,
936- self . grace_period ,
919+ self . options . grace_period ,
937920 )
938921 . await ?;
939922
@@ -1294,7 +1277,6 @@ impl MessagePolicy {
12941277 }
12951278}
12961279
1297- #[ non_exhaustive]
12981280#[ derive( Debug , Clone ) ]
12991281pub struct ChainClientOptions {
13001282 /// Maximum number of pending message bundles processed at a time in a block.
@@ -1310,6 +1292,21 @@ pub struct ChainClientOptions {
13101292 pub blob_download_timeout : Duration ,
13111293}
13121294
1295+ #[ cfg( with_testing) ]
1296+ impl ChainClientOptions {
1297+ pub fn test_default ( ) -> Self {
1298+ use crate :: DEFAULT_GRACE_PERIOD ;
1299+
1300+ ChainClientOptions {
1301+ max_pending_message_bundles : 10 ,
1302+ message_policy : MessagePolicy :: new_accept_all ( ) ,
1303+ cross_chain_message_delivery : CrossChainMessageDelivery :: NonBlocking ,
1304+ grace_period : DEFAULT_GRACE_PERIOD ,
1305+ blob_download_timeout : Duration :: from_secs ( 1 ) ,
1306+ }
1307+ }
1308+ }
1309+
13131310/// Client to operate a chain by interacting with validators and the given local storage
13141311/// implementation.
13151312/// * The chain being operated is called the "local chain" or just the "chain".
0 commit comments