Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dre): vote sleep duration #471

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Cargo.Bazel.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "91e6a6c9b71afdbf7120bcb3c9ead14e12bb92ae59f99b6024eabe319d4696a4",
"checksum": "e5c2553cb5e7ef216889a9b6b25bac1b4c50ba484e36a2f4359ca5d9a82b9a70",
"crates": {
"actix-codec 0.5.2": {
"name": "actix-codec",
Expand Down Expand Up @@ -11277,6 +11277,10 @@
"id": "futures-util 0.3.30",
"target": "futures_util"
},
{
"id": "humantime 2.1.0",
"target": "humantime"
},
{
"id": "ic-base-types 0.9.0",
"target": "ic_base_types"
Expand Down Expand Up @@ -11467,6 +11471,10 @@
"id": "clap_complete 4.5.4",
"target": "clap_complete"
},
{
"id": "humantime 2.1.0",
"target": "humantime"
},
{
"id": "ic-base-types 0.9.0",
"target": "ic_base_types"
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rs/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ tabular = { workspace = true }
tempfile = "3.10.0"
tokio = { workspace = true }
url = { workspace = true }
humantime = { workspace = true }

[dev-dependencies]
wiremock = { workspace = true }
Expand All @@ -81,6 +82,7 @@ ic-management-types = { workspace = true }
url = { workspace = true }
ic-nns-governance = { workspace = true }
ic-registry-keys = { workspace = true }
humantime = { workspace = true }

[[bin]]
name = "dre"
Expand Down
7 changes: 6 additions & 1 deletion rs/cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::path::PathBuf;
use std::{path::PathBuf, time::Duration};

use clap::{Parser, Subcommand};
use clap_num::maybe_hex;
use humantime::parse_duration;
use ic_base_types::PrincipalId;
use ic_management_types::Artifact;
use ic_registry_keys::FirewallRulesScope;
Expand Down Expand Up @@ -116,6 +117,10 @@ pub enum Commands {
/// By default: SubnetReplicaVersionManagement
#[clap(long, use_value_delimiter = true, value_delimiter = ',', value_name = "PROPOSER_ID", default_value = "12")]
accepted_topics: Vec<i32>,

/// Override default sleep time
#[clap(long, default_value = "60s", value_parser = parse_duration)]
sleep_time: Duration,
},

/// Trustworthy Metrics
Expand Down
11 changes: 8 additions & 3 deletions rs/cli/src/general.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use candid::Decode;
use cycles_minting_canister::SetAuthorizedSubnetworkListArgs;
use humantime::format_duration;
use ic_base_types::{CanisterId, PrincipalId};
use ic_management_types::Network;
use ic_nervous_system_clients::canister_id_record::CanisterIdRecord;
Expand Down Expand Up @@ -68,6 +69,7 @@ pub async fn vote_on_proposals(
accepted_proposers: &[u64],
accepted_topics: &[i32],
simulate: bool,
sleep: Duration,
) -> anyhow::Result<()> {
let client: GovernanceCanisterWrapper = match &neuron.get_auth().await? {
Auth::Hsm { pin, slot, key_id } => CanisterClient::from_hsm(pin.to_string(), *slot, key_id.to_string(), &nns_urls[0])?.into(),
Expand Down Expand Up @@ -111,15 +113,18 @@ pub async fn vote_on_proposals(
voted_proposals.insert(proposal.id.unwrap().id);
}

let mut sp = Spinner::with_timer(Spinners::Dots12, "Sleeping 15s before another check for pending proposals...".into());
let sleep = tokio::time::sleep(Duration::from_secs(15));
let mut sp = Spinner::with_timer(
Spinners::Dots12,
format!("Sleeping {} before another check for pending proposals...", format_duration(sleep)),
);
let sleep_func = tokio::time::sleep(sleep);
tokio::select! {
_ = tokio::signal::ctrl_c() => {
info!("Received Ctrl-C, exiting...");
sp.stop();
break;
}
_ = sleep => {
_ = sleep_func => {
sp.stop_with_message("Done sleeping, checking for pending proposals...".into());
continue
}
Expand Down
2 changes: 2 additions & 0 deletions rs/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ async fn async_main() -> Result<(), anyhow::Error> {
cli::Commands::Vote {
accepted_neurons,
accepted_topics,
sleep_time,
} => {
let cli = dre::parsed_cli::ParsedCli::from_opts(&cli_opts).await?;
vote_on_proposals(
Expand All @@ -420,6 +421,7 @@ async fn async_main() -> Result<(), anyhow::Error> {
accepted_neurons,
accepted_topics,
simulate,
*sleep_time,
)
.await
}
Expand Down
Loading