fix(wallet): suggestions 3

This commit is contained in:
Pravdyvy 2026-07-20 11:34:05 +03:00
parent a0971018ea
commit eaa76f5e7e
5 changed files with 16 additions and 19 deletions

View File

@ -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()`. /// This loads a wallet that was previously created with `wallet_ffi_create_new()`.
/// ///
/// # Parameters /// # Parameters
/// - `handle` - Valid wallet handle
/// - `config_path`: Path to the wallet configuration file (JSON) /// - `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) /// - `statistics_path`: Path to the wallet statistics file (JSON)
/// ///
/// # Returns /// # Returns
@ -164,7 +164,6 @@ pub unsafe extern "C" fn wallet_ffi_create_new(
/// ///
/// # Safety /// # Safety
/// All string parameters must be valid null-terminated UTF-8 strings. /// 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] #[no_mangle]
pub unsafe extern "C" fn wallet_ffi_open( pub unsafe extern "C" fn wallet_ffi_open(
config_path: *const c_char, config_path: *const c_char,

View File

@ -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()`. * This loads a wallet that was previously created with `wallet_ffi_create_new()`.
* *
* # Parameters * # Parameters
* - `handle` - Valid wallet handle
* - `config_path`: Path to the wallet configuration file (JSON) * - `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) * - `statistics_path`: Path to the wallet statistics file (JSON)
* *
* # Returns * # Returns
@ -1643,7 +1643,6 @@ struct FfiCreateWalletOutput wallet_ffi_create_new(const char *config_path,
* *
* # Safety * # Safety
* All string parameters must be valid null-terminated UTF-8 strings. * 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, struct WalletHandle *wallet_ffi_open(const char *config_path,
const char *storage_path, const char *storage_path,

View File

@ -7,6 +7,8 @@ use log::warn;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;
const DEFAULT_CALLIBRATION_LIMIT: usize = 100;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SequencerConnectionData { pub struct SequencerConnectionData {
/// Connection data of all known sequencers. /// Connection data of all known sequencers.
@ -49,6 +51,7 @@ pub struct WalletConfig {
/// Max amount of blocks to poll in one request. /// Max amount of blocks to poll in one request.
pub seq_block_poll_max_amount: u64, pub seq_block_poll_max_amount: u64,
/// Limit number of sequencer polls during calibration, should not be zero /// Limit number of sequencer polls during calibration, should not be zero
#[serde(default = "default_calibration_limit")]
pub calibration_limit: usize, pub calibration_limit: usize,
} }
@ -63,7 +66,7 @@ impl Default for WalletConfig {
seq_tx_poll_max_blocks: 5, seq_tx_poll_max_blocks: 5,
seq_poll_max_retries: 5, seq_poll_max_retries: 5,
seq_block_poll_max_amount: 100, 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
}

View File

@ -213,17 +213,11 @@ impl MultiSequencerClient {
resp resp
} }
/// Update statistics of a leader, clear statist updates log.
pub async fn update_statistics(&self, leader_statistic: &mut Statistics) { pub async fn update_statistics(&self, leader_statistic: &mut Statistics) {
{ let mut statistic_updates = self.statistic_updates.write().await;
let statistic_updates = self.statistic_updates.read().await; leader_statistic.apply_updates(statistic_updates.as_ref());
leader_statistic.apply_updates(statistic_updates.as_ref()); statistic_updates.clear();
}
// Clear updates
{
let mut statistic_updates = self.statistic_updates.write().await;
statistic_updates.clear();
}
} }
} }
@ -368,10 +362,8 @@ pub fn choose_leader(
client_list: &HashMap<Url, SequencerClient>, client_list: &HashMap<Url, SequencerClient>,
statistics: &HashMap<Url, Statistics>, statistics: &HashMap<Url, Statistics>,
) -> Option<(Url, SequencerClient)> { ) -> Option<(Url, SequencerClient)> {
let mut client_vec = vec![];
// Sort out all unmetered clients // Sort out all unmetered clients
client_vec = client_list let mut client_vec: Vec<_> = client_list
.keys() .keys()
.filter(|item| statistics.contains_key(*item)) .filter(|item| statistics.contains_key(*item))
.collect(); .collect();

View File

@ -203,7 +203,7 @@ pub fn wallet_config(sequencer_addr: SocketAddr) -> Result<WalletConfig> {
seq_tx_poll_max_blocks: 15, seq_tx_poll_max_blocks: 15,
seq_poll_max_retries: 10, seq_poll_max_retries: 10,
seq_block_poll_max_amount: 100, seq_block_poll_max_amount: 100,
calibration_limit: 1, calibration_limit: 5,
}) })
} }