Skip to content

Commit

Permalink
Improve error logging in toCeloFn (#2157)
Browse files Browse the repository at this point in the history
This might help us debug
#2134 if it happens
again.
  • Loading branch information
karlb committed Jul 12, 2023
1 parent 4860e01 commit b1bba65
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions contracts/currency/currency.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package currency

import (
"fmt"
"math/big"

"github.com/celo-org/celo-blockchain/common"
Expand Down Expand Up @@ -113,10 +114,10 @@ type ExchangeRate struct {
// Requires numerator >=0 && denominator >= 0
func NewExchangeRate(numerator *big.Int, denominator *big.Int) (*ExchangeRate, error) {
if numerator == nil || common.Big0.Cmp(numerator) >= 0 {
return nil, contracts.ErrExchangeRateZero
return nil, fmt.Errorf("numerator zero: %w", contracts.ErrExchangeRateZero)
}
if denominator == nil || common.Big0.Cmp(denominator) >= 0 {
return nil, contracts.ErrExchangeRateZero
return nil, fmt.Errorf("denominator zero: %w", contracts.ErrExchangeRateZero)
}
return &ExchangeRate{numerator, denominator}, nil
}
Expand Down
5 changes: 4 additions & 1 deletion miner/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,10 @@ func createConversionFunctions(sysCtx *core.SysContractCallCtx, chain *core.Bloc
return sysCtx.GetGasPriceMinimum(feeCurrency)
}
toCeloFn := func(amount *big.Int, feeCurrency *common.Address) *big.Int {
curr, _ := currencyManager.GetCurrency(feeCurrency)
curr, err := currencyManager.GetCurrency(feeCurrency)
if err != nil {
log.Error("toCeloFn: could not get currency", "err", err)
}
return curr.ToCELO(amount)
}

Expand Down

0 comments on commit b1bba65

Please sign in to comment.