Skip to content

Commit

Permalink
Add sequencer slowdown (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
sieniven authored Jul 9, 2024
1 parent 8fab3fa commit f27add6
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cmd/utils/flags_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
// XLayer apollo
// X Layer apollo
ApolloEnableFlag = cli.BoolFlag{
Name: "zkevm.apollo-enabled",
Usage: "Apollo enable flag.",
Expand Down Expand Up @@ -152,6 +152,11 @@ var (
Usage: "Used to determine whether pending tx has reached the threshold for congestion",
Value: 0,
}
SequencerBatchSleepDuration = cli.DurationFlag{
Name: "zkevm.sequencer-batch-sleep-duration",
Usage: "Full batch sleep duration is the time the sequencer sleeps between each full batch iteration.",
Value: 0 * time.Second,
}
)

func setGPOXLayer(ctx *cli.Context, cfg *gaspricecfg.XLayerConfig) {
Expand Down
10 changes: 10 additions & 0 deletions eth/ethconfig/apollo_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ethconfig
import (
"fmt"
"sync"
"time"
)

// ApolloConfig is the apollo eth backend dynamic config
Expand Down Expand Up @@ -41,3 +42,12 @@ func (c *ApolloConfig) Enable() bool {
defer c.RUnlock()
return c.EnableApollo
}

func GetFullBatchSleepDuration(localDuration time.Duration) time.Duration {
conf, err := GetApolloConfig()
if err != nil {
return localDuration
} else {
return conf.Zk.XLayer.SequencerBatchSleepDuration
}
}
4 changes: 4 additions & 0 deletions eth/ethconfig/config_xlayer.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package ethconfig

import "time"

// XLayerConfig is the X Layer config used on the eth backend
type XLayerConfig struct {
Apollo ApolloClientConfig
Nacos NacosConfig
EnableInnerTx bool
// Sequencer
SequencerBatchSleepDuration time.Duration
}

var DefaultXLayerConfig = &XLayerConfig{}
Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1435,9 +1435,9 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down
1 change: 1 addition & 0 deletions test/config/test.erigon.rpc.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ zkevm.sequencer-initial-fork-id: 9
zkevm.sequencer-block-seal-time: "6s"
zkevm.sequencer-batch-seal-time: "12s"
zkevm.sequencer-non-empty-batch-seal-time: "3s"
zkevm.sequencer-batch-sleep-duration: "0s"

zkevm.data-stream-host: "localhost"
zkevm.data-stream-port: 6900
Expand Down
1 change: 1 addition & 0 deletions test/config/test.erigon.seq.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ zkevm.sequencer-initial-fork-id: 9
zkevm.sequencer-block-seal-time: "6s"
zkevm.sequencer-batch-seal-time: "12s"
zkevm.sequencer-non-empty-batch-seal-time: "3s"
zkevm.sequencer-batch-sleep-duration: "0s"

zkevm.data-stream-host: "localhost"
zkevm.data-stream-port: 6900
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,5 @@ var DefaultFlags = []cli.Flag{
&utils.TxPoolEnableWhitelistFlag,
&utils.TxPoolWhiteList,
&utils.TxPoolBlockedList,
&utils.SequencerBatchSleepDuration,
}
3 changes: 2 additions & 1 deletion turbo/cli/flags_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func ApplyFlagsForXLayerConfig(ctx *cli.Context, cfg *ethconfig.Config) {
ApplicationName: ctx.String(utils.NacosApplicationNameFlag.Name),
ExternalListenAddr: ctx.String(utils.NacosExternalListenAddrFlag.Name),
},
EnableInnerTx: ctx.Bool(utils.AllowInternalTransactions.Name),
EnableInnerTx: ctx.Bool(utils.AllowInternalTransactions.Name),
SequencerBatchSleepDuration: ctx.Duration(utils.SequencerBatchSleepDuration.Name),
}
}
3 changes: 3 additions & 0 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ func SpawnSequencingStage(
}
}

// X Layer handle
tryToSleepSequencer(cfg.zk.XLayer.SequencerBatchSleepDuration, logPrefix)

return nil
}

Expand Down
17 changes: 17 additions & 0 deletions zk/stages/stage_sequence_execute_xlayer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package stages

import (
"fmt"
"time"

"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/log/v3"
)

func tryToSleepSequencer(localDuration time.Duration, logPrefix string) {
fullBatchSleepDuration := ethconfig.GetFullBatchSleepDuration(localDuration)
if fullBatchSleepDuration > 0 {
log.Info(fmt.Sprintf("[%s] Slow down sequencer: %v", logPrefix, fullBatchSleepDuration))
time.Sleep(fullBatchSleepDuration)
}
}

0 comments on commit f27add6

Please sign in to comment.