Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fork-id-flag-increase-effect #203

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Changes from 1 commit
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
60 changes: 32 additions & 28 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const (
stateStreamLimit uint64 = 1_000

transactionGasLimit = 30000000
blockGasLimit = 18446744073709551615

totalVirtualCounterSmtLevel = 80 // todo [zkevm] this should be read from the db

Expand Down Expand Up @@ -190,6 +189,33 @@ func SpawnSequencingStage(
return err
}

var forkId uint64 = 0

if executionAt == 0 {
// capture the initial sequencer fork id for the first batch
forkId = cfg.zk.SequencerInitialForkId
for fId := uint64(chain.ForkID5Dragonfruit); fId <= forkId; fId++ {
if err := hermezDb.WriteForkId(1, fId); err != nil {
kstoykov marked this conversation as resolved.
Show resolved Hide resolved
return err
}
if err := hermezDb.WriteForkIdBlockOnce(fId, 1); err != nil {
return err
}
}
} else {
forkId, err = hermezDb.GetForkId(lastBatch)
if err != nil {
return err
}
if forkId == 0 {
return errors.New("the network cannot have a 0 fork id")
}
}

if err := stagedsync.UpdateZkEVMBlockCfg(cfg.chainConfig, hermezDb, logPrefix); err != nil {
return err
}

nextBlockNum := executionAt + 1
thisBatch := lastBatch + 1
newBlockTimestamp := uint64(time.Now().Unix())
Expand All @@ -199,27 +225,17 @@ func SpawnSequencingStage(
Coinbase: constMiner,
Difficulty: blockDifficulty,
Number: new(big.Int).SetUint64(nextBlockNum),
GasLimit: blockGasLimit,
GasLimit: getGasLimit(uint16(forkId)),
Time: newBlockTimestamp,
BaseFee: big.NewInt(0),
}

stateReader := state.NewPlainStateReader(tx)
ibs := state.New(stateReader)

var forkId uint64 = 0

// here we have a special case and need to inject in the initial batch on the network before
// we can continue accepting transactions from the pool
if executionAt == 0 {
// capture the initial sequencer fork id for the first batch
forkId = cfg.zk.SequencerInitialForkId
if err := hermezDb.WriteForkId(1, forkId); err != nil {
return err
}
if err := hermezDb.WriteForkIdBlockOnce(forkId, 1); err != nil {
return err
}
err = processInjectedInitialBatch(hermezDb, ibs, tx, cfg, header, parentBlock, stateReader, forkId)
if err != nil {
return err
Expand All @@ -230,20 +246,8 @@ func SpawnSequencingStage(
}
}
return nil
} else {
forkId, err = hermezDb.GetForkId(lastBatch)
if err != nil {
return err
}
if forkId == 0 {
return errors.New("the network cannot have a 0 fork id")
}
}

if err := stagedsync.UpdateZkEVMBlockCfg(cfg.chainConfig, hermezDb, logPrefix); err != nil {
return err
}

batchCounters := vm.NewBatchCounterCollector(totalVirtualCounterSmtLevel, uint16(forkId))

// whilst in the 1 batch = 1 block = 1 tx flow we can immediately add in the changeL2BlockTx calculation
Expand Down Expand Up @@ -282,7 +286,7 @@ LOOP:
log.Info(fmt.Sprintf("[%s] Waiting some more for txs from the pool...", logPrefix))
default:
cfg.txPool.LockFlusher()
transactions, err := getNextTransactions(cfg, executionAt, yielded)
transactions, err := getNextTransactions(cfg, executionAt, forkId, yielded)
if err != nil {
return err
}
Expand Down Expand Up @@ -344,7 +348,7 @@ LOOP:
return nil
}

func getNextTransactions(cfg SequenceBlockCfg, executionAt uint64, alreadyYielded mapset.Set[[32]byte]) ([]types.Transaction, error) {
func getNextTransactions(cfg SequenceBlockCfg, executionAt, forkId uint64, alreadyYielded mapset.Set[[32]byte]) ([]types.Transaction, error) {
var transactions []types.Transaction
var err error
var count int
Expand All @@ -359,7 +363,7 @@ LOOP:
}
if err := cfg.txPoolDb.View(context.Background(), func(poolTx kv.Tx) error {
slots := types2.TxsRlp{}
_, count, err = cfg.txPool.YieldBest(yieldSize, &slots, poolTx, executionAt, blockGasLimit, alreadyYielded)
_, count, err = cfg.txPool.YieldBest(yieldSize, &slots, poolTx, executionAt, getGasLimit(uint16(forkId)), alreadyYielded)
if err != nil {
return err
}
Expand Down Expand Up @@ -584,7 +588,7 @@ func finaliseBlock(

finalHeader := finalBlock.Header()
finalHeader.Coinbase = constMiner
finalHeader.GasLimit = blockGasLimit
finalHeader.GasLimit = getGasLimit(uint16(forkId))
finalHeader.ReceiptHash = types.DeriveSha(receipts)
newNum := finalBlock.Number()

Expand Down
Loading