flip dev to cancun

This commit is contained in:
Sina Mahmoodi 2024-02-29 12:46:19 +01:00
parent 0b4adbc4a6
commit a8b9fd90d2
2 changed files with 23 additions and 39 deletions

View file

@ -151,32 +151,20 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
c.feeRecipientLock.Unlock() c.feeRecipientLock.Unlock()
// Reset to CurrentBlock in case of the chain was rewound // Reset to CurrentBlock in case of the chain was rewound
var ( if header := c.eth.BlockChain().CurrentBlock(); c.curForkchoiceState.HeadBlockHash != header.Hash() {
header = c.eth.BlockChain().CurrentBlock()
number = new(big.Int).Add(header.Number, big.NewInt(1))
isCancun = c.eth.BlockChain().Config().IsCancun(number, timestamp)
)
if c.curForkchoiceState.HeadBlockHash != header.Hash() {
finalizedHash := c.finalizedBlockHash(header.Number.Uint64()) finalizedHash := c.finalizedBlockHash(header.Number.Uint64())
c.setCurrentState(header.Hash(), *finalizedHash) c.setCurrentState(header.Hash(), *finalizedHash)
} }
var random [32]byte var random [32]byte
rand.Read(random[:]) rand.Read(random[:])
var ( fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, &engine.PayloadAttributes{
payloadVersion = engine.PayloadV2
attrs = &engine.PayloadAttributes{
Timestamp: timestamp, Timestamp: timestamp,
SuggestedFeeRecipient: feeRecipient, SuggestedFeeRecipient: feeRecipient,
Withdrawals: withdrawals, Withdrawals: withdrawals,
Random: random, Random: random,
} BeaconRoot: &common.Hash{},
) }, engine.PayloadV3, true)
if isCancun {
payloadVersion = engine.PayloadV3
attrs.BeaconRoot = &common.Hash{}
}
fcResponse, err := c.engineAPI.forkchoiceUpdated(c.curForkchoiceState, attrs, payloadVersion, true)
if err != nil { if err != nil {
return err return err
} }
@ -200,8 +188,7 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
} }
} }
// Mark the payload as canon // Independently calculate the blob hashes from sidecars.
if isCancun {
blobHashes := make([]common.Hash, 0) blobHashes := make([]common.Hash, 0)
if envelope.BlobsBundle != nil { if envelope.BlobsBundle != nil {
hasher := sha256.New() hasher := sha256.New()
@ -214,14 +201,10 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c)) blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c))
} }
} }
// Mark the payload as canon
if _, err = c.engineAPI.NewPayloadV3(*payload, blobHashes, &common.Hash{}); err != nil { if _, err = c.engineAPI.NewPayloadV3(*payload, blobHashes, &common.Hash{}); err != nil {
return err return err
} }
} else {
if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil {
return err
}
}
c.setCurrentState(payload.BlockHash, finalizedHash) c.setCurrentState(payload.BlockHash, finalizedHash)
// Mark the block containing the payload as canonical // Mark the block containing the payload as canonical

View file

@ -183,6 +183,7 @@ var (
ArrowGlacierBlock: big.NewInt(0), ArrowGlacierBlock: big.NewInt(0),
GrayGlacierBlock: big.NewInt(0), GrayGlacierBlock: big.NewInt(0),
ShanghaiTime: newUint64(0), ShanghaiTime: newUint64(0),
CancunTime: newUint64(0),
TerminalTotalDifficulty: big.NewInt(0), TerminalTotalDifficulty: big.NewInt(0),
TerminalTotalDifficultyPassed: true, TerminalTotalDifficultyPassed: true,
} }