Skip to content

Commit 412f5ab

Browse files
committed
Fix txFee calculation in dencun
1 parent 6605518 commit 412f5ab

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

db/bigtable_eth1.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -914,15 +914,18 @@ func CalculateTxFeesFromBlock(block *types.Eth1Block) *big.Int {
914914
func CalculateTxFeeFromTransaction(tx *types.Eth1Transaction, blockBaseFee *big.Int) *big.Int {
915915
// calculate tx fee depending on tx type
916916
txFee := new(big.Int).SetUint64(tx.GasUsed)
917-
if tx.Type == uint32(2) {
917+
switch tx.Type {
918+
case 0, 1:
919+
txFee.Mul(txFee, new(big.Int).SetBytes(tx.GasPrice))
920+
case 2, 3:
918921
// multiply gasused with min(baseFee + maxpriorityfee, maxfee)
919922
if normalGasPrice, maxGasPrice := new(big.Int).Add(blockBaseFee, new(big.Int).SetBytes(tx.MaxPriorityFeePerGas)), new(big.Int).SetBytes(tx.MaxFeePerGas); normalGasPrice.Cmp(maxGasPrice) <= 0 {
920923
txFee.Mul(txFee, normalGasPrice)
921924
} else {
922925
txFee.Mul(txFee, maxGasPrice)
923926
}
924-
} else {
925-
txFee.Mul(txFee, new(big.Int).SetBytes(tx.GasPrice))
927+
default:
928+
logger.Errorf("unknown tx type %v", tx.Type)
926929
}
927930
return txFee
928931
}

db/statistics.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ func WriteExecutionChartSeriesForDay(day int64) error {
16161616
// totalMinerTips = totalMinerTips.Add(tipFee.Mul(gasUsed))
16171617
txFees = baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))
16181618
totalTxSavings = totalTxSavings.Add(maxFee.Mul(gasUsed).Sub(baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))))
1619-
1619+
// TODO: Handle type 3?
16201620
default:
16211621
logger.Fatalf("error unknown tx type %v hash: %x", tx.Status, tx.Hash)
16221622
}

0 commit comments

Comments
 (0)