Skip to content

Commit dc38a71

Browse files
committed
Refactor: Replace KeyHash with PoolId for verifier.rs
1 parent 68a5d59 commit dc38a71

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

modules/accounts_state/src/rewards.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
33
use crate::snapshot::{Snapshot, SnapshotSPO};
44
use acropolis_common::{
5-
protocol_params::ShelleyParams, rational_number::RationalNumber, Lovelace, PoolId, SPORewards,
6-
StakeAddress,
5+
protocol_params::ShelleyParams, rational_number::RationalNumber, Lovelace, PoolId, RewardType,
6+
SPORewards, StakeAddress,
77
};
8-
use acropolis_common::{PoolId, RewardType};
98
use anyhow::{bail, Result};
109
use bigdecimal::{BigDecimal, One, ToPrimitive, Zero};
1110
use std::cmp::min;
@@ -389,7 +388,7 @@ fn calculate_spo_rewards(
389388
account: delegator_stake_address.clone(),
390389
rtype: RewardType::Member,
391390
amount: to_pay,
392-
pool: operator_id.to_vec(),
391+
pool: *operator_id,
393392
});
394393
total_paid += to_pay;
395394
delegators_paid += 1;
@@ -407,7 +406,7 @@ fn calculate_spo_rewards(
407406
account: spo.reward_account.clone(),
408407
rtype: RewardType::Leader,
409408
amount: spo_benefit,
410-
pool: operator_id.to_vec(),
409+
pool: *operator_id,
411410
});
412411
} else {
413412
info!(

modules/accounts_state/src/verifier.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Verification of calculated values against captured CSV from Haskell node / DBSync
22
use crate::rewards::{RewardDetail, RewardsResult};
33
use crate::state::Pots;
4-
use acropolis_common::{KeyHash, RewardType, StakeAddress};
4+
use acropolis_common::{PoolId, RewardType, StakeAddress};
55
use hex::FromHex;
66
use itertools::EitherOrBoth::{Both, Left, Right};
77
use itertools::Itertools;
@@ -131,7 +131,7 @@ impl Verifier {
131131
};
132132

133133
// Expect CSV header: spo,address,type,amount
134-
let mut expected_rewards: BTreeMap<KeyHash, Vec<RewardDetail>> = BTreeMap::new();
134+
let mut expected_rewards: BTreeMap<PoolId, Vec<RewardDetail>> = BTreeMap::new();
135135
for result in reader.deserialize() {
136136
let (spo, address, rtype, amount): (String, String, String, u64) = match result {
137137
Ok(row) => row,
@@ -141,10 +141,13 @@ impl Verifier {
141141
}
142142
};
143143

144-
let Ok(spo) = Vec::from_hex(&spo) else {
145-
error!("Bad hex in {path} for SPO: {spo} - skipping");
144+
let Some(spo) =
145+
Vec::from_hex(&spo).ok().and_then(|bytes| PoolId::try_from(bytes).ok())
146+
else {
147+
error!("Bad hex/SPO in {path} for SPO: {spo} - skipping");
146148
continue;
147149
};
150+
148151
let Ok(account) = Vec::from_hex(&address) else {
149152
error!("Bad hex in {path} for address: {address} - skipping");
150153
continue;
@@ -167,7 +170,7 @@ impl Verifier {
167170
continue;
168171
};
169172

170-
expected_rewards.entry(spo.clone()).or_default().push(RewardDetail {
173+
expected_rewards.entry(spo).or_default().push(RewardDetail {
171174
account: stake_address,
172175
rtype,
173176
amount,

modules/historical_accounts_state/src/immutable_historical_account_store.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ impl ImmutableHistoricalAccountStore {
153153
&self,
154154
account: &StakeAddress,
155155
) -> Result<Option<Vec<AccountReward>>> {
156-
let mut immutable_rewards =
157-
self.collect_partition::<AccountReward>(&self.rewards_history, account.get_hash())?;
156+
let mut immutable_rewards = self.collect_partition::<AccountReward>(
157+
&self.rewards_history,
158+
account.get_hash().as_ref(),
159+
)?;
158160

159161
self.merge_pending(
160162
account,

0 commit comments

Comments
 (0)