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

Commit 64ec861

Browse files
feat(prover): update server APIs (#618)
1 parent 4145dae commit 64ec861

File tree

11 files changed

+153
-147
lines changed

11 files changed

+153
-147
lines changed

internal/testutils/helper.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,16 @@ func (s *ClientTestSuite) NewTestProverServer(
171171
s.Nil(err)
172172

173173
srv, err := server.New(&server.NewProverServerOpts{
174-
ProverPrivateKey: proverPrivKey,
175-
MinOptimisticTierFee: common.Big1,
176-
MinSgxTierFee: common.Big1,
177-
MinSgxAndZkVMTierFee: common.Big1,
178-
MaxExpiry: 24 * time.Hour,
179-
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
180-
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
181-
ProposeConcurrencyGuard: make(chan struct{}, 1024),
182-
RPC: s.RPCClient,
183-
ProtocolConfigs: &protocolConfig,
184-
LivenessBond: protocolConfig.LivenessBond,
174+
ProverPrivateKey: proverPrivKey,
175+
MinOptimisticTierFee: common.Big1,
176+
MinSgxTierFee: common.Big1,
177+
MinSgxAndZkVMTierFee: common.Big1,
178+
MaxExpiry: 24 * time.Hour,
179+
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
180+
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
181+
RPC: s.RPCClient,
182+
ProtocolConfigs: &protocolConfig,
183+
LivenessBond: protocolConfig.LivenessBond,
185184
})
186185
s.Nil(err)
187186

prover/event_handler/assignment_expired.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ import (
88
"github.com/ethereum/go-ethereum/log"
99
"github.com/taikoxyz/taiko-client/bindings"
1010
"github.com/taikoxyz/taiko-client/pkg/rpc"
11-
proofSubmitter "github.com/taikoxyz/taiko-client/prover/proof_submitter"
11+
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
1212
)
1313

1414
// AssignmentExpiredEventHandler is responsible for handling the expiration of proof assignments.
1515
type AssignmentExpiredEventHandler struct {
1616
rpc *rpc.Client
1717
proverAddress common.Address
18-
proofSubmissionCh chan<- *proofSubmitter.ProofRequestBody
19-
proofContestCh chan<- *proofSubmitter.ContestRequestBody
18+
proofSubmissionCh chan<- *proofProducer.ProofRequestBody
19+
proofContestCh chan<- *proofProducer.ContestRequestBody
2020
contesterMode bool
2121
}
2222

2323
// NewAssignmentExpiredEventHandler creates a new AssignmentExpiredEventHandler instance.
2424
func NewAssignmentExpiredEventHandler(
2525
rpc *rpc.Client,
2626
proverAddress common.Address,
27-
proofSubmissionCh chan *proofSubmitter.ProofRequestBody,
28-
proofContestCh chan *proofSubmitter.ContestRequestBody,
27+
proofSubmissionCh chan *proofProducer.ProofRequestBody,
28+
proofContestCh chan *proofProducer.ContestRequestBody,
2929
contesterMode bool,
3030
) *AssignmentExpiredEventHandler {
3131
return &AssignmentExpiredEventHandler{rpc, proverAddress, proofSubmissionCh, proofContestCh, contesterMode}
@@ -60,7 +60,7 @@ func (h *AssignmentExpiredEventHandler) Handle(
6060

6161
// If there is no contester, we submit a contest to protocol.
6262
if proofStatus.CurrentTransitionState.Contester == rpc.ZeroAddress {
63-
h.proofContestCh <- &proofSubmitter.ContestRequestBody{
63+
h.proofContestCh <- &proofProducer.ContestRequestBody{
6464
BlockID: e.BlockId,
6565
ProposedIn: new(big.Int).SetUint64(e.Raw.BlockNumber),
6666
ParentHash: proofStatus.ParentHeader.Hash(),
@@ -72,7 +72,7 @@ func (h *AssignmentExpiredEventHandler) Handle(
7272
}
7373

7474
go func() {
75-
h.proofSubmissionCh <- &proofSubmitter.ProofRequestBody{
75+
h.proofSubmissionCh <- &proofProducer.ProofRequestBody{
7676
Tier: proofStatus.CurrentTransitionState.Tier + 1,
7777
Event: e,
7878
}
@@ -82,7 +82,7 @@ func (h *AssignmentExpiredEventHandler) Handle(
8282
}
8383

8484
go func() {
85-
h.proofSubmissionCh <- &proofSubmitter.ProofRequestBody{Tier: e.Meta.MinTier, Event: e}
85+
h.proofSubmissionCh <- &proofProducer.ProofRequestBody{Tier: e.Meta.MinTier, Event: e}
8686
}()
8787
return nil
8888
}

prover/event_handler/block_proposed.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/taikoxyz/taiko-client/pkg/rpc"
1919
guardianProverHeartbeater "github.com/taikoxyz/taiko-client/prover/guardian_prover_heartbeater"
2020
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
21-
proofSubmitter "github.com/taikoxyz/taiko-client/prover/proof_submitter"
2221
state "github.com/taikoxyz/taiko-client/prover/shared_state"
2322
)
2423

@@ -35,8 +34,8 @@ type BlockProposedEventHandler struct {
3534
rpc *rpc.Client
3635
proofGenerationCh chan<- *proofProducer.ProofWithHeader
3736
assignmentExpiredCh chan<- *bindings.TaikoL1ClientBlockProposed
38-
proofSubmissionCh chan<- *proofSubmitter.ProofRequestBody
39-
proofContestCh chan<- *proofSubmitter.ContestRequestBody
37+
proofSubmissionCh chan<- *proofProducer.ProofRequestBody
38+
proofContestCh chan<- *proofProducer.ContestRequestBody
4039
backOffRetryInterval time.Duration
4140
backOffMaxRetrys uint64
4241
contesterMode bool
@@ -52,8 +51,8 @@ type NewBlockProposedEventHandlerOps struct {
5251
RPC *rpc.Client
5352
ProofGenerationCh chan *proofProducer.ProofWithHeader
5453
AssignmentExpiredCh chan *bindings.TaikoL1ClientBlockProposed
55-
ProofSubmissionCh chan *proofSubmitter.ProofRequestBody
56-
ProofContestCh chan *proofSubmitter.ContestRequestBody
54+
ProofSubmissionCh chan *proofProducer.ProofRequestBody
55+
ProofContestCh chan *proofProducer.ContestRequestBody
5756
BackOffRetryInterval time.Duration
5857
BackOffMaxRetrys uint64
5958
ContesterMode bool
@@ -265,7 +264,7 @@ func (h *BlockProposedEventHandler) checkExpirationAndSubmitProof(
265264
}
266265

267266
// The proof submitted to protocol is invalid.
268-
h.proofContestCh <- &proofSubmitter.ContestRequestBody{
267+
h.proofContestCh <- &proofProducer.ContestRequestBody{
269268
BlockID: e.BlockId,
270269
ProposedIn: new(big.Int).SetUint64(e.Raw.BlockNumber),
271270
ParentHash: proofStatus.ParentHeader.Hash(),
@@ -352,7 +351,7 @@ func (h *BlockProposedEventHandler) checkExpirationAndSubmitProof(
352351

353352
metrics.ProverProofsAssigned.Inc(1)
354353

355-
h.proofSubmissionCh <- &proofSubmitter.ProofRequestBody{Tier: tier, Event: e}
354+
h.proofSubmissionCh <- &proofProducer.ProofRequestBody{Tier: tier, Event: e}
356355

357356
return nil
358357
}

prover/event_handler/transition_contested.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ import (
99
"github.com/ethereum/go-ethereum/log"
1010
"github.com/taikoxyz/taiko-client/bindings"
1111
"github.com/taikoxyz/taiko-client/pkg/rpc"
12-
proofSubmitter "github.com/taikoxyz/taiko-client/prover/proof_submitter"
12+
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
1313
)
1414

1515
// TransitionContestedEventHandler is responsible for handling the TransitionContested event.
1616
type TransitionContestedEventHandler struct {
1717
rpc *rpc.Client
18-
proofSubmissionCh chan<- *proofSubmitter.ProofRequestBody
18+
proofSubmissionCh chan<- *proofProducer.ProofRequestBody
1919
contesterMode bool
2020
}
2121

2222
// NewTransitionContestedEventHandler creates a new TransitionContestedEventHandler instance.
2323
func NewTransitionContestedEventHandler(
2424
rpc *rpc.Client,
25-
proofSubmissionCh chan *proofSubmitter.ProofRequestBody,
25+
proofSubmissionCh chan *proofProducer.ProofRequestBody,
2626
contesterMode bool,
2727
) *TransitionContestedEventHandler {
2828
return &TransitionContestedEventHandler{rpc, proofSubmissionCh, contesterMode}
@@ -99,7 +99,7 @@ func (h *TransitionContestedEventHandler) Handle(
9999
}
100100

101101
go func() {
102-
h.proofSubmissionCh <- &proofSubmitter.ProofRequestBody{
102+
h.proofSubmissionCh <- &proofProducer.ProofRequestBody{
103103
Tier: e.Tier + 1, // We need to send a higher tier proof to resolve the current contest.
104104
Event: blockProposedEvent,
105105
}

prover/event_handler/transition_proved.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ import (
1010
"github.com/taikoxyz/taiko-client/bindings"
1111
"github.com/taikoxyz/taiko-client/internal/metrics"
1212
"github.com/taikoxyz/taiko-client/pkg/rpc"
13-
proofSubmitter "github.com/taikoxyz/taiko-client/prover/proof_submitter"
13+
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
1414
)
1515

1616
// TransitionProvedEventHandler is responsible for handling the TransitionProved event.
1717
type TransitionProvedEventHandler struct {
1818
rpc *rpc.Client
19-
proofContestCh chan<- *proofSubmitter.ContestRequestBody
19+
proofContestCh chan<- *proofProducer.ContestRequestBody
2020
contesterMode bool
2121
}
2222

2323
// NewTransitionProvedEventHandler creates a new TransitionProvedEventHandler instance.
2424
func NewTransitionProvedEventHandler(
2525
rpc *rpc.Client,
26-
proofContestCh chan *proofSubmitter.ContestRequestBody,
26+
proofContestCh chan *proofProducer.ContestRequestBody,
2727
contesterMode bool,
2828
) *TransitionProvedEventHandler {
2929
return &TransitionProvedEventHandler{rpc, proofContestCh, contesterMode}
@@ -80,7 +80,7 @@ func (h *TransitionProvedEventHandler) Handle(
8080
)
8181

8282
go func() {
83-
h.proofContestCh <- &proofSubmitter.ContestRequestBody{
83+
h.proofContestCh <- &proofProducer.ContestRequestBody{
8484
BlockID: e.BlockId,
8585
ProposedIn: new(big.Int).SetUint64(blockInfo.Blk.ProposedIn),
8686
ParentHash: e.Tran.ParentHash,

prover/proof_producer/proof_producer.go

+15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ var (
1717
errProofGenerating = errors.New("proof is generating")
1818
)
1919

20+
// ProofRequestBody represents a request body to generate a proof.
21+
type ProofRequestBody struct {
22+
Tier uint16
23+
Event *bindings.TaikoL1ClientBlockProposed
24+
}
25+
26+
// ContestRequestBody represents a request body to generate a proof for contesting.
27+
type ContestRequestBody struct {
28+
BlockID *big.Int
29+
ProposedIn *big.Int
30+
ParentHash common.Hash
31+
Meta *bindings.TaikoDataBlockMetadata
32+
Tier uint16
33+
}
34+
2035
// ProofRequestOptions contains all options that need to be passed to a backend proof producer service.
2136
type ProofRequestOptions struct {
2237
BlockID *big.Int

prover/proof_submitter/interface.go

-15
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,6 @@ import (
1010
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
1111
)
1212

13-
// ProofRequestBody represents a request body to generate a proof.
14-
type ProofRequestBody struct {
15-
Tier uint16
16-
Event *bindings.TaikoL1ClientBlockProposed
17-
}
18-
19-
// ContestRequestBody represents a request body to generate a proof for contesting.
20-
type ContestRequestBody struct {
21-
BlockID *big.Int
22-
ProposedIn *big.Int
23-
ParentHash common.Hash
24-
Meta *bindings.TaikoDataBlockMetadata
25-
Tier uint16
26-
}
27-
2813
// Submitter is the interface for submitting proofs of the L2 blocks.
2914
type Submitter interface {
3015
RequestProof(ctx context.Context, event *bindings.TaikoL1ClientBlockProposed) error

prover/prover.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ type Prover struct {
6565
proveNotify chan struct{}
6666

6767
// Proof related channels
68-
proofSubmissionCh chan *proofSubmitter.ProofRequestBody
69-
proofContestCh chan *proofSubmitter.ContestRequestBody
68+
proofSubmissionCh chan *proofProducer.ProofRequestBody
69+
proofContestCh chan *proofProducer.ContestRequestBody
7070
proofGenerationCh chan *proofProducer.ProofWithHeader
7171

7272
ctx context.Context
@@ -121,8 +121,8 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) {
121121
chBufferSize := p.protocolConfigs.BlockMaxProposals
122122
p.proofGenerationCh = make(chan *proofProducer.ProofWithHeader, chBufferSize)
123123
p.assignmentExpiredCh = make(chan *bindings.TaikoL1ClientBlockProposed, chBufferSize)
124-
p.proofSubmissionCh = make(chan *proofSubmitter.ProofRequestBody, p.cfg.Capacity)
125-
p.proofContestCh = make(chan *proofSubmitter.ContestRequestBody, p.cfg.Capacity)
124+
p.proofSubmissionCh = make(chan *proofProducer.ProofRequestBody, p.cfg.Capacity)
125+
p.proofContestCh = make(chan *proofProducer.ContestRequestBody, p.cfg.Capacity)
126126
p.proveNotify = make(chan struct{}, 1)
127127

128128
if err := p.initL1Current(cfg.StartingBlockID); err != nil {
@@ -361,7 +361,7 @@ func (p *Prover) proveOp() error {
361361
}
362362

363363
// contestProofOp performs a proof contest operation.
364-
func (p *Prover) contestProofOp(req *proofSubmitter.ContestRequestBody) error {
364+
func (p *Prover) contestProofOp(req *proofProducer.ContestRequestBody) error {
365365
if err := p.proofContester.SubmitContest(
366366
p.ctx,
367367
req.BlockID,

0 commit comments

Comments
 (0)