Skip to content

Commit

Permalink
configurable witness unwind limit (#1617) (#1618)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Fairclough <[email protected]>
  • Loading branch information
IvanBelyakoff and hexoscott authored Jan 9, 2025
1 parent 63a2d8e commit ba9c7a4
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
6 changes: 6 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,12 @@ var (
Usage: "A size of the memdb used on witness generation in format \"2GB\". Might fail generation for older batches if not enough for the unwind.",
Value: datasizeFlagValue(2 * datasize.GB),
}
WitnessUnwindLimit = cli.Uint64Flag{
Name: "zkevm.witness-unwind-limit",
Usage: "The maximum number of blocks the witness generation can unwind",
Value: 500_000,
}

ExecutorMaxConcurrentRequests = cli.IntFlag{
Name: "zkevm.executor-max-concurrent-requests",
Usage: "The maximum number of concurrent requests to the executor",
Expand Down
1 change: 1 addition & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
backend.config.Zk,
backend.engine,
backend.config.WitnessContractInclusion,
backend.config.WitnessUnwindLimit,
)

var legacyExecutors []*legacy_executor_verifier.Executor = make([]*legacy_executor_verifier.Executor, 0, len(cfg.ExecutorUrls))
Expand Down
1 change: 1 addition & 0 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Zk struct {
ExecutorRequestTimeout time.Duration
DatastreamNewBlockTimeout time.Duration
WitnessMemdbSize datasize.ByteSize
WitnessUnwindLimit uint64
ExecutorMaxConcurrentRequests int
Limbo bool
AllowFreeTransactions bool
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 @@ -220,6 +220,7 @@ var DefaultFlags = []cli.Flag{
&utils.ExecutorRequestTimeout,
&utils.DatastreamNewBlockTimeout,
&utils.WitnessMemdbSize,
&utils.WitnessUnwindLimit,
&utils.ExecutorMaxConcurrentRequests,
&utils.Limbo,
&utils.AllowFreeTransactions,
Expand Down
2 changes: 2 additions & 0 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
}

witnessMemSize := utils.DatasizeFlagValue(ctx, utils.WitnessMemdbSize.Name)
witnessUnwindLimit := ctx.Uint64(utils.WitnessUnwindLimit.Name)

badBatchStrings := strings.Split(ctx.String(utils.BadBatches.Name), ",")
badBatches := make([]uint64, 0)
Expand Down Expand Up @@ -214,6 +215,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
ExecutorRequestTimeout: ctx.Duration(utils.ExecutorRequestTimeout.Name),
DatastreamNewBlockTimeout: ctx.Duration(utils.DatastreamNewBlockTimeout.Name),
WitnessMemdbSize: *witnessMemSize,
WitnessUnwindLimit: witnessUnwindLimit,
ExecutorMaxConcurrentRequests: ctx.Int(utils.ExecutorMaxConcurrentRequests.Name),
Limbo: ctx.Bool(utils.Limbo.Name),
AllowFreeTransactions: ctx.Bool(utils.AllowFreeTransactions.Name),
Expand Down
1 change: 1 addition & 0 deletions turbo/jsonrpc/zkevm_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ func (api *ZkEvmAPIImpl) buildGenerator(ctx context.Context, tx kv.Tx, witnessMo
api.config.Zk,
api.ethApi._engine,
api.config.WitnessContractInclusion,
api.config.WitnessUnwindLimit,
)

fullWitness := false
Expand Down
43 changes: 22 additions & 21 deletions zk/witness/witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,20 @@ import (
)

var (
maxGetProofRewindBlockCount uint64 = 500_000

ErrEndBeforeStart = errors.New("end block must be higher than start block")
)

type Generator struct {
tx kv.Tx
dirs datadir.Dirs
historyV3 bool
agg *libstate.Aggregator
blockReader services.FullBlockReader
chainCfg *chain.Config
zkConfig *ethconfig.Zk
engine consensus.EngineReader
forcedContracts []libcommon.Address
tx kv.Tx
dirs datadir.Dirs
historyV3 bool
agg *libstate.Aggregator
blockReader services.FullBlockReader
chainCfg *chain.Config
zkConfig *ethconfig.Zk
engine consensus.EngineReader
forcedContracts []libcommon.Address
witnessUnwindLimit uint64
}

func NewGenerator(
Expand All @@ -61,16 +60,18 @@ func NewGenerator(
zkConfig *ethconfig.Zk,
engine consensus.EngineReader,
forcedContracs []libcommon.Address,
witnessUnwindLimit uint64,
) *Generator {
return &Generator{
dirs: dirs,
historyV3: historyV3,
agg: agg,
blockReader: blockReader,
chainCfg: chainCfg,
zkConfig: zkConfig,
engine: engine,
forcedContracts: forcedContracs,
dirs: dirs,
historyV3: historyV3,
agg: agg,
blockReader: blockReader,
chainCfg: chainCfg,
zkConfig: zkConfig,
engine: engine,
forcedContracts: forcedContracs,
witnessUnwindLimit: witnessUnwindLimit,
}
}

Expand Down Expand Up @@ -197,8 +198,8 @@ func (g *Generator) generateWitness(tx kv.Tx, ctx context.Context, batchNum uint
}

if startBlock-1 < latestBlock {
if latestBlock-startBlock > maxGetProofRewindBlockCount {
return nil, fmt.Errorf("requested block is too old, block must be within %d blocks of the head block number (currently %d)", maxGetProofRewindBlockCount, latestBlock)
if latestBlock-startBlock > g.witnessUnwindLimit {
return nil, fmt.Errorf("requested block is too old, block must be within %d blocks of the head block number (currently %d)", g.witnessUnwindLimit, latestBlock)
}

if err := UnwindForWitness(ctx, rwtx, startBlock, latestBlock, g.dirs, g.historyV3, g.agg); err != nil {
Expand Down

0 comments on commit ba9c7a4

Please sign in to comment.