Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(prover): update guardian prover check
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Oct 23, 2023
1 parent 498616f commit f0f9800
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 0 additions & 2 deletions prover/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
1 change: 0 additions & 1 deletion prover/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 9 additions & 4 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions prover/prover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f0f9800

Please sign in to comment.