Skip to content

Commit

Permalink
Fix txFee calculation in dencun
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta committed Jan 12, 2024
1 parent 6605518 commit 412f5ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions db/bigtable_eth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -914,15 +914,18 @@ func CalculateTxFeesFromBlock(block *types.Eth1Block) *big.Int {
func CalculateTxFeeFromTransaction(tx *types.Eth1Transaction, blockBaseFee *big.Int) *big.Int {
// calculate tx fee depending on tx type
txFee := new(big.Int).SetUint64(tx.GasUsed)
if tx.Type == uint32(2) {
switch tx.Type {
case 0, 1:
txFee.Mul(txFee, new(big.Int).SetBytes(tx.GasPrice))
case 2, 3:
// multiply gasused with min(baseFee + maxpriorityfee, maxfee)
if normalGasPrice, maxGasPrice := new(big.Int).Add(blockBaseFee, new(big.Int).SetBytes(tx.MaxPriorityFeePerGas)), new(big.Int).SetBytes(tx.MaxFeePerGas); normalGasPrice.Cmp(maxGasPrice) <= 0 {
txFee.Mul(txFee, normalGasPrice)
} else {
txFee.Mul(txFee, maxGasPrice)
}
} else {
txFee.Mul(txFee, new(big.Int).SetBytes(tx.GasPrice))
default:
logger.Errorf("unknown tx type %v", tx.Type)
}
return txFee
}
Expand Down
2 changes: 1 addition & 1 deletion db/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ func WriteExecutionChartSeriesForDay(day int64) error {
// totalMinerTips = totalMinerTips.Add(tipFee.Mul(gasUsed))
txFees = baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))
totalTxSavings = totalTxSavings.Add(maxFee.Mul(gasUsed).Sub(baseFee.Mul(gasUsed).Add(tipFee.Mul(gasUsed))))

// TODO: Handle type 3?
default:
logger.Fatalf("error unknown tx type %v hash: %x", tx.Status, tx.Hash)
}
Expand Down

0 comments on commit 412f5ab

Please sign in to comment.