eth/catalyst: update simulated beacon for cancun (#28829)
* eth/catalyst: update simulated beacon for cancun * validate blob hashes * compute hashes from commitment * fix beacon root and payload version * check commitment conversion * fix random attr * flip dev to cancun
This commit is contained in:
parent
865e1e9f57
commit
0a2f33946b
|
@ -18,6 +18,7 @@ package catalyst
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"crypto/sha256"
|
||||||
"errors"
|
"errors"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -27,6 +28,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core/txpool"
|
"github.com/ethereum/go-ethereum/core/txpool"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/crypto/kzg4844"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
|
@ -161,14 +163,14 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
SuggestedFeeRecipient: feeRecipient,
|
SuggestedFeeRecipient: feeRecipient,
|
||||||
Withdrawals: withdrawals,
|
Withdrawals: withdrawals,
|
||||||
Random: random,
|
Random: random,
|
||||||
}, engine.PayloadV2, true)
|
BeaconRoot: &common.Hash{},
|
||||||
|
}, engine.PayloadV3, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if fcResponse == engine.STATUS_SYNCING {
|
if fcResponse == engine.STATUS_SYNCING {
|
||||||
return errors.New("chain rewind prevented invocation of payload creation")
|
return errors.New("chain rewind prevented invocation of payload creation")
|
||||||
}
|
}
|
||||||
|
|
||||||
envelope, err := c.engineAPI.getPayload(*fcResponse.PayloadID, true)
|
envelope, err := c.engineAPI.getPayload(*fcResponse.PayloadID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -186,8 +188,21 @@ func (c *SimulatedBeacon) sealBlock(withdrawals []*types.Withdrawal, timestamp u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Independently calculate the blob hashes from sidecars.
|
||||||
|
blobHashes := make([]common.Hash, 0)
|
||||||
|
if envelope.BlobsBundle != nil {
|
||||||
|
hasher := sha256.New()
|
||||||
|
for _, commit := range envelope.BlobsBundle.Commitments {
|
||||||
|
var c kzg4844.Commitment
|
||||||
|
if len(commit) != len(c) {
|
||||||
|
return errors.New("invalid commitment length")
|
||||||
|
}
|
||||||
|
copy(c[:], commit)
|
||||||
|
blobHashes = append(blobHashes, kzg4844.CalcBlobHashV1(hasher, &c))
|
||||||
|
}
|
||||||
|
}
|
||||||
// Mark the payload as canon
|
// Mark the payload as canon
|
||||||
if _, err = c.engineAPI.NewPayloadV2(*payload); err != nil {
|
if _, err = c.engineAPI.NewPayloadV3(*payload, blobHashes, &common.Hash{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.setCurrentState(payload.BlockHash, finalizedHash)
|
c.setCurrentState(payload.BlockHash, finalizedHash)
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue