mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-08-27 04:11:08 +00:00
feat(wallet): multi-sequecner cli commands
This commit is contained in:
@@ -59,6 +59,15 @@ impl ConfigSubcommand {
|
||||
"seq_block_poll_max_amount" => {
|
||||
println!("{}", config.seq_block_poll_max_amount);
|
||||
}
|
||||
"distribution_limit" => {
|
||||
println!(
|
||||
"{}",
|
||||
config.multi_sequencer_client_config.distribution_limit
|
||||
);
|
||||
}
|
||||
"calibration_limit" => {
|
||||
println!("{}", config.multi_sequencer_client_config.calibration_limit);
|
||||
}
|
||||
_ => {
|
||||
println!("Unknown field");
|
||||
}
|
||||
@@ -77,6 +86,9 @@ impl ConfigSubcommand {
|
||||
) -> Result<SubcommandReturnValue> {
|
||||
let mut config = wallet_core.config().clone();
|
||||
match key.as_str() {
|
||||
"sequencers" => {
|
||||
anyhow::bail!("Not settable via this method, use add-sequencer subcommand");
|
||||
}
|
||||
"seq_poll_timeout" => {
|
||||
config.seq_poll_timeout = humantime::parse_duration(&value)
|
||||
.map_err(|e| anyhow::anyhow!("Invalid duration: {e}"))?;
|
||||
@@ -90,8 +102,11 @@ impl ConfigSubcommand {
|
||||
"seq_block_poll_max_amount" => {
|
||||
config.seq_block_poll_max_amount = value.parse()?;
|
||||
}
|
||||
"initial_accounts" => {
|
||||
anyhow::bail!("Setting this field from wallet is not supported");
|
||||
"distribution_limit" => {
|
||||
config.multi_sequencer_client_config.distribution_limit = value.parse()?;
|
||||
}
|
||||
"calibration_limit" => {
|
||||
config.multi_sequencer_client_config.calibration_limit = value.parse()?;
|
||||
}
|
||||
_ => {
|
||||
anyhow::bail!("Unknown field");
|
||||
@@ -109,8 +124,8 @@ impl ConfigSubcommand {
|
||||
"override_rust_log" => {
|
||||
println!("Value of variable RUST_LOG to override, affects logging");
|
||||
}
|
||||
"sequencer_addr" => {
|
||||
println!("HTTP V4 account_id of sequencer");
|
||||
"sequencer" => {
|
||||
println!("A list of HTTP V4 addresses of sequencer, with authorization");
|
||||
}
|
||||
"seq_poll_timeout" => {
|
||||
println!(
|
||||
@@ -132,11 +147,15 @@ impl ConfigSubcommand {
|
||||
"Sequencer client polling variable: max number of blocks to request in one polling call"
|
||||
);
|
||||
}
|
||||
"initial_accounts" => {
|
||||
println!("List of initial accounts' keys(both public and private)");
|
||||
"distribution_limit" => {
|
||||
println!(
|
||||
"Sequencer multi node variable: max number of nodes to distribute transaction(can not be zero)"
|
||||
);
|
||||
}
|
||||
"basic_auth" => {
|
||||
println!("Basic authentication credentials for sequencer HTTP requests");
|
||||
"calibration_limit" => {
|
||||
println!(
|
||||
"Sequencer multi node variable: max number of callibration runs before the end of handshake(can not be zero)"
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
println!("Unknown field");
|
||||
|
||||
@@ -25,6 +25,7 @@ use crate::{
|
||||
native_token_transfer::AuthTransferSubcommand, pinata::PinataProgramAgnosticSubcommand,
|
||||
token::TokenProgramAgnosticSubcommand, vault::VaultSubcommand,
|
||||
},
|
||||
statistics::StatisticsSubcommand,
|
||||
},
|
||||
config::SequencerConnectionData,
|
||||
storage::Storage,
|
||||
@@ -37,6 +38,7 @@ pub mod group;
|
||||
pub mod keycard;
|
||||
pub mod network;
|
||||
pub mod programs;
|
||||
pub mod statistics;
|
||||
|
||||
pub(crate) trait WalletSubcommand {
|
||||
async fn handle_subcommand(self, wallet_core: &mut WalletCore)
|
||||
@@ -101,6 +103,9 @@ pub enum Command {
|
||||
/// Keycard hardware wallet management.
|
||||
#[command(subcommand)]
|
||||
Keycard(KeycardSubcommand),
|
||||
/// Metrics management.
|
||||
#[command(subcommand)]
|
||||
Statistics(StatisticsSubcommand),
|
||||
}
|
||||
|
||||
/// To execute commands, env var `LEE_WALLET_HOME_DIR` must be set into directory with config.
|
||||
@@ -320,6 +325,9 @@ pub async fn execute_subcommand(
|
||||
.await
|
||||
.context("Transaction finalization error")?
|
||||
}
|
||||
Command::Statistics(statistics_subcommand) => {
|
||||
statistics_subcommand.handle_subcommand(wallet_core).await?
|
||||
}
|
||||
};
|
||||
|
||||
// Kind of a sledgehammer solution, but it is not clear if there is the case to not store
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
use anyhow::Result;
|
||||
use clap::Subcommand;
|
||||
|
||||
use crate::{
|
||||
WalletCore,
|
||||
cli::{SubcommandReturnValue, WalletSubcommand},
|
||||
config::SequencerConnectionData,
|
||||
multi_client::{calibrate_client, make_subclient},
|
||||
};
|
||||
|
||||
/// Represents generic config CLI subcommand.
|
||||
#[derive(Subcommand, Debug, Clone)]
|
||||
pub enum StatisticsSubcommand {
|
||||
/// Show the list of the current leaders.
|
||||
ShowLeaders,
|
||||
/// Execute client list rotation, applies all statistics, the re-chooses the leaders.
|
||||
ExecuteRotation,
|
||||
/// (Re)callibrate the client.
|
||||
Callibrate { addr: String },
|
||||
/// Shpw the statistics of the client.
|
||||
ShowStatistics { addr: String },
|
||||
}
|
||||
|
||||
impl WalletSubcommand for StatisticsSubcommand {
|
||||
async fn handle_subcommand(
|
||||
self,
|
||||
wallet_core: &mut WalletCore,
|
||||
) -> Result<SubcommandReturnValue> {
|
||||
match self {
|
||||
Self::ShowLeaders => {
|
||||
let leader_urls = wallet_core
|
||||
.leaders()
|
||||
.iter()
|
||||
.map(|(_, url)| url)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
println!("Leader URLs is {leader_urls:?}");
|
||||
|
||||
Ok(SubcommandReturnValue::Empty)
|
||||
}
|
||||
Self::ExecuteRotation => {
|
||||
wallet_core.client_rotation().await?;
|
||||
|
||||
Ok(SubcommandReturnValue::Empty)
|
||||
}
|
||||
Self::Callibrate { addr } => {
|
||||
let url_addr = addr.parse()?;
|
||||
let calibration_limit = wallet_core
|
||||
.config()
|
||||
.multi_sequencer_client_config
|
||||
.calibration_limit;
|
||||
let SequencerConnectionData {
|
||||
sequencer_addr,
|
||||
basic_auth,
|
||||
} = wallet_core
|
||||
.config()
|
||||
.sequencers
|
||||
.iter()
|
||||
.find(|conn_data| conn_data.sequencer_addr == url_addr)
|
||||
.ok_or_else(|| {
|
||||
anyhow::anyhow!("Sequencer with this addr was not found in config")
|
||||
})?;
|
||||
let client = make_subclient(sequencer_addr, basic_auth)?;
|
||||
|
||||
let statistics = calibrate_client(client, calibration_limit)
|
||||
.await
|
||||
.ok_or_else(|| anyhow::anyhow!("Failed to callibrate the sequencer"))?;
|
||||
|
||||
wallet_core.statistics.insert(url_addr, statistics);
|
||||
|
||||
Ok(SubcommandReturnValue::Empty)
|
||||
}
|
||||
Self::ShowStatistics { addr } => {
|
||||
let url_addr = addr.parse()?;
|
||||
|
||||
println!(
|
||||
"Statistics of a {url_addr:?} is {:?}",
|
||||
wallet_core.get_statistics(&url_addr)
|
||||
);
|
||||
|
||||
Ok(SubcommandReturnValue::Empty)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
use std::{collections::HashMap, path::Path, sync::Arc};
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use common::{HashType, transaction::LeeTransaction};
|
||||
use common::{HashType, config::BasicAuth, transaction::LeeTransaction};
|
||||
use itertools::Itertools as _;
|
||||
use lee_core::BlockId;
|
||||
use sequencer_service_rpc::{RpcClient as _, SequencerClient, SequencerClientBuilder};
|
||||
@@ -115,23 +115,7 @@ impl MultiSequencerClient {
|
||||
basic_auth,
|
||||
} in conn_data
|
||||
{
|
||||
let sequencer_client = {
|
||||
let mut builder = SequencerClientBuilder::default();
|
||||
if let Some(basic_auth) = &basic_auth {
|
||||
builder = builder.set_headers(
|
||||
std::iter::once((
|
||||
"Authorization".parse().expect("Header name is valid"),
|
||||
format!("Basic {basic_auth}")
|
||||
.parse()
|
||||
.context("Invalid basic auth format")?,
|
||||
))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
builder
|
||||
.build(sequencer_addr)
|
||||
.context("Failed to create sequencer client")?
|
||||
};
|
||||
let sequencer_client = make_subclient(sequencer_addr, basic_auth)?;
|
||||
|
||||
if statistics.contains_key(sequencer_addr) {
|
||||
actualization_list.push((sequencer_addr.clone(), sequencer_client.clone()));
|
||||
@@ -472,9 +456,33 @@ async fn measure_request_duration(client: &SequencerClient) -> (u128, Option<Blo
|
||||
)
|
||||
}
|
||||
|
||||
pub fn make_subclient(
|
||||
sequencer_addr: &Url,
|
||||
basic_auth: &Option<BasicAuth>,
|
||||
) -> Result<SequencerClient> {
|
||||
let mut builder = SequencerClientBuilder::default();
|
||||
if let Some(basic_auth) = &basic_auth {
|
||||
builder = builder.set_headers(
|
||||
std::iter::once((
|
||||
"Authorization".parse().expect("Header name is valid"),
|
||||
format!("Basic {basic_auth}")
|
||||
.parse()
|
||||
.context("Invalid basic auth format")?,
|
||||
))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
builder
|
||||
.build(sequencer_addr)
|
||||
.context("Failed to create sequencer client")
|
||||
}
|
||||
|
||||
/// Calibrate statistics for one client. Takes `client` by value deliberately, cloning
|
||||
/// `SequencerClient` is cheap.
|
||||
async fn calibrate_client(client: SequencerClient, calibration_limit: usize) -> Option<Statistics> {
|
||||
pub async fn calibrate_client(
|
||||
client: SequencerClient,
|
||||
calibration_limit: usize,
|
||||
) -> Option<Statistics> {
|
||||
let mut latencies = vec![];
|
||||
let mut latest_block_id = 0;
|
||||
let mut errors: u64 = 0;
|
||||
|
||||
Reference in New Issue
Block a user