Skip to content

Commit 0d25e5f

Browse files
committed
refactor: expand StakeRewardDelta with pool field
Signed-off-by: William Hankins <[email protected]>
1 parent 262a5e3 commit 0d25e5f

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

common/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ pub struct StakeRewardDelta {
214214
pub stake_address: StakeAddress,
215215
pub delta: u64,
216216
pub reward_type: RewardType,
217+
pub pool: PoolId,
217218
}
218219

219220
/// Type of reward being given

modules/accounts_state/src/rewards.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Acropolis AccountsState: rewards calculations
22
33
use crate::snapshot::{Snapshot, SnapshotSPO};
4-
use acropolis_common::RewardType;
54
use acropolis_common::{
65
protocol_params::ShelleyParams, rational_number::RationalNumber, KeyHash, Lovelace, SPORewards,
76
StakeAddress,
87
};
8+
use acropolis_common::{PoolId, RewardType};
99
use anyhow::{bail, Result};
1010
use bigdecimal::{BigDecimal, One, ToPrimitive, Zero};
1111
use std::cmp::min;
@@ -25,6 +25,9 @@ pub struct RewardDetail {
2525

2626
/// Reward amount
2727
pub amount: Lovelace,
28+
29+
// Pool that reward came from
30+
pub pool: PoolId,
2831
}
2932

3033
/// Result of a rewards calculation
@@ -386,6 +389,7 @@ fn calculate_spo_rewards(
386389
account: delegator_stake_address.clone(),
387390
rtype: RewardType::Member,
388391
amount: to_pay,
392+
pool: operator_id.to_vec(),
389393
});
390394
total_paid += to_pay;
391395
delegators_paid += 1;
@@ -403,6 +407,7 @@ fn calculate_spo_rewards(
403407
account: spo.reward_account.clone(),
404408
rtype: RewardType::Leader,
405409
amount: spo_benefit,
410+
pool: operator_id.to_vec(),
406411
});
407412
} else {
408413
info!(

modules/accounts_state/src/state.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ use acropolis_common::{
1515
protocol_params::ProtocolParams,
1616
stake_addresses::{StakeAddressMap, StakeAddressState},
1717
BlockInfo, DRepChoice, DRepCredential, DelegatedStake, InstantaneousRewardSource,
18-
InstantaneousRewardTarget, KeyHash, Lovelace, MoveInstantaneousReward, PoolLiveStakeInfo,
19-
PoolRegistration, Pot, SPORewards, StakeAddress, StakeRewardDelta, TxCertificate,
18+
InstantaneousRewardTarget, KeyHash, Lovelace, MoveInstantaneousReward, PoolId,
19+
PoolLiveStakeInfo, PoolRegistration, Pot, SPORewards, StakeAddress, StakeRewardDelta,
20+
TxCertificate,
2021
};
2122
use anyhow::Result;
2223
use imbl::OrdMap;
@@ -115,7 +116,7 @@ pub struct State {
115116
previous_protocol_parameters: Option<ProtocolParams>,
116117

117118
/// Pool refunds to apply next epoch (list of reward accounts to refund to)
118-
pool_refunds: Vec<StakeAddress>,
119+
pool_refunds: Vec<(PoolId, StakeAddress)>,
119120

120121
/// Addresses registration changes in current epoch
121122
current_epoch_registration_changes: Arc<Mutex<Vec<RegistrationChange>>>,
@@ -466,14 +467,15 @@ impl State {
466467
}
467468

468469
// Send them their deposits back
469-
for stake_address in refunds {
470+
for (pool, stake_address) in refunds {
470471
// If their reward account has been deregistered, it goes to Treasury
471472
let mut stake_addresses = self.stake_addresses.lock().unwrap();
472473
if stake_addresses.is_registered(&stake_address) {
473474
reward_deltas.push(StakeRewardDelta {
474475
stake_address: stake_address.clone(),
475476
delta: deposit,
476477
reward_type: RewardType::PoolRefund,
478+
pool,
477479
});
478480
stake_addresses.add_to_reward(&stake_address, deposit);
479481
} else {
@@ -622,6 +624,7 @@ impl State {
622624
stake_address: reward.account.clone(),
623625
delta: reward.amount,
624626
reward_type: reward.rtype.clone(),
627+
pool: reward.pool.clone(),
625628
})
626629
.collect::<Vec<_>>(),
627630
);
@@ -736,7 +739,11 @@ impl State {
736739
hex::encode(id),
737740
retired_spo.reward_account
738741
);
739-
self.pool_refunds.push(retired_spo.reward_account.clone()); // Store full StakeAddress
742+
self.pool_refunds.push((
743+
retired_spo.operator.clone(),
744+
retired_spo.reward_account.clone(),
745+
));
746+
// Store full StakeAddress
740747
}
741748

742749
// Schedule to retire - we need them to still be in place when we count

modules/accounts_state/src/verifier.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,11 @@ impl Verifier {
166166
continue;
167167
};
168168

169-
expected_rewards.entry(spo).or_default().push(RewardDetail {
169+
expected_rewards.entry(spo.clone()).or_default().push(RewardDetail {
170170
account: stake_address,
171171
rtype,
172172
amount,
173+
pool: spo,
173174
});
174175
}
175176

modules/historical_accounts_state/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl State {
111111
let update = RewardHistory {
112112
epoch,
113113
amount: reward.delta,
114-
pool: Vec::new(),
114+
pool: reward.pool.clone(),
115115
reward_type: reward.reward_type.clone(),
116116
};
117117
entry.reward_history.get_or_insert_with(Vec::new).push(update);

0 commit comments

Comments
 (0)