From d5b798dbd8568af2e71285b6a29c0c4a327198e1 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 9 Jan 2024 12:36:04 +0800 Subject: [PATCH] feat(prover): set default `--prover.proveUnassignedBlocks` and `--mode.contester` value for guardian provers (#492) --- prover/config.go | 19 ++++++++++++++----- prover/config_test.go | 4 +++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/prover/config.go b/prover/config.go index d2730dc98..e71cd097e 100644 --- a/prover/config.go +++ b/prover/config.go @@ -59,9 +59,7 @@ type Config struct { // NewConfigFromCliContext creates a new config instance from command line flags. func NewConfigFromCliContext(c *cli.Context) (*Config, error) { - l1ProverPrivKeyStr := c.String(flags.L1ProverPrivKey.Name) - - l1ProverPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(l1ProverPrivKeyStr)) + l1ProverPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(c.String(flags.L1ProverPrivKey.Name))) if err != nil { return nil, fmt.Errorf("invalid L1 prover private key: %w", err) } @@ -108,8 +106,19 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { var guardianProverHealthCheckServerEndpoint *url.URL if c.IsSet(flags.GuardianProverHealthCheckServerEndpoint.Name) { - guardianProverHealthCheckServerEndpoint, err = url.Parse(c.String(flags.GuardianProverHealthCheckServerEndpoint.Name)) - if err != nil { + if guardianProverHealthCheckServerEndpoint, err = url.Parse( + c.String(flags.GuardianProverHealthCheckServerEndpoint.Name), + ); err != nil { + return nil, err + } + } + + // If we are running a guardian prover, we need to prove unassigned blocks and run in contester mode by default. + if c.IsSet(flags.GuardianProver.Name) { + if err := c.Set(flags.ProveUnassignedBlocks.Name, "true"); err != nil { + return nil, err + } + if err := c.Set(flags.ContesterMode.Name, "true"); err != nil { return nil, err } } diff --git a/prover/config_test.go b/prover/config_test.go index 8e2c2ede3..673164991 100644 --- a/prover/config_test.go +++ b/prover/config_test.go @@ -40,7 +40,8 @@ func (s *ProverTestSuite) TestNewConfigFromCliContextGuardianProver() { ) s.True(c.Dummy) s.Equal("", c.Graffiti) - s.Equal(true, c.ProveUnassignedBlocks) + s.True(c.ProveUnassignedBlocks) + s.True(c.ContesterMode) s.Equal(rpcTimeout, *c.RPCTimeout) s.Equal(uint64(8), c.Capacity) s.Equal(uint64(minTierFee), c.MinOptimisticTierFee.Uint64()) @@ -126,6 +127,7 @@ func (s *ProverTestSuite) SetupApp() *cli.App { &cli.Uint64Flag{Name: flags.MaxProposedIn.Name}, &cli.StringFlag{Name: flags.ProverAssignmentHookAddress.Name}, &cli.StringFlag{Name: flags.Allowance.Name}, + &cli.StringFlag{Name: flags.ContesterMode.Name}, } app.Action = func(ctx *cli.Context) error { _, err := NewConfigFromCliContext(ctx)