From 64ec861e88a0db6754364d113c91ddf24a95c15f Mon Sep 17 00:00:00 2001 From: David Date: Mon, 11 Mar 2024 09:53:07 +0800 Subject: [PATCH] feat(prover): update server APIs (#618) --- internal/testutils/helper.go | 21 ++-- prover/event_handler/assignment_expired.go | 16 +-- prover/event_handler/block_proposed.go | 13 +-- prover/event_handler/transition_contested.go | 8 +- prover/event_handler/transition_proved.go | 8 +- prover/proof_producer/proof_producer.go | 15 +++ prover/proof_submitter/interface.go | 15 --- prover/prover.go | 10 +- prover/server/api.go | 59 +++++----- prover/server/server.go | 113 ++++++++++--------- prover/server/server_test.go | 22 ++-- 11 files changed, 153 insertions(+), 147 deletions(-) diff --git a/internal/testutils/helper.go b/internal/testutils/helper.go index 043fb317f..c106869b6 100644 --- a/internal/testutils/helper.go +++ b/internal/testutils/helper.go @@ -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) diff --git a/prover/event_handler/assignment_expired.go b/prover/event_handler/assignment_expired.go index 495ea693d..aa183c67d 100644 --- a/prover/event_handler/assignment_expired.go +++ b/prover/event_handler/assignment_expired.go @@ -8,15 +8,15 @@ 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 } @@ -24,8 +24,8 @@ type AssignmentExpiredEventHandler struct { 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} @@ -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(), @@ -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, } @@ -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 } diff --git a/prover/event_handler/block_proposed.go b/prover/event_handler/block_proposed.go index 7b9fdd7d2..1c7cc2924 100644 --- a/prover/event_handler/block_proposed.go +++ b/prover/event_handler/block_proposed.go @@ -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" ) @@ -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 @@ -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 @@ -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(), @@ -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 } diff --git a/prover/event_handler/transition_contested.go b/prover/event_handler/transition_contested.go index da62dddba..934ff2c73 100644 --- a/prover/event_handler/transition_contested.go +++ b/prover/event_handler/transition_contested.go @@ -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} @@ -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, } diff --git a/prover/event_handler/transition_proved.go b/prover/event_handler/transition_proved.go index 4c8d3f003..b74e4ca58 100644 --- a/prover/event_handler/transition_proved.go +++ b/prover/event_handler/transition_proved.go @@ -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} @@ -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, diff --git a/prover/proof_producer/proof_producer.go b/prover/proof_producer/proof_producer.go index 391ae2316..6ecf72387 100644 --- a/prover/proof_producer/proof_producer.go +++ b/prover/proof_producer/proof_producer.go @@ -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 diff --git a/prover/proof_submitter/interface.go b/prover/proof_submitter/interface.go index 500d5981e..07a66ae2f 100644 --- a/prover/proof_submitter/interface.go +++ b/prover/proof_submitter/interface.go @@ -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 diff --git a/prover/prover.go b/prover/prover.go index cbcb4a16f..bcad2fac5 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -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 @@ -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 { @@ -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, diff --git a/prover/server/api.go b/prover/server/api.go index 25c44c087..a0bcf57c2 100644 --- a/prover/server/api.go +++ b/prover/server/api.go @@ -37,6 +37,7 @@ type CreateAssignmentRequestBody struct { type Status struct { MinOptimisticTierFee uint64 `json:"minOptimisticTierFee"` MinSgxTierFee uint64 `json:"minSgxTierFee"` + MinSgxAndZkVMTierFee uint64 `json:"minSgxAndZkVMTierFee"` MaxExpiry uint64 `json:"maxExpiry"` Prover string `json:"prover"` } @@ -49,12 +50,13 @@ type Status struct { // @Produce json // @Success 200 {object} Status // @Router /status [get] -func (srv *ProverServer) GetStatus(c echo.Context) error { +func (s *ProverServer) GetStatus(c echo.Context) error { return c.JSON(http.StatusOK, &Status{ - MinOptimisticTierFee: srv.minOptimisticTierFee.Uint64(), - MinSgxTierFee: srv.minSgxTierFee.Uint64(), - MaxExpiry: uint64(srv.maxExpiry.Seconds()), - Prover: srv.proverAddress.Hex(), + MinOptimisticTierFee: s.minOptimisticTierFee.Uint64(), + MinSgxTierFee: s.minSgxTierFee.Uint64(), + MinSgxAndZkVMTierFee: s.minSgxAndZkVMTierFee.Uint64(), + MaxExpiry: uint64(s.maxExpiry.Seconds()), + Prover: s.proverAddress.Hex(), }) } @@ -83,7 +85,7 @@ type ProposeBlockResponse struct { // @Failure 422 {string} string "expiry too long" // @Failure 422 {string} string "prover does not have capacity" // @Router /assignment [post] -func (srv *ProverServer) CreateAssignment(c echo.Context) error { +func (s *ProverServer) CreateAssignment(c echo.Context) error { req := new(CreateAssignmentRequestBody) if err := c.Bind(req); err != nil { return c.JSON(http.StatusUnprocessableEntity, err) @@ -95,9 +97,11 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error { "expiry", req.Expiry, "tierFees", req.TierFees, "txListHash", req.TxListHash, + "currentUsedCapacity", len(s.proofSubmissionCh), ) if req.TxListHash == (common.Hash{}) { + log.Info("Invalid txList hash") return echo.NewHTTPError(http.StatusUnprocessableEntity, "invalid txList hash") } @@ -107,10 +111,10 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error { ok, err := rpc.CheckProverBalance( c.Request().Context(), - srv.rpc, - srv.proverAddress, - srv.assignmentHookAddress, - srv.livenessBond, + s.rpc, + s.proverAddress, + s.assignmentHookAddress, + s.livenessBond, ) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, err) @@ -119,7 +123,7 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error { if !ok { log.Warn( "Insufficient prover balance, please get more tokens or wait for verification of the blocks you proved", - "prover", srv.proverAddress, + "prover", s.proverAddress, ) return echo.NewHTTPError(http.StatusUnprocessableEntity, "insufficient prover balance") } @@ -132,11 +136,11 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error { var minTierFee *big.Int switch tier.Tier { case encoding.TierOptimisticID: - minTierFee = srv.minOptimisticTierFee + minTierFee = s.minOptimisticTierFee case encoding.TierSgxID: - minTierFee = srv.minSgxTierFee + minTierFee = s.minSgxTierFee case encoding.TierSgxAndZkVMID: - minTierFee = srv.minSgxAndZkVMTierFee + minTierFee = s.minSgxAndZkVMTierFee default: log.Warn("Unknown tier", "tier", tier.Tier, "fee", tier.Fee, "proposerIP", c.RealIP()) } @@ -153,36 +157,37 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error { } } - if req.Expiry > uint64(time.Now().Add(srv.maxExpiry).Unix()) { + if req.Expiry > uint64(time.Now().Add(s.maxExpiry).Unix()) { log.Warn( "Expiry too long", "requestExpiry", req.Expiry, - "srvMaxExpiry", srv.maxExpiry, + "srvMaxExpiry", s.maxExpiry, "proposerIP", c.RealIP(), ) return echo.NewHTTPError(http.StatusUnprocessableEntity, "expiry too long") } // Check if the prover has any capacity now. - if len(srv.proposeConcurrencyGuard) == cap(srv.proposeConcurrencyGuard) { + if s.proofSubmissionCh != nil && len(s.proofSubmissionCh) == cap(s.proofSubmissionCh) { + log.Warn("Prover does not have capacity", "capacity", cap(s.proofSubmissionCh)) return echo.NewHTTPError(http.StatusUnprocessableEntity, "prover does not have capacity") } - l1Head, err := srv.rpc.L1.BlockNumber(c.Request().Context()) + l1Head, err := s.rpc.L1.BlockNumber(c.Request().Context()) if err != nil { log.Error("Failed to get L1 block head", "error", err) return echo.NewHTTPError(http.StatusUnprocessableEntity, err) } encoded, err := encoding.EncodeProverAssignmentPayload( - srv.protocolConfigs.ChainId, - srv.taikoL1Address, - srv.assignmentHookAddress, + s.protocolConfigs.ChainId, + s.taikoL1Address, + s.assignmentHookAddress, req.TxListHash, req.FeeToken, req.Expiry, - l1Head+srv.maxSlippage, - srv.maxProposedIn, + l1Head+s.maxSlippage, + s.maxProposedIn, req.TierFees, ) if err != nil { @@ -190,15 +195,15 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error { return echo.NewHTTPError(http.StatusUnprocessableEntity, err) } - signed, err := crypto.Sign(crypto.Keccak256Hash(encoded).Bytes(), srv.proverPrivateKey) + signed, err := crypto.Sign(crypto.Keccak256Hash(encoded).Bytes(), s.proverPrivateKey) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, err) } return c.JSON(http.StatusOK, &ProposeBlockResponse{ SignedPayload: signed, - Prover: srv.proverAddress, - MaxBlockID: l1Head + srv.maxSlippage, - MaxProposedIn: srv.maxProposedIn, + Prover: s.proverAddress, + MaxBlockID: l1Head + s.maxSlippage, + MaxProposedIn: s.maxProposedIn, }) } diff --git a/prover/server/server.go b/prover/server/server.go index 7b48b2d15..99abcc927 100644 --- a/prover/server/server.go +++ b/prover/server/server.go @@ -15,6 +15,7 @@ import ( "github.com/taikoxyz/taiko-client/bindings" "github.com/taikoxyz/taiko-client/pkg/rpc" + proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer" ) // @title Taiko Prover Server API @@ -30,58 +31,58 @@ import ( // ProverServer represents a prover server instance. type ProverServer struct { - echo *echo.Echo - proverPrivateKey *ecdsa.PrivateKey - proverAddress common.Address - minOptimisticTierFee *big.Int - minSgxTierFee *big.Int - minSgxAndZkVMTierFee *big.Int - maxExpiry time.Duration - maxSlippage uint64 - maxProposedIn uint64 - proposeConcurrencyGuard chan struct{} - taikoL1Address common.Address - assignmentHookAddress common.Address - rpc *rpc.Client - protocolConfigs *bindings.TaikoDataConfig - livenessBond *big.Int + echo *echo.Echo + proverPrivateKey *ecdsa.PrivateKey + proverAddress common.Address + minOptimisticTierFee *big.Int + minSgxTierFee *big.Int + minSgxAndZkVMTierFee *big.Int + maxExpiry time.Duration + maxSlippage uint64 + maxProposedIn uint64 + taikoL1Address common.Address + assignmentHookAddress common.Address + proofSubmissionCh chan<- proofProducer.ProofRequestBody + rpc *rpc.Client + protocolConfigs *bindings.TaikoDataConfig + livenessBond *big.Int } // NewProverServerOpts contains all configurations for creating a prover server instance. type NewProverServerOpts struct { - ProverPrivateKey *ecdsa.PrivateKey - MinOptimisticTierFee *big.Int - MinSgxTierFee *big.Int - MinSgxAndZkVMTierFee *big.Int - MaxExpiry time.Duration - MaxBlockSlippage uint64 - MaxProposedIn uint64 - ProposeConcurrencyGuard chan struct{} - TaikoL1Address common.Address - AssignmentHookAddress common.Address - RPC *rpc.Client - ProtocolConfigs *bindings.TaikoDataConfig - LivenessBond *big.Int + ProverPrivateKey *ecdsa.PrivateKey + MinOptimisticTierFee *big.Int + MinSgxTierFee *big.Int + MinSgxAndZkVMTierFee *big.Int + MaxExpiry time.Duration + MaxBlockSlippage uint64 + MaxProposedIn uint64 + TaikoL1Address common.Address + AssignmentHookAddress common.Address + ProofSubmissionCh chan<- proofProducer.ProofRequestBody + RPC *rpc.Client + ProtocolConfigs *bindings.TaikoDataConfig + LivenessBond *big.Int } // New creates a new prover server instance. func New(opts *NewProverServerOpts) (*ProverServer, error) { srv := &ProverServer{ - proverPrivateKey: opts.ProverPrivateKey, - proverAddress: crypto.PubkeyToAddress(opts.ProverPrivateKey.PublicKey), - echo: echo.New(), - minOptimisticTierFee: opts.MinOptimisticTierFee, - minSgxTierFee: opts.MinSgxTierFee, - minSgxAndZkVMTierFee: opts.MinSgxAndZkVMTierFee, - maxExpiry: opts.MaxExpiry, - maxProposedIn: opts.MaxProposedIn, - maxSlippage: opts.MaxBlockSlippage, - proposeConcurrencyGuard: opts.ProposeConcurrencyGuard, - taikoL1Address: opts.TaikoL1Address, - assignmentHookAddress: opts.AssignmentHookAddress, - rpc: opts.RPC, - protocolConfigs: opts.ProtocolConfigs, - livenessBond: opts.LivenessBond, + proverPrivateKey: opts.ProverPrivateKey, + proverAddress: crypto.PubkeyToAddress(opts.ProverPrivateKey.PublicKey), + echo: echo.New(), + minOptimisticTierFee: opts.MinOptimisticTierFee, + minSgxTierFee: opts.MinSgxTierFee, + minSgxAndZkVMTierFee: opts.MinSgxAndZkVMTierFee, + maxExpiry: opts.MaxExpiry, + maxProposedIn: opts.MaxProposedIn, + maxSlippage: opts.MaxBlockSlippage, + taikoL1Address: opts.TaikoL1Address, + assignmentHookAddress: opts.AssignmentHookAddress, + proofSubmissionCh: opts.ProofSubmissionCh, + rpc: opts.RPC, + protocolConfigs: opts.ProtocolConfigs, + livenessBond: opts.LivenessBond, } srv.echo.HideBanner = true @@ -92,17 +93,17 @@ func New(opts *NewProverServerOpts) (*ProverServer, error) { } // Start starts the HTTP server. -func (srv *ProverServer) Start(address string) error { - return srv.echo.Start(address) +func (s *ProverServer) Start(address string) error { + return s.echo.Start(address) } // Shutdown shuts down the HTTP server. -func (srv *ProverServer) Shutdown(ctx context.Context) error { - return srv.echo.Shutdown(ctx) +func (s *ProverServer) Shutdown(ctx context.Context) error { + return s.echo.Shutdown(ctx) } // Health endpoints for probes. -func (srv *ProverServer) Health(c echo.Context) error { +func (s *ProverServer) Health(c echo.Context) error { return c.NoContent(http.StatusOK) } @@ -117,10 +118,10 @@ func LogSkipper(c echo.Context) bool { } // configureMiddleware configures the server middlewares. -func (srv *ProverServer) configureMiddleware() { - srv.echo.Use(middleware.RequestID()) +func (s *ProverServer) configureMiddleware() { + s.echo.Use(middleware.RequestID()) - srv.echo.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ + s.echo.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ Skipper: LogSkipper, Format: `{"time":"${time_rfc3339_nano}","level":"INFO","message":{"id":"${id}","remote_ip":"${remote_ip}",` + `"host":"${host}","method":"${method}","uri":"${uri}","user_agent":"${user_agent}",` + @@ -131,9 +132,9 @@ func (srv *ProverServer) configureMiddleware() { } // configureRoutes contains all routes which will be used by prover server. -func (srv *ProverServer) configureRoutes() { - srv.echo.GET("/", srv.Health) - srv.echo.GET("/healthz", srv.Health) - srv.echo.GET("/status", srv.GetStatus) - srv.echo.POST("/assignment", srv.CreateAssignment) +func (s *ProverServer) configureRoutes() { + s.echo.GET("/", s.Health) + s.echo.GET("/healthz", s.Health) + s.echo.GET("/status", s.GetStatus) + s.echo.POST("/assignment", s.CreateAssignment) } diff --git a/prover/server/server_test.go b/prover/server/server_test.go index 1bab15c54..749607328 100644 --- a/prover/server/server_test.go +++ b/prover/server/server_test.go @@ -18,6 +18,7 @@ import ( "github.com/phayes/freeport" "github.com/stretchr/testify/suite" "github.com/taikoxyz/taiko-client/pkg/rpc" + proofProducer "github.com/taikoxyz/taiko-client/prover/proof_producer" ) type ProverServerTestSuite struct { @@ -46,16 +47,17 @@ func (s *ProverServerTestSuite) SetupTest() { s.Nil(err) p, err := New(&NewProverServerOpts{ - ProverPrivateKey: l1ProverPrivKey, - MinOptimisticTierFee: common.Big1, - MinSgxTierFee: common.Big1, - MaxExpiry: time.Hour, - ProposeConcurrencyGuard: make(chan struct{}, 1024), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), - RPC: rpcClient, - ProtocolConfigs: &configs, - LivenessBond: common.Big0, + ProverPrivateKey: l1ProverPrivKey, + MinOptimisticTierFee: common.Big1, + MinSgxTierFee: common.Big1, + MinSgxAndZkVMTierFee: common.Big1, + MaxExpiry: time.Hour, + ProofSubmissionCh: make(chan<- proofProducer.ProofRequestBody, 1024), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), + RPC: rpcClient, + ProtocolConfigs: &configs, + LivenessBond: common.Big0, }) s.Nil(err)