diff --git a/lez/wallet-ffi/src/wallet.rs b/lez/wallet-ffi/src/wallet.rs index e9c12f63..b2846912 100644 --- a/lez/wallet-ffi/src/wallet.rs +++ b/lez/wallet-ffi/src/wallet.rs @@ -154,8 +154,8 @@ pub unsafe extern "C" fn wallet_ffi_create_new( /// This loads a wallet that was previously created with `wallet_ffi_create_new()`. /// /// # Parameters -/// - `handle` - Valid wallet handle /// - `config_path`: Path to the wallet configuration file (JSON) +/// - `storage_path`: Path to the wallet storage (JSON) /// - `statistics_path`: Path to the wallet statistics file (JSON) /// /// # Returns @@ -164,7 +164,6 @@ pub unsafe extern "C" fn wallet_ffi_create_new( /// /// # Safety /// All string parameters must be valid null-terminated UTF-8 strings. -/// `handle` must be a valid wallet handle from `wallet_ffi_create_new` or `wallet_ffi_open`. #[no_mangle] pub unsafe extern "C" fn wallet_ffi_open( config_path: *const c_char, diff --git a/lez/wallet-ffi/wallet_ffi.h b/lez/wallet-ffi/wallet_ffi.h index 4a795c23..bbd7da1f 100644 --- a/lez/wallet-ffi/wallet_ffi.h +++ b/lez/wallet-ffi/wallet_ffi.h @@ -1633,8 +1633,8 @@ struct FfiCreateWalletOutput wallet_ffi_create_new(const char *config_path, * This loads a wallet that was previously created with `wallet_ffi_create_new()`. * * # Parameters - * - `handle` - Valid wallet handle * - `config_path`: Path to the wallet configuration file (JSON) + * - `storage_path`: Path to the wallet storage (JSON) * - `statistics_path`: Path to the wallet statistics file (JSON) * * # Returns @@ -1643,7 +1643,6 @@ struct FfiCreateWalletOutput wallet_ffi_create_new(const char *config_path, * * # Safety * All string parameters must be valid null-terminated UTF-8 strings. - * `handle` must be a valid wallet handle from `wallet_ffi_create_new` or `wallet_ffi_open`. */ struct WalletHandle *wallet_ffi_open(const char *config_path, const char *storage_path, diff --git a/lez/wallet/src/config.rs b/lez/wallet/src/config.rs index cb09f5c2..ede71073 100644 --- a/lez/wallet/src/config.rs +++ b/lez/wallet/src/config.rs @@ -7,6 +7,8 @@ use log::warn; use serde::{Deserialize, Serialize}; use url::Url; +const DEFAULT_CALLIBRATION_LIMIT: usize = 100; + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SequencerConnectionData { /// Connection data of all known sequencers. @@ -49,6 +51,7 @@ pub struct WalletConfig { /// Max amount of blocks to poll in one request. pub seq_block_poll_max_amount: u64, /// Limit number of sequencer polls during calibration, should not be zero + #[serde(default = "default_calibration_limit")] pub calibration_limit: usize, } @@ -63,7 +66,7 @@ impl Default for WalletConfig { seq_tx_poll_max_blocks: 5, seq_poll_max_retries: 5, seq_block_poll_max_amount: 100, - calibration_limit: 100, + calibration_limit: DEFAULT_CALLIBRATION_LIMIT, } } } @@ -151,3 +154,7 @@ impl WalletConfig { } } } + +const fn default_calibration_limit() -> usize { + DEFAULT_CALLIBRATION_LIMIT +} diff --git a/lez/wallet/src/multi_client.rs b/lez/wallet/src/multi_client.rs index 7a8968fa..499cf7a1 100644 --- a/lez/wallet/src/multi_client.rs +++ b/lez/wallet/src/multi_client.rs @@ -213,17 +213,11 @@ impl MultiSequencerClient { resp } + /// Update statistics of a leader, clear statist updates log. pub async fn update_statistics(&self, leader_statistic: &mut Statistics) { - { - let statistic_updates = self.statistic_updates.read().await; - leader_statistic.apply_updates(statistic_updates.as_ref()); - } - - // Clear updates - { - let mut statistic_updates = self.statistic_updates.write().await; - statistic_updates.clear(); - } + let mut statistic_updates = self.statistic_updates.write().await; + leader_statistic.apply_updates(statistic_updates.as_ref()); + statistic_updates.clear(); } } @@ -368,10 +362,8 @@ pub fn choose_leader( client_list: &HashMap, statistics: &HashMap, ) -> Option<(Url, SequencerClient)> { - let mut client_vec = vec![]; - // Sort out all unmetered clients - client_vec = client_list + let mut client_vec: Vec<_> = client_list .keys() .filter(|item| statistics.contains_key(*item)) .collect(); diff --git a/test_fixtures/src/config.rs b/test_fixtures/src/config.rs index b35f7f16..449308eb 100644 --- a/test_fixtures/src/config.rs +++ b/test_fixtures/src/config.rs @@ -203,7 +203,7 @@ pub fn wallet_config(sequencer_addr: SocketAddr) -> Result { seq_tx_poll_max_blocks: 15, seq_poll_max_retries: 10, seq_block_poll_max_amount: 100, - calibration_limit: 1, + calibration_limit: 5, }) }