Skip to content

Commit

Permalink
Merge branch 'brent/fix-misc-pos' (#2210)
Browse files Browse the repository at this point in the history
* origin/brent/fix-misc-pos:
  fix more comments and docstrings
  edits to localnet README
  clean comments
  fix typo
  init_chain: compute consensus stake for `current_epoch` and not `default`
  add a `checked_add`
  • Loading branch information
tzemanovic committed Dec 7, 2023
2 parents 681fffb + 686c0d8 commit 6e053ef
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
14 changes: 7 additions & 7 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3091,7 +3091,7 @@ pub mod args {
pub const TRANSFER_SOURCE: Arg<WalletTransferSource> = arg("source");
pub const TRANSFER_TARGET: Arg<WalletTransferTarget> = arg("target");
pub const TX_HASH: Arg<String> = arg("tx-hash");
pub const THRESOLD: ArgOpt<u8> = arg_opt("threshold");
pub const THRESHOLD: ArgOpt<u8> = arg_opt("threshold");
pub const UNSAFE_DONT_ENCRYPT: ArgFlag = flag("unsafe-dont-encrypt");
pub const UNSAFE_SHOW_SECRET: ArgFlag = flag("unsafe-show-secret");
pub const USE_DEVICE: ArgFlag = flag("use-device");
Expand Down Expand Up @@ -4040,7 +4040,7 @@ pub mod args {
.unwrap_or_else(|| PathBuf::from(VP_USER_WASM));
let tx_code_path = PathBuf::from(TX_INIT_ACCOUNT_WASM);
let public_keys = PUBLIC_KEYS.parse(matches);
let threshold = THRESOLD.parse(matches);
let threshold = THRESHOLD.parse(matches);
Self {
tx,
vp_code_path,
Expand All @@ -4061,7 +4061,7 @@ pub mod args {
"A list public keys to be associated with the new account \
in hexadecimal encoding.",
))
.arg(THRESOLD.def().help(
.arg(THRESHOLD.def().help(
"The minimum number of signature to be provided for \
authorization. Must be less then the maximum number of \
public keys provided.",
Expand Down Expand Up @@ -4253,7 +4253,7 @@ pub mod args {
let tx_init_account_code_path = PathBuf::from(TX_INIT_ACCOUNT_WASM);
let tx_become_validator_code_path =
PathBuf::from(TX_BECOME_VALIDATOR_WASM);
let threshold = THRESOLD.parse(matches);
let threshold = THRESHOLD.parse(matches);
Self {
tx,
scheme,
Expand Down Expand Up @@ -4330,7 +4330,7 @@ pub mod args {
"UNSAFE: Do not encrypt the generated keypairs. Do not \
use this for keys used in a live network.",
))
.arg(THRESOLD.def().help(
.arg(THRESHOLD.def().help(
"The minimum number of signature to be provided for \
authorization. Must be less then the maximum number of \
public keys provided.",
Expand Down Expand Up @@ -4364,7 +4364,7 @@ pub mod args {
let addr = ADDRESS.parse(matches);
let tx_code_path = PathBuf::from(TX_UPDATE_ACCOUNT_WASM);
let public_keys = PUBLIC_KEYS.parse(matches);
let threshold = THRESOLD.parse(matches);
let threshold = THRESHOLD.parse(matches);
Self {
tx,
vp_code_path,
Expand All @@ -4390,7 +4390,7 @@ pub mod args {
"A list public keys to be associated with the new account \
in hexadecimal encoding.",
))
.arg(THRESOLD.def().help(
.arg(THRESHOLD.def().help(
"The minimum number of signature to be provided for \
authorization. Must be less then the maximum number of \
public keys provided.",
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ where

pos::namada_proof_of_stake::compute_and_store_total_consensus_stake(
&mut self.wl_storage,
Default::default(),
current_epoch,
)
.expect("Could not compute total consensus stake at genesis");
// This has to be done after `apply_genesis_txs_validator_account`
Expand Down
4 changes: 2 additions & 2 deletions genesis/localnet/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Localnet genesis templates

This directory contains genesis templates for a local network with a single validator. The `src` directory contains generated pre-genesis wallet pre-loaded with unencrypted keys and a single validator `"validator-0" wallet that are being used in the templates.
This directory contains genesis templates for a local network with a single validator. The `src` directory contains generated pre-genesis wallet pre-loaded with unencrypted keys and a single validator `validator-0` wallet that are being used in the templates.

If you're modifying any of the files here, you can run this to ensure that the changes are valid:

Expand All @@ -10,7 +10,7 @@ cargo watch -x "test test_validate_localnet_genesis_templates"

## balances.toml

The pre-genesis balances wallet is located at [pre-genesis/wallet.toml](pre-genesis/wallet.toml) was used to setup the [balances.toml](balances.toml) and can be re-generated from the repo's root dir with:
The pre-genesis balances wallet is located at [pre-genesis/wallet.toml](pre-genesis/wallet.toml) and is used to setup the [balances.toml](balances.toml) and can be re-generated from the repo's root dir with:

```shell
cargo run --bin namadaw -- --base-dir "genesis/localnet/src" key gen \
Expand Down
12 changes: 6 additions & 6 deletions proof_of_stake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ where
}

/// Copies the validator sets into all epochs up through the pipeline epoch at
/// genesis. Also computes the total
/// genesis.
pub fn copy_genesis_validator_sets<S>(
storage: &mut S,
params: &OwnedPosParams,
Expand All @@ -335,7 +335,6 @@ where
current_epoch,
epoch,
)?;
// compute_and_store_total_consensus_stake(storage, epoch)?;
}
Ok(())
}
Expand Down Expand Up @@ -1019,8 +1018,6 @@ where

let tokens_pre = read_validator_stake(storage, params, validator, epoch)?;

// tracing::debug!("VALIDATOR STAKE BEFORE UPDATE: {}", tokens_pre);

let tokens_post = tokens_pre
.change()
.checked_add(&token_change)
Expand Down Expand Up @@ -1548,7 +1545,6 @@ where
S: StorageRead,
{
let handle = validator_set_positions_handle();
// handle.get_position(storage, &epoch, validator, params)
handle.get_data_handler().at(&epoch).get(storage, validator)
}

Expand Down Expand Up @@ -4500,7 +4496,11 @@ where
Ok(())
}

/// Process slashes NEW
/// Process enqueued slashes that were discovered earlier. This function is
/// called upon a new epoch. The final slash rate considering according to the
/// cubic slashing rate is computed. Then, each slash is recorded in storage
/// along with its computed rate, and stake is deducted from the affected
/// validators.
pub fn process_slashes<S>(
storage: &mut S,
current_epoch: Epoch,
Expand Down
3 changes: 2 additions & 1 deletion proof_of_stake/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ impl PosRewardsCalculator {
.total_stake
.checked_mul(2.into())
.expect("Amount overflow while computing minimum required votes")
+ (3u64 - 1u64))
.checked_add((3u64 - 1u64).into())
.expect("Amount overflow while computing minimum required votes"))
/ 3u64
}
}

0 comments on commit 6e053ef

Please sign in to comment.