Skip to content

Commit 465b906

Browse files
authored
Merge pull request #310 from input-output-hk/prc/303-missing-spo-rewards
Force networkId on pool reward accounts
2 parents f11dfa6 + 3421f79 commit 465b906

File tree

7 files changed

+43
-9
lines changed

7 files changed

+43
-9
lines changed

codec/src/map_parameters.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,14 @@ pub fn map_certificate(
376376
numerator: margin.numerator,
377377
denominator: margin.denominator,
378378
},
379-
reward_account: StakeAddress::from_binary(reward_account)?,
379+
// Force networkId - in mainnet epoch 208, one SPO (c63dab6d780a) uses
380+
// an e0 (testnet!) address, and this then fails to match their actual
381+
// reward account (e1). Feels like this should have been
382+
// a validation failure, but clearly wasn't!
383+
reward_account: StakeAddress::new(
384+
StakeAddress::from_binary(reward_account)?.credential,
385+
network_id.clone(),
386+
),
380387
pool_owners: pool_owners
381388
.into_iter()
382389
.map(|v| {

common/src/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl StakeAddress {
484484

485485
impl Display for StakeAddress {
486486
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
487-
write!(f, "{}", hex::encode(self.get_credential().get_hash()))
487+
write!(f, "{}", hex::encode(self.to_binary()))
488488
}
489489
}
490490

modules/accounts_state/src/rewards.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pub struct RewardsResult {
5252
/// Calculate rewards for a given epoch based on current rewards state and protocol parameters
5353
/// The epoch is the one that has just ended - we assume the snapshot for this has already been
5454
/// taken.
55+
/// Registrations/deregistrations are net changes between 'staking' and 'performance' snapshots
5556
/// Note immutable - only state change allowed is to push a new snapshot
5657
pub fn calculate_rewards(
5758
epoch: u64,
@@ -130,10 +131,21 @@ pub fn calculate_rewards(
130131
// Also, to handle the early Shelley timing bug, we allow it if it was registered
131132
// during the current epoch
132133
if !pay_to_pool_reward_account {
133-
debug!("Checking old reward account {}", staking_spo.reward_account);
134+
debug!(
135+
"Checking old reward account {} for late registration",
136+
staking_spo.reward_account
137+
);
134138

135139
// Note we use the staking reward account - it could have changed
136140
pay_to_pool_reward_account = registrations.contains(&staking_spo.reward_account);
141+
142+
if pay_to_pool_reward_account {
143+
info!(
144+
"SPO {}'s reward account {} was registered in this epoch",
145+
hex::encode(operator_id),
146+
staking_spo.reward_account
147+
);
148+
}
137149
}
138150

139151
// There was a bug in the original node from Shelley until Allegra where if multiple SPOs
@@ -161,7 +173,7 @@ pub fn calculate_rewards(
161173
}
162174
} else {
163175
info!(
164-
"Reward account for SPO {} was deregistered",
176+
"Reward account for SPO {} isn't registered",
165177
hex::encode(operator_id)
166178
)
167179
}

modules/accounts_state/src/snapshot.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub struct Snapshot {
6060
}
6161

6262
impl Snapshot {
63-
/// Get a stake snapshot based the current stake addresses
63+
/// Get a stake snapshot based on the current stake addresses
6464
#[allow(clippy::too_many_arguments)]
6565
pub fn new(
6666
epoch: u64,
@@ -95,6 +95,13 @@ impl Snapshot {
9595
.unwrap_or(false),
9696
None => false,
9797
};
98+
debug!(
99+
epoch,
100+
previous_epoch = two_previous_snapshot.epoch,
101+
"Two previous reward account for SPO {} registered: {}",
102+
hex::encode(spo_id),
103+
two_previous_reward_account_is_registered
104+
);
98105

99106
// Add the new one
100107
snapshot.spos.insert(
@@ -128,7 +135,7 @@ impl Snapshot {
128135
// SPO has retired - this stake is simply ignored
129136
debug!(
130137
epoch,
131-
"SPO {} for hash {} retired? Ignored",
138+
"SPO {} for stake address {} retired? Ignored",
132139
hex::encode(spo_id),
133140
stake_address
134141
);

modules/accounts_state/src/state.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ impl State {
385385
);
386386

387387
if tracing::enabled!(Level::DEBUG) {
388-
registrations.iter().for_each(|addr| debug!("Registration {}", addr));
389-
deregistrations.iter().for_each(|addr| debug!("Deregistration {}", addr));
388+
registrations.iter().for_each(|addr| debug!(epoch, "Registration {}", addr));
389+
deregistrations.iter().for_each(|addr| debug!(epoch, "Deregistration {}", addr));
390390
}
391391

392392
// Calculate reward payouts for previous epoch
@@ -734,12 +734,14 @@ impl State {
734734
if spo.pledge != old_spo.pledge
735735
|| spo.cost != old_spo.cost
736736
|| spo.margin != old_spo.margin
737+
|| spo.reward_account != old_spo.reward_account
737738
{
738739
debug!(
739740
epoch = spo_msg.epoch,
740741
pledge = spo.pledge,
741742
cost = spo.cost,
742743
margin = ?spo.margin,
744+
reward = %spo.reward_account,
743745
"Updated parameters for SPO {}",
744746
hex::encode(id)
745747
);
@@ -752,6 +754,7 @@ impl State {
752754
pledge = spo.pledge,
753755
cost = spo.cost,
754756
margin = ?spo.margin,
757+
reward = %spo.reward_account,
755758
"Registered new SPO {}",
756759
hex::encode(id)
757760
);
@@ -791,6 +794,7 @@ impl State {
791794

792795
/// Register a stake address, with a specified deposit if known
793796
fn register_stake_address(&mut self, stake_address: &StakeAddress, deposit: Option<Lovelace>) {
797+
debug!("Register stake address {stake_address}");
794798
// Stake addresses can be registered after being used in UTXOs
795799
let mut stake_addresses = self.stake_addresses.lock().unwrap();
796800
if stake_addresses.register_stake_address(stake_address) {
@@ -819,6 +823,8 @@ impl State {
819823

820824
/// Deregister a stake address, with specified refund if known
821825
fn deregister_stake_address(&mut self, stake_address: &StakeAddress, refund: Option<Lovelace>) {
826+
debug!("Deregister stake address {stake_address}");
827+
822828
// Check if it existed
823829
let mut stake_addresses = self.stake_addresses.lock().unwrap();
824830
if stake_addresses.deregister_stake_address(stake_address) {

modules/spo_state/src/spo_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl SPOState {
272272
}
273273
}
274274

275-
// Handle EochActivityMessage
275+
// Handle EpochActivityMessage
276276
let (_, ea_message) = ea_message_f.await?;
277277
if let Message::Cardano((
278278
block_info,

modules/spo_state/src/state.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ impl State {
315315
) {
316316
if self.spos.contains_key(&reg.operator) {
317317
debug!(
318+
epoch = self.epoch,
318319
block = block.number,
319320
"New pending SPO update {} {:?}",
320321
hex::encode(&reg.operator),
@@ -323,6 +324,7 @@ impl State {
323324
self.pending_updates.insert(reg.operator.clone(), reg.clone());
324325
} else {
325326
debug!(
327+
epoch = self.epoch,
326328
block = block.number,
327329
"Registering SPO {} {:?}",
328330
hex::encode(&reg.operator),

0 commit comments

Comments
 (0)