From f0f980054fadd618087509c95485f412b0d4cf9d Mon Sep 17 00:00:00 2001 From: David Date: Mon, 23 Oct 2023 21:47:54 +0800 Subject: [PATCH] feat(prover): update guardian prover check --- prover/config.go | 2 -- prover/config_test.go | 1 - prover/prover.go | 13 +++++++++---- prover/prover_test.go | 3 --- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/prover/config.go b/prover/config.go index 5afcd6878..4699e1cf7 100644 --- a/prover/config.go +++ b/prover/config.go @@ -27,7 +27,6 @@ type Config struct { StartingBlockID *big.Int MaxConcurrentProvingJobs uint Dummy bool - GuardianProver bool GuardianProverAddress common.Address GuardianProverPrivateKey *ecdsa.PrivateKey GuardianProofSubmissionDelay time.Duration @@ -116,7 +115,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { StartingBlockID: startingBlockID, MaxConcurrentProvingJobs: c.Uint(flags.MaxConcurrentProvingJobs.Name), Dummy: c.Bool(flags.Dummy.Name), - GuardianProver: c.IsSet(flags.GuardianProver.Name), GuardianProverAddress: common.HexToAddress(c.String(flags.GuardianProver.Name)), GuardianProverPrivateKey: guardianProverPrivKey, GuardianProofSubmissionDelay: c.Duration(flags.GuardianProofSubmissionDelay.Name), diff --git a/prover/config_test.go b/prover/config_test.go index ebf2afb99..274a4098d 100644 --- a/prover/config_test.go +++ b/prover/config_test.go @@ -38,7 +38,6 @@ func (s *ProverTestSuite) TestNewConfigFromCliContextGuardianProver() { crypto.PubkeyToAddress(c.L1ProverPrivKey.PublicKey), ) s.True(c.Dummy) - s.True(c.GuardianProver) s.Equal( crypto.PubkeyToAddress(s.p.cfg.GuardianProverPrivateKey.PublicKey), crypto.PubkeyToAddress(c.GuardianProverPrivateKey.PublicKey), diff --git a/prover/prover.go b/prover/prover.go index b8e7d2be6..dbde8dc6f 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -229,9 +229,9 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) { TaikoL1Address: p.cfg.TaikoL1Address, Rpc: p.rpc, LivenessBond: protocolConfigs.LivenessBond, - IsGuardian: p.cfg.GuardianProver, + IsGuardian: p.IsGuardianProver(), } - if p.cfg.GuardianProver { + if p.IsGuardianProver() { proverServerOpts.ProverPrivateKey = p.cfg.GuardianProverPrivateKey } if p.srv, err = server.New(proverServerOpts); err != nil { @@ -1038,9 +1038,14 @@ func (p *Prover) getSubmitterByTier(tier uint16) proofSubmitter.Submitter { return nil } +// IsGuardianProver reutrns true if the current prover is a guardian prover. +func (p *Prover) IsGuardianProver() bool { + return p.cfg.GuardianProverAddress != common.Address{} +} + // takeOneCapacity takes one capacity from the capacity manager. func (p *Prover) takeOneCapacity(blockID *big.Int) error { - if !p.cfg.GuardianProver { + if !p.IsGuardianProver() { if _, ok := p.capacityManager.TakeOneCapacity(blockID.Uint64()); !ok { return errNoCapacity } @@ -1051,7 +1056,7 @@ func (p *Prover) takeOneCapacity(blockID *big.Int) error { // releaseOneCapacity releases one capacity to the capacity manager. func (p *Prover) releaseOneCapacity(blockID *big.Int) { - if !p.cfg.GuardianProver { + if !p.IsGuardianProver() { _, released := p.capacityManager.ReleaseOneCapacity(blockID.Uint64()) if !released { log.Error("Failed to release capacity", "id", blockID) diff --git a/prover/prover_test.go b/prover/prover_test.go index a81972662..a7ae360af 100644 --- a/prover/prover_test.go +++ b/prover/prover_test.go @@ -53,7 +53,6 @@ func (s *ProverTestSuite) SetupTest() { GuardianProverAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")), L1ProverPrivKey: l1ProverPrivKey, GuardianProverPrivateKey: l1ProverPrivKey, - GuardianProver: false, Dummy: true, MaxConcurrentProvingJobs: 1, ProveUnassignedBlocks: true, @@ -149,7 +148,6 @@ func (s *ProverTestSuite) TestInitError() { } func (s *ProverTestSuite) TestOnBlockProposed() { - s.p.cfg.GuardianProver = true // Init prover l1ProverPrivKey, err := crypto.ToECDSA(common.Hex2Bytes(os.Getenv("L1_PROVER_PRIVATE_KEY"))) s.Nil(err) @@ -221,7 +219,6 @@ func (s *ProverTestSuite) TestContestWrongBlocks() { Tier: e.MinTier, })) s.p.cfg.ContesterMode = true - s.p.cfg.GuardianProver = true // Submit a wrong proof at first. sink := make(chan *bindings.TaikoL1ClientTransitionProved)