diff --git a/contracts/hydro/src/lsm_integration.rs b/contracts/hydro/src/lsm_integration.rs index b5bbdfe..edf9caf 100644 --- a/contracts/hydro/src/lsm_integration.rs +++ b/contracts/hydro/src/lsm_integration.rs @@ -82,6 +82,7 @@ pub fn get_round_validators(storage: &dyn Storage, round_id: u64) -> Vec VALIDATORS_INFO .prefix(round_id) .range(storage, None, None, Order::Ascending) + .filter(|val_res| val_res.is_ok()) .map(|val_res| { let val = val_res.unwrap(); val.0 diff --git a/contracts/hydro/src/score_keeper.rs b/contracts/hydro/src/score_keeper.rs index a8909b4..8f692e1 100644 --- a/contracts/hydro/src/score_keeper.rs +++ b/contracts/hydro/src/score_keeper.rs @@ -1,19 +1,10 @@ use cosmwasm_std::{Decimal, StdError, StdResult, Storage}; use cw_storage_plus::Map; -use crate::lsm_integration::get_validator_power_ratio_for_round; - -// The score keeper is a module that keeps track of amounts of individual validator shares, and power ratios (i.e. how many -// tokens a share of a validator represents). It stores the shares and power ratios for each validator in separate maps, -// and keeps those up-to-date with the total power (computed by multiplying the individual shares with the power ratio). -// The total is updated when either the shares or the power ratio of a validator is updated. - -// SCALED_PROPOSAL_SHARES_MAP: key(proposal_id, validator_address) -> number_of_shares -const SCALED_PROPOSAL_SHARES_MAP: Map<(u64, String), Decimal> = - Map::new("scaled_proposal_power_shares"); - -// PROPOSAL_TOTAL_MAP: key(proposal_id) -> total_power -const PROPOSAL_TOTAL_MAP: Map = Map::new("proposal_power_total"); +use crate::{ + lsm_integration::get_validator_power_ratio_for_round, + state::{PROPOSAL_TOTAL_MAP, SCALED_PROPOSAL_SHARES_MAP}, +}; pub fn get_total_power_for_proposal(storage: &dyn Storage, prop_id: u64) -> StdResult { Ok(PROPOSAL_TOTAL_MAP diff --git a/contracts/hydro/src/state.rs b/contracts/hydro/src/state.rs index 22ebf75..ab9f657 100644 --- a/contracts/hydro/src/state.rs +++ b/contracts/hydro/src/state.rs @@ -115,6 +115,19 @@ pub const VALIDATORS_INFO: Map<(u64, String), ValidatorInfo> = Map::new("validat pub const SCALED_ROUND_POWER_SHARES_MAP: Map<(u64, String), Decimal> = Map::new("scaled_round_power_shares"); +// The following two store fields are supposed to be kept in sync, +// i.e. whenever the shares of a proposal (or the power ratio of a validator) +// get updated, the total power of the proposal should be updated as well. +// For each proposal and validator, it stores the time-scaled number of shares of that validator +// that voted for the proposal. +// SCALED_PROPOSAL_SHARES_MAP: key(proposal_id, validator_address) -> number_of_shares +pub const SCALED_PROPOSAL_SHARES_MAP: Map<(u64, String), Decimal> = + Map::new("scaled_proposal_power_shares"); + +// Stores the total power for each proposal. +// PROPOSAL_TOTAL_MAP: key(proposal_id) -> total_power +pub const PROPOSAL_TOTAL_MAP: Map = Map::new("proposal_power_total"); + #[cw_serde] #[derive(Default)] pub struct ValidatorInfo {