From 656b3498954f40a303393ee52343c811dd958030 Mon Sep 17 00:00:00 2001 From: Louis Liu <35095310+louisliu2048@users.noreply.github.com> Date: Wed, 28 Aug 2024 15:43:06 +0800 Subject: [PATCH 1/2] Optimize sequencer wait time by distinguishing between 'txpool not ready' and 'txpool empty' states. (#1037) --- zk/stages/stage_sequence_execute.go | 11 +++++++++-- zk/stages/stage_sequence_execute_transactions.go | 9 +++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/zk/stages/stage_sequence_execute.go b/zk/stages/stage_sequence_execute.go index d975075b0e0..14918403187 100644 --- a/zk/stages/stage_sequence_execute.go +++ b/zk/stages/stage_sequence_execute.go @@ -137,6 +137,7 @@ func SpawnSequencingStage( log.Info(fmt.Sprintf("[%s] Starting batch %d...", logPrefix, batchState.batchNumber)) + var allConditionsOK bool for blockNumber := executionAt + 1; runLoopBlocks; blockNumber++ { log.Info(fmt.Sprintf("[%s] Starting block %d (forkid %v)...", logPrefix, blockNumber, batchState.forkId)) logTicker.Reset(10 * time.Second) @@ -223,12 +224,18 @@ func SpawnSequencingStage( return err } } else if !batchState.isL1Recovery() { - batchState.blockState.transactionsForInclusion, err = getNextPoolTransactions(ctx, cfg, executionAt, batchState.forkId, batchState.yieldedTransactions) + batchState.blockState.transactionsForInclusion, allConditionsOK, err = getNextPoolTransactions(ctx, cfg, executionAt, batchState.forkId, batchState.yieldedTransactions) if err != nil { return err } + if len(batchState.blockState.transactionsForInclusion) == 0 { - time.Sleep(batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool) + if allConditionsOK { + time.Sleep(batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool) + } else { + time.Sleep(batchContext.cfg.zk.SequencerTimeoutOnEmptyTxPool / 5) // we do not need to sleep too long for txpool not ready + } + } else { log.Trace(fmt.Sprintf("[%s] Yielded transactions from the pool", logPrefix), "txCount", len(batchState.blockState.transactionsForInclusion)) } diff --git a/zk/stages/stage_sequence_execute_transactions.go b/zk/stages/stage_sequence_execute_transactions.go index 5348eace90d..42ff1285b2e 100644 --- a/zk/stages/stage_sequence_execute_transactions.go +++ b/zk/stages/stage_sequence_execute_transactions.go @@ -21,18 +21,19 @@ import ( "github.com/ledgerwatch/log/v3" ) -func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executionAt, forkId uint64, alreadyYielded mapset.Set[[32]byte]) ([]types.Transaction, error) { +func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executionAt, forkId uint64, alreadyYielded mapset.Set[[32]byte]) ([]types.Transaction, bool, error) { cfg.txPool.LockFlusher() defer cfg.txPool.UnlockFlusher() var transactions []types.Transaction + var allConditionsOk bool var err error gasLimit := utils.GetBlockGasLimitForFork(forkId) if err := cfg.txPoolDb.View(ctx, func(poolTx kv.Tx) error { slots := types2.TxsRlp{} - if _, _, err = cfg.txPool.YieldBest(cfg.yieldSize, &slots, poolTx, executionAt, gasLimit, alreadyYielded); err != nil { + if allConditionsOk, _, err = cfg.txPool.YieldBest(cfg.yieldSize, &slots, poolTx, executionAt, gasLimit, alreadyYielded); err != nil { return err } yieldedTxs, err := extractTransactionsFromSlot(&slots) @@ -42,10 +43,10 @@ func getNextPoolTransactions(ctx context.Context, cfg SequenceBlockCfg, executio transactions = append(transactions, yieldedTxs...) return nil }); err != nil { - return nil, err + return nil, allConditionsOk, err } - return transactions, err + return transactions, allConditionsOk, err } func getLimboTransaction(ctx context.Context, cfg SequenceBlockCfg, txHash *common.Hash) ([]types.Transaction, error) { From 26ea48955c57b4d9306118fcabbf628be2dd72c5 Mon Sep 17 00:00:00 2001 From: hexoscott <70711990+hexoscott@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:54:14 +0100 Subject: [PATCH 2/2] increase defaults for data stream server timeouts (#1045) --- cmd/utils/flags.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 53d5aa415e7..991d313a311 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -560,17 +560,17 @@ var ( DataStreamWriteTimeout = cli.DurationFlag{ Name: "zkevm.data-stream-writeTimeout", Usage: "Define the TCP write timeout when sending data to a datastream client", - Value: 5 * time.Second, + Value: 20 * time.Second, } DataStreamInactivityTimeout = cli.DurationFlag{ Name: "zkevm.data-stream-inactivity-timeout", Usage: "Define the inactivity timeout when interacting with a data stream server", - Value: 10 * time.Second, + Value: 10 * time.Minute, } DataStreamInactivityCheckInterval = cli.DurationFlag{ Name: "zkevm.data-stream-inactivity-check-interval", Usage: "Define the inactivity check interval timeout when interacting with a data stream server", - Value: 2 * time.Second, + Value: 5 * time.Minute, } Limbo = cli.BoolFlag{ Name: "zkevm.limbo",