Skip to content

Commit 376bf8b

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 ffdea9e commit 376bf8b

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
@@ -549,7 +549,7 @@ type TxWithMinerFee struct {
549549
tx *Transaction
550550
minerFee *big.Int // in CELO
551551
}
552-
type ToCELOFn func(amount *big.Int, feeCurrency *common.Address) *big.Int
552+
type ToCELOFn func(amount *big.Int, feeCurrency *common.Address) (*big.Int, error)
553553

554554
// NewTxWithMinerFee creates a wrapped transaction, calculating the effective
555555
// miner gasTipCap if a base fee is provided. The MinerFee is converted to CELO.
@@ -559,9 +559,14 @@ func NewTxWithMinerFee(tx *Transaction, baseFeeFn func(feeCurrency *common.Addre
559559
if err != nil {
560560
return nil, err
561561
}
562+
minerFeeInCelo, err := toCELO(minerFee, tx.FeeCurrency())
563+
if err != nil {
564+
log.Error("NewTxWithMinerFee: Could not convert fees for tx", "tx", tx, "err", err)
565+
return nil, err
566+
}
562567
return &TxWithMinerFee{
563568
tx: tx,
564-
minerFee: toCELO(minerFee, tx.FeeCurrency()),
569+
minerFee: minerFeeInCelo,
565570
}, nil
566571
}
567572

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
@@ -394,7 +394,11 @@ func totalFees(block *types.Block, receipts []*types.Receipt, baseFeeFn func(*co
394394
if espresso {
395395
basefee = baseFeeFn(tx.FeeCurrency())
396396
}
397-
fee := toCELO(new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), tx.EffectiveGasTipValue(basefee)), tx.FeeCurrency())
397+
fee, err := toCELO(new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), tx.EffectiveGasTipValue(basefee)), tx.FeeCurrency())
398+
if err != nil {
399+
log.Error("totalFees: Could not convert fees for tx", "tx", tx, "err", err)
400+
continue
401+
}
398402
feesWei.Add(feesWei, fee)
399403
}
400404
return new(big.Float).Quo(new(big.Float).SetInt(feesWei), new(big.Float).SetInt(big.NewInt(params.Ether)))
@@ -409,12 +413,12 @@ func createConversionFunctions(sysCtx *core.SysContractCallCtx, chain *core.Bloc
409413
baseFeeFn := func(feeCurrency *common.Address) *big.Int {
410414
return sysCtx.GetGasPriceMinimum(feeCurrency)
411415
}
412-
toCeloFn := func(amount *big.Int, feeCurrency *common.Address) *big.Int {
416+
toCeloFn := func(amount *big.Int, feeCurrency *common.Address) (*big.Int, error) {
413417
curr, err := currencyManager.GetCurrency(feeCurrency)
414418
if err != nil {
415-
log.Error("toCeloFn: could not get currency", "err", err)
419+
return nil, fmt.Errorf("toCeloFn: %w", err)
416420
}
417-
return curr.ToCELO(amount)
421+
return curr.ToCELO(amount), nil
418422
}
419423

420424
return baseFeeFn, toCeloFn

0 commit comments

Comments
 (0)