Skip to content

Commit

Permalink
Revert "Merge branch 'ray/utils-next-epoch' (#1621)"
Browse files Browse the repository at this point in the history
This reverts commit 119210b, reversing
changes made to 141ce4b.
  • Loading branch information
juped committed Jul 11, 2023
1 parent 25e1c0d commit 62ce559
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 131 deletions.
2 changes: 0 additions & 2 deletions .changelog/unreleased/improvements/1621-utils-next-epoch.md

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/scripts/e2e.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"e2e::ledger_tests::test_namada_shuts_down_if_tendermint_dies": 2,
"e2e::ledger_tests::test_genesis_validators": 14,
"e2e::ledger_tests::test_node_connectivity_and_consensus": 28,
"e2e::ledger_tests::test_epoch_sleep": 12,
"e2e::wallet_tests::wallet_address_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds": 1,
"e2e::wallet_tests::wallet_encrypted_key_cmds_env_var": 1,
Expand Down
12 changes: 0 additions & 12 deletions apps/src/bin/namada-client/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,18 +471,6 @@ pub async fn main() -> Result<()> {
Utils::DefaultBaseDir(DefaultBaseDir(args)) => {
utils::default_base_dir(global_args, args)
}
Utils::EpochSleep(EpochSleep(mut args)) => {
let mut ctx = cli::Context::new(global_args)?;
let ledger_address = args.ledger_address.clone();
let client = HttpClient::new(utils::take_config_address(
&mut args.ledger_address,
))
.unwrap();
wait_until_node_is_synched(&client).await;
let client = HttpClient::new(ledger_address).unwrap();
let args = args.to_sdk(&mut ctx);
rpc::epoch_sleep(&client, args).await;
}
},
}
Ok(())
Expand Down
26 changes: 0 additions & 26 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,28 +1700,6 @@ pub mod cmds {
}
}

#[derive(Clone, Debug)]
pub struct EpochSleep(pub args::Query<args::CliTypes>);

impl SubCmd for EpochSleep {
const CMD: &'static str = "epoch-sleep";

fn parse(matches: &ArgMatches) -> Option<Self> {
matches
.subcommand_matches(Self::CMD)
.map(|matches| Self(args::Query::parse(matches)))
}

fn def() -> App {
App::new(Self::CMD)
.about(
"Query for the current epoch, then sleep until the next \
epoch.",
)
.add_args::<args::Query<args::CliTypes>>()
}
}

#[derive(Clone, Debug)]
pub enum Utils {
JoinNetwork(JoinNetwork),
Expand All @@ -1730,7 +1708,6 @@ pub mod cmds {
InitGenesisValidator(InitGenesisValidator),
PkToTmAddress(PkToTmAddress),
DefaultBaseDir(DefaultBaseDir),
EpochSleep(EpochSleep),
}

impl SubCmd for Utils {
Expand All @@ -1749,14 +1726,12 @@ pub mod cmds {
SubCmd::parse(matches).map(Self::PkToTmAddress);
let default_base_dir =
SubCmd::parse(matches).map(Self::DefaultBaseDir);
let epoch_sleep = SubCmd::parse(matches).map(Self::EpochSleep);
join_network
.or(fetch_wasms)
.or(init_network)
.or(init_genesis)
.or(pk_to_tm_address)
.or(default_base_dir)
.or(epoch_sleep)
})
}

Expand All @@ -1769,7 +1744,6 @@ pub mod cmds {
.subcommand(InitGenesisValidator::def())
.subcommand(PkToTmAddress::def())
.subcommand(DefaultBaseDir::def())
.subcommand(EpochSleep::def())
.subcommand_required(true)
.arg_required_else_help(true)
}
Expand Down
15 changes: 0 additions & 15 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2150,21 +2150,6 @@ pub async fn query_result<C: namada::ledger::queries::Client + Sync>(
}
}

pub async fn epoch_sleep<C: namada::ledger::queries::Client + Sync>(
client: &C,
_args: args::Query,
) {
let start_epoch = query_and_print_epoch(client).await;
loop {
tokio::time::sleep(core::time::Duration::from_secs(1)).await;
let current_epoch = query_epoch(client).await;
if current_epoch > start_epoch {
println!("Reached epoch {}", current_epoch);
break;
}
}
}

pub async fn get_proposal_votes<C: namada::ledger::queries::Client + Sync>(
client: &C,
epoch: Epoch,
Expand Down
37 changes: 14 additions & 23 deletions tests/src/e2e/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,29 +424,20 @@ pub fn epoch_sleep(
ledger_address: &str,
timeout_secs: u64,
) -> Result<Epoch> {
let mut find = run!(
test,
Bin::Client,
&["utils", "epoch-sleep", "--node", ledger_address],
Some(timeout_secs)
)?;
parse_reached_epoch(&mut find)
}

pub fn parse_reached_epoch(find: &mut NamadaCmd) -> Result<Epoch> {
let (unread, matched) = find.exp_regex("Reached epoch .*")?;
let epoch_str = strip_trailing_newline(&matched)
.trim()
.rsplit_once(' ')
.unwrap()
.1;
let epoch = u64::from_str(epoch_str).map_err(|e| {
eyre!(format!(
"Epoch: {} parsed from {}, Error: {}\n\nOutput: {}",
epoch_str, matched, e, unread
))
})?;
Ok(Epoch(epoch))
let old_epoch = get_epoch(test, ledger_address)?;
let start = Instant::now();
let loop_timeout = Duration::new(timeout_secs, 0);
loop {
if Instant::now().duration_since(start) > loop_timeout {
panic!("Timed out waiting for the next epoch");
}
let epoch = get_epoch(test, ledger_address)?;
if epoch > old_epoch {
break Ok(epoch);
} else {
sleep(10);
}
}
}

/// Wait for txs and VPs WASM compilations to finish. This is useful to avoid a
Expand Down
57 changes: 5 additions & 52 deletions tests/src/e2e/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use super::helpers::{
use super::setup::{get_all_wasms_hashes, set_ethereum_bridge_mode};
use crate::e2e::helpers::{
epoch_sleep, find_address, find_bonded_stake, get_actor_rpc, get_epoch,
parse_reached_epoch,
};
use crate::e2e::setup::{self, default_port_offset, sleep, Bin, Who};
use crate::{run, run_as};
Expand Down Expand Up @@ -2151,7 +2150,7 @@ fn pos_bonds() -> Result<()> {
delegation_withdrawable_epoch
);
}
let epoch = epoch_sleep(&test, &validator_one_rpc, 40)?;
let epoch = get_epoch(&test, &validator_one_rpc)?;
if epoch >= delegation_withdrawable_epoch {
break;
}
Expand Down Expand Up @@ -2358,7 +2357,7 @@ fn pos_rewards() -> Result<()> {
if Instant::now().duration_since(start) > loop_timeout {
panic!("Timed out waiting for epoch: {}", wait_epoch);
}
let epoch = epoch_sleep(&test, &validator_zero_rpc, 40)?;
let epoch = get_epoch(&test, &validator_zero_rpc)?;
if dbg!(epoch) >= wait_epoch {
break;
}
Expand Down Expand Up @@ -2441,7 +2440,7 @@ fn test_bond_queries() -> Result<()> {
if Instant::now().duration_since(start) > loop_timeout {
panic!("Timed out waiting for epoch: {}", 1);
}
let epoch = epoch_sleep(&test, &validator_one_rpc, 40)?;
let epoch = get_epoch(&test, &validator_one_rpc)?;
if epoch >= Epoch(4) {
break;
}
Expand Down Expand Up @@ -2500,7 +2499,7 @@ fn test_bond_queries() -> Result<()> {

// 6. Wait for withdraw_epoch
loop {
let epoch = epoch_sleep(&test, &validator_one_rpc, 40)?;
let epoch = epoch_sleep(&test, &validator_one_rpc, 120)?;
if epoch >= withdraw_epoch {
break;
}
Expand Down Expand Up @@ -2740,7 +2739,7 @@ fn pos_init_validator() -> Result<()> {
if Instant::now().duration_since(start) > loop_timeout {
panic!("Timed out waiting for epoch: {}", earliest_update_epoch);
}
let epoch = epoch_sleep(&test, &non_validator_rpc, 40)?;
let epoch = get_epoch(&test, &non_validator_rpc)?;
if epoch >= earliest_update_epoch {
break;
}
Expand Down Expand Up @@ -4664,52 +4663,6 @@ fn implicit_account_reveal_pk() -> Result<()> {
Ok(())
}

#[test]
fn test_epoch_sleep() -> Result<()> {
// Use slightly longer epochs to give us time to sleep
let test = setup::network(
|genesis| {
let parameters = ParametersConfig {
epochs_per_year: epochs_per_year_from_min_duration(30),
min_num_of_blocks: 1,
..genesis.parameters
};
GenesisConfig {
parameters,
..genesis
}
},
None,
)?;

// 1. Run the ledger node
let mut ledger =
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;
wait_for_wasm_pre_compile(&mut ledger)?;

let _bg_ledger = ledger.background();

let validator_one_rpc = get_actor_rpc(&test, &Who::Validator(0));

// 2. Query the current epoch
let start_epoch = get_epoch(&test, &validator_one_rpc).unwrap();

// 3. Use epoch-sleep to sleep for an epoch
let args = ["utils", "epoch-sleep", "--node", &validator_one_rpc];
let mut client = run!(test, Bin::Client, &args, None)?;
let reached_epoch = parse_reached_epoch(&mut client)?;
client.assert_success();

// 4. Confirm the current epoch is larger
// possibly badly, we assume we get here within 30 seconds of the last step
// should be fine haha (future debuggers: sorry)
let current_epoch = get_epoch(&test, &validator_one_rpc).unwrap();
assert!(current_epoch > start_epoch);
assert_eq!(current_epoch, reached_epoch);

Ok(())
}

/// Prepare proposal data in the test's temp dir from the given source address.
/// This can be submitted with "init-proposal" command.
fn prepare_proposal_data(
Expand Down

0 comments on commit 62ce559

Please sign in to comment.