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

Commit

Permalink
feat(prover): add more capacity related logs (#408)
Browse files Browse the repository at this point in the history
Co-authored-by: David <[email protected]>
  • Loading branch information
cyberhorsey and davidtaikocha committed Sep 26, 2023
1 parent a66614c commit cdc6c96
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/rpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,25 @@ func CheckProverBalance(
return false, err
}

log.Info("Prover's deposited taikoTokenBalance", "balance", depositedBalance.String(), "address", prover.Hex())

if bond.Cmp(depositedBalance) > 0 {
// Check allowance on taiko token contract
allowance, err := rpc.TaikoToken.Allowance(&bind.CallOpts{Context: ctxWithTimeout}, prover, taikoL1Address)
if err != nil {
return false, err
}

log.Info("Prover allowance for TaikoL1 contract", "allowance", allowance.String(), "address", prover.Hex())

// Check prover's taiko token balance
balance, err := rpc.TaikoToken.BalanceOf(&bind.CallOpts{Context: ctxWithTimeout}, prover)
if err != nil {
return false, err
}

log.Info("Prover's wallet taiko token balance", "balance", balance.String(), "address", prover.Hex())

if bond.Cmp(allowance) > 0 || bond.Cmp(balance) > 0 {
log.Info(
"Assigned prover does not have required on-chain token balance or allowance",
Expand Down
13 changes: 12 additions & 1 deletion prover/capacity_manager/capacity_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package capacity_manager

import (
"sync"

"github.com/ethereum/go-ethereum/log"
)

// CapacityManager manages the prover capacity concurrent-safely.
Expand All @@ -20,6 +22,8 @@ func (m *CapacityManager) ReadCapacity() uint64 {
m.mutex.RLock()
defer m.mutex.RUnlock()

log.Info("Reading capacity", "capacity", m.capacity)

return m.capacity
}

Expand All @@ -29,18 +33,25 @@ func (m *CapacityManager) ReleaseOneCapacity() uint64 {
defer m.mutex.Unlock()

m.capacity += 1

log.Info("Released capacity", "capacityAfterRelease", m.capacity)

return m.capacity
}

// TakeOneCapacity takes one capacit·y.
// TakeOneCapacity takes one capacity.
func (m *CapacityManager) TakeOneCapacity() (uint64, bool) {
m.mutex.Lock()
defer m.mutex.Unlock()

if m.capacity == 0 {
log.Info("Could not take one capacity", "capacity", m.capacity)
return 0, false
}

m.capacity -= 1

log.Info("Took one capacity", "capacityAfterTaking", m.capacity)

return m.capacity, true
}
14 changes: 13 additions & 1 deletion prover/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,27 @@ func (srv *ProverServer) CreateAssignment(c echo.Context) error {
}

if req.Fee.Cmp(srv.minProofFee) < 0 {
log.Warn(
"Proof fee too low",
"reqFee", req.Fee.String(),
"srvMinProofFee", srv.minProofFee.String(),
"proposerIP", c.RealIP(),
)
return echo.NewHTTPError(http.StatusUnprocessableEntity, "proof fee too low")
}

if req.Expiry > uint64(time.Now().Add(srv.maxExpiry).Unix()) {
log.Warn(
"Expiry too long",
"requestExpiry", req.Expiry,
"srvMaxExpiry", srv.maxExpiry,
"proposerIP", c.RealIP(),
)
return echo.NewHTTPError(http.StatusUnprocessableEntity, "expiry too long")
}

if srv.capacityManager.ReadCapacity() == 0 {
log.Warn("Prover does not have capacity")
log.Warn("Prover does not have capacity", "proposerIP", c.RealIP())
return echo.NewHTTPError(http.StatusUnprocessableEntity, "prover does not have capacity")
}

Expand Down

0 comments on commit cdc6c96

Please sign in to comment.