@@ -96,7 +96,7 @@ public Snapshot apply(ChainConfig config, Header head) {
96
96
Context .require (validators .contains (sealer ), "UnauthorizedValidator" );
97
97
98
98
EthAddresses newRecents = new EthAddresses (recents );
99
- if (newNumber . longValue () >= getMinerHistoryLength () + 1 && newRecents . size () > 0 ) {
99
+ if (newRecents . size () >= getMinerHistoryLength () + 1 ) {
100
100
newRecents .remove (0 );
101
101
}
102
102
@@ -123,18 +123,19 @@ public Snapshot apply(ChainConfig config, Header head) {
123
123
if (newNumber .longValue () % config .Epoch == getMinerHistoryLength ()) {
124
124
newCurrTurnLength = nextTurnLength ;
125
125
newValidators = candidates ;
126
+
127
+ // If the number of current validators is less than the number of previous validators,
128
+ // the capacity of the recent signers should be adjusted
129
+ int limit = Utils .calcMinerHistoryLength (newValidators .size (), newCurrTurnLength ) + 1 ;
130
+ for (int i = 0 ; i < newRecents .size () - limit ; i ++) {
131
+ newRecents .remove (i );
132
+ }
133
+
126
134
if (config .isBohr (head .getTime ())) {
127
135
// BEP-404: Clear Miner History when switching validators set
128
136
for (int i = 0 ; i < newRecents .size (); i ++) {
129
137
newRecents .set (i , EthAddress .EMPTY );
130
138
}
131
- } else {
132
- // If the number of current validators is less than the number of previous validators,
133
- // the capacity of the recent signers should be adjusted
134
- int limit = newValidators .size () / 2 ;
135
- for (int i = 0 ; i < newRecents .size () - limit ; i ++) {
136
- newRecents .remove (i );
137
- }
138
139
}
139
140
}
140
141
if (newNumber .longValue () % config .Epoch == (long ) (voters .size () / 2 + 1 ) * currTurnLength ) {
@@ -146,7 +147,7 @@ public Snapshot apply(ChainConfig config, Header head) {
146
147
}
147
148
148
149
public int getMinerHistoryLength () {
149
- return (validators .size () / 2 + 1 ) * currTurnLength - 1 ;
150
+ return Utils . calcMinerHistoryLength (validators .size (), currTurnLength ) ;
150
151
}
151
152
152
153
public boolean isRecentlySigned (EthAddress signer ) {
0 commit comments