@@ -31,7 +31,11 @@ public class Header {
31
31
public static final int VALIDATOR_NUMBER_SIZE = 1 ;
32
32
public static final int VALIDATOR_BYTES_LENGTH = EthAddress .LENGTH + BLSPublicKey .LENGTH ;
33
33
// pre-calculated constant uncle hash:) rlp([])
34
- public static final Hash UNCLE_HASH = Hash .of ("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" );
34
+ public static final Hash UNCLE_HASH =
35
+ Hash .of ("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347" );
36
+ // known hash of empty withdrawl set
37
+ public static final Hash EMPTY_WITHDRAWALS_HASH =
38
+ Hash .of ("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" );
35
39
public static final BigInteger INTURN_DIFF = BigInteger .valueOf (2L );
36
40
public static final BigInteger NOTURN_DIFF = BigInteger .valueOf (1L );
37
41
public static final BigInteger GAS_LIMIT_BOUND_DIVISOR = BigInteger .valueOf (256L );
@@ -54,6 +58,9 @@ public class Header {
54
58
private final Hash mixDigest ;
55
59
private final byte [] nonce ;
56
60
private final BigInteger baseFee ;
61
+ private final Hash withdrawalsHash ;
62
+ private final BigInteger blobGasUsed ;
63
+ private final BigInteger excessBlobGas ;
57
64
58
65
// caches
59
66
private Hash hashCache ;
@@ -63,7 +70,8 @@ public class Header {
63
70
public Header (Hash parentHash , Hash uncleHash , EthAddress coinbase , Hash root ,
64
71
Hash txHash , Hash receiptHash , byte [] bloom , BigInteger difficulty ,
65
72
BigInteger number , BigInteger gasLimit , BigInteger gasUsed , long time ,
66
- byte [] extra , Hash mixDigest , byte [] nonce , BigInteger baseFee )
73
+ byte [] extra , Hash mixDigest , byte [] nonce , BigInteger baseFee , Hash withdrawalsHash ,
74
+ BigInteger blobGasUsed , BigInteger excessBlobGas )
67
75
{
68
76
this .parentHash = parentHash ;
69
77
this .uncleHash = uncleHash ;
@@ -81,6 +89,9 @@ public Header(Hash parentHash, Hash uncleHash, EthAddress coinbase, Hash root,
81
89
this .mixDigest = mixDigest ;
82
90
this .nonce = nonce ;
83
91
this .baseFee = baseFee ;
92
+ this .withdrawalsHash = withdrawalsHash ;
93
+ this .blobGasUsed = blobGasUsed ;
94
+ this .excessBlobGas = excessBlobGas ;
84
95
}
85
96
86
97
public static Header readObject (ObjectReader r ) {
@@ -100,17 +111,37 @@ public static Header readObject(ObjectReader r) {
100
111
byte [] extra = r .readByteArray ();
101
112
Hash mixDigest = r .read (Hash .class );
102
113
byte [] nonce = r .readByteArray ();
114
+
115
+ // For Hertz Upgrade
103
116
BigInteger baseFee = null ;
104
117
if (ChainConfig .getInstance ().isHertz (number )) {
105
118
baseFee = r .readBigInteger ();
106
119
}
120
+
121
+ // For Tycho Upgrade
122
+ Hash withdrawalsHash = Hash .EMPTY ;
123
+ BigInteger blobGasUsed = null ;
124
+ BigInteger excessBlobGas = null ;
125
+ if (ChainConfig .getInstance ().isTycho (number )) {
126
+ withdrawalsHash = r .read (Hash .class );
127
+ blobGasUsed = r .readBigInteger ();
128
+ excessBlobGas = r .readBigInteger ();
129
+ }
130
+
107
131
r .end ();
108
132
return new Header (parentHash , uncleHash , coinbase , root , txHash , receiptHash , bloom ,
109
- difficulty , number , gasLimit , gasUsed , time , extra , mixDigest , nonce , baseFee );
133
+ difficulty , number , gasLimit , gasUsed , time , extra , mixDigest , nonce , baseFee ,
134
+ withdrawalsHash , blobGasUsed , excessBlobGas );
110
135
}
111
136
112
137
public static void writeObject (ObjectWriter w , Header o ) {
113
- w .beginList (15 + (o .baseFee != null ? 1 : 0 ));
138
+ if (ChainConfig .getInstance ().isTycho (o .number )) {
139
+ w .beginList (19 );
140
+ } else if (ChainConfig .getInstance ().isHertz (o .number )) {
141
+ w .beginList (16 );
142
+ } else {
143
+ w .beginList (15 );
144
+ }
114
145
w .write (o .parentHash );
115
146
w .write (o .uncleHash );
116
147
w .write (o .coinbase );
@@ -126,9 +157,17 @@ public static void writeObject(ObjectWriter w, Header o) {
126
157
w .write (o .extra );
127
158
w .write (o .mixDigest );
128
159
w .write (o .nonce );
129
- if (o .baseFee != null ) {
160
+ if (ChainConfig .getInstance ().isHertz (o .number )) {
161
+ Context .require (o .baseFee != null , "no fields for hertz" );
130
162
w .write (o .baseFee );
131
163
}
164
+ if (ChainConfig .getInstance ().isTycho (o .number )) {
165
+ Context .require (o .withdrawalsHash != Hash .EMPTY && o .blobGasUsed != null
166
+ && o .excessBlobGas != null , "no fields for tycho" );
167
+ w .write (o .withdrawalsHash );
168
+ w .write (o .blobGasUsed );
169
+ w .write (o .excessBlobGas );
170
+ }
132
171
w .end ();
133
172
}
134
173
@@ -275,4 +314,8 @@ public byte[] getExtra() {
275
314
public Hash getMixDigest () {
276
315
return this .mixDigest ;
277
316
}
317
+
318
+ public Hash getWithdrawalsHash () {
319
+ return this .withdrawalsHash ;
320
+ }
278
321
}
0 commit comments