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 server APIs (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored Mar 11, 2024
1 parent 4145dae commit 64ec861
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 147 deletions.
21 changes: 10 additions & 11 deletions internal/testutils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,16 @@ func (s *ClientTestSuite) NewTestProverServer(
s.Nil(err)

srv, err := server.New(&server.NewProverServerOpts{
ProverPrivateKey: proverPrivKey,
MinOptimisticTierFee: common.Big1,
MinSgxTierFee: common.Big1,
MinSgxAndZkVMTierFee: common.Big1,
MaxExpiry: 24 * time.Hour,
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
ProposeConcurrencyGuard: make(chan struct{}, 1024),
RPC: s.RPCClient,
ProtocolConfigs: &protocolConfig,
LivenessBond: protocolConfig.LivenessBond,
ProverPrivateKey: proverPrivKey,
MinOptimisticTierFee: common.Big1,
MinSgxTierFee: common.Big1,
MinSgxAndZkVMTierFee: common.Big1,
MaxExpiry: 24 * time.Hour,
TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")),
AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")),
RPC: s.RPCClient,
ProtocolConfigs: &protocolConfig,
LivenessBond: protocolConfig.LivenessBond,
})
s.Nil(err)

Expand Down
16 changes: 8 additions & 8 deletions prover/event_handler/assignment_expired.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/pkg/rpc"
proofSubmitter "github.com/taikoxyz/taiko-client/prover/proof_submitter"
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
)

// AssignmentExpiredEventHandler is responsible for handling the expiration of proof assignments.
type AssignmentExpiredEventHandler struct {
rpc *rpc.Client
proverAddress common.Address
proofSubmissionCh chan<- *proofSubmitter.ProofRequestBody
proofContestCh chan<- *proofSubmitter.ContestRequestBody
proofSubmissionCh chan<- *proofProducer.ProofRequestBody
proofContestCh chan<- *proofProducer.ContestRequestBody
contesterMode bool
}

// NewAssignmentExpiredEventHandler creates a new AssignmentExpiredEventHandler instance.
func NewAssignmentExpiredEventHandler(
rpc *rpc.Client,
proverAddress common.Address,
proofSubmissionCh chan *proofSubmitter.ProofRequestBody,
proofContestCh chan *proofSubmitter.ContestRequestBody,
proofSubmissionCh chan *proofProducer.ProofRequestBody,
proofContestCh chan *proofProducer.ContestRequestBody,
contesterMode bool,
) *AssignmentExpiredEventHandler {
return &AssignmentExpiredEventHandler{rpc, proverAddress, proofSubmissionCh, proofContestCh, contesterMode}
Expand Down Expand Up @@ -60,7 +60,7 @@ func (h *AssignmentExpiredEventHandler) Handle(

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

go func() {
h.proofSubmissionCh <- &proofSubmitter.ProofRequestBody{
h.proofSubmissionCh <- &proofProducer.ProofRequestBody{
Tier: proofStatus.CurrentTransitionState.Tier + 1,
Event: e,
}
Expand All @@ -82,7 +82,7 @@ func (h *AssignmentExpiredEventHandler) Handle(
}

go func() {
h.proofSubmissionCh <- &proofSubmitter.ProofRequestBody{Tier: e.Meta.MinTier, Event: e}
h.proofSubmissionCh <- &proofProducer.ProofRequestBody{Tier: e.Meta.MinTier, Event: e}
}()
return nil
}
13 changes: 6 additions & 7 deletions prover/event_handler/block_proposed.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/taikoxyz/taiko-client/pkg/rpc"
guardianProverHeartbeater "github.com/taikoxyz/taiko-client/prover/guardian_prover_heartbeater"
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
proofSubmitter "github.com/taikoxyz/taiko-client/prover/proof_submitter"
state "github.com/taikoxyz/taiko-client/prover/shared_state"
)

Expand All @@ -35,8 +34,8 @@ type BlockProposedEventHandler struct {
rpc *rpc.Client
proofGenerationCh chan<- *proofProducer.ProofWithHeader
assignmentExpiredCh chan<- *bindings.TaikoL1ClientBlockProposed
proofSubmissionCh chan<- *proofSubmitter.ProofRequestBody
proofContestCh chan<- *proofSubmitter.ContestRequestBody
proofSubmissionCh chan<- *proofProducer.ProofRequestBody
proofContestCh chan<- *proofProducer.ContestRequestBody
backOffRetryInterval time.Duration
backOffMaxRetrys uint64
contesterMode bool
Expand All @@ -52,8 +51,8 @@ type NewBlockProposedEventHandlerOps struct {
RPC *rpc.Client
ProofGenerationCh chan *proofProducer.ProofWithHeader
AssignmentExpiredCh chan *bindings.TaikoL1ClientBlockProposed
ProofSubmissionCh chan *proofSubmitter.ProofRequestBody
ProofContestCh chan *proofSubmitter.ContestRequestBody
ProofSubmissionCh chan *proofProducer.ProofRequestBody
ProofContestCh chan *proofProducer.ContestRequestBody
BackOffRetryInterval time.Duration
BackOffMaxRetrys uint64
ContesterMode bool
Expand Down Expand Up @@ -265,7 +264,7 @@ func (h *BlockProposedEventHandler) checkExpirationAndSubmitProof(
}

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

metrics.ProverProofsAssigned.Inc(1)

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

return nil
}
Expand Down
8 changes: 4 additions & 4 deletions prover/event_handler/transition_contested.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/pkg/rpc"
proofSubmitter "github.com/taikoxyz/taiko-client/prover/proof_submitter"
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
)

// TransitionContestedEventHandler is responsible for handling the TransitionContested event.
type TransitionContestedEventHandler struct {
rpc *rpc.Client
proofSubmissionCh chan<- *proofSubmitter.ProofRequestBody
proofSubmissionCh chan<- *proofProducer.ProofRequestBody
contesterMode bool
}

// NewTransitionContestedEventHandler creates a new TransitionContestedEventHandler instance.
func NewTransitionContestedEventHandler(
rpc *rpc.Client,
proofSubmissionCh chan *proofSubmitter.ProofRequestBody,
proofSubmissionCh chan *proofProducer.ProofRequestBody,
contesterMode bool,
) *TransitionContestedEventHandler {
return &TransitionContestedEventHandler{rpc, proofSubmissionCh, contesterMode}
Expand Down Expand Up @@ -99,7 +99,7 @@ func (h *TransitionContestedEventHandler) Handle(
}

go func() {
h.proofSubmissionCh <- &proofSubmitter.ProofRequestBody{
h.proofSubmissionCh <- &proofProducer.ProofRequestBody{
Tier: e.Tier + 1, // We need to send a higher tier proof to resolve the current contest.
Event: blockProposedEvent,
}
Expand Down
8 changes: 4 additions & 4 deletions prover/event_handler/transition_proved.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import (
"github.com/taikoxyz/taiko-client/bindings"
"github.com/taikoxyz/taiko-client/internal/metrics"
"github.com/taikoxyz/taiko-client/pkg/rpc"
proofSubmitter "github.com/taikoxyz/taiko-client/prover/proof_submitter"
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
)

// TransitionProvedEventHandler is responsible for handling the TransitionProved event.
type TransitionProvedEventHandler struct {
rpc *rpc.Client
proofContestCh chan<- *proofSubmitter.ContestRequestBody
proofContestCh chan<- *proofProducer.ContestRequestBody
contesterMode bool
}

// NewTransitionProvedEventHandler creates a new TransitionProvedEventHandler instance.
func NewTransitionProvedEventHandler(
rpc *rpc.Client,
proofContestCh chan *proofSubmitter.ContestRequestBody,
proofContestCh chan *proofProducer.ContestRequestBody,
contesterMode bool,
) *TransitionProvedEventHandler {
return &TransitionProvedEventHandler{rpc, proofContestCh, contesterMode}
Expand Down Expand Up @@ -80,7 +80,7 @@ func (h *TransitionProvedEventHandler) Handle(
)

go func() {
h.proofContestCh <- &proofSubmitter.ContestRequestBody{
h.proofContestCh <- &proofProducer.ContestRequestBody{
BlockID: e.BlockId,
ProposedIn: new(big.Int).SetUint64(blockInfo.Blk.ProposedIn),
ParentHash: e.Tran.ParentHash,
Expand Down
15 changes: 15 additions & 0 deletions prover/proof_producer/proof_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ var (
errProofGenerating = errors.New("proof is generating")
)

// ProofRequestBody represents a request body to generate a proof.
type ProofRequestBody struct {
Tier uint16
Event *bindings.TaikoL1ClientBlockProposed
}

// ContestRequestBody represents a request body to generate a proof for contesting.
type ContestRequestBody struct {
BlockID *big.Int
ProposedIn *big.Int
ParentHash common.Hash
Meta *bindings.TaikoDataBlockMetadata
Tier uint16
}

// ProofRequestOptions contains all options that need to be passed to a backend proof producer service.
type ProofRequestOptions struct {
BlockID *big.Int
Expand Down
15 changes: 0 additions & 15 deletions prover/proof_submitter/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ import (
proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer"
)

// ProofRequestBody represents a request body to generate a proof.
type ProofRequestBody struct {
Tier uint16
Event *bindings.TaikoL1ClientBlockProposed
}

// ContestRequestBody represents a request body to generate a proof for contesting.
type ContestRequestBody struct {
BlockID *big.Int
ProposedIn *big.Int
ParentHash common.Hash
Meta *bindings.TaikoDataBlockMetadata
Tier uint16
}

// Submitter is the interface for submitting proofs of the L2 blocks.
type Submitter interface {
RequestProof(ctx context.Context, event *bindings.TaikoL1ClientBlockProposed) error
Expand Down
10 changes: 5 additions & 5 deletions prover/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ type Prover struct {
proveNotify chan struct{}

// Proof related channels
proofSubmissionCh chan *proofSubmitter.ProofRequestBody
proofContestCh chan *proofSubmitter.ContestRequestBody
proofSubmissionCh chan *proofProducer.ProofRequestBody
proofContestCh chan *proofProducer.ContestRequestBody
proofGenerationCh chan *proofProducer.ProofWithHeader

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

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

// contestProofOp performs a proof contest operation.
func (p *Prover) contestProofOp(req *proofSubmitter.ContestRequestBody) error {
func (p *Prover) contestProofOp(req *proofProducer.ContestRequestBody) error {
if err := p.proofContester.SubmitContest(
p.ctx,
req.BlockID,
Expand Down
Loading

0 comments on commit 64ec861

Please sign in to comment.