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

Commit

Permalink
feat(prover): improve /status API (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha committed Nov 3, 2023
1 parent b155b5a commit e688c25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions prover/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Status struct {
MinPseZkevmTierFee uint64 `json:"minPseZkevmTierFee"`
MaxExpiry uint64 `json:"maxExpiry"`
CurrentCapacity uint64 `json:"currentCapacity"`
Prover string `json:"prover"`
HeartBeatSignature []byte `json:"heartBeatSignature"`
}

// GetStatus handles a query to the current prover server status.
Expand All @@ -50,12 +52,19 @@ type Status struct {
// @Success 200 {object} Status
// @Router /status [get]
func (srv *ProverServer) GetStatus(c echo.Context) error {
sig, err := crypto.Sign(crypto.Keccak256Hash([]byte("HEART_BEAT")).Bytes(), srv.proverPrivateKey)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err)
}

return c.JSON(http.StatusOK, &Status{
MinOptimisticTierFee: srv.minOptimisticTierFee.Uint64(),
MinSgxTierFee: srv.minSgxTierFee.Uint64(),
MinPseZkevmTierFee: srv.minPseZkevmTierFee.Uint64(),
MaxExpiry: uint64(srv.maxExpiry.Seconds()),
CurrentCapacity: srv.capacityManager.ReadCapacity(),
Prover: srv.proverAddress.Hex(),
HeartBeatSignature: sig,
})
}

Expand Down
6 changes: 6 additions & 0 deletions prover/server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/taikoxyz/taiko-client/bindings/encoding"
)

Expand All @@ -27,6 +28,11 @@ func (s *ProverServerTestSuite) TestGetStatusSuccess() {
s.Equal(s.s.minSgxAndPseZkevmTierFee.Uint64(), status.MinSgxTierFee)
s.Equal(uint64(s.s.maxExpiry.Seconds()), status.MaxExpiry)
s.Greater(status.CurrentCapacity, uint64(0))
s.NotEmpty(status.HeartBeatSignature)
pubKey, err := crypto.SigToPub(crypto.Keccak256Hash([]byte("HEART_BEAT")).Bytes(), status.HeartBeatSignature)
s.Nil(err)
s.NotEmpty(status.Prover)
s.Equal(status.Prover, crypto.PubkeyToAddress(*pubKey).Hex())
}

func (s *ProverServerTestSuite) TestProposeBlockSuccess() {
Expand Down

0 comments on commit e688c25

Please sign in to comment.