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

feat(prover): improve /status API #444

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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