Skip to content

Commit

Permalink
fix(taiko-client): fix a prover balance check issue (#17318)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaikocha authored May 24, 2024
1 parent 0adb40d commit f0b26b9
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions packages/taiko-client/prover/server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func (s *ProverServer) CreateAssignment(c echo.Context) error {
"currentUsedCapacity", len(s.proofSubmissionCh),
)

// If the prover set address is set, use it as the prover address.
prover := s.proverAddress
if s.proverSetAddress != rpc.ZeroAddress {
prover = s.proverSetAddress
}

// 1. Check if the request body is valid.
if req.BlobHash == (common.Hash{}) {
log.Warn("Empty blob hash", "prover", s.proverAddress)
Expand All @@ -119,7 +125,7 @@ func (s *ProverServer) CreateAssignment(c echo.Context) error {
}

// 2. Check if the prover has the required minimum on-chain ETH and Taiko token balance.
ok, err := s.checkMinEthAndToken(c.Request().Context())
ok, err := s.checkMinEthAndToken(c.Request().Context(), prover)
if err != nil {
log.Error("Failed to check prover's ETH and Taiko token balance", "error", err)
return echo.NewHTTPError(http.StatusInternalServerError, err)
Expand Down Expand Up @@ -208,12 +214,6 @@ func (s *ProverServer) CreateAssignment(c echo.Context) error {
return echo.NewHTTPError(http.StatusUnprocessableEntity, err)
}

// If the prover set address is set, use it as the prover address.
prover := s.proverAddress
if s.proverSetAddress != rpc.ZeroAddress {
prover = s.proverSetAddress
}

encoded, err := encoding.EncodeProverAssignmentPayload(
s.protocolConfigs.ChainId,
s.taikoL1Address,
Expand Down Expand Up @@ -247,48 +247,48 @@ func (s *ProverServer) CreateAssignment(c echo.Context) error {
}

// checkMinEthAndToken checks if the prover has the required minimum on-chain ETH and Taiko token balance.
func (s *ProverServer) checkMinEthAndToken(ctx context.Context) (bool, error) {
func (s *ProverServer) checkMinEthAndToken(ctx context.Context, proverAddress common.Address) (bool, error) {
ctx, cancel := context.WithTimeout(ctx, rpcTimeout)
defer cancel()

// 1. Check prover's ETH balance.
ethBalance, err := s.rpc.L1.BalanceAt(ctx, s.proverAddress, nil)
ethBalance, err := s.rpc.L1.BalanceAt(ctx, proverAddress, nil)
if err != nil {
return false, err
}

log.Info(
"Prover's ETH balance",
"balance", utils.WeiToEther(ethBalance),
"address", s.proverAddress.Hex(),
"address", proverAddress,
)

if ethBalance.Cmp(s.minEthBalance) <= 0 {
log.Warn(
"Prover does not have required minimum on-chain ETH balance",
"providedProver", s.proverAddress.Hex(),
"providedProver", proverAddress,
"ethBalance", utils.WeiToEther(ethBalance),
"minEthBalance", utils.WeiToEther(s.minEthBalance),
)
return false, nil
}

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

log.Info(
"Prover's Taiko token balance",
"balance", utils.WeiToEther(balance),
"address", s.proverAddress.Hex(),
"address", proverAddress,
)

if balance.Cmp(s.minTaikoTokenBalance) <= 0 {
log.Warn(
"Prover does not have required on-chain Taiko token balance",
"providedProver", s.proverAddress.Hex(),
"providedProver", proverAddress,
"taikoTokenBalance", utils.WeiToEther(balance),
"minTaikoTokenBalance", utils.WeiToEther(s.minTaikoTokenBalance),
)
Expand Down

0 comments on commit f0b26b9

Please sign in to comment.