Skip to content

Commit a8d48d4

Browse files
authored
Merge pull request #513 from input-output-hk/prc/spdd-216-fix
Fix SPDD for epoch 216/217
2 parents 86740af + 3672bec commit a8d48d4

File tree

7 files changed

+154427
-18
lines changed

7 files changed

+154427
-18
lines changed

common/src/messages.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Definition of Acropolis messages
22
3+
use crate::address::StakeAddress;
34
use crate::commands::chain_sync::ChainSyncCommand;
45
use crate::commands::transactions::{TransactionsCommand, TransactionsCommandResponse};
56
use crate::genesis_values::GenesisValues;
@@ -304,7 +305,8 @@ pub struct SPOStateMessage {
304305
pub spos: Vec<PoolRegistration>,
305306

306307
/// SPOs in the above list which retired at the start of this epoch, by operator ID
307-
pub retired_spos: Vec<PoolId>,
308+
/// and the reward account to pay the deposit refund to
309+
pub retired_spos: Vec<(PoolId, StakeAddress)>,
308310
}
309311

310312
/// Cardano message enum

modules/accounts_state/src/state.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -815,15 +815,12 @@ impl State {
815815

816816
// Check for any SPOs that have retired this epoch and need deposit refunds
817817
self.pool_refunds = Vec::new();
818-
for id in &spo_msg.retired_spos {
819-
if let Some(retired_spo) = new_spos.get(id) {
820-
debug!(
821-
"SPO {} has retired - refunding their deposit to {}",
822-
id, retired_spo.reward_account
823-
);
824-
self.pool_refunds.push((retired_spo.operator, retired_spo.reward_account.clone()));
825-
// Store full StakeAddress
826-
}
818+
for (id, reward_account) in &spo_msg.retired_spos {
819+
debug!(
820+
"SPO {} has retired - refunding their deposit to {}",
821+
id, reward_account
822+
);
823+
self.pool_refunds.push((*id, reward_account.clone()));
827824

828825
// Schedule to retire - we need them to still be in place when we count
829826
// blocks for the previous epoch

modules/accounts_state/test-data/rewards.mainnet.219.csv

Lines changed: 49480 additions & 0 deletions
Large diffs are not rendered by default.

modules/accounts_state/test-data/rewards.mainnet.220.csv

Lines changed: 51426 additions & 0 deletions
Large diffs are not rendered by default.

modules/accounts_state/test-data/rewards.mainnet.221.csv

Lines changed: 53503 additions & 0 deletions
Large diffs are not rendered by default.

modules/spo_state/src/spo_state.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ impl SPOState {
270270
CardanoMessage::SPOState(SPOStateMessage { retired_spos, .. }),
271271
)) = message.as_ref()
272272
{
273-
retired_pools_history
274-
.handle_deregistrations(block_info, retired_spos);
273+
let pool_ids: Vec<PoolId> =
274+
retired_spos.iter().map(|(spo, _sa)| *spo).collect();
275+
retired_pools_history.handle_deregistrations(block_info, &pool_ids);
275276
}
276277

277278
// publish spo message

modules/spo_state/src/state.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,26 +273,26 @@ impl State {
273273
debug!(epoch = self.epoch, "New epoch");
274274

275275
// Flatten into vector of registrations, before retirement so retiring ones
276-
// are still included
276+
// are still included **
277277
let spos = self.spos.values().cloned().collect();
278278

279-
// Update any pending
279+
// Now apply it fully to persistent state, including creating new ones
280280
for (operator, reg) in &self.pending_updates {
281281
self.spos.insert(*operator, reg.clone());
282282
}
283283
self.pending_updates.clear();
284284

285285
// Deregister any pending
286-
let mut retired_spos: Vec<PoolId> = Vec::new();
286+
let mut retired_spos: Vec<(PoolId, StakeAddress)> = Vec::new();
287287
let deregistrations = self.pending_deregistrations.remove(&self.epoch);
288288
if let Some(deregistrations) = deregistrations {
289289
for dr in deregistrations {
290290
debug!("Retiring SPO {}", dr);
291291
match self.spos.remove(&dr) {
292292
None => vld
293293
.push_anyhow(anyhow!("Retirement requested for unregistered SPO {}", dr,)),
294-
Some(_de_reg) => {
295-
retired_spos.push(dr);
294+
Some(de_reg) => {
295+
retired_spos.push((dr, de_reg.reward_account.clone()));
296296
}
297297
};
298298
}
@@ -302,7 +302,7 @@ impl State {
302302
block.clone(),
303303
CardanoMessage::SPOState(SPOStateMessage {
304304
epoch: block.epoch - 1,
305-
spos,
305+
spos, // Note - list captured at ** before creation and deletion
306306
retired_spos,
307307
}),
308308
)))

0 commit comments

Comments
 (0)