Skip to content

Commit

Permalink
read total active stake (exclude jailed + inactive)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Mar 6, 2024
1 parent d01850e commit f40e225
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
18 changes: 11 additions & 7 deletions crates/apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ use namada::governance::{
};
use namada::ibc;
use namada::ledger::governance::utils::ProposalEvent;
use namada::ledger::pos::{validator_state_handle, BondId};
use namada::proof_of_stake::bond_amount;
use namada::proof_of_stake::parameters::PosParams;
use namada::proof_of_stake::storage::read_total_stake;
use namada::proof_of_stake::types::ValidatorState;
use namada::proof_of_stake::storage::{
read_total_active_stake, validator_state_handle,
};
use namada::proof_of_stake::types::{BondId, ValidatorState};
use namada::state::StorageWrite;
use namada::tx::{Code, Data};
use namada_sdk::proof_of_stake::storage::read_validator_stake;
Expand Down Expand Up @@ -79,8 +80,8 @@ where
let is_steward = pgf::is_steward(&shell.state, &proposal_author)?;

let params = read_pos_params(&shell.state)?;
let total_voting_power =
read_total_stake(&shell.state, &params, proposal_end_epoch)?;
let total_active_voting_power =
read_total_active_stake(&shell.state, &params, proposal_end_epoch)?;

let tally_type = TallyType::from(proposal_type.clone(), is_steward);
let votes = compute_proposal_votes(
Expand All @@ -89,8 +90,11 @@ where
id,
proposal_end_epoch,
)?;
let proposal_result =
compute_proposal_result(votes, total_voting_power, tally_type);
let proposal_result = compute_proposal_result(
votes,
total_active_voting_power,
tally_type,
);
gov_api::write_proposal_result(&mut shell.state, id, proposal_result)?;

let transfer_address = match proposal_result.result {
Expand Down
20 changes: 20 additions & 0 deletions crates/proof_of_stake/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,26 @@ where
Ok(amnt)
}

/// Read PoS total stake (sum of deltas).
pub fn read_total_active_stake<S>(
storage: &S,
params: &PosParams,
epoch: namada_core::storage::Epoch,
) -> namada_storage::Result<token::Amount>
where
S: StorageRead,
{
let handle = total_active_voting_power_handle();
let amnt = handle
.get_sum(storage, epoch, params)?
.map(|change| {
debug_assert!(change.non_negative());
token::Amount::from_change(change)
})
.unwrap_or_default();
Ok(amnt)
}

/// Read all addresses from consensus validator set.
pub fn read_consensus_validator_set_addresses<S>(
storage: &S,
Expand Down

0 comments on commit f40e225

Please sign in to comment.