Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions execution/execmodule/block_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,14 @@ func (e *ExecModule) AssembleBlock(ctx context.Context, params *builder.Paramete
func blockValue(br *types.BlockWithReceipts, baseFee *uint256.Int) *uint256.Int {
blockValue := uint256.NewInt(0)
txs := br.Block.Transactions()
var gas, txValue uint256.Int
for i := range txs {
gas := new(uint256.Int).SetUint64(br.Receipts[i].GasUsed)
gas.SetUint64(br.Receipts[i].GasUsed)

effectiveTip := txs[i].GetEffectiveGasTip(baseFee)
txValue := new(uint256.Int).Mul(gas, effectiveTip)
blockValue.Add(blockValue, txValue)

txValue.Mul(&gas, &effectiveTip)
blockValue.Add(blockValue, &txValue)
}
return blockValue
}
Expand Down
6 changes: 4 additions & 2 deletions execution/protocol/aa/aa_gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ func chargeGas(
preTxCost uint64,
) error {
baseFee := header.BaseFee
effectiveGasPrice := new(uint256.Int).Add(baseFee, tx.GetEffectiveGasTip(baseFee))
effectiveGasTip := tx.GetEffectiveGasTip(baseFee)
effectiveGasPrice := new(uint256.Int).Add(baseFee, &effectiveGasTip)

totalGasLimit := preTxCost + tx.ValidationGasLimit + tx.PaymasterValidationGasLimit + tx.GasLimit + tx.PostOpGasLimit
preCharge := new(uint256.Int).SetUint64(totalGasLimit)
Expand Down Expand Up @@ -57,7 +58,8 @@ func refundGas(
gasUsed uint64,
) error {
baseFee := header.BaseFee
effectiveGasPrice := new(uint256.Int).Add(baseFee, tx.GetEffectiveGasTip(baseFee))
effectiveGasTip := tx.GetEffectiveGasTip(baseFee)
effectiveGasPrice := new(uint256.Int).Add(baseFee, &effectiveGasTip)
actualGasCost := new(uint256.Int).Mul(effectiveGasPrice, new(uint256.Int).SetUint64(gasUsed))

totalGasLimit := params.TxAAGas + tx.ValidationGasLimit + tx.PaymasterValidationGasLimit + tx.GasLimit + tx.PostOpGasLimit
Expand Down
3 changes: 2 additions & 1 deletion execution/tests/blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,8 @@ func TestEIP1559Transition(t *testing.T) {
err = m.DB.ViewTemporal(m.Ctx, func(tx kv.TemporalTx) error {
statedb := state.New(m.NewHistoryStateReader(1, tx))
baseFee := block.BaseFee()
effectiveTip := block.Transactions()[0].GetEffectiveGasTip(baseFee).Uint64()
tip := block.Transactions()[0].GetEffectiveGasTip(baseFee)
effectiveTip := tip.Uint64()

// 6+5: Ensure that miner received only the tx's effective tip.
actual, err := statedb.GetBalance(accounts.InternAddress(block.Coinbase()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ func benchTracer(b *testing.B, tracerName string, test *callTracerTest) {
baseFee := test.Context.BaseFee
txContext := evmtypes.TxContext{
Origin: origin,
GasPrice: *tx.GetEffectiveGasTip(baseFee),
GasPrice: tx.GetEffectiveGasTip(baseFee),
}
m := execmoduletester.New(b)
dbTx, err := m.DB.BeginTemporalRw(m.Ctx)
Expand Down
2 changes: 1 addition & 1 deletion execution/types/aa_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (tx *AccountAbstractionTransaction) GetPrice() *uint256.Int {
return tx.Tip
}

func (tx *AccountAbstractionTransaction) GetEffectiveGasTip(baseFee *uint256.Int) *uint256.Int {
func (tx *AccountAbstractionTransaction) GetEffectiveGasTip(baseFee *uint256.Int) uint256.Int {
return CalcEffectiveGasTip(baseFee, tx.GetTipCap, tx.GetFeeCap)
}

Expand Down
2 changes: 1 addition & 1 deletion execution/types/blob_tx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (txw *BlobTxWrapper) Type() byte { return txw.Tx.Type() }
func (txw *BlobTxWrapper) GetChainID() *uint256.Int { return txw.Tx.GetChainID() }
func (txw *BlobTxWrapper) GetNonce() uint64 { return txw.Tx.GetNonce() }
func (txw *BlobTxWrapper) GetTipCap() *uint256.Int { return txw.Tx.GetTipCap() }
func (txw *BlobTxWrapper) GetEffectiveGasTip(baseFee *uint256.Int) *uint256.Int {
func (txw *BlobTxWrapper) GetEffectiveGasTip(baseFee *uint256.Int) uint256.Int {
return txw.Tx.GetEffectiveGasTip(baseFee)
}
func (txw *BlobTxWrapper) GetFeeCap() *uint256.Int { return txw.Tx.GetFeeCap() }
Expand Down
2 changes: 1 addition & 1 deletion execution/types/dynamic_fee_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type DynamicFeeTransaction struct {

func (tx *DynamicFeeTransaction) GetFeeCap() *uint256.Int { return &tx.FeeCap }
func (tx *DynamicFeeTransaction) GetTipCap() *uint256.Int { return &tx.TipCap }
func (tx *DynamicFeeTransaction) GetEffectiveGasTip(baseFee *uint256.Int) *uint256.Int {
func (tx *DynamicFeeTransaction) GetEffectiveGasTip(baseFee *uint256.Int) uint256.Int {
return CalcEffectiveGasTip(baseFee, tx.GetTipCap, tx.GetFeeCap)
}

Expand Down
4 changes: 3 additions & 1 deletion execution/types/ethutils/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func MarshalReceipt(
fields["effectiveGasPrice"] = (*hexutil.Big)(txn.GetTipCap().ToBig())
} else {
baseFee := header.BaseFee
gasPrice := new(uint256.Int).Add(baseFee, txn.GetEffectiveGasTip(baseFee))
effectiveTip := txn.GetEffectiveGasTip(baseFee)
var gasPrice uint256.Int
gasPrice.Add(baseFee, &effectiveTip)
fields["effectiveGasPrice"] = (*hexutil.Big)(gasPrice.ToBig())
}

Expand Down
2 changes: 1 addition & 1 deletion execution/types/legacy_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type LegacyTx struct {

func (tx *LegacyTx) GetTipCap() *uint256.Int { return &tx.GasPrice }
func (tx *LegacyTx) GetFeeCap() *uint256.Int { return &tx.GasPrice }
func (tx *LegacyTx) GetEffectiveGasTip(baseFee *uint256.Int) *uint256.Int {
func (tx *LegacyTx) GetEffectiveGasTip(baseFee *uint256.Int) uint256.Int {
return CalcEffectiveGasTip(baseFee, tx.GetTipCap, tx.GetFeeCap)
}

Expand Down
20 changes: 11 additions & 9 deletions execution/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ type Transaction interface {
Type() byte
GetChainID() *uint256.Int
GetNonce() uint64
GetTipCap() *uint256.Int // max_priority_fee_per_gas in EIP-1559
GetEffectiveGasTip(baseFee *uint256.Int) *uint256.Int // effective_gas_price in EIP-1559
GetFeeCap() *uint256.Int // max_fee_per_gas in EIP-1559
GetTipCap() *uint256.Int // max_priority_fee_per_gas in EIP-1559
GetEffectiveGasTip(baseFee *uint256.Int) uint256.Int // priority_fee_per_gas in EIP-1559
GetFeeCap() *uint256.Int // max_fee_per_gas in EIP-1559
GetBlobHashes() []common.Hash
GetGasLimit() uint64
GetBlobGas() uint64
Expand Down Expand Up @@ -108,17 +108,19 @@ type TransactionMisc struct {

// CalcEffectiveGasTip computes the effective gas tip given a transaction's tip/fee caps and a base fee.
// Shared logic used by all transaction types that implement GetEffectiveGasTip.
func CalcEffectiveGasTip(baseFee *uint256.Int, getTipCap func() *uint256.Int, getFeeCap func() *uint256.Int) *uint256.Int {
func CalcEffectiveGasTip(baseFee *uint256.Int, getTipCap func() *uint256.Int, getFeeCap func() *uint256.Int) uint256.Int {
if baseFee == nil {
return getTipCap()
return *getTipCap()
}
gasFeeCap := getFeeCap()
if gasFeeCap.Lt(baseFee) {
return uint256.NewInt(0)
var zero uint256.Int
return zero
}
effectiveFee := new(uint256.Int).Sub(gasFeeCap, baseFee)
if getTipCap().Lt(effectiveFee) {
return getTipCap()
var effectiveFee uint256.Int
effectiveFee.Sub(gasFeeCap, baseFee)
if getTipCap().Lt(&effectiveFee) {
return *getTipCap()
}
return effectiveFee
}
Expand Down
7 changes: 4 additions & 3 deletions rpc/gasprice/gasprice.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,15 @@ func (oracle *Oracle) getBlockPricesFromBackend(ctx context.Context, backend Ora
// Pre-compute effective tip for every transaction exactly once.
type txWithTip struct {
tx types.Transaction
tip *uint256.Int
tip uint256.Int
}
items := make([]txWithTip, len(block.Transactions()))
for i, tx := range block.Transactions() {
items[i] = txWithTip{tx: tx, tip: tx.GetEffectiveGasTip(baseFee)}
}

// Sort ascending by effective tip; slices.SortFunc uses pdqsort (no reflection).
slices.SortFunc(items, func(a, b txWithTip) int { return a.tip.Cmp(b.tip) })
slices.SortFunc(items, func(a, b txWithTip) int { return a.tip.Cmp(&b.tip) })

// Since items are sorted ascending, all tips below ignoreUnder form a
// contiguous prefix that we can skip with a single pass.
Expand All @@ -320,7 +320,8 @@ func (oracle *Oracle) getBlockPricesFromBackend(ctx context.Context, backend Ora
}
sender, _ := item.tx.GetSender()
if sender.Value() != coinbase {
*out = append(*out, item.tip)
tipCopy := new(uint256.Int).Set(&item.tip)
*out = append(*out, tipCopy)
count++
}
}
Expand Down
21 changes: 10 additions & 11 deletions rpc/jsonrpc/otterscan_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,27 +309,26 @@ func delegateIssuance(tx kv.Tx, block *types.Block, chainConfig *chain.Config, e
}

func delegateBlockFees(ctx context.Context, tx kv.Tx, block *types.Block, senders []common.Address, chainConfig *chain.Config, receipts types.Receipts) (*big.Int, error) {
fee := big.NewInt(0)
gasUsed := big.NewInt(0)
var fee, gasUsed, totalFees uint256.Int
isLondon := chainConfig.IsLondon(block.NumberU64())
baseFee := block.BaseFee()

totalFees := big.NewInt(0)
for _, receipt := range receipts {
txn := block.Transactions()[receipt.TransactionIndex]
if !chainConfig.IsLondon(block.NumberU64()) {
fee.Set(txn.GetTipCap().ToBig())
if !isLondon {
fee.Set(txn.GetTipCap())
} else {
baseFee := block.BaseFee()
gasPrice := new(uint256.Int).Add(baseFee, txn.GetEffectiveGasTip(baseFee))
fee.Set(gasPrice.ToBig())
effectiveTip := txn.GetEffectiveGasTip(baseFee)
fee.Add(baseFee, &effectiveTip)
}

gasUsed.SetUint64(receipt.GasUsed)
fee.Mul(fee, gasUsed)
fee.Mul(&fee, &gasUsed)

totalFees.Add(totalFees, fee)
totalFees.Add(&totalFees, &fee)
}

return totalFees, nil
return totalFees.ToBig(), nil
}

func (api *OtterscanAPIImpl) getBlockWithSenders(ctx context.Context, number rpc.BlockNumber, tx kv.Tx) (*types.Block, []common.Address, error) {
Expand Down
Loading