Skip to content

Commit 02c80eb

Browse files
committed
Return errors from toCeloFn
#2134 leads us to believe that there are failures happening in production. This change * Handles error cases by skipping processing of respective txs instead of segfaulting * Logs tx information in these cases to better understand why this is happening Skipping transactions where conversion is not possible is analogous to handling other cases of bad transactions. But since the linked issue only happens for some nodes, I am not sure if this is the right thing to do or if we should intentionally panic in that case to avoid harder to debug consensus failures due to having different nodes process a different set of transactions.
1 parent a0d49c2 commit 02c80eb

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

core/types/transaction.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ type TxWithMinerFee struct {
541541
tx *Transaction
542542
minerFee *big.Int // in CELO
543543
}
544-
type ToCELOFn func(amount *big.Int, feeCurrency *common.Address) *big.Int
544+
type ToCELOFn func(amount *big.Int, feeCurrency *common.Address) (*big.Int, error)
545545

546546
// NewTxWithMinerFee creates a wrapped transaction, calculating the effective
547547
// miner gasTipCap if a base fee is provided. The MinerFee is converted to CELO.
@@ -551,9 +551,14 @@ func NewTxWithMinerFee(tx *Transaction, baseFeeFn func(feeCurrency *common.Addre
551551
if err != nil {
552552
return nil, err
553553
}
554+
minerFeeInCelo, err := toCELO(minerFee, tx.FeeCurrency())
555+
if err != nil {
556+
log.Error("NewTxWithMinerFee: Could not convert fees for tx", "tx", tx, "err", err)
557+
return nil, err
558+
}
554559
return &TxWithMinerFee{
555560
tx: tx,
556-
minerFee: toCELO(minerFee, tx.FeeCurrency()),
561+
minerFee: minerFeeInCelo,
557562
}, nil
558563
}
559564

core/types/transaction_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ func TestTxEthCompatible(t *testing.T) {
397397
}
398398

399399
// toCELO converter assuming that feeCurrency is always nil
400-
func toCELOMockFn(amount *big.Int, feeCurrency *common.Address) *big.Int {
401-
return amount
400+
func toCELOMockFn(amount *big.Int, feeCurrency *common.Address) (*big.Int, error) {
401+
return amount, nil
402402
}
403403

404404
func TestTransactionPriceNonceSortLegacy(t *testing.T) {

miner/block.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ func totalFees(block *types.Block, receipts []*types.Receipt, baseFeeFn func(*co
371371
if espresso {
372372
basefee = baseFeeFn(tx.FeeCurrency())
373373
}
374-
fee := toCELO(new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), tx.EffectiveGasTipValue(basefee)), tx.FeeCurrency())
374+
fee, err := toCELO(new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), tx.EffectiveGasTipValue(basefee)), tx.FeeCurrency())
375+
if err != nil {
376+
log.Error("totalFees: Could not convert fees for tx", "tx", tx, "err", err)
377+
continue
378+
}
375379
feesWei.Add(feesWei, fee)
376380
}
377381
return new(big.Float).Quo(new(big.Float).SetInt(feesWei), new(big.Float).SetInt(big.NewInt(params.Ether)))
@@ -386,12 +390,12 @@ func createConversionFunctions(sysCtx *core.SysContractCallCtx, chain *core.Bloc
386390
baseFeeFn := func(feeCurrency *common.Address) *big.Int {
387391
return sysCtx.GetGasPriceMinimum(feeCurrency)
388392
}
389-
toCeloFn := func(amount *big.Int, feeCurrency *common.Address) *big.Int {
393+
toCeloFn := func(amount *big.Int, feeCurrency *common.Address) (*big.Int, error) {
390394
curr, err := currencyManager.GetCurrency(feeCurrency)
391395
if err != nil {
392-
log.Error("toCeloFn: could not get currency", "err", err)
396+
return nil, fmt.Errorf("toCeloFn: %w", err)
393397
}
394-
return curr.ToCELO(amount)
398+
return curr.ToCELO(amount), nil
395399
}
396400

397401
return baseFeeFn, toCeloFn

0 commit comments

Comments
 (0)