From d11a0b11ab652256b0acd0f18d3d2c696dfa942b Mon Sep 17 00:00:00 2001 From: brentstone Date: Sat, 4 Nov 2023 12:28:00 +0100 Subject: [PATCH] WIP somemoree --- apps/src/lib/cli.rs | 13 +- tests/src/e2e/ledger_tests.rs | 232 ++++++++++++++++++ wasm/checksums.json | 44 ++-- wasm/wasm_source/Makefile | 2 + .../src/tx_deactivate_validator.rs | 12 + .../src/tx_reactivate_validator.rs | 12 + 6 files changed, 288 insertions(+), 27 deletions(-) create mode 100644 wasm/wasm_source/src/tx_deactivate_validator.rs create mode 100644 wasm/wasm_source/src/tx_reactivate_validator.rs diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 15ee3785997..a0675d88ac8 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -225,6 +225,8 @@ pub mod cmds { // PoS transactions .subcommand(TxInitValidator::def().display_order(2)) .subcommand(TxUnjailValidator::def().display_order(2)) + .subcommand(TxDeactivateValidator::def().display_order(2)) + .subcommand(TxReactivateValidator::def().display_order(2)) .subcommand(Bond::def().display_order(2)) .subcommand(Unbond::def().display_order(2)) .subcommand(Withdraw::def().display_order(2)) @@ -1391,7 +1393,7 @@ pub mod cmds { ); impl SubCmd for TxDeactivateValidator { - const CMD: &'static str = "unjail-validator"; + const CMD: &'static str = "deactivate-validator"; fn parse(matches: &ArgMatches) -> Option { matches.subcommand_matches(Self::CMD).map(|matches| { @@ -1403,9 +1405,7 @@ pub mod cmds { fn def() -> App { App::new(Self::CMD) - .about( - "Send a signed transaction to unjail a jailed validator.", - ) + .about("Send a signed transaction to deactivate a validator.") .add_args::>() } } @@ -1416,7 +1416,7 @@ pub mod cmds { ); impl SubCmd for TxReactivateValidator { - const CMD: &'static str = "unjail-validator"; + const CMD: &'static str = "reactivate-validator"; fn parse(matches: &ArgMatches) -> Option { matches.subcommand_matches(Self::CMD).map(|matches| { @@ -1429,7 +1429,8 @@ pub mod cmds { fn def() -> App { App::new(Self::CMD) .about( - "Send a signed transaction to unjail a jailed validator.", + "Send a signed transaction to reactivate an inactive \ + validator.", ) .add_args::>() } diff --git a/tests/src/e2e/ledger_tests.rs b/tests/src/e2e/ledger_tests.rs index 2ee44c62ae7..0bfeaea5f2a 100644 --- a/tests/src/e2e/ledger_tests.rs +++ b/tests/src/e2e/ledger_tests.rs @@ -3647,3 +3647,235 @@ fn prepare_proposal_data( ); valid_proposal_json_path } + +#[test] +fn deactivate_and_reactivate_validator() -> Result<()> { + let pipeline_len = 2; + let unbonding_len = 4; + let test = setup::network( + |genesis| { + let parameters = ParametersConfig { + min_num_of_blocks: 6, + max_expected_time_per_block: 1, + epochs_per_year: 31_536_000, + ..genesis.parameters + }; + let pos_params = PosParamsConfig { + pipeline_len, + unbonding_len, + ..genesis.pos_params + }; + let genesis = GenesisConfig { + parameters, + pos_params, + ..genesis + }; + // let mut genesis = + setup::set_validators(4, genesis, default_port_offset) + // Remove stake from the 2nd validator so chain can run with a + // single node + // genesis.validator.get_mut("validator-1").unwrap().tokens = None; + // genesis + // .validator + // .get_mut("validator-1") + // .unwrap() + // .non_staked_balance = Some(1); + // genesis + }, + None, + )?; + + set_ethereum_bridge_mode( + &test, + &test.net.chain_id, + &Who::Validator(0), + ethereum_bridge::ledger::Mode::Off, + None, + ); + + // 1. Run the ledger node + let _bg_validator_0 = + start_namada_ledger_node_wait_wasm(&test, Some(0), Some(40))? + .background(); + + let _bg_validator_1 = + start_namada_ledger_node_wait_wasm(&test, Some(1), Some(40))? + .background(); + + let _bg_validator_2 = + start_namada_ledger_node_wait_wasm(&test, Some(2), Some(40))? + .background(); + + let _bg_validator_3 = + start_namada_ledger_node_wait_wasm(&test, Some(3), Some(40))? + .background(); + + // let validator_0_rpc = get_actor_rpc(&test, &Who::Validator(0)); + let validator_1_rpc = get_actor_rpc(&test, &Who::Validator(1)); + + // Check the state of validator-1 + let tx_args = vec![ + "validator-state", + "--validator", + "validator-1", + "--node", + &validator_1_rpc, + ]; + let mut client = run!(test, Bin::Client, tx_args, Some(40))?; + client.exp_string("consensus set")?; + client.assert_success(); + + // Deactivate validator-1 + let tx_args = vec![ + "deactivate-validator", + "--validator", + "validator-1", + "--signing-keys", + "validator-1-account-key", + "--node", + &validator_1_rpc, + ]; + let mut client = + run_as!(test, Who::Validator(1), Bin::Client, tx_args, Some(40))?; + client.exp_string("Transaction applied with result:")?; + client.exp_string("Transaction is valid.")?; + client.assert_success(); + + let deactivate_epoch = get_epoch(&test, &validator_1_rpc)?; + let start = Instant::now(); + let loop_timeout = Duration::new(120, 0); + loop { + if Instant::now().duration_since(start) > loop_timeout { + panic!( + "Timed out waiting for epoch: {}", + deactivate_epoch + pipeline_len + ); + } + let epoch = epoch_sleep(&test, &validator_1_rpc, 40)?; + if epoch >= deactivate_epoch + pipeline_len { + break; + } + } + + // // 2. Submit a self-bond for the first genesis validator + // let tx_args = vec![ + // "bond", + // "--validator", + // "validator-0", + // "--amount", + // "10000.0", + // "--signing-keys", + // "validator-0-account-key", + // "--node", + // &validator_0_rpc, + // ]; + // let mut client = + // run_as!(test, Who::Validator(0), Bin::Client, tx_args, Some(40))?; + // client.exp_string("Transaction applied with result:")?; + // client.exp_string("Transaction is valid.")?; + // client.assert_success(); + + // // 3. Submit a delegation to the first genesis validator + // let tx_args = vec![ + // "bond", + // "--validator", + // "validator-0", + // "--source", + // BERTHA, + // "--amount", + // "5000.0", + // "--signing-keys", + // BERTHA_KEY, + // "--node", + // &validator_0_rpc, + // ]; + // let mut client = run!(test, Bin::Client, tx_args, Some(40))?; + // client.exp_string("Transaction applied with result:")?; + // client.exp_string("Transaction is valid.")?; + // client.assert_success(); + + // // 4. Submit a re-delegation from the first to the second genesis + // validator let tx_args = vec![ + // "redelegate", + // "--source-validator", + // "validator-0", + // "--destination-validator", + // "validator-1", + // "--owner", + // BERTHA, + // "--amount", + // "2500.0", + // "--signing-keys", + // BERTHA_KEY, + // "--node", + // &validator_0_rpc, + // ]; + // let mut client = run!(test, Bin::Client, tx_args, Some(40))?; + // client.exp_string("Transaction applied with result:")?; + // client.exp_string("Transaction is valid.")?; + // client.assert_success(); + + // // 5. Submit an unbond of the self-bond + // let tx_args = vec![ + // "unbond", + // "--validator", + // "validator-0", + // "--amount", + // "5100.0", + // "--signing-keys", + // "validator-0-account-key", + // "--node", + // &validator_0_rpc, + // ]; + // let mut client = + // run_as!(test, Who::Validator(0), Bin::Client, tx_args, Some(40))?; + // client + // .exp_string("Amount 5100.000000 withdrawable starting from epoch ")?; + // client.assert_success(); + + // // 6. Submit an unbond of the delegation from the first validator + // let tx_args = vec![ + // "unbond", + // "--validator", + // "validator-0", + // "--source", + // BERTHA, + // "--amount", + // "1600.", + // "--signing-keys", + // BERTHA_KEY, + // "--node", + // &validator_0_rpc, + // ]; + // let mut client = run!(test, Bin::Client, tx_args, Some(40))?; + // let expected = "Amount 1600.000000 withdrawable starting from epoch "; + // let _ = client.exp_regex(&format!("{expected}.*\n"))?; + // client.assert_success(); + + // // 7. Submit an unbond of the re-delegation from the second validator + // let tx_args = vec![ + // "unbond", + // "--validator", + // "validator-1", + // "--source", + // BERTHA, + // "--amount", + // "1600.", + // "--signing-keys", + // BERTHA_KEY, + // "--node", + // &validator_0_rpc, + // ]; + // let mut client = run!(test, Bin::Client, tx_args, Some(40))?; + // let expected = "Amount 1600.000000 withdrawable starting from epoch "; + // let (_unread, matched) = client.exp_regex(&format!("{expected}.*\n"))?; + // let epoch_raw = matched.trim().split_once(expected).unwrap().1; + // let delegation_withdrawable_epoch = Epoch::from_str(epoch_raw).unwrap(); + // client.assert_success(); + + // // 8. Wait for the delegation withdrawable epoch (the self-bond was + // unbonded // before it) + // let epoch = get_epoch(&test, &validator_0_rpc)?; + + Ok(()) +} diff --git a/wasm/checksums.json b/wasm/checksums.json index 873f8ae6a12..f65d0f9c4e3 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,23 +1,25 @@ { - "tx_bond.wasm": "tx_bond.dbfe330a50d8d3511e125f611d88a3a32952de2077345ee79b5b320e9d11ece6.wasm", - "tx_bridge_pool.wasm": "tx_bridge_pool.ae875a5ddd27035b768678b2dbf70c8ecfa1bce316faee01b26bd0cbffb48b19.wasm", - "tx_change_validator_commission.wasm": "tx_change_validator_commission.39b26c8ff0c06220163322c15a0f304232f5e3a6333c147d10d5a65e3d06c061.wasm", - "tx_ibc.wasm": "tx_ibc.d550ec9d20d965d91530ca4df74a75eeb27f88ae4484da3eef4b5599727bd94f.wasm", - "tx_init_account.wasm": "tx_init_account.06c8639a68cecf1160818bd92d81974a9990aceea08cbbcc47e18c51b2ec9449.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.daa176497bb1f4bb97346d1ba2387e0cc84e704eca70ef78a56228e03969fb76.wasm", - "tx_init_validator.wasm": "tx_init_validator.8d393d2cfdf55fd88beb4f26840d22e98da5e0390aac5fbcf1dc314e0eb4a9ca.wasm", - "tx_redelegate.wasm": "tx_redelegate.c586dc50a452948e2dd79718519bfa7b966999126ba52807bc4ba3a6f7a6290d.wasm", - "tx_resign_steward.wasm": "tx_resign_steward.994a9a3e10baacf900087382d2d8bb8045033927a3d040bf882c6d60ecfe0d5b.wasm", - "tx_reveal_pk.wasm": "tx_reveal_pk.aceb2779c307f96e377e3e189589ea54e7b05d712cac27c6943e1d941334b421.wasm", - "tx_transfer.wasm": "tx_transfer.adab8a00709de083b6b4b534d4dfe002d479085ce1a766718dd3afe920659ac3.wasm", - "tx_unbond.wasm": "tx_unbond.a1dc615400ad625cf9b82ea28735a2fbffd1dd6745761eff6df4d08358162195.wasm", - "tx_unjail_validator.wasm": "tx_unjail_validator.9debbc06681dd602e8a34ccf20d50dddee9963447409d2597893bf54937e7cee.wasm", - "tx_update_account.wasm": "tx_update_account.3917c5c25d2ffb0d717b9475a74d825840db94d48fcb4a0fe7450f3b32258cbe.wasm", - "tx_update_steward_commission.wasm": "tx_update_steward_commission.1a6f68eaf3b2eff9da777ce8c73f94865c49fa2ef94b5c0e1d65f46960cc9a5e.wasm", - "tx_vote_proposal.wasm": "tx_vote_proposal.3f818de8c638e24249a26ccd20ec6a1700092c3700dcf6b91aea11058586ebef.wasm", - "tx_withdraw.wasm": "tx_withdraw.3cf7e6b6b77abd0eae58302659c9de31919894f36c0f7dbd85a6c853cd023483.wasm", - "vp_implicit.wasm": "vp_implicit.46d4206719acaaa8d0a422b6f969719b458cc5ca7c25677eb4bf23b52b4b6490.wasm", - "vp_masp.wasm": "vp_masp.c1e8f569ed3ad2bf5152e34f8ea9e255439066e0800ae73620a7be9a976f2ff7.wasm", - "vp_user.wasm": "vp_user.6b5bf2c3a5367d4f379187a8d2cf71457085aa1184a2b98b9e00ab6978847e08.wasm", - "vp_validator.wasm": "vp_validator.a683a9724e335cdf8f33eaee9ac3127a21d9f76e9769a5f3aea63b3bf04f2011.wasm" + "tx_bond.wasm": "tx_bond.70e7863eade59d637217f133cf8dacbb28fbe7c22936396055e8228c87199f83.wasm", + "tx_bridge_pool.wasm": "tx_bridge_pool.69971943e6ad81a537197ee4d7fe8f1211882a17de572b28e71906572e8193af.wasm", + "tx_change_validator_commission.wasm": "tx_change_validator_commission.94615c76f6f32b627adbbb1279a345bd06c6bd0d4eb65a6286c0038f78e91321.wasm", + "tx_deactivate_validator.wasm": "tx_deactivate_validator.38bdc4c2cda3f09c9c233ccea8f8df64e1d3b7916f67723d079248f36042ec82.wasm", + "tx_ibc.wasm": "tx_ibc.a74c56e43a62bc89018b2ccc19a4daf02d24a2f7c25ccc7b8e57c1f8ce272b82.wasm", + "tx_init_account.wasm": "tx_init_account.67cf30a5dc66ed3456e209f6983bb2d17c44b0dc952aeecccee6499939c5c58d.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.42f0735b45cebb72c10c4f2a6298d838adf89c1ab2d8eb31e0c726e33b1efdbd.wasm", + "tx_init_validator.wasm": "tx_init_validator.b33e386e3695a676a028040fbe6ce32762c9299e41f673f8636feb959535982d.wasm", + "tx_reactivate_validator.wasm": "tx_reactivate_validator.60f635af60a6172d2f32ae69332185cd658a0a49eecf2ad232f372d35a96c905.wasm", + "tx_redelegate.wasm": "tx_redelegate.5fc225fed027677e5f374a6e03ba14a97ffe730e2b600fccf23f4990ca7a19d8.wasm", + "tx_resign_steward.wasm": "tx_resign_steward.0852161a0947dc129fd1a581f79e5725c63760aed6cc71bbf3e2b554f913a540.wasm", + "tx_reveal_pk.wasm": "tx_reveal_pk.57f11af958daa0d52db27c1036a3d82eea964e976238561ad48baf89423b110b.wasm", + "tx_transfer.wasm": "tx_transfer.c3cecec1bbd1eb452a5aef6f70d45e1ed8590da4ff670fafe28163847405e934.wasm", + "tx_unbond.wasm": "tx_unbond.fc0a8f16733ee5cedb4a3e56e211bba168cb5f97e977d2eeebdf2c28ff26a4a6.wasm", + "tx_unjail_validator.wasm": "tx_unjail_validator.2f973ea13bf7a0060fdec2faa4a30d95fd018b54aa4bb6283b2a53fe21b5ab77.wasm", + "tx_update_account.wasm": "tx_update_account.a4b02b42cc0428030085ffde5b5169ecb4b5d02c8f316b162df5bb1e3ea15c3a.wasm", + "tx_update_steward_commission.wasm": "tx_update_steward_commission.17439af7a44254111415e28cc8a5d8ab62e0a67d2825a82dcb2eb5666689fad9.wasm", + "tx_vote_proposal.wasm": "tx_vote_proposal.8b5d3d2a258f08eb0fe7727c81f55b60134985bb30ac2e13814d1f3a38082cb2.wasm", + "tx_withdraw.wasm": "tx_withdraw.26952ab447ba48aa08ffa7d12700877b1beef3c73b3e8fb2b8ddb1839e80fa8f.wasm", + "vp_implicit.wasm": "vp_implicit.32f0dee40e3c6730327193a32a191bdd6bfca768d9176f02bb63da04eb97a17f.wasm", + "vp_masp.wasm": "vp_masp.a5fc24c02e34d2345353abfd355f7fc665b980b185676e921f0994c02ca6bb6d.wasm", + "vp_user.wasm": "vp_user.238f0f88b402059130a1e4868ff62e4880320725155c275c626798d69d04cecf.wasm", + "vp_validator.wasm": "vp_validator.e8721ed7520d7b0940adb4d8f195ab4d1d2eeca2fa36688b618e6ecd545f25fc.wasm" } \ No newline at end of file diff --git a/wasm/wasm_source/Makefile b/wasm/wasm_source/Makefile index e78237c89d1..6f7faac2509 100644 --- a/wasm/wasm_source/Makefile +++ b/wasm/wasm_source/Makefile @@ -8,11 +8,13 @@ nightly := $(shell cat ../../rust-nightly-version) wasms := tx_bond wasms += tx_bridge_pool wasms += tx_change_validator_commission +wasms += tx_deactivate_validator wasms += tx_ibc wasms += tx_init_account wasms += tx_init_proposal wasms += tx_init_validator wasms += tx_redelegate +wasms += tx_reactivate_validator wasms += tx_reveal_pk wasms += tx_transfer wasms += tx_unbond diff --git a/wasm/wasm_source/src/tx_deactivate_validator.rs b/wasm/wasm_source/src/tx_deactivate_validator.rs new file mode 100644 index 00000000000..cd62efc1140 --- /dev/null +++ b/wasm/wasm_source/src/tx_deactivate_validator.rs @@ -0,0 +1,12 @@ +//! A tx to deactivate a validator. + +use namada_tx_prelude::*; + +#[transaction(gas = 340000)] +fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { + let signed = tx_data; + let data = signed.data().ok_or_err_msg("Missing data")?; + let validator = Address::try_from_slice(&data[..]) + .wrap_err("failed to decode an Address")?; + ctx.deactivate_validator(&validator) +} diff --git a/wasm/wasm_source/src/tx_reactivate_validator.rs b/wasm/wasm_source/src/tx_reactivate_validator.rs new file mode 100644 index 00000000000..19bfd746484 --- /dev/null +++ b/wasm/wasm_source/src/tx_reactivate_validator.rs @@ -0,0 +1,12 @@ +//! A tx to reactivate a validator. + +use namada_tx_prelude::*; + +#[transaction(gas = 340000)] +fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { + let signed = tx_data; + let data = signed.data().ok_or_err_msg("Missing data")?; + let validator = Address::try_from_slice(&data[..]) + .wrap_err("failed to decode an Address")?; + ctx.reactivate_validator(&validator) +}