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

Update TendermintMode in Namada config for new post-genesis validator #1549

Merged
merged 28 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
022c61a
pos: fix is_validator to be epoch agnostic
tzemanovic Jun 13, 2023
6cfee90
test/pos: check is_validator for a new validator
tzemanovic Jun 13, 2023
5ae25fb
[ci] wasm checksums update
github-actions[bot] Jun 13, 2023
3be1d72
changelog: add #1553
tzemanovic Jun 13, 2023
b46bd1b
update TendermintMode in Namada config for new post-genesis validator
brentstone Jun 12, 2023
a3ff0d4
fix: remove invalid condition around prepare-proposal
Fraccaman Jun 13, 2023
b18f1c0
test/e2e/pos_init_validator: ensure that node after init-validator works
tzemanovic Jun 13, 2023
000e72d
changelog: add #1549
tzemanovic Jun 13, 2023
cecb22f
update TendermintMode in Namada config for new post-genesis validator
brentstone Jun 12, 2023
7a2ebf7
fix: remove invalid condition around prepare-proposal
Fraccaman Jun 13, 2023
79ae826
core/storage: Store last committed block's hash and time with its height
tzemanovic Jun 12, 2023
9efa19c
shared/queries/shell: expose the last committed block from storage
tzemanovic Jun 12, 2023
8afdf28
core/time: impl Display for DateTimeUtc
tzemanovic Jun 12, 2023
b88ccfd
core/storage: impl Display for BlockHash
tzemanovic Jun 12, 2023
77cba8e
rpc: use the new shell last_block query to find last committed block
tzemanovic Jun 12, 2023
6e458cf
test/e2e/ledger/genesis_validators: validator wait for tx block height
tzemanovic Jun 12, 2023
93df661
test/storage: fill-in block header for commit if missing
tzemanovic Jun 12, 2023
45379a2
[ci] wasm checksums update
github-actions[bot] Jun 12, 2023
cf48f70
changelog: add #1534
tzemanovic Jun 12, 2023
a804265
Namada 0.17.1
Fraccaman Jun 12, 2023
0f17566
pos: fix is_validator to be epoch agnostic
tzemanovic Jun 13, 2023
26c2681
test/pos: check is_validator for a new validator
tzemanovic Jun 13, 2023
e957027
[ci] wasm checksums update
github-actions[bot] Jun 13, 2023
da62169
changelog: add #1553
tzemanovic Jun 13, 2023
1c1a910
test/e2e/pos_init_validator: ensure that node after init-validator works
tzemanovic Jun 13, 2023
7bacbba
changelog: add #1549
tzemanovic Jun 13, 2023
a546c4e
Merge branch 'brent/fix-init-validator-tendermint-mode' of https://gi…
Fraccaman Jun 14, 2023
2a066d7
client: mention to restart the node after init validator
Fraccaman Jun 14, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- PoS: Fixed the client to change configuration to validator
mode after a successful `init-validator` transaction.
([\#1549](https://github.com/anoma/namada/pull/1549))
3 changes: 3 additions & 0 deletions .changelog/unreleased/bug-fixes/1553-fix-is-validator-fn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- PoS: fixed a check for whether a given address belongs to a
validator account to work properly with newly created accounts.
([\#1553](https://github.com/anoma/namada/pull/1553))
26 changes: 25 additions & 1 deletion apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use namada::ledger::governance::storage as gov_storage;
use namada::ledger::rpc::{TxBroadcastData, TxResponse};
use namada::ledger::signing::TxSigningKey;
use namada::ledger::wallet::{Wallet, WalletUtils};
use namada::ledger::{masp, tx};
use namada::ledger::{masp, pos, tx};
use namada::proof_of_stake::parameters::PosParams;
use namada::proto::{Code, Data, Section, Tx};
use namada::types::address::Address;
use namada::types::governance::{
Expand All @@ -39,6 +40,7 @@ use crate::cli::{args, safe_exit, Context};
use crate::client::rpc::query_wasm_code_hash;
use crate::client::signing::find_keypair;
use crate::client::tx::tx::ProcessTxResponse;
use crate::config::TendermintMode;
use crate::facade::tendermint_rpc::endpoint::broadcast::tx_sync::Response;
use crate::node::ledger::tendermint_node;
use crate::wallet::{
Expand Down Expand Up @@ -292,6 +294,23 @@ pub async fn submit_init_validator<
tendermint_node::write_validator_key(&tendermint_home, &consensus_key);
tendermint_node::write_validator_state(tendermint_home);

// Write Namada config stuff or figure out how to do the above
// tendermint_node things two epochs in the future!!!
ctx.config.ledger.tendermint.tendermint_mode =
TendermintMode::Validator;
ctx.config
.write(
&ctx.config.ledger.shell.base_dir,
&ctx.config.ledger.chain_id,
true,
)
.unwrap();

let key = pos::params_key();
let pos_params = rpc::query_storage_value::<C, PosParams>(client, &key)
.await
.expect("Pos parameter should be defined.");

println!();
println!(
"The validator's addresses and keys were stored in the wallet:"
Expand All @@ -303,6 +322,11 @@ pub async fn submit_init_validator<
"The ledger node has been setup to use this validator's address \
and consensus key."
);
println!(
"Your validator will be active in {} epochs. Be sure to restart \
your node for the changes to take effect!",
pos_params.pipeline_len
);
} else {
println!("Transaction dry run. No addresses have been saved.")
}
Expand Down
55 changes: 24 additions & 31 deletions apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::facade::tendermint_proto::abci::RequestPrepareProposal;
#[cfg(feature = "abcipp")]
use crate::facade::tendermint_proto::abci::{tx_record::TxAction, TxRecord};
use crate::facade::tendermint_proto::google::protobuf::Timestamp;
use crate::node::ledger::shell::ShellMode;
use crate::node::ledger::shims::abcipp_shim_types::shim::{response, TxBytes};

impl<D, H> Shell<D, H>
Expand All @@ -45,36 +44,30 @@ where
&self,
req: RequestPrepareProposal,
) -> response::PrepareProposal {
let txs = if let ShellMode::Validator { .. } = self.mode {
// start counting allotted space for txs
let alloc = self.get_encrypted_txs_allocator();
// add encrypted txs
let (encrypted_txs, alloc) = self.build_encrypted_txs(
alloc,
TempWlStorage::new(&self.wl_storage.storage),
&req.txs,
&req.time,
);
let mut txs = encrypted_txs;

// decrypt the wrapper txs included in the previous block
let (mut decrypted_txs, alloc) = self.build_decrypted_txs(alloc);
txs.append(&mut decrypted_txs);

// add vote extension protocol txs
let mut protocol_txs = self.build_protocol_txs(
alloc,
#[cfg(feature = "abcipp")]
req.local_last_commit,
#[cfg(not(feature = "abcipp"))]
&req.txs,
);
txs.append(&mut protocol_txs);

txs
} else {
vec![]
};
// start counting allotted space for txs
let alloc = self.get_encrypted_txs_allocator();
// add encrypted txs
let (encrypted_txs, alloc) = self.build_encrypted_txs(
alloc,
TempWlStorage::new(&self.wl_storage.storage),
&req.txs,
&req.time,
);
let mut txs = encrypted_txs;

// decrypt the wrapper txs included in the previous block
let (mut decrypted_txs, alloc) = self.build_decrypted_txs(alloc);
txs.append(&mut decrypted_txs);

// add vote extension protocol txs
let mut protocol_txs = self.build_protocol_txs(
alloc,
#[cfg(feature = "abcipp")]
req.local_last_commit,
#[cfg(not(feature = "abcipp"))]
&req.txs,
);
txs.append(&mut protocol_txs);

tracing::info!(
height = req.height,
Expand Down
16 changes: 5 additions & 11 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,14 +808,12 @@ where
pub fn is_validator<S>(
storage: &S,
address: &Address,
params: &PosParams,
epoch: namada_core::types::storage::Epoch,
) -> storage_api::Result<bool>
where
S: StorageRead + StorageWrite,
{
let state = validator_state_handle(address).get(storage, epoch, params)?;
Ok(state.is_some())
let rate = read_validator_max_commission_rate_change(storage, address)?;
Ok(rate.is_some())
}

/// Check if the provided address is a delegator address, optionally at a
Expand Down Expand Up @@ -868,9 +866,7 @@ where
let params = read_pos_params(storage)?;
let pipeline_epoch = current_epoch + params.pipeline_len;
if let Some(source) = source {
if source != validator
&& is_validator(storage, source, &params, pipeline_epoch)?
{
if source != validator && is_validator(storage, source)? {
return Err(
BondError::SourceMustNotBeAValidator(source.clone()).into()
);
Expand Down Expand Up @@ -1534,16 +1530,14 @@ where

// Make sure source is not some other validator
if let Some(source) = source {
if source != validator
&& is_validator(storage, source, &params, pipeline_epoch)?
{
if source != validator && is_validator(storage, source)? {
return Err(
BondError::SourceMustNotBeAValidator(source.clone()).into()
);
}
}
// Make sure the target is actually a validator
if !is_validator(storage, validator, &params, pipeline_epoch)? {
if !is_validator(storage, validator)? {
return Err(BondError::NotAValidator(validator.clone()).into());
}
// Make sure the validator is not currently frozen
Expand Down
4 changes: 3 additions & 1 deletion proof_of_stake/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::{
bond_tokens, bonds_and_unbonds, consensus_validator_set_handle,
copy_validator_sets_and_positions, find_validator_by_raw_hash,
get_num_consensus_validators, init_genesis,
insert_validator_into_validator_set, process_slashes,
insert_validator_into_validator_set, is_validator, process_slashes,
read_below_capacity_validator_set_addresses_with_stake,
read_consensus_validator_set_addresses_with_stake, read_total_stake,
read_validator_delta_value, read_validator_stake, slash,
Expand Down Expand Up @@ -789,6 +789,7 @@ fn test_become_validator_aux(
min(validators.len() as u64, params.max_validator_slots),
num_consensus_before
);
assert!(!is_validator(&s, &new_validator).unwrap());

// Initialize the validator account
let consensus_key = new_validator_consensus_key.to_public();
Expand All @@ -802,6 +803,7 @@ fn test_become_validator_aux(
Decimal::new(5, 2),
)
.unwrap();
assert!(is_validator(&s, &new_validator).unwrap());

let num_consensus_after =
get_num_consensus_validators(&s, current_epoch + params.pipeline_len)
Expand Down
8 changes: 1 addition & 7 deletions proof_of_stake/src/tests/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,7 @@ impl StateMachineTest for ConcretePosState {
// This must be ensured by both transitions generator and
// pre-conditions!
assert!(
crate::is_validator(
&state.s,
&id.validator,
&params,
pipeline,
)
.unwrap(),
crate::is_validator(&state.s, &id.validator).unwrap(),
"{} is not a validator",
id.validator
);
Expand Down
8 changes: 1 addition & 7 deletions shared/src/ledger/queries/vp/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ where
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
{
let params = namada_proof_of_stake::read_pos_params(ctx.wl_storage)?;
namada_proof_of_stake::is_validator(
ctx.wl_storage,
&addr,
&params,
ctx.wl_storage.storage.block.epoch,
)
namada_proof_of_stake::is_validator(ctx.wl_storage, &addr)
}

/// Find if the given address is a delegator
Expand Down
Loading