Skip to content

Commit c58a463

Browse files
committed
Merge branch 'origin/brent/fix-init-validator-tendermint-mode' (#1549)
* origin/brent/fix-init-validator-tendermint-mode: client: mention to restart the node after init validator changelog: add #1549 test/e2e/pos_init_validator: ensure that node after init-validator works changelog: add #1553 [ci] wasm checksums update test/pos: check is_validator for a new validator pos: fix is_validator to be epoch agnostic Namada 0.17.1 changelog: add #1534 [ci] wasm checksums update test/storage: fill-in block header for commit if missing test/e2e/ledger/genesis_validators: validator wait for tx block height rpc: use the new shell last_block query to find last committed block core/storage: impl Display for BlockHash core/time: impl Display for DateTimeUtc shared/queries/shell: expose the last committed block from storage core/storage: Store last committed block's hash and time with its height fix: remove invalid condition around prepare-proposal update TendermintMode in Namada config for new post-genesis validator changelog: add #1549 test/e2e/pos_init_validator: ensure that node after init-validator works fix: remove invalid condition around prepare-proposal update TendermintMode in Namada config for new post-genesis validator
2 parents 04a12b9 + 2a066d7 commit c58a463

File tree

5 files changed

+134
-65
lines changed

5 files changed

+134
-65
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- PoS: Fixed the client to change configuration to validator
2+
mode after a successful `init-validator` transaction.
3+
([\#1549](https://github.com/anoma/namada/pull/1549))

apps/src/lib/client/tx.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ use namada::ledger::governance::storage as gov_storage;
1515
use namada::ledger::rpc::{TxBroadcastData, TxResponse};
1616
use namada::ledger::signing::TxSigningKey;
1717
use namada::ledger::wallet::{Wallet, WalletUtils};
18-
use namada::ledger::{masp, tx};
18+
use namada::ledger::{masp, pos, tx};
19+
use namada::proof_of_stake::parameters::PosParams;
1920
use namada::proto::{Code, Data, Section, Tx};
2021
use namada::types::address::Address;
2122
use namada::types::governance::{
@@ -39,6 +40,7 @@ use crate::cli::{args, safe_exit, Context};
3940
use crate::client::rpc::query_wasm_code_hash;
4041
use crate::client::signing::find_keypair;
4142
use crate::client::tx::tx::ProcessTxResponse;
43+
use crate::config::TendermintMode;
4244
use crate::facade::tendermint_rpc::endpoint::broadcast::tx_sync::Response;
4345
use crate::node::ledger::tendermint_node;
4446
use crate::wallet::{
@@ -294,6 +296,23 @@ pub async fn submit_init_validator<
294296
tendermint_node::write_validator_key(&tendermint_home, &consensus_key);
295297
tendermint_node::write_validator_state(tendermint_home);
296298

299+
// Write Namada config stuff or figure out how to do the above
300+
// tendermint_node things two epochs in the future!!!
301+
ctx.config.ledger.tendermint.tendermint_mode =
302+
TendermintMode::Validator;
303+
ctx.config
304+
.write(
305+
&ctx.config.ledger.shell.base_dir,
306+
&ctx.config.ledger.chain_id,
307+
true,
308+
)
309+
.unwrap();
310+
311+
let key = pos::params_key();
312+
let pos_params = rpc::query_storage_value::<C, PosParams>(client, &key)
313+
.await
314+
.expect("Pos parameter should be defined.");
315+
297316
println!();
298317
println!(
299318
"The validator's addresses and keys were stored in the wallet:"
@@ -305,6 +324,11 @@ pub async fn submit_init_validator<
305324
"The ledger node has been setup to use this validator's address \
306325
and consensus key."
307326
);
327+
println!(
328+
"Your validator will be active in {} epochs. Be sure to restart \
329+
your node for the changes to take effect!",
330+
pos_params.pipeline_len
331+
);
308332
} else {
309333
println!("Transaction dry run. No addresses have been saved.")
310334
}

apps/src/lib/node/ledger/shell/prepare_proposal.rs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use crate::facade::tendermint_proto::abci::RequestPrepareProposal;
2525
#[cfg(feature = "abcipp")]
2626
use crate::facade::tendermint_proto::abci::{tx_record::TxAction, TxRecord};
2727
use crate::facade::tendermint_proto::google::protobuf::Timestamp;
28-
use crate::node::ledger::shell::ShellMode;
2928
use crate::node::ledger::shims::abcipp_shim_types::shim::{response, TxBytes};
3029

3130
impl<D, H> Shell<D, H>
@@ -45,36 +44,30 @@ where
4544
&self,
4645
req: RequestPrepareProposal,
4746
) -> response::PrepareProposal {
48-
let txs = if let ShellMode::Validator { .. } = self.mode {
49-
// start counting allotted space for txs
50-
let alloc = self.get_encrypted_txs_allocator();
51-
// add encrypted txs
52-
let (encrypted_txs, alloc) = self.build_encrypted_txs(
53-
alloc,
54-
TempWlStorage::new(&self.wl_storage.storage),
55-
&req.txs,
56-
&req.time,
57-
);
58-
let mut txs = encrypted_txs;
59-
60-
// decrypt the wrapper txs included in the previous block
61-
let (mut decrypted_txs, alloc) = self.build_decrypted_txs(alloc);
62-
txs.append(&mut decrypted_txs);
63-
64-
// add vote extension protocol txs
65-
let mut protocol_txs = self.build_protocol_txs(
66-
alloc,
67-
#[cfg(feature = "abcipp")]
68-
req.local_last_commit,
69-
#[cfg(not(feature = "abcipp"))]
70-
&req.txs,
71-
);
72-
txs.append(&mut protocol_txs);
73-
74-
txs
75-
} else {
76-
vec![]
77-
};
47+
// start counting allotted space for txs
48+
let alloc = self.get_encrypted_txs_allocator();
49+
// add encrypted txs
50+
let (encrypted_txs, alloc) = self.build_encrypted_txs(
51+
alloc,
52+
TempWlStorage::new(&self.wl_storage.storage),
53+
&req.txs,
54+
&req.time,
55+
);
56+
let mut txs = encrypted_txs;
57+
58+
// decrypt the wrapper txs included in the previous block
59+
let (mut decrypted_txs, alloc) = self.build_decrypted_txs(alloc);
60+
txs.append(&mut decrypted_txs);
61+
62+
// add vote extension protocol txs
63+
let mut protocol_txs = self.build_protocol_txs(
64+
alloc,
65+
#[cfg(feature = "abcipp")]
66+
req.local_last_commit,
67+
#[cfg(not(feature = "abcipp"))]
68+
&req.txs,
69+
);
70+
txs.append(&mut protocol_txs);
7871

7972
tracing::info!(
8073
height = req.height,

tests/src/e2e/ledger_tests.rs

Lines changed: 72 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,8 +2350,15 @@ All unbonds total withdrawable: 412\r",
23502350
#[test]
23512351
fn pos_init_validator() -> Result<()> {
23522352
let pipeline_len = 1;
2353+
let validator_stake = 200000_u64;
23532354
let test = setup::network(
23542355
|genesis| {
2356+
assert_eq!(
2357+
genesis.validator.get("validator-0").unwrap().tokens,
2358+
Some(validator_stake),
2359+
"Assuming this stake, we give the same amount to the new \
2360+
validator to have half of voting power",
2361+
);
23552362
let parameters = ParametersConfig {
23562363
min_num_of_blocks: 4,
23572364
epochs_per_year: 31_536_000,
@@ -2372,16 +2379,28 @@ fn pos_init_validator() -> Result<()> {
23722379
None,
23732380
)?;
23742381

2375-
// 1. Run the ledger node
2376-
let mut ledger =
2377-
run_as!(test, Who::Validator(0), Bin::Node, &["ledger"], Some(40))?;
2382+
// 1. Run a validator and non-validator ledger node
2383+
let args = ["ledger"];
2384+
let mut validator_0 =
2385+
run_as!(test, Who::Validator(0), Bin::Node, args, Some(60))?;
2386+
let mut non_validator =
2387+
run_as!(test, Who::NonValidator, Bin::Node, args, Some(60))?;
23782388

2379-
wait_for_wasm_pre_compile(&mut ledger)?;
2380-
let _bg_ledger = ledger.background();
2389+
wait_for_wasm_pre_compile(&mut validator_0)?;
2390+
// let _bg_ledger = validator_0.background();
23812391

2382-
let validator_one_rpc = get_actor_rpc(&test, &Who::Validator(0));
2392+
wait_for_wasm_pre_compile(&mut non_validator)?;
2393+
// let _bg_ledger = non_validator.background();
2394+
2395+
// Wait for a first block
2396+
validator_0.exp_string("Committed block hash")?;
2397+
let _bg_validator_0 = validator_0.background();
2398+
non_validator.exp_string("Committed block hash")?;
2399+
let bg_non_validator = non_validator.background();
2400+
2401+
let non_validator_rpc = get_actor_rpc(&test, &Who::NonValidator);
23832402

2384-
// 2. Initialize a new validator account
2403+
// 2. Initialize a new validator account with the non-validator node
23852404
let new_validator = "new-validator";
23862405
let new_validator_key = format!("{}-key", new_validator);
23872406
let tx_args = vec![
@@ -2402,7 +2421,7 @@ fn pos_init_validator() -> Result<()> {
24022421
"--max-commission-rate-change",
24032422
"0.01",
24042423
"--node",
2405-
&validator_one_rpc,
2424+
&non_validator_rpc,
24062425
];
24072426
let mut client = run!(test, Bin::Client, tx_args, Some(40))?;
24082427
client.exp_string("Transaction is valid.")?;
@@ -2427,34 +2446,37 @@ fn pos_init_validator() -> Result<()> {
24272446
"--gas-token",
24282447
NAM,
24292448
"--node",
2430-
&validator_one_rpc,
2449+
&non_validator_rpc,
24312450
];
24322451
let mut client = run!(test, Bin::Client, tx_args, Some(40))?;
24332452
client.exp_string("Transaction is valid.")?;
24342453
client.assert_success();
24352454
// Then self-bond the tokens:
2455+
let delegation = 5_u64;
2456+
let delegation_str = &delegation.to_string();
24362457
let tx_args = vec![
24372458
"bond",
24382459
"--validator",
24392460
new_validator,
24402461
"--source",
24412462
BERTHA,
24422463
"--amount",
2443-
"1000.5",
2464+
delegation_str,
24442465
"--gas-amount",
24452466
"0",
24462467
"--gas-limit",
24472468
"0",
24482469
"--gas-token",
24492470
NAM,
24502471
"--node",
2451-
&validator_one_rpc,
2472+
&non_validator_rpc,
24522473
];
24532474
let mut client = run!(test, Bin::Client, tx_args, Some(40))?;
24542475
client.exp_string("Transaction is valid.")?;
24552476
client.assert_success();
24562477

24572478
// 4. Transfer some NAM to the new validator
2479+
let validator_stake_str = &validator_stake.to_string();
24582480
let tx_args = vec![
24592481
"transfer",
24602482
"--source",
@@ -2464,15 +2486,15 @@ fn pos_init_validator() -> Result<()> {
24642486
"--token",
24652487
NAM,
24662488
"--amount",
2467-
"10999.5",
2489+
validator_stake_str,
24682490
"--gas-amount",
24692491
"0",
24702492
"--gas-limit",
24712493
"0",
24722494
"--gas-token",
24732495
NAM,
24742496
"--node",
2475-
&validator_one_rpc,
2497+
&non_validator_rpc,
24762498
];
24772499
let mut client = run!(test, Bin::Client, tx_args, Some(40))?;
24782500
client.exp_string("Transaction is valid.")?;
@@ -2484,23 +2506,47 @@ fn pos_init_validator() -> Result<()> {
24842506
"--validator",
24852507
new_validator,
24862508
"--amount",
2487-
"10000",
2509+
validator_stake_str,
24882510
"--gas-amount",
24892511
"0",
24902512
"--gas-limit",
24912513
"0",
24922514
"--gas-token",
24932515
NAM,
24942516
"--node",
2495-
&validator_one_rpc,
2517+
&non_validator_rpc,
24962518
];
24972519
let mut client = run!(test, Bin::Client, tx_args, Some(40))?;
24982520
client.exp_string("Transaction is valid.")?;
24992521
client.assert_success();
25002522

2523+
// Stop the non-validator node and run it as the new validator
2524+
let mut non_validator = bg_non_validator.foreground();
2525+
non_validator.interrupt()?;
2526+
2527+
// it takes a bit before the node is shutdown. We dont want flasky test.
2528+
sleep(6);
2529+
2530+
let loc = format!("{}:{}", std::file!(), std::line!());
2531+
let validator_1_base_dir = test.get_base_dir(&Who::NonValidator);
2532+
let mut validator_1 = setup::run_cmd(
2533+
Bin::Node,
2534+
args,
2535+
Some(60),
2536+
&test.working_dir,
2537+
validator_1_base_dir,
2538+
None,
2539+
loc,
2540+
)?;
2541+
2542+
validator_1.exp_string("Namada ledger node started")?;
2543+
validator_1.exp_string("This node is a validator")?;
2544+
validator_1.exp_string("Committed block hash")?;
2545+
let _bg_validator_1 = validator_1.background();
2546+
25012547
// 6. Wait for the pipeline epoch when the validator's bonded stake should
25022548
// be non-zero
2503-
let epoch = get_epoch(&test, &validator_one_rpc)?;
2549+
let epoch = get_epoch(&test, &non_validator_rpc)?;
25042550
let earliest_update_epoch = epoch + pipeline_len;
25052551
println!(
25062552
"Current epoch: {}, earliest epoch with updated bonded stake: {}",
@@ -2512,16 +2558,19 @@ fn pos_init_validator() -> Result<()> {
25122558
if Instant::now().duration_since(start) > loop_timeout {
25132559
panic!("Timed out waiting for epoch: {}", earliest_update_epoch);
25142560
}
2515-
let epoch = get_epoch(&test, &validator_one_rpc)?;
2561+
let epoch = get_epoch(&test, &non_validator_rpc)?;
25162562
if epoch >= earliest_update_epoch {
25172563
break;
25182564
}
25192565
}
25202566

25212567
// 7. Check the new validator's bonded stake
25222568
let bonded_stake =
2523-
find_bonded_stake(&test, new_validator, &validator_one_rpc)?;
2524-
assert_eq!(bonded_stake, token::Amount::from_str("11_000.5").unwrap());
2569+
find_bonded_stake(&test, new_validator, &non_validator_rpc)?;
2570+
assert_eq!(
2571+
bonded_stake,
2572+
token::Amount::whole(validator_stake + delegation)
2573+
);
25252574

25262575
Ok(())
25272576
}
@@ -3709,7 +3758,7 @@ fn test_genesis_validators() -> Result<()> {
37093758
Some(5),
37103759
&working_dir,
37113760
&test_dir,
3712-
"validator",
3761+
None,
37133762
format!("{}:{}", std::file!(), std::line!()),
37143763
)?;
37153764
init_genesis_validator_0.assert_success();
@@ -3751,7 +3800,7 @@ fn test_genesis_validators() -> Result<()> {
37513800
Some(5),
37523801
&working_dir,
37533802
&test_dir,
3754-
"validator",
3803+
None,
37553804
format!("{}:{}", std::file!(), std::line!()),
37563805
)?;
37573806
init_genesis_validator_1.assert_success();
@@ -3828,7 +3877,7 @@ fn test_genesis_validators() -> Result<()> {
38283877
Some(5),
38293878
&working_dir,
38303879
&test_dir,
3831-
"validator",
3880+
None,
38323881
format!("{}:{}", std::file!(), std::line!()),
38333882
)?;
38343883

@@ -4140,7 +4189,7 @@ fn double_signing_gets_slashed() -> Result<()> {
41404189
Some(40),
41414190
&test.working_dir,
41424191
validator_0_base_dir_copy,
4143-
"validator",
4192+
None,
41444193
loc,
41454194
)?;
41464195
validator_0_copy.exp_string("Namada ledger node started")?;

0 commit comments

Comments
 (0)