Skip to content

Commit

Permalink
fix(stakes): use by_validator in rank function to prevent duplicated …
Browse files Browse the repository at this point in the history
…entries
  • Loading branch information
drcpu-github committed Nov 27, 2024
1 parent 65134e2 commit ee578c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions data_structures/src/staking/stakes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ where
capability: Capability,
epoch: Epoch,
strategy: CensusStrategy,
) -> Box<dyn Iterator<Item = StakeKey<Address>> + '_> {
) -> Box<dyn Iterator<Item = Address> + '_> {
let iterator = self.rank(capability, epoch).map(|(address, _)| address);

match strategy {
Expand Down Expand Up @@ -256,13 +256,17 @@ where
&self,
capability: Capability,
current_epoch: Epoch,
) -> impl Iterator<Item = (StakeKey<Address>, Power)> + '_ {
self.by_coins
) -> impl Iterator<Item = (Address, Power)> + '_ {
self.by_validator
.iter()
.map(move |(CoinsAndAddresses { addresses, .. }, stake)| {
let power = stake.read_value().power(capability, current_epoch);

(addresses.clone(), power)
.map(move |(address, stakes)| {
let power = stakes
.first()
.unwrap()
.read_value()
.power(capability, current_epoch);

(address.clone(), power)
})
.sorted_by_key(|(_, power)| *power)
.rev()
Expand Down
6 changes: 3 additions & 3 deletions node/src/actors/chain_manager/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ impl Handler<EpochNotification<EveryEpochPayload>> for ChainManager {
.rank(Capability::Mining, previous_epoch)
.take(replication_factor.into())
.collect();
for (i, (stake_key, _)) in rank_subset.into_iter().enumerate() {
for (i, (validator, _)) in rank_subset.into_iter().enumerate() {
log::warn!(
"Slashed the power of {} as it did not propose a block",
stake_key.validator
validator
);
let _ = stakes.reset_age(
stake_key.validator,
validator,
Capability::Mining,
msg.checkpoint,
// This should never fail
Expand Down

0 comments on commit ee578c1

Please sign in to comment.