Skip to content

Commit

Permalink
Clear recent sealers on validator set change
Browse files Browse the repository at this point in the history
  • Loading branch information
mksong76 committed Sep 3, 2024
1 parent 8d736c5 commit f0e86f1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public int count(EthAddress cmp) {
return cnt;
}

public void clear() {
addresses.clear();
}

@Override
public String toString() {
return "EthAddresses{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,15 @@ public Snapshot apply(ChainConfig config, Header head) {
newCurrTurnLength = nextTurnLength;
newValidators = candidates;

// If the number of current validators is less than the number of previous validators,
// the capacity of the recent signers should be adjusted
int limit = Utils.calcMinerHistoryLength(newValidators.size(), newCurrTurnLength) + 1;
for (int i = 0; i < newRecents.size() - limit; i++) {
newRecents.remove(i);
}

if (config.isBohr(head.getTime())) {
// BEP-404: Clear Miner History when switching validators set
for (int i = 0; i < newRecents.size(); i++) {
newRecents.set(i, EthAddress.EMPTY);
newRecents.clear();
} else {
// If the number of current validators is less than the number of previous validators,
// the capacity of the recent signers should be adjusted
int limit = Utils.calcMinerHistoryLength(newValidators.size(), newCurrTurnLength) + 1;
for (int i = 0; i < newRecents.size() - limit; i++) {
newRecents.remove(i);
}
}
}
Expand Down

0 comments on commit f0e86f1

Please sign in to comment.