Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions node/core/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

var (
MainnetUpgradeBatchTime uint64 = 2000
HoleskyUpgradeBatchTime uint64 = 350000
MainnetUpgradeBatchTime uint64 = 0
MainnetBlsKeyCheckForkHeight uint64 = 18409547
)

type Config struct {
Expand All @@ -35,6 +35,7 @@ type Config struct {
L2StakingAddress common.Address `json:"l2staking_address"`
MaxL1MessageNumPerBlock uint64 `json:"max_l1_message_num_per_block"`
UpgradeBatchTime uint64 `json:"upgrade_batch_time"`
BlsKeyCheckForkHeight uint64 `json:"bls_key_check_fork_height"`
DevSequencer bool `json:"dev_sequencer"`
Logger tmlog.Logger `json:"logger"`
}
Expand Down Expand Up @@ -157,12 +158,12 @@ func (c *Config) SetCliContext(ctx *cli.Context) error {
c.DevSequencer = ctx.GlobalBool(flags.DevSequencer.Name)
}

// setup batch upgrade index
// setup batch upgrade index and fork heights
switch {
case ctx.GlobalIsSet(flags.MainnetFlag.Name):
c.UpgradeBatchTime = MainnetUpgradeBatchTime
case ctx.GlobalIsSet(flags.HoleskyFlag.Name):
c.UpgradeBatchTime = HoleskyUpgradeBatchTime
c.BlsKeyCheckForkHeight = MainnetBlsKeyCheckForkHeight
logger.Info("set UpgradeBatchTime: ", c.UpgradeBatchTime, "BlsKeyCheckForkHeight: ", c.BlsKeyCheckForkHeight)
case ctx.GlobalIsSet(flags.UpgradeBatchTime.Name):
c.UpgradeBatchTime = ctx.GlobalUint64(flags.UpgradeBatchTime.Name)
logger.Info("set UpgradeBatchTime: ", ctx.GlobalUint64(flags.UpgradeBatchTime.Name))
Expand Down
58 changes: 36 additions & 22 deletions node/core/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ type Executor struct {
isSequencer bool
devSequencer bool

UpgradeBatchTime uint64
rollupABI *abi.ABI
batchingCache *BatchingCache
UpgradeBatchTime uint64
blsKeyCheckForkHeight uint64
rollupABI *abi.ABI
batchingCache *BatchingCache

logger tmlog.Logger
metrics *Metrics
Expand Down Expand Up @@ -108,21 +109,22 @@ func NewExecutor(newSyncFunc NewSyncerFunc, config *Config, tmPubKey crypto.PubK
tmPubKeyBytes = tmPubKey.Bytes()
}
executor := &Executor{
l2Client: l2Client,
bc: &Version1Converter{},
govCaller: gov,
sequencerCaller: sequencer,
l2StakingCaller: l2Staking,
tmPubKey: tmPubKeyBytes,
nextL1MsgIndex: index,
maxL1MsgNumPerBlock: config.MaxL1MessageNumPerBlock,
newSyncerFunc: newSyncFunc,
devSequencer: config.DevSequencer,
rollupABI: rollupAbi,
batchingCache: NewBatchingCache(),
UpgradeBatchTime: config.UpgradeBatchTime,
logger: logger,
metrics: PrometheusMetrics("morphnode"),
l2Client: l2Client,
bc: &Version1Converter{},
govCaller: gov,
sequencerCaller: sequencer,
l2StakingCaller: l2Staking,
tmPubKey: tmPubKeyBytes,
nextL1MsgIndex: index,
maxL1MsgNumPerBlock: config.MaxL1MessageNumPerBlock,
newSyncerFunc: newSyncFunc,
devSequencer: config.DevSequencer,
rollupABI: rollupAbi,
batchingCache: NewBatchingCache(),
UpgradeBatchTime: config.UpgradeBatchTime,
blsKeyCheckForkHeight: config.BlsKeyCheckForkHeight,
logger: logger,
metrics: PrometheusMetrics("morphnode"),
}

if config.DevSequencer {
Expand All @@ -135,7 +137,12 @@ func NewExecutor(newSyncFunc NewSyncerFunc, config *Config, tmPubKey crypto.PubK
return executor, nil
}

if _, err = executor.updateSequencerSet(); err != nil {
// Get current height for initial sequencer set update
currentHeight, err := l2Client.BlockNumber(context.Background())
if err != nil {
return nil, err
}
if _, err = executor.updateSequencerSet(currentHeight); err != nil {
return nil, err
}

Expand Down Expand Up @@ -327,7 +334,7 @@ func (e *Executor) DeliverBlock(txs [][]byte, metaData []byte, consensusData l2n
var newValidatorSet = consensusData.ValidatorSet
var newBatchParams *tmproto.BatchParams
if !e.devSequencer {
if newValidatorSet, err = e.updateSequencerSet(); err != nil {
if newValidatorSet, err = e.updateSequencerSet(l2Block.Number); err != nil {
return nil, nil, err
}
if newBatchParams, err = e.batchParamsUpdates(l2Block.Number); err != nil {
Expand Down Expand Up @@ -390,9 +397,16 @@ func (e *Executor) getParamsAndValsAtHeight(height int64) (*tmproto.BatchParams,
if err != nil {
return nil, nil, err
}
newValidators := make([][]byte, len(addrs))
newValidators := make([][]byte, 0, len(addrs))
for i := range stakesInfo {
newValidators[i] = stakesInfo[i].TmKey[:]
// validate blsKey to keep consistent with sequencerSetUpdates
if _, err := decodeBlsPubKey(stakesInfo[i].BlsKey); err != nil {
e.logger.Error("getParamsAndValsAtHeight: failed to decode bls key", "key bytes", hexutil.Encode(stakesInfo[i].BlsKey), "error", err)
if e.isBlsKeyCheckFork(uint64(height)) {
continue
}
}
newValidators = append(newValidators, stakesInfo[i].TmKey[:])
}

return &tmproto.BatchParams{
Expand Down
21 changes: 15 additions & 6 deletions node/core/sequencers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import (

const tmKeySize = ed25519.PubKeySize

// isBlsKeyCheckFork returns true if blsKey validation should be enforced at the given height.
// For mainnet, blsKey validation is skipped before fork height to maintain historical compatibility.
func (e *Executor) isBlsKeyCheckFork(height uint64) bool {
return e.blsKeyCheckForkHeight == 0 || height > e.blsKeyCheckForkHeight
}

type validatorInfo struct {
address common.Address
blsPubKey blssignatures.PublicKey
Expand Down Expand Up @@ -55,12 +61,14 @@ func (e *Executor) VerifySignature(tmPubKey []byte, messageHash []byte, blsSig [
return blssignatures.VerifySignature(sig, messageHash, blsKey)
}

func (e *Executor) sequencerSetUpdates() ([][]byte, error) {
func (e *Executor) sequencerSetUpdates(height uint64) ([][]byte, error) {
seqHash, err := e.sequencerCaller.SequencerSetVerifyHash(nil)
if err != nil {
return nil, err
}
if e.currentSeqHash != nil && bytes.Equal(e.currentSeqHash[:], seqHash[:]) {
// Don't use cache at fork height boundary to ensure correct blsKey validation behavior change
atForkBoundary := e.blsKeyCheckForkHeight > 0 && (height == e.blsKeyCheckForkHeight || height == e.blsKeyCheckForkHeight+1)
if e.currentSeqHash != nil && bytes.Equal(e.currentSeqHash[:], seqHash[:]) && !atForkBoundary {
return e.nextValidators, nil
}

Expand Down Expand Up @@ -98,8 +106,9 @@ func (e *Executor) sequencerSetUpdates() ([][]byte, error) {
blsPK, err := decodeBlsPubKey(stakesInfo[i].BlsKey)
if err != nil {
e.logger.Error("failed to decode bls key", "key bytes", hexutil.Encode(stakesInfo[i].BlsKey), "error", err)
continue
// return nil, err
if e.isBlsKeyCheckFork(height) {
continue
}
}
// sequencerSet2 is the latest updated sequencer set which is considered as the next validator set for tendermint
if slices.Contains(sequencerSet2, stakesInfo[i].Addr) {
Expand Down Expand Up @@ -148,8 +157,8 @@ func (e *Executor) batchParamsUpdates(height uint64) (*tmproto.BatchParams, erro
return nil, nil
}

func (e *Executor) updateSequencerSet() ([][]byte, error) {
validatorUpdates, err := e.sequencerSetUpdates()
func (e *Executor) updateSequencerSet(height uint64) ([][]byte, error) {
validatorUpdates, err := e.sequencerSetUpdates(height)
if err != nil {
e.logger.Error("failed to get sequencer set from geth", "err", err)
return nil, err
Expand Down
5 changes: 0 additions & 5 deletions node/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ var (
Name: "mainnet",
Usage: "Morph mainnet",
}
HoleskyFlag = cli.BoolFlag{
Name: "holesky",
Usage: "Morph Holesky",
}

DerivationConfirmations = cli.Int64Flag{
Name: "derivation.confirmations",
Expand Down Expand Up @@ -345,7 +341,6 @@ var Flags = []cli.Flag{
// batch rules
UpgradeBatchTime,
MainnetFlag,
HoleskyFlag,

// logger
LogLevel,
Expand Down
Loading