Skip to content

Commit

Permalink
cmd/era: don't hardcode batch size
Browse files Browse the repository at this point in the history
  • Loading branch information
lightclient committed Feb 16, 2023
1 parent 34abdff commit 4001b0c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions cmd/era/main.go
Expand Up @@ -51,6 +51,11 @@ var (
Usage: "network name associated with Era files",
Value: "mainnet",
}
batchSizeFlag = &cli.IntFlag{
Name: "batchSize",
Usage: "number blocks per era batch",
Value: era.MaxEraBatchSize,
}
txsFlag = &cli.BoolFlag{
Name: "txs",
Usage: "print full transaction values",
Expand All @@ -74,9 +79,10 @@ var (
Action: info,
}
verifyCommand = &cli.Command{
Name: "verify",
Usage: "verifies each epoch",
Action: verify,
Name: "verify",
ArgsUsage: "<expected>",
Usage: "verifies each epoch against expected accumulator root",
Action: verify,
}
convertCommand = &cli.Command{
Name: "convert",
Expand All @@ -95,6 +101,7 @@ func init() {
app.Flags = []cli.Flag{
dirFlag,
networkFlag,
batchSizeFlag,
}
}

Expand All @@ -112,7 +119,7 @@ func block(ctx *cli.Context) error {
return fmt.Errorf("invalid block number: %w", err)
}

r, err := openEra(ctx, num/uint64(era.MaxEraBatchSize))
r, err := openEra(ctx, num/uint64(ctx.Int(batchSizeFlag.Name)))
defer r.Close()

// Read block with number.
Expand Down Expand Up @@ -250,7 +257,7 @@ func verify(ctx *cli.Context) error {
if err == io.EOF {
break
} else if err != nil {
return fmt.Errorf("error reading block %d: %w", i*era.MaxEraBatchSize+j, err)
return fmt.Errorf("error reading block %d: %w", i*ctx.Int(batchSizeFlag.Name)+j, err)
}
// Calculate receipt root from receipt list and check
// value against block.
Expand Down Expand Up @@ -329,7 +336,7 @@ func recompute(ctx *cli.Context) error {
if err == io.EOF {
break
} else if err != nil {
return fmt.Errorf("error reading block %d: %w", i*era.MaxEraBatchSize+j, err)
return fmt.Errorf("error reading block %d: %w", i*ctx.Int(batchSizeFlag.Name)+j, err)
}
td.Add(td, b.Difficulty())
blocks = append(blocks, b)
Expand Down

0 comments on commit 4001b0c

Please sign in to comment.