@@ -31,10 +31,11 @@ public class Snapshot {
31
31
private final VoteAttestation attestation ;
32
32
private final int currTurnLength ;
33
33
private final int nextTurnLength ;
34
+ private final int pastTurnLength ;
34
35
35
36
public Snapshot (Hash hash , BigInteger number , Validators validators ,
36
37
Validators candidates , Validators voters , EthAddresses recents ,
37
- VoteAttestation attestation , int currTurnLength , int nextTurnLength ) {
38
+ VoteAttestation attestation , int currTurnLength , int nextTurnLength , int pastTurnLength ) {
38
39
39
40
this .hash = hash ;
40
41
this .number = number ;
@@ -47,6 +48,7 @@ public Snapshot(Hash hash, BigInteger number, Validators validators,
47
48
this .attestation = attestation ;
48
49
this .currTurnLength = currTurnLength ;
49
50
this .nextTurnLength = nextTurnLength ;
51
+ this .pastTurnLength = pastTurnLength ;
50
52
}
51
53
52
54
public static void writeObject (ObjectWriter w , Snapshot o ) {
@@ -60,6 +62,7 @@ public static void writeObject(ObjectWriter w, Snapshot o) {
60
62
w .write (o .attestation );
61
63
w .write (o .currTurnLength );
62
64
w .write (o .nextTurnLength );
65
+ w .write (o .pastTurnLength );
63
66
w .end ();
64
67
}
65
68
@@ -74,9 +77,10 @@ public static Snapshot readObject(ObjectReader r) {
74
77
VoteAttestation attestation = r .read (VoteAttestation .class );
75
78
int currTurnLength = r .readOrDefault (Integer .class , Header .DEFAULT_TURN_LENGTH );
76
79
int nextTurnLength = r .readOrDefault (Integer .class , Header .DEFAULT_TURN_LENGTH );
80
+ int pastTurnLength = r .readOrDefault (Integer .class , currTurnLength );
77
81
r .end ();
78
82
return new Snapshot (hash , number , validators , candidates , voters , recents , attestation ,
79
- currTurnLength , nextTurnLength );
83
+ currTurnLength , nextTurnLength , pastTurnLength );
80
84
}
81
85
82
86
public boolean inturn (EthAddress validator ) {
@@ -111,6 +115,7 @@ public Snapshot apply(ChainConfig config, Header head) {
111
115
newAttestation = attestation ;
112
116
}
113
117
118
+ int newPastTurnLength = pastTurnLength ;
114
119
int newCurrTurnLength = currTurnLength ;
115
120
int newNextTurnLength = nextTurnLength ;
116
121
Validators newValidators = validators ;
@@ -136,12 +141,13 @@ public Snapshot apply(ChainConfig config, Header head) {
136
141
}
137
142
}
138
143
}
139
- if (newNumber .longValue () % config .Epoch == ( long ) ( voters .size () / 2 + 1 ) * currTurnLength ) {
144
+ if (newNumber .longValue () % config .Epoch == Utils . calcMinerHistoryLength ( voters .size (), pastTurnLength ) + 1 ) {
140
145
newVoters = validators ;
146
+ newPastTurnLength = currTurnLength ;
141
147
}
142
148
143
149
return new Snapshot (head .getHash (), newNumber , newValidators , newCandidates , newVoters ,
144
- newRecents , newAttestation , newCurrTurnLength , newNextTurnLength );
150
+ newRecents , newAttestation , newCurrTurnLength , newNextTurnLength , newPastTurnLength );
145
151
}
146
152
147
153
public int getMinerHistoryLength () {
0 commit comments