@@ -30,6 +30,7 @@ public class Header {
30
30
public static final int EXTRA_SEAL = 65 ;
31
31
public static final int VALIDATOR_NUMBER_SIZE = 1 ;
32
32
public static final int VALIDATOR_BYTES_LENGTH = EthAddress .LENGTH + BLSPublicKey .LENGTH ;
33
+ public static final int TURN_LENGTH_SIZE = 1 ;
33
34
// pre-calculated constant uncle hash:) rlp([])
34
35
public static final Hash UNCLE_HASH =
35
36
Hash .of ("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" );
@@ -41,6 +42,7 @@ public class Header {
41
42
public static final BigInteger GAS_LIMIT_BOUND_DIVISOR = BigInteger .valueOf (256L );
42
43
public static final BigInteger MAX_GAS_LIMIT = BigInteger .valueOf (0x7FFFFFFFFFFFFFFFL ); // (2^63-1)
43
44
public static final BigInteger MIN_GAS_LIMIT = BigInteger .valueOf (5000L );
45
+ public static final int DEFAULT_TURN_LENGTH = 1 ;
44
46
45
47
private final Hash parentHash ;
46
48
private final Hash uncleHash ;
@@ -61,6 +63,7 @@ public class Header {
61
63
private final Hash withdrawalsHash ;
62
64
private final BigInteger blobGasUsed ;
63
65
private final BigInteger excessBlobGas ;
66
+ private final Hash parentBeaconRoot ;
64
67
65
68
// caches
66
69
private Hash hashCache ;
@@ -92,6 +95,7 @@ public Header(Hash parentHash, Hash uncleHash, EthAddress coinbase, Hash root,
92
95
this .withdrawalsHash = withdrawalsHash ;
93
96
this .blobGasUsed = blobGasUsed ;
94
97
this .excessBlobGas = excessBlobGas ;
98
+ this .parentBeaconRoot = Hash .EMPTY ;
95
99
}
96
100
97
101
public static Header readObject (ObjectReader r ) {
@@ -135,7 +139,9 @@ public static Header readObject(ObjectReader r) {
135
139
}
136
140
137
141
public static void writeObject (ObjectWriter w , Header o ) {
138
- if (ChainConfig .getInstance ().isTycho (o .time )) {
142
+ if (ChainConfig .getInstance ().isBohr (o .time )) {
143
+ w .beginList (20 );
144
+ } else if (ChainConfig .getInstance ().isTycho (o .time )) {
139
145
w .beginList (19 );
140
146
} else if (ChainConfig .getInstance ().isHertz (o .number )) {
141
147
w .beginList (16 );
@@ -168,6 +174,9 @@ public static void writeObject(ObjectWriter w, Header o) {
168
174
w .write (o .blobGasUsed );
169
175
w .write (o .excessBlobGas );
170
176
}
177
+ if (ChainConfig .getInstance ().isBohr (o .time )) {
178
+ w .write (o .parentBeaconRoot );
179
+ }
171
180
w .end ();
172
181
}
173
182
@@ -232,6 +241,9 @@ public VoteAttestation getVoteAttestation(ChainConfig config) {
232
241
return null ;
233
242
}
234
243
int start = EXTRA_VANITY + VALIDATOR_NUMBER_SIZE + num * VALIDATOR_BYTES_LENGTH ;
244
+ if (config .isBohr (time )) {
245
+ start += TURN_LENGTH_SIZE ;
246
+ }
235
247
int end = extra .length - EXTRA_SEAL ;
236
248
blob = Arrays .copyOfRange (extra , start , end );
237
249
}
@@ -240,34 +252,73 @@ public VoteAttestation getVoteAttestation(ChainConfig config) {
240
252
return atteCache ;
241
253
}
242
254
243
- public EthAddress getSigner (BigInteger cid ) {
255
+ public int getTurnLength (ChainConfig config ) {
256
+ Context .require (config .isEpoch (number ), "no turn length" );
257
+ if (!config .isBohr (time )) {
258
+ return DEFAULT_TURN_LENGTH ;
259
+ }
260
+
261
+ Context .require (extra .length > EXTRA_VANITY + EXTRA_SEAL , "too short extra data for including turn length" );
262
+ int num = extra [EXTRA_VANITY ];
263
+ int pos = EXTRA_VANITY + VALIDATOR_NUMBER_SIZE + num * VALIDATOR_BYTES_LENGTH ;
264
+ Context .require (extra .length > pos , "no field for turn length" );
265
+ return extra [pos ];
266
+ }
267
+
268
+ public EthAddress getSigner (ChainConfig config , BigInteger cid ) {
244
269
Context .require (extra .length >= EXTRA_SEAL , "Invalid seal bytes" );
245
270
byte [] signature = Arrays .copyOfRange (extra , extra .length - EXTRA_SEAL , extra .length );
246
- byte [] pubkey = Context .recoverKey ("ecdsa-secp256k1" , getSealHash (cid ), signature , false );
271
+ byte [] pubkey = Context .recoverKey ("ecdsa-secp256k1" , getSealHash (config , cid ), signature , false );
247
272
byte [] pubhash = Context .hash ("keccak-256" , Arrays .copyOfRange (pubkey , 1 , pubkey .length ));
248
273
return new EthAddress (Arrays .copyOfRange (pubhash , 12 , pubhash .length ));
249
274
}
250
275
251
- private byte [] getSealHash (BigInteger cid ) {
276
+ private byte [] getSealHash (ChainConfig config , BigInteger cid ) {
252
277
ByteArrayObjectWriter w = Context .newByteArrayObjectWriter ("RLP" );
253
- w .beginList (16 );
254
- w .write (cid );
255
- w .write (parentHash );
256
- w .write (uncleHash );
257
- w .write (coinbase );
258
- w .write (root );
259
- w .write (txHash );
260
- w .write (receiptHash );
261
- w .write (bloom );
262
- w .write (difficulty );
263
- w .write (number );
264
- w .write (gasLimit );
265
- w .write (gasUsed );
266
- w .write (time );
267
- w .write (Arrays .copyOfRange (extra , 0 , extra .length -65 ));
268
- w .write (mixDigest );
269
- w .write (nonce );
270
- w .end ();
278
+ if (config .isBohr (time )) {
279
+ w .beginList (21 );
280
+ w .write (cid );
281
+ w .write (parentHash );
282
+ w .write (uncleHash );
283
+ w .write (coinbase );
284
+ w .write (root );
285
+ w .write (txHash );
286
+ w .write (receiptHash );
287
+ w .write (bloom );
288
+ w .write (difficulty );
289
+ w .write (number );
290
+ w .write (gasLimit );
291
+ w .write (gasUsed );
292
+ w .write (time );
293
+ w .write (Arrays .copyOfRange (extra , 0 , extra .length -65 ));
294
+ w .write (mixDigest );
295
+ w .write (nonce );
296
+ w .write (baseFee );
297
+ w .write (withdrawalsHash );
298
+ w .write (blobGasUsed );
299
+ w .write (excessBlobGas );
300
+ w .write (parentBeaconRoot );
301
+ w .end ();
302
+ } else {
303
+ w .beginList (16 );
304
+ w .write (cid );
305
+ w .write (parentHash );
306
+ w .write (uncleHash );
307
+ w .write (coinbase );
308
+ w .write (root );
309
+ w .write (txHash );
310
+ w .write (receiptHash );
311
+ w .write (bloom );
312
+ w .write (difficulty );
313
+ w .write (number );
314
+ w .write (gasLimit );
315
+ w .write (gasUsed );
316
+ w .write (time );
317
+ w .write (Arrays .copyOfRange (extra , 0 , extra .length -65 ));
318
+ w .write (mixDigest );
319
+ w .write (nonce );
320
+ w .end ();
321
+ }
271
322
return Context .hash ("keccak-256" , w .toByteArray ());
272
323
}
273
324
0 commit comments