@@ -33,6 +33,8 @@ import (
33
33
"github.com/ethereum/go-ethereum/event"
34
34
"github.com/ethereum/go-ethereum/log"
35
35
"github.com/ethereum/go-ethereum/node"
36
+ "github.com/ethereum/go-ethereum/params"
37
+ "github.com/ethereum/go-ethereum/params/forks"
36
38
"github.com/ethereum/go-ethereum/rpc"
37
39
)
38
40
@@ -95,6 +97,16 @@ type SimulatedBeacon struct {
95
97
lastBlockTime uint64
96
98
}
97
99
100
+ func payloadVersion (config * params.ChainConfig , time uint64 ) engine.PayloadVersion {
101
+ switch config .LatestFork (time ) {
102
+ case forks .Prague , forks .Cancun :
103
+ return engine .PayloadV3
104
+ case forks .Paris , forks .Shanghai :
105
+ return engine .PayloadV2
106
+ }
107
+ panic ("invalid fork, simulated beacon needs to be started post-merge" )
108
+ }
109
+
98
110
// NewSimulatedBeacon constructs a new simulated beacon chain.
99
111
func NewSimulatedBeacon (period uint64 , eth * eth.Ethereum ) (* SimulatedBeacon , error ) {
100
112
block := eth .BlockChain ().CurrentBlock ()
@@ -107,7 +119,8 @@ func NewSimulatedBeacon(period uint64, eth *eth.Ethereum) (*SimulatedBeacon, err
107
119
108
120
// if genesis block, send forkchoiceUpdated to trigger transition to PoS
109
121
if block .Number .Sign () == 0 {
110
- if _ , err := engineAPI .ForkchoiceUpdatedV3 (current , nil ); err != nil {
122
+ version := payloadVersion (eth .BlockChain ().Config (), block .Time )
123
+ if _ , err := engineAPI .forkchoiceUpdated (current , nil , version , false ); err != nil {
111
124
return nil , err
112
125
}
113
126
}
@@ -171,6 +184,8 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
171
184
return fmt .Errorf ("failed to sync txpool: %w" , err )
172
185
}
173
186
187
+ version := payloadVersion (c .eth .BlockChain ().Config (), timestamp )
188
+
174
189
var random [32 ]byte
175
190
rand .Read (random [:])
176
191
fcResponse , err := c .engineAPI .forkchoiceUpdated (c .curForkchoiceState , & engine.PayloadAttributes {
@@ -179,7 +194,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
179
194
Withdrawals : withdrawals ,
180
195
Random : random ,
181
196
BeaconRoot : & common.Hash {},
182
- }, engine . PayloadV3 , false )
197
+ }, version , false )
183
198
if err != nil {
184
199
return err
185
200
}
@@ -204,28 +219,39 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
204
219
}
205
220
}
206
221
207
- // Independently calculate the blob hashes from sidecars.
208
- blobHashes := make ([]common.Hash , 0 )
209
- if envelope .BlobsBundle != nil {
210
- hasher := sha256 .New ()
211
- for _ , commit := range envelope .BlobsBundle .Commitments {
212
- var c kzg4844.Commitment
213
- if len (commit ) != len (c ) {
214
- return errors .New ("invalid commitment length" )
222
+ var (
223
+ blobHashes []common.Hash
224
+ beaconRoot * common.Hash
225
+ requests [][]byte
226
+ )
227
+ // Compute post-shanghai fields
228
+ if version > engine .PayloadV2 {
229
+ // Independently calculate the blob hashes from sidecars.
230
+ blobHashes = make ([]common.Hash , 0 )
231
+ if envelope .BlobsBundle != nil {
232
+ hasher := sha256 .New ()
233
+ for _ , commit := range envelope .BlobsBundle .Commitments {
234
+ var c kzg4844.Commitment
235
+ if len (commit ) != len (c ) {
236
+ return errors .New ("invalid commitment length" )
237
+ }
238
+ copy (c [:], commit )
239
+ blobHashes = append (blobHashes , kzg4844 .CalcBlobHashV1 (hasher , & c ))
215
240
}
216
- copy (c [:], commit )
217
- blobHashes = append (blobHashes , kzg4844 .CalcBlobHashV1 (hasher , & c ))
218
241
}
242
+ beaconRoot = & common.Hash {}
243
+ requests = envelope .Requests
219
244
}
245
+
220
246
// Mark the payload as canon
221
- _ , err = c .engineAPI .newPayload (* payload , blobHashes , & common. Hash {}, envelope . Requests , false )
247
+ _ , err = c .engineAPI .newPayload (* payload , blobHashes , beaconRoot , requests , false )
222
248
if err != nil {
223
249
return err
224
250
}
225
251
c .setCurrentState (payload .BlockHash , finalizedHash )
226
252
227
253
// Mark the block containing the payload as canonical
228
- if _ , err = c .engineAPI .ForkchoiceUpdatedV3 (c .curForkchoiceState , nil ); err != nil {
254
+ if _ , err = c .engineAPI .forkchoiceUpdated (c .curForkchoiceState , nil , version , false ); err != nil {
229
255
return err
230
256
}
231
257
c .lastBlockTime = payload .Timestamp
0 commit comments