From c73661ebbf880556699020acc0a74a98f10a427b Mon Sep 17 00:00:00 2001 From: David Date: Fri, 26 Jan 2024 09:02:07 +0800 Subject: [PATCH] feat(prover): fix a tier selection issue (#534) --- prover/prover.go | 8 +++++++- prover/prover_test.go | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/prover/prover.go b/prover/prover.go index 1ea4a3fe5..a9f1bb467 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -803,17 +803,23 @@ func (p *Prover) handleNewBlockProposedEvent(ctx context.Context, e *bindings.Ta } } + tier := e.Meta.MinTier + if p.IsGuardianProver() { + tier = encoding.TierGuardianID + } + log.Info( "Proposed block is provable", "blockID", e.BlockId, "prover", e.AssignedProver, "expiresAt", provingWindowExpiresAt, "minTier", e.Meta.MinTier, + "currentTier", tier, ) metrics.ProverProofsAssigned.Inc(1) - if proofSubmitter := p.selectSubmitter(e.Meta.MinTier); proofSubmitter != nil { + if proofSubmitter := p.selectSubmitter(tier); proofSubmitter != nil { return proofSubmitter.RequestProof(ctx, e) } diff --git a/prover/prover_test.go b/prover/prover_test.go index 0bffd81e5..ea0abae50 100644 --- a/prover/prover_test.go +++ b/prover/prover_test.go @@ -235,7 +235,10 @@ func (s *ProverTestSuite) TestContestWrongBlocks() { contesterKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_CONTRACT_OWNER_PRIVATE_KEY"))) s.Nil(err) - s.NotNil(s.initProver(context.Background(), contesterKey)) + s.NotNil(s.initProver( + context.Background(), + contesterKey, + )) s.p.cfg.ContesterMode = true s.Greater(header.Number.Uint64(), uint64(0)) @@ -247,8 +250,13 @@ func (s *ProverTestSuite) TestContestWrongBlocks() { s.Equal(header.ParentHash, common.BytesToHash(contestedEvent.Tran.ParentHash[:])) s.Nil(s.p.onTransitionContested(context.Background(), contestedEvent)) + + s.p.cfg.GuardianProverAddress = common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")) s.True(s.p.IsGuardianProver()) + s.p.rpc.GuardianProver, err = bindings.NewGuardianProver(s.p.cfg.GuardianProverAddress, s.p.rpc.L1) + s.Nil(err) + approvedSink := make(chan *bindings.GuardianProverApproved) approvedSub, err := s.p.rpc.GuardianProver.WatchApproved(nil, approvedSink, [](*big.Int){}) s.Nil(err) @@ -455,7 +463,10 @@ func TestProverTestSuite(t *testing.T) { suite.Run(t, new(ProverTestSuite)) } -func (s *ProverTestSuite) initProver(ctx context.Context, key *ecdsa.PrivateKey) *url.URL { +func (s *ProverTestSuite) initProver( + ctx context.Context, + key *ecdsa.PrivateKey, +) *url.URL { proverServerURL := testutils.LocalRandomProverEndpoint() port, err := strconv.Atoi(proverServerURL.Port()) s.Nil(err) @@ -475,7 +486,6 @@ func (s *ProverTestSuite) initProver(ctx context.Context, key *ecdsa.PrivateKey) TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), - GuardianProverAddress: common.HexToAddress(os.Getenv("GUARDIAN_PROVER_CONTRACT_ADDRESS")), L1ProverPrivKey: key, Dummy: true, ProveUnassignedBlocks: true,