EIP1559 #31

Merged
ramilexe merged 16 commits from 1559_rework into 1559_test 2020-11-05 12:09:04 +00:00
25 changed files with 396 additions and 396 deletions

View File

@ -555,23 +555,23 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
// If we have finalized EIP1559 and do not have a properly formed EIP1559 trx, sub in default values // If we have finalized EIP1559 and do not have a properly formed EIP1559 trx, sub in default values
eip1559 := b.config.IsEIP1559(block.Number()) eip1559 := b.config.IsEIP1559(block.Number())
eip1559Finalized := b.config.IsEIP1559Finalized(block.Number()) eip1559Finalized := b.config.IsEIP1559Finalized(block.Number())
if eip1559Finalized && (call.GasPremium == nil || call.FeeCap == nil || call.GasPrice != nil) { if eip1559Finalized && (call.MaxMinerBribePerGas == nil || call.FeeCapPerGas == nil || call.GasPrice != nil) {
call.GasPremium = big.NewInt(1) call.MaxMinerBribePerGas = big.NewInt(1)
call.FeeCap = big.NewInt(10) call.FeeCapPerGas = big.NewInt(10)
call.GasPrice = nil call.GasPrice = nil
} }
// If we have not activated EIP1559 and do not have a properly formed legacy trx, sub in default values // If we have not activated EIP1559 and do not have a properly formed legacy trx, sub in default values
if !eip1559 && (call.GasPremium != nil || call.FeeCap != nil || call.GasPrice == nil) { if !eip1559 && (call.MaxMinerBribePerGas != nil || call.FeeCapPerGas != nil || call.GasPrice == nil) {
call.GasPremium = nil call.MaxMinerBribePerGas = nil
call.FeeCap = nil call.FeeCapPerGas = nil
call.GasPrice = big.NewInt(1) call.GasPrice = big.NewInt(1)
} }
// If we are in between activation and finalization // If we are in between activation and finalization
if eip1559 && !eip1559Finalized { if eip1559 && !eip1559Finalized {
// and we have neither a properly formed legacy or EIP1559 transaction, sub in default legacy values // and we have neither a properly formed legacy or EIP1559 transaction, sub in default legacy values
if (call.GasPremium == nil || call.FeeCap == nil && call.GasPrice == nil) || (call.GasPremium != nil || call.FeeCap != nil && call.GasPrice != nil) { if (call.MaxMinerBribePerGas == nil || call.FeeCapPerGas == nil && call.GasPrice == nil) || (call.MaxMinerBribePerGas != nil || call.FeeCapPerGas != nil && call.GasPrice != nil) {
call.GasPremium = nil call.MaxMinerBribePerGas = nil
call.FeeCap = nil call.FeeCapPerGas = nil
call.GasPrice = big.NewInt(1) call.GasPrice = big.NewInt(1)
} }
} }
@ -612,16 +612,16 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa
if eip1559 && b.pendingBlock.BaseFee() == nil { if eip1559 && b.pendingBlock.BaseFee() == nil {
return core.ErrNoBaseFee return core.ErrNoBaseFee
} }
if eip1559Finalized && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { if eip1559Finalized && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) {
return core.ErrTxNotEIP1559 return core.ErrTxNotEIP1559
} }
if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { if !eip1559 && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) {
return core.ErrTxIsEIP1559 return core.ErrTxIsEIP1559
} }
if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) { if tx.GasPrice() != nil && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil) {
return core.ErrTxSetsLegacyAndEIP1559Fields return core.ErrTxSetsLegacyAndEIP1559Fields
} }
if tx.GasPrice() == nil && (tx.GasPremium() == nil || tx.FeeCap() == nil) { if tx.GasPrice() == nil && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil) {
return core.ErrMissingGasFields return core.ErrMissingGasFields
} }
@ -779,8 +779,8 @@ func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas } func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value } func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data } func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) GasPremium() *big.Int { return m.CallMsg.GasPremium } func (m callmsg) MaxMinerBribe() *big.Int { return m.CallMsg.MaxMinerBribePerGas }
func (m callmsg) FeeCap() *big.Int { return m.CallMsg.FeeCap } func (m callmsg) FeeCap() *big.Int { return m.CallMsg.FeeCapPerGas }
// filterBackend implements filters.Backend to support filtering for logs without // filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account. // taking bloom-bits acceleration structures into account.

View File

@ -54,8 +54,8 @@ type TransactOpts struct {
// If GasPrice, GasPremium, and FeeCap are all nil then we defer to the gas price oracle // If GasPrice, GasPremium, and FeeCap are all nil then we defer to the gas price oracle
GasPrice *big.Int // Gas price to use for the transaction execution GasPrice *big.Int // Gas price to use for the transaction execution
GasPremium *big.Int // Gas premium (tip) to use for EIP1559 transaction execution ( MaxMinerBribePerGas *big.Int // Gas premium (tip) to use for EIP1559 transaction execution (
FeeCap *big.Int // Fee cap to use for EIP1559 transaction execution FeeCapPerGas *big.Int // Fee cap to use for EIP1559 transaction execution
Context context.Context // Network context to support cancellation and timeouts (nil = no timeout) Context context.Context // Network context to support cancellation and timeouts (nil = no timeout)
} }
@ -217,7 +217,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
} }
// Figure out the gas allowance and gas price values // Figure out the gas allowance and gas price values
gasPrice := opts.GasPrice gasPrice := opts.GasPrice
if gasPrice == nil && opts.FeeCap == nil && opts.GasPremium == nil { if gasPrice == nil && opts.FeeCapPerGas == nil && opts.MaxMinerBribePerGas == nil {
gasPrice, err = c.transactor.SuggestGasPrice(ensureContext(opts.Context)) gasPrice, err = c.transactor.SuggestGasPrice(ensureContext(opts.Context))
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to suggest gas price: %v", err) return nil, fmt.Errorf("failed to suggest gas price: %v", err)
@ -240,8 +240,8 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
GasPrice: gasPrice, GasPrice: gasPrice,
Value: value, Value: value,
Data: input, Data: input,
GasPremium: opts.GasPremium, MaxMinerBribePerGas: opts.MaxMinerBribePerGas,
FeeCap: opts.FeeCap, FeeCapPerGas: opts.FeeCapPerGas,
} }
gasLimit, err = c.transactor.EstimateGas(ensureContext(opts.Context), msg) gasLimit, err = c.transactor.EstimateGas(ensureContext(opts.Context), msg)
if err != nil { if err != nil {
@ -251,9 +251,9 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
// Create the transaction, sign it and schedule it for execution // Create the transaction, sign it and schedule it for execution
var rawTx *types.Transaction var rawTx *types.Transaction
if contract == nil { if contract == nil {
rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input, opts.GasPremium, opts.FeeCap) rawTx = types.NewContractCreation(nonce, value, gasLimit, gasPrice, input, opts.MaxMinerBribePerGas, opts.FeeCapPerGas)
} else { } else {
rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input, opts.GasPremium, opts.FeeCap) rawTx = types.NewTransaction(nonce, c.address, value, gasLimit, gasPrice, input, opts.MaxMinerBribePerGas, opts.FeeCapPerGas)
} }
if opts.Signer == nil { if opts.Signer == nil {
return nil, errors.New("no signer to authorize the transaction with") return nil, errors.New("no signer to authorize the transaction with")

View File

@ -205,8 +205,8 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
Value: hexutil.Big(*tx.Value()), Value: hexutil.Big(*tx.Value()),
Gas: hexutil.Uint64(tx.Gas()), Gas: hexutil.Uint64(tx.Gas()),
GasPrice: (*hexutil.Big)(tx.GasPrice()), GasPrice: (*hexutil.Big)(tx.GasPrice()),
GasPremium: (*hexutil.Big)(tx.GasPremium()), MaxMinerBribePerGas: (*hexutil.Big)(tx.MaxMinerBribe()),
FeeCap: (*hexutil.Big)(tx.FeeCap()), FeeCapPerGas: (*hexutil.Big)(tx.FeeCap()),
To: to, To: to,
From: common.NewMixedcaseAddress(account.Address), From: common.NewMixedcaseAddress(account.Address),
} }

View File

@ -18,6 +18,7 @@ package misc
import ( import (
"errors" "errors"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -59,6 +60,37 @@ func VerifyEIP1559BaseFee(config *params.ChainConfig, header, parent *types.Head
return nil return nil
} }
func computeBaseFee(pBaseFee *big.Int, pGasUsed, pGasTarget, denominator uint64) *big.Int {
var baseFee *big.Int
if pGasUsed == pGasTarget {
baseFee = new(big.Int).Set(pBaseFee)
} else if pGasUsed > pGasTarget {
gasDelta := big.NewInt(int64(pGasUsed) - int64(pGasTarget))
feeDelta := math.BigMax(
new(big.Int).Div(
new(big.Int).Mul(pBaseFee, gasDelta),
new(big.Int).Mul(
new(big.Int).SetUint64(pGasTarget),
new(big.Int).SetUint64(denominator),
),
),
big.NewInt(1),
)
baseFee = new(big.Int).Add(pBaseFee, feeDelta)
} else {
gasDelta := big.NewInt(int64(pGasTarget) - int64(pGasUsed))
feeDelta := new(big.Int).Div(
new(big.Int).Mul(pBaseFee, gasDelta),
new(big.Int).Mul(
new(big.Int).SetUint64(pGasTarget),
new(big.Int).SetUint64(denominator),
),
)
baseFee = new(big.Int).Sub(pBaseFee, feeDelta)
}
return baseFee
}
// CalcBaseFee returns the baseFee for the current block provided the parent header and config parameters // CalcBaseFee returns the baseFee for the current block provided the parent header and config parameters
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int { func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
height := new(big.Int).Add(parent.Number, common.Big1) height := new(big.Int).Add(parent.Number, common.Big1)
@ -73,42 +105,12 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
return new(big.Int).SetUint64(config.EIP1559.InitialBaseFee) return new(big.Int).SetUint64(config.EIP1559.InitialBaseFee)
} }
parentBaseFee := parent.BaseFee return computeBaseFee(
parentBlockGasUsed := new(big.Int).SetUint64(parent.GasUsed) parent.BaseFee,
targetGasUsed := new(big.Int).SetUint64(parent.GasLimit) parent.GasUsed,
baseFeeMaxChangeDenominator := new(big.Int).SetUint64(config.EIP1559.EIP1559BaseFeeMaxChangeDenominator) parent.GasLimit,
config.EIP1559.EIP1559BaseFeeMaxChangeDenominator,
cmp := parentBlockGasUsed.Cmp(targetGasUsed)
if cmp == 0 {
return targetGasUsed
}
if cmp > 0 {
gasDelta := new(big.Int).Sub(parentBlockGasUsed, targetGasUsed)
feeDelta := math.BigMax(
new(big.Int).Div(
new(big.Int).Div(
new(big.Int).Mul(parentBaseFee, gasDelta),
targetGasUsed,
),
baseFeeMaxChangeDenominator,
),
common.Big1,
) )
return new(big.Int).Add(parentBaseFee, feeDelta)
}
gasDelta := new(big.Int).Sub(targetGasUsed, parentBlockGasUsed)
feeDelta := new(big.Int).Div(
new(big.Int).Div(
new(big.Int).Mul(parentBaseFee, gasDelta),
targetGasUsed,
),
baseFeeMaxChangeDenominator,
)
return new(big.Int).Sub(parentBaseFee, feeDelta)
} }
// CalcEIP1559GasTarget returns the EIP1559GasTarget at the current height and header.GasLimit // CalcEIP1559GasTarget returns the EIP1559GasTarget at the current height and header.GasLimit

View File

@ -155,7 +155,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000), big.NewInt(1000000000),
1000000, 1000000,
10000000, 10000000,
big.NewInt(1125000000), big.NewInt(2125000000),
}, },
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
@ -165,7 +165,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000), big.NewInt(1000000000),
500000, 500000,
10000000, 10000000,
big.NewInt(1125000000), big.NewInt(3375000000),
}, },
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
@ -175,7 +175,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000), big.NewInt(1000000000),
1000000, 1000000,
10000000, 10000000,
big.NewInt(1125000000), big.NewInt(2125000000),
}, },
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
@ -217,7 +217,7 @@ func TestCalcBaseFee(t *testing.T) {
10000000, 10000000,
big.NewInt(1013888888), big.NewInt(1013888888),
}, },
{ { // 10
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
big.NewInt(1000), big.NewInt(1000),
1000, 1000,
@ -225,7 +225,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000), big.NewInt(1000000000),
10000000, 10000000,
10000000, 10000000,
big.NewInt(999999999), // baseFee diff is -1 when usage == target big.NewInt(1000000000), // baseFee diff is -1 when usage == target
}, },
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
@ -235,7 +235,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000), big.NewInt(1000000000),
11000000, 11000000,
10000000, 10000000,
big.NewInt(988636363), big.NewInt(988636364),
}, },
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
@ -245,7 +245,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(900000000), big.NewInt(900000000),
1000000, 1000000,
10000000, 10000000,
big.NewInt(1012500000), big.NewInt(1912500000),
}, },
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
@ -255,7 +255,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1100000000), big.NewInt(1100000000),
1000000, 1000000,
10000000, 10000000,
big.NewInt(1237500000), big.NewInt(2337500000),
}, },
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
@ -265,7 +265,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1200000000), big.NewInt(1200000000),
1000000, 1000000,
10000000, 10000000,
big.NewInt(1350000000), big.NewInt(2550000000),
}, },
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
@ -328,7 +328,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(0), big.NewInt(0),
1000000000000000, 1000000000000000,
1, 1,
big.NewInt(1), big.NewInt(0),
}, },
// parent gas usage == parent gas limit // parent gas usage == parent gas limit
// parent baseFee == 0 // parent baseFee == 0
@ -355,11 +355,8 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1), big.NewInt(1),
1, 1,
1000000000000000, 1000000000000000,
big.NewInt(2), big.NewInt(125000000000000),
}, },
// parent gas usage <<<< parent gas limit
// parent baseFee == 1
// as expected, decrement by 1
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
big.NewInt(1000), big.NewInt(1000),
@ -368,11 +365,8 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1), big.NewInt(1),
1000000000000000, 1000000000000000,
1, 1,
big.NewInt(0), big.NewInt(1),
}, },
// parent gas usage == parent gas limit
// parent baseFee == 1
// as expected, decrement by 1 when gas usage equals the gas target
{ {
params.EIP1559ChainConfig, params.EIP1559ChainConfig,
big.NewInt(1000), big.NewInt(1000),
@ -381,7 +375,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1), big.NewInt(1),
1, 1,
1, 1,
big.NewInt(0), big.NewInt(1),
}, },
} }
for i, test := range testConditions { for i, test := range testConditions {

View File

@ -245,8 +245,8 @@ func generateChainDuringTransition(t *testing.T) {
if state.GetBalance(addr1).Uint64() != 989000 { if state.GetBalance(addr1).Uint64() != 989000 {
t.Fatalf("expected balance of addr1 to equal %d got %d", 989000, state.GetBalance(addr1).Uint64()) t.Fatalf("expected balance of addr1 to equal %d got %d", 989000, state.GetBalance(addr1).Uint64())
} }
if state.GetBalance(addr2).Uint64() != 4901403728000 { if state.GetBalance(addr2).Uint64() != 4911639338000 {
t.Fatalf("expected balance of addr2 to equal %d got %d", 4901403728000, state.GetBalance(addr2).Uint64()) t.Fatalf("expected balance of addr2 to equal %d got %d", 4911639338000, state.GetBalance(addr2).Uint64())
} }
// This value is different because the test config we use has Constantinople active (uses ConstantinopleBlockReward) // This value is different because the test config we use has Constantinople active (uses ConstantinopleBlockReward)
bal, _ := new(big.Int).SetString("7875000000000001000", 10) bal, _ := new(big.Int).SetString("7875000000000001000", 10)
@ -389,11 +389,11 @@ func generateChainAfterFinalization2(t *testing.T) {
if blockchain.CurrentBlock().Number().Uint64() != 5 { if blockchain.CurrentBlock().Number().Uint64() != 5 {
t.Fatalf("expected last block to equal %d got %d", 5, blockchain.CurrentBlock().Number().Uint64()) t.Fatalf("expected last block to equal %d got %d", 5, blockchain.CurrentBlock().Number().Uint64())
} }
if state.GetBalance(addr1).Uint64() != 7536639348000 { if state.GetBalance(addr1).Uint64() != 7536639327000 {
t.Fatalf("expected balance of addr1 to equal %d got %d", 7536639348000, state.GetBalance(addr1).Uint64()) t.Fatalf("expected balance of addr1 to equal %d got %d", 7536639327000, state.GetBalance(addr1).Uint64())
} }
if state.GetBalance(addr2).Uint64() != 4911639359000 { if state.GetBalance(addr2).Uint64() != 4911639338000 {
t.Fatalf("expected balance of addr2 to equal %d got %d", 4911639359000, state.GetBalance(addr2).Uint64()) t.Fatalf("expected balance of addr2 to equal %d got %d", 4911639338000, state.GetBalance(addr2).Uint64())
} }
// This value is different than in TestGenerateChain because the test config we use has Constantinople active (uses ConstantinopleBlockReward) // This value is different than in TestGenerateChain because the test config we use has Constantinople active (uses ConstantinopleBlockReward)
bal, _ := new(big.Int).SetString("7875000000000001000", 10) bal, _ := new(big.Int).SetString("7875000000000001000", 10)

View File

@ -18,10 +18,10 @@ package core
import ( import (
"errors" "errors"
"math"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
@ -76,7 +76,7 @@ type Message interface {
CheckNonce() bool CheckNonce() bool
Data() []byte Data() []byte
GasPremium() *big.Int MaxMinerBribe() *big.Int
FeeCap() *big.Int FeeCap() *big.Int
} }
@ -154,7 +154,7 @@ func IntrinsicGas(data []byte, contractCreation, isHomestead bool, isEIP2028 boo
// NewStateTransition initialises and returns a new state transition object. // NewStateTransition initialises and returns a new state transition object.
func NewStateTransition(evm *vm.EVM, msg Message, gp, gp1559 *GasPool) *StateTransition { func NewStateTransition(evm *vm.EVM, msg Message, gp, gp1559 *GasPool) *StateTransition {
isEIP1559 := evm.ChainConfig().IsEIP1559(evm.BlockNumber) && msg.GasPrice() == nil && msg.GasPremium() != nil && msg.FeeCap() != nil && evm.BaseFee != nil && gp1559 != nil isEIP1559 := evm.ChainConfig().IsEIP1559(evm.BlockNumber) && msg.GasPrice() == nil && msg.MaxMinerBribe() != nil && msg.FeeCap() != nil && evm.BaseFee != nil && gp1559 != nil
st := &StateTransition{ st := &StateTransition{
gp: gp, gp: gp,
gp1559: gp1559, gp1559: gp1559,
@ -167,11 +167,14 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp, gp1559 *GasPool) *StateTra
isEIP1559: isEIP1559, isEIP1559: isEIP1559,
} }
if isEIP1559 { if isEIP1559 {
// EP1559 gasPrice = min(BASEFEE + tx.fee_premium, tx.fee_cap) // # bribe is capped such that base fee is filled first
st.eip1559GasPrice = new(big.Int).Add(evm.BaseFee, msg.GasPremium()) // bribe_per_gas = min(transaction.max_miner_bribe_per_gas, transaction.fee_cap_per_gas - block.base_fee)
if st.eip1559GasPrice.Cmp(msg.FeeCap()) > 0 { // # signer pays both the bribe and the base fee
st.eip1559GasPrice.Set(msg.FeeCap()) // effective_gas_price = bribe_per_gas + block.base_fee
} st.eip1559GasPrice = new(big.Int).Add(evm.BaseFee, math.BigMin(
new(big.Int).Set(msg.MaxMinerBribe()),
new(big.Int).Sub(msg.FeeCap(), evm.BaseFee),
))
} }
return st return st
} }
@ -248,11 +251,11 @@ func (st *StateTransition) preCheck() error {
return ErrTxNotEIP1559 return ErrTxNotEIP1559
} }
// If we are before the EIP1559 activation block, throw an error if we have EIP1559 fields or do not have a GasPrice // If we are before the EIP1559 activation block, throw an error if we have EIP1559 fields or do not have a GasPrice
if !st.evm.ChainConfig().IsEIP1559(st.evm.BlockNumber) && (st.msg.GasPremium() != nil || st.msg.FeeCap() != nil || st.gp1559 != nil || st.evm.BaseFee != nil || st.msg.GasPrice() == nil) { if !st.evm.ChainConfig().IsEIP1559(st.evm.BlockNumber) && (st.msg.MaxMinerBribe() != nil || st.msg.FeeCap() != nil || st.gp1559 != nil || st.evm.BaseFee != nil || st.msg.GasPrice() == nil) {
return ErrTxIsEIP1559 return ErrTxIsEIP1559
} }
// If transaction has both legacy and EIP1559 fields, throw an error // If transaction has both legacy and EIP1559 fields, throw an error
if (st.msg.GasPremium() != nil || st.msg.FeeCap() != nil) && st.msg.GasPrice() != nil { if (st.msg.MaxMinerBribe() != nil || st.msg.FeeCap() != nil) && st.msg.GasPrice() != nil {
return ErrTxSetsLegacyAndEIP1559Fields return ErrTxSetsLegacyAndEIP1559Fields
} }
// We need a BaseFee if we are past EIP1559 activation // We need a BaseFee if we are past EIP1559 activation
@ -260,7 +263,7 @@ func (st *StateTransition) preCheck() error {
return ErrNoBaseFee return ErrNoBaseFee
} }
// We need either a GasPrice or a FeeCap and GasPremium to be set // We need either a GasPrice or a FeeCap and GasPremium to be set
if st.msg.GasPrice() == nil && (st.msg.GasPremium() == nil || st.msg.FeeCap() == nil) { if st.msg.GasPrice() == nil && (st.msg.MaxMinerBribe() == nil || st.msg.FeeCap() == nil) {
return ErrMissingGasFields return ErrMissingGasFields
} }
// If it is an EIp1559 transaction, make sure the derived gasPrice is >= baseFee // If it is an EIp1559 transaction, make sure the derived gasPrice is >= baseFee

View File

@ -265,7 +265,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64, baseFee *big.Int)
} }
} else { } else {
eip1559 = true eip1559 = true
newGasPrice := new(big.Int).Add(baseFee, tx.GasPremium()) newGasPrice := new(big.Int).Add(baseFee, tx.MaxMinerBribe())
if newGasPrice.Cmp(tx.FeeCap()) > 0 { if newGasPrice.Cmp(tx.FeeCap()) > 0 {
newGasPrice.Set(tx.FeeCap()) newGasPrice.Set(tx.FeeCap())
} }
@ -274,7 +274,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64, baseFee *big.Int)
} }
} }
} else { } else {
oldGasPrice := new(big.Int).Add(baseFee, old.GasPremium()) oldGasPrice := new(big.Int).Add(baseFee, old.MaxMinerBribe())
if oldGasPrice.Cmp(old.FeeCap()) > 0 { if oldGasPrice.Cmp(old.FeeCap()) > 0 {
oldGasPrice.Set(old.FeeCap()) oldGasPrice.Set(old.FeeCap())
} }
@ -285,7 +285,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64, baseFee *big.Int)
} }
} else { } else {
eip1559 = true eip1559 = true
newGasPrice := new(big.Int).Add(baseFee, tx.GasPremium()) newGasPrice := new(big.Int).Add(baseFee, tx.MaxMinerBribe())
if newGasPrice.Cmp(tx.FeeCap()) > 0 { if newGasPrice.Cmp(tx.FeeCap()) > 0 {
newGasPrice.Set(tx.FeeCap()) newGasPrice.Set(tx.FeeCap())
} }
@ -335,7 +335,7 @@ func (l *txList) Filter(costLimit *big.Int, legacyGasLimit, eip1559GasLimit uint
l.eip1559GasCap = eip1559GasLimit l.eip1559GasCap = eip1559GasLimit
// Filter out all the transactions above the account's funds // Filter out all the transactions above the account's funds
removed := l.txs.Filter(func(tx *types.Transaction) bool { removed := l.txs.Filter(func(tx *types.Transaction) bool {
return tx.Cost(baseFee).Cmp(costLimit) > 0 || (tx.GasPrice() != nil && tx.Gas() > legacyGasLimit) || (tx.GasPremium()) != nil && tx.Gas() > eip1559GasLimit return tx.Cost(baseFee).Cmp(costLimit) > 0 || (tx.GasPrice() != nil && tx.Gas() > legacyGasLimit) || (tx.MaxMinerBribe()) != nil && tx.Gas() > eip1559GasLimit
}) })
// If the list was strict, filter anything above the lowest nonce // If the list was strict, filter anything above the lowest nonce
@ -418,13 +418,13 @@ func (h priceHeap) Less(i, j int) bool {
iPrice := h.txs[i].GasPrice() iPrice := h.txs[i].GasPrice()
jPrice := h.txs[j].GasPrice() jPrice := h.txs[j].GasPrice()
if iPrice == nil { if iPrice == nil {
iPrice = new(big.Int).Add(h.baseFee, h.txs[i].GasPremium()) iPrice = new(big.Int).Add(h.baseFee, h.txs[i].MaxMinerBribe())
if iPrice.Cmp(h.txs[i].FeeCap()) > 0 { if iPrice.Cmp(h.txs[i].FeeCap()) > 0 {
iPrice.Set(h.txs[i].FeeCap()) iPrice.Set(h.txs[i].FeeCap())
} }
} }
if jPrice == nil { if jPrice == nil {
jPrice = new(big.Int).Add(h.baseFee, h.txs[j].GasPremium()) jPrice = new(big.Int).Add(h.baseFee, h.txs[j].MaxMinerBribe())
if jPrice.Cmp(h.txs[j].FeeCap()) > 0 { if jPrice.Cmp(h.txs[j].FeeCap()) > 0 {
jPrice.Set(h.txs[j].FeeCap()) jPrice.Set(h.txs[j].FeeCap())
} }
@ -513,7 +513,7 @@ func (l *txPricedList) Cap(threshold *big.Int, local *accountSet) types.Transact
// Stop the discards if we've reached the threshold // Stop the discards if we've reached the threshold
gasPrice := tx.GasPrice() gasPrice := tx.GasPrice()
if gasPrice == nil { if gasPrice == nil {
gasPrice = new(big.Int).Add(l.items.baseFee, tx.GasPremium()) gasPrice = new(big.Int).Add(l.items.baseFee, tx.MaxMinerBribe())
if gasPrice.Cmp(tx.FeeCap()) > 0 { if gasPrice.Cmp(tx.FeeCap()) > 0 {
gasPrice.Set(tx.FeeCap()) gasPrice.Set(tx.FeeCap())
} }
@ -560,14 +560,14 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo
cheapest := l.items.txs[0] cheapest := l.items.txs[0]
cheapestPrice := cheapest.GasPrice() cheapestPrice := cheapest.GasPrice()
if cheapestPrice == nil { if cheapestPrice == nil {
cheapestPrice = new(big.Int).Add(l.items.baseFee, cheapest.GasPremium()) cheapestPrice = new(big.Int).Add(l.items.baseFee, cheapest.MaxMinerBribe())
if cheapestPrice.Cmp(cheapest.FeeCap()) > 0 { if cheapestPrice.Cmp(cheapest.FeeCap()) > 0 {
cheapestPrice.Set(cheapest.FeeCap()) cheapestPrice.Set(cheapest.FeeCap())
} }
} }
txPrice := tx.GasPrice() txPrice := tx.GasPrice()
if txPrice == nil { if txPrice == nil {
txPrice = new(big.Int).Add(l.items.baseFee, tx.GasPremium()) txPrice = new(big.Int).Add(l.items.baseFee, tx.MaxMinerBribe())
if txPrice.Cmp(tx.FeeCap()) > 0 { if txPrice.Cmp(tx.FeeCap()) > 0 {
txPrice.Set(tx.FeeCap()) txPrice.Set(tx.FeeCap())
} }

View File

@ -548,16 +548,16 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if eip1559 && pool.chain.CurrentBlock().BaseFee() == nil { if eip1559 && pool.chain.CurrentBlock().BaseFee() == nil {
return ErrNoBaseFee return ErrNoBaseFee
} }
if eip1559Finalized && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { if eip1559Finalized && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) {
return ErrTxNotEIP1559 return ErrTxNotEIP1559
} }
if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { if !eip1559 && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) {
return ErrTxIsEIP1559 return ErrTxIsEIP1559
} }
if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) { if tx.GasPrice() != nil && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil) {
return ErrTxSetsLegacyAndEIP1559Fields return ErrTxSetsLegacyAndEIP1559Fields
} }
if tx.GasPrice() == nil && (tx.GasPremium() == nil || tx.FeeCap() == nil) { if tx.GasPrice() == nil && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil) {
return ErrMissingGasFields return ErrMissingGasFields
} }
// Set the gasPrice to the tx.GasPrice() if it is non nil (legacy transaction) // Set the gasPrice to the tx.GasPrice() if it is non nil (legacy transaction)
@ -565,7 +565,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if tx.GasPrice() != nil { if tx.GasPrice() != nil {
gasPrice = tx.GasPrice() gasPrice = tx.GasPrice()
} else { // Derive the gasPrice from the tx.GasPremium() and tx.FeeCap() (EIP1559 transaction) } else { // Derive the gasPrice from the tx.GasPremium() and tx.FeeCap() (EIP1559 transaction)
gasPrice = new(big.Int).Add(pool.chain.CurrentBlock().BaseFee(), tx.GasPremium()) gasPrice = new(big.Int).Add(pool.chain.CurrentBlock().BaseFee(), tx.MaxMinerBribe())
if gasPrice.Cmp(tx.FeeCap()) > 0 { if gasPrice.Cmp(tx.FeeCap()) > 0 {
gasPrice.Set(tx.FeeCap()) gasPrice.Set(tx.FeeCap())
} }

View File

@ -451,7 +451,7 @@ func TestInvalidTransactionsEIP1559(t *testing.T) {
} }
fakeBaseFee := big.NewInt(5) fakeBaseFee := big.NewInt(5)
eip1559GasPrice := new(big.Int).Add(fakeBaseFee, tx.GasPremium()) eip1559GasPrice := new(big.Int).Add(fakeBaseFee, tx.MaxMinerBribe())
balance := new(big.Int).Add(tx.Value(), new(big.Int).Mul(new(big.Int).SetUint64(tx.Gas()), eip1559GasPrice)) balance := new(big.Int).Add(tx.Value(), new(big.Int).Mul(new(big.Int).SetUint64(tx.Gas()), eip1559GasPrice))
pool.currentState.AddBalance(from, balance) pool.currentState.AddBalance(from, balance)
@ -518,7 +518,7 @@ func TestInvalidTransactionsEIP1559Finalized(t *testing.T) {
} }
fakeBaseFee := big.NewInt(5) fakeBaseFee := big.NewInt(5)
eip1559GasPrice := new(big.Int).Add(fakeBaseFee, tx.GasPremium()) eip1559GasPrice := new(big.Int).Add(fakeBaseFee, tx.MaxMinerBribe())
balance := new(big.Int).Add(tx.Value(), new(big.Int).Mul(new(big.Int).SetUint64(tx.Gas()), eip1559GasPrice)) balance := new(big.Int).Add(tx.Value(), new(big.Int).Mul(new(big.Int).SetUint64(tx.Gas()), eip1559GasPrice))
pool.currentState.AddBalance(from, balance) pool.currentState.AddBalance(from, balance)

View File

@ -22,8 +22,8 @@ func (t txdata) MarshalJSON() ([]byte, error) {
Recipient *common.Address `json:"to" rlp:"nil"` Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"` Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload hexutil.Bytes `json:"input" gencodec:"required"` Payload hexutil.Bytes `json:"input" gencodec:"required"`
GasPremium *hexutil.Big `json:"gasPremium" rlp:"nil"` MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas" rlp:"nil"`
FeeCap *hexutil.Big `json:"feeCap" rlp:"nil"` FeeCapPerGas *hexutil.Big `json:"feeCapPerGas" rlp:"nil"`
V *hexutil.Big `json:"v" gencodec:"required"` V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"` R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"` S *hexutil.Big `json:"s" gencodec:"required"`
@ -36,8 +36,8 @@ func (t txdata) MarshalJSON() ([]byte, error) {
enc.Recipient = t.Recipient enc.Recipient = t.Recipient
enc.Amount = (*hexutil.Big)(t.Amount) enc.Amount = (*hexutil.Big)(t.Amount)
enc.Payload = t.Payload enc.Payload = t.Payload
enc.GasPremium = (*hexutil.Big)(t.GasPremium) enc.MaxMinerBribePerGas = (*hexutil.Big)(t.MaxMinerBribePerGas)
enc.FeeCap = (*hexutil.Big)(t.FeeCap) enc.FeeCapPerGas = (*hexutil.Big)(t.FeeCapPerGas)
enc.V = (*hexutil.Big)(t.V) enc.V = (*hexutil.Big)(t.V)
enc.R = (*hexutil.Big)(t.R) enc.R = (*hexutil.Big)(t.R)
enc.S = (*hexutil.Big)(t.S) enc.S = (*hexutil.Big)(t.S)
@ -54,8 +54,8 @@ func (t *txdata) UnmarshalJSON(input []byte) error {
Recipient *common.Address `json:"to" rlp:"nil"` Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"` Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload *hexutil.Bytes `json:"input" gencodec:"required"` Payload *hexutil.Bytes `json:"input" gencodec:"required"`
GasPremium *hexutil.Big `json:"gasPremium" rlp:"nil"` MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas" rlp:"nil"`
FeeCap *hexutil.Big `json:"feeCap" rlp:"nil"` FeeCapPerGas *hexutil.Big `json:"feeCapPerGas" rlp:"nil"`
V *hexutil.Big `json:"v" gencodec:"required"` V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"` R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"` S *hexutil.Big `json:"s" gencodec:"required"`
@ -87,11 +87,11 @@ func (t *txdata) UnmarshalJSON(input []byte) error {
return errors.New("missing required field 'input' for txdata") return errors.New("missing required field 'input' for txdata")
} }
t.Payload = *dec.Payload t.Payload = *dec.Payload
if dec.GasPremium != nil { if dec.MaxMinerBribePerGas != nil {
t.GasPremium = (*big.Int)(dec.GasPremium) t.MaxMinerBribePerGas = (*big.Int)(dec.MaxMinerBribePerGas)
} }
if dec.FeeCap != nil { if dec.FeeCapPerGas != nil {
t.FeeCap = (*big.Int)(dec.FeeCap) t.FeeCapPerGas = (*big.Int)(dec.FeeCapPerGas)
} }
if dec.V == nil { if dec.V == nil {
return errors.New("missing required field 'v' for txdata") return errors.New("missing required field 'v' for txdata")

View File

@ -25,6 +25,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
) )
@ -52,8 +53,8 @@ type txdata struct {
Payload []byte `json:"input" gencodec:"required"` Payload []byte `json:"input" gencodec:"required"`
// EIP1559 gas values // EIP1559 gas values
GasPremium *big.Int `json:"gasPremium" rlp:"nil"` // nil means legacy transaction MaxMinerBribePerGas *big.Int `json:"maxMinerBribePerGas" rlp:"nil"`
FeeCap *big.Int `json:"feeCap" rlp:"nil"` // nil means legacy transaction FeeCapPerGas *big.Int `json:"feeCapPerGas" rlp:"nil"`
// Signature values // Signature values
V *big.Int `json:"v" gencodec:"required"` V *big.Int `json:"v" gencodec:"required"`
@ -70,22 +71,22 @@ type txdataMarshaling struct {
GasLimit hexutil.Uint64 GasLimit hexutil.Uint64
Amount *hexutil.Big Amount *hexutil.Big
Payload hexutil.Bytes Payload hexutil.Bytes
GasPremium *hexutil.Big MaxMinerBribePerGas *hexutil.Big
FeeCap *hexutil.Big FeeCapPerGas *hexutil.Big
V *hexutil.Big V *hexutil.Big
R *hexutil.Big R *hexutil.Big
S *hexutil.Big S *hexutil.Big
} }
func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, gasPremium, feeCap *big.Int) *Transaction { func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, maxMinerBribePerGas, feeCapPerGas *big.Int) *Transaction {
return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data, gasPremium, feeCap) return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data, maxMinerBribePerGas, feeCapPerGas)
} }
func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, gasPremium, feeCap *big.Int) *Transaction { func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, maxMinerBribePerGas, feeCapPerGas *big.Int) *Transaction {
return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data, gasPremium, feeCap) return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data, maxMinerBribePerGas, feeCapPerGas)
} }
func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, gasPremium, feeCap *big.Int) *Transaction { func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, maxMinerBribePerGas, feeCapPerGas *big.Int) *Transaction {
if len(data) > 0 { if len(data) > 0 {
data = common.CopyBytes(data) data = common.CopyBytes(data)
} }
@ -105,19 +106,12 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit
if gasPrice != nil { if gasPrice != nil {
d.Price = gasPrice d.Price = gasPrice
} }
if gasPremium != nil { if maxMinerBribePerGas != nil {
d.GasPremium = gasPremium d.MaxMinerBribePerGas = maxMinerBribePerGas
} }
if feeCap != nil { if feeCapPerGas != nil {
d.FeeCap = feeCap d.FeeCapPerGas = feeCapPerGas
} }
if gasPremium != nil {
d.GasPremium = gasPremium
}
if feeCap != nil {
d.FeeCap = feeCap
}
return &Transaction{data: d} return &Transaction{data: d}
} }
@ -142,7 +136,7 @@ func isProtectedV(V *big.Int) bool {
// EncodeRLP implements rlp.Encoder // EncodeRLP implements rlp.Encoder
func (tx *Transaction) EncodeRLP(w io.Writer) error { func (tx *Transaction) EncodeRLP(w io.Writer) error {
if tx.data.FeeCap == nil || tx.data.GasPremium == nil { if tx.data.FeeCapPerGas == nil || tx.data.MaxMinerBribePerGas == nil {
return rlp.Encode(w, []interface{}{ return rlp.Encode(w, []interface{}{
tx.data.AccountNonce, tx.data.AccountNonce,
tx.data.Price, tx.data.Price,
@ -203,12 +197,12 @@ func (tx *Transaction) DecodeRLP(stream *rlp.Stream) error {
if err = stream.Decode(payload); err != nil { if err = stream.Decode(payload); err != nil {
return err return err
} }
gasPremium := new(big.Int) maxMinerBribePerGas := new(big.Int)
if err = stream.Decode(gasPremium); err != nil { if err = stream.Decode(maxMinerBribePerGas); err != nil {
return err return err
} }
feeCap := new(big.Int) feeCapPerGas := new(big.Int)
if err = stream.Decode(feeCap); err != nil { if err = stream.Decode(feeCapPerGas); err != nil {
return err return err
} }
v := new(big.Int) v := new(big.Int)
@ -225,8 +219,8 @@ func (tx *Transaction) DecodeRLP(stream *rlp.Stream) error {
Recipient: recipient, Recipient: recipient,
Amount: amount, Amount: amount,
Payload: *payload, Payload: *payload,
V: gasPremium, V: maxMinerBribePerGas,
R: feeCap, R: feeCapPerGas,
S: v, S: v,
} }
tx.size.Store(common.StorageSize(rlp.ListSize(size))) tx.size.Store(common.StorageSize(rlp.ListSize(size)))
@ -255,8 +249,8 @@ func (tx *Transaction) DecodeRLP(stream *rlp.Stream) error {
Recipient: recipient, Recipient: recipient,
Amount: amount, Amount: amount,
Payload: *payload, Payload: *payload,
GasPremium: gasPremium, MaxMinerBribePerGas: maxMinerBribePerGas,
FeeCap: feeCap, FeeCapPerGas: feeCapPerGas,
V: v, V: v,
R: r, R: r,
S: s, S: s,
@ -304,8 +298,8 @@ func (tx *Transaction) GasPrice() *big.Int { return tx.data.Price }
func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) } func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.data.Amount) }
func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce } func (tx *Transaction) Nonce() uint64 { return tx.data.AccountNonce }
func (tx *Transaction) CheckNonce() bool { return true } func (tx *Transaction) CheckNonce() bool { return true }
func (tx *Transaction) GasPremium() *big.Int { return tx.data.GasPremium } func (tx *Transaction) MaxMinerBribe() *big.Int { return tx.data.MaxMinerBribePerGas }
func (tx *Transaction) FeeCap() *big.Int { return tx.data.FeeCap } func (tx *Transaction) FeeCap() *big.Int { return tx.data.FeeCapPerGas }
// To returns the recipient address of the transaction. // To returns the recipient address of the transaction.
// It returns nil if the transaction is a contract creation. // It returns nil if the transaction is a contract creation.
@ -354,8 +348,8 @@ func (tx *Transaction) AsMessage(s Signer) (Message, error) {
amount: tx.data.Amount, amount: tx.data.Amount,
data: tx.data.Payload, data: tx.data.Payload,
checkNonce: true, checkNonce: true,
gasPremium: tx.data.GasPremium, maxMinerBribePerGas: tx.data.MaxMinerBribePerGas,
feeCap: tx.data.FeeCap, feeCapPerGas: tx.data.FeeCapPerGas,
} }
var err error var err error
@ -382,11 +376,15 @@ func (tx *Transaction) Cost(baseFee *big.Int) *big.Int {
total.Add(total, tx.data.Amount) total.Add(total, tx.data.Amount)
return total return total
} }
if baseFee != nil && tx.data.GasPremium != nil && tx.data.FeeCap != nil { if baseFee != nil && tx.data.MaxMinerBribePerGas != nil && tx.data.FeeCapPerGas != nil {
eip1559GasPrice := new(big.Int).Add(baseFee, tx.data.GasPremium) // # bribe is capped such that base fee is filled first
if eip1559GasPrice.Cmp(tx.data.FeeCap) > 0 { // bribe_per_gas = min(transaction.max_miner_bribe_per_gas, transaction.fee_cap_per_gas - block.base_fee)
eip1559GasPrice.Set(tx.data.FeeCap) // # signer pays both the bribe and the base fee
} // effective_gas_price = bribe_per_gas + block.base_fee
eip1559GasPrice := new(big.Int).Add(baseFee, math.BigMin(
new(big.Int).Set(tx.data.MaxMinerBribePerGas),
new(big.Int).Sub(tx.data.FeeCapPerGas, baseFee),
))
total := new(big.Int).Mul(eip1559GasPrice, new(big.Int).SetUint64(tx.data.GasLimit)) total := new(big.Int).Mul(eip1559GasPrice, new(big.Int).SetUint64(tx.data.GasLimit))
total.Add(total, tx.data.Amount) total.Add(total, tx.data.Amount)
return total return total
@ -451,20 +449,21 @@ type TxByPrice struct {
func (s TxByPrice) Len() int { return len(s.txs) } func (s TxByPrice) Len() int { return len(s.txs) }
//ToDo1559: check it
// Note that this returns true if j is less than i, as the ordering needs to be from highest price to lowest // Note that this returns true if j is less than i, as the ordering needs to be from highest price to lowest
func (s TxByPrice) Less(i, j int) bool { func (s TxByPrice) Less(i, j int) bool {
iPrice := s.txs[i].data.Price iPrice := s.txs[i].data.Price
jPrice := s.txs[j].data.Price jPrice := s.txs[j].data.Price
if iPrice == nil { if iPrice == nil {
iPrice = new(big.Int).Add(s.baseFee, s.txs[i].data.GasPremium) iPrice = new(big.Int).Add(s.baseFee, s.txs[i].data.MaxMinerBribePerGas)
if iPrice.Cmp(s.txs[i].data.FeeCap) > 0 { if iPrice.Cmp(s.txs[i].data.FeeCapPerGas) > 0 {
iPrice.Set(s.txs[i].data.FeeCap) iPrice.Set(s.txs[i].data.FeeCapPerGas)
} }
} }
if jPrice == nil { if jPrice == nil {
jPrice = new(big.Int).Add(s.baseFee, s.txs[j].data.GasPremium) jPrice = new(big.Int).Add(s.baseFee, s.txs[j].data.MaxMinerBribePerGas)
if jPrice.Cmp(s.txs[j].data.FeeCap) > 0 { if jPrice.Cmp(s.txs[j].data.FeeCapPerGas) > 0 {
jPrice.Set(s.txs[j].data.FeeCap) jPrice.Set(s.txs[j].data.FeeCapPerGas)
} }
} }
return iPrice.Cmp(jPrice) > 0 return iPrice.Cmp(jPrice) > 0
@ -560,12 +559,12 @@ type Message struct {
gasPrice *big.Int gasPrice *big.Int
data []byte data []byte
checkNonce bool checkNonce bool
gasPremium *big.Int maxMinerBribePerGas *big.Int
feeCap *big.Int feeCapPerGas *big.Int
} }
// NewMessage creates and returns a new message // NewMessage creates and returns a new message
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, gasPremium, feeCap *big.Int) Message { func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, checkNonce bool, maxMinerBribePerGas, feeCapPerGas *big.Int) Message {
return Message{ return Message{
from: from, from: from,
to: to, to: to,
@ -575,8 +574,8 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
gasPrice: gasPrice, gasPrice: gasPrice,
data: data, data: data,
checkNonce: checkNonce, checkNonce: checkNonce,
gasPremium: gasPremium, maxMinerBribePerGas: maxMinerBribePerGas,
feeCap: feeCap, feeCapPerGas: feeCapPerGas,
} }
} }
@ -588,5 +587,5 @@ func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce } func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data } func (m Message) Data() []byte { return m.data }
func (m Message) CheckNonce() bool { return m.checkNonce } func (m Message) CheckNonce() bool { return m.checkNonce }
func (m Message) GasPremium() *big.Int { return m.gasPremium } func (m Message) MaxMinerBribe() *big.Int { return m.maxMinerBribePerGas }
func (m Message) FeeCap() *big.Int { return m.feeCap } func (m Message) FeeCap() *big.Int { return m.feeCapPerGas }

View File

@ -161,8 +161,8 @@ func (s EIP155Signer) Hash(tx *Transaction) common.Hash {
tx.data.Amount, tx.data.Amount,
tx.data.Payload, tx.data.Payload,
} }
if tx.data.GasPremium != nil && tx.data.FeeCap != nil { if tx.data.MaxMinerBribePerGas != nil && tx.data.FeeCapPerGas != nil {
txFields = append(txFields, tx.data.GasPremium, tx.data.FeeCap) txFields = append(txFields, tx.data.MaxMinerBribePerGas, tx.data.FeeCapPerGas)
} }
txFields = append(txFields, s.chainId, uint(0), uint(0)) txFields = append(txFields, s.chainId, uint(0), uint(0))
return rlpHash(txFields) return rlpHash(txFields)
@ -217,8 +217,8 @@ func (fs FrontierSigner) Hash(tx *Transaction) common.Hash {
tx.data.Amount, tx.data.Amount,
tx.data.Payload, tx.data.Payload,
} }
if tx.data.GasPremium != nil && tx.data.FeeCap != nil { if tx.data.MaxMinerBribePerGas != nil && tx.data.FeeCapPerGas != nil {
txFields = append(txFields, tx.data.GasPremium, tx.data.FeeCap) txFields = append(txFields, tx.data.MaxMinerBribePerGas, tx.data.FeeCapPerGas)
} }
return rlpHash(txFields) return rlpHash(txFields)
} }

View File

@ -152,10 +152,10 @@ func TestEIP1159TransactionDecode(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if tx.data.FeeCap == nil || tx.data.FeeCap.Cmp(eip1559Tx.data.FeeCap) != 0 { if tx.data.FeeCapPerGas == nil || tx.data.FeeCapPerGas.Cmp(eip1559Tx.data.FeeCapPerGas) != 0 {
t.Fatal("unexpected FeeCap") t.Fatal("unexpected FeeCap")
} }
if tx.data.GasPremium == nil || tx.data.GasPremium.Cmp(eip1559Tx.data.GasPremium) != 0 { if tx.data.MaxMinerBribePerGas == nil || tx.data.MaxMinerBribePerGas.Cmp(eip1559Tx.data.MaxMinerBribePerGas) != 0 {
t.Fatal("unexpected GasPremium") t.Fatal("unexpected GasPremium")
} }
if tx.data.Price != nil { if tx.data.Price != nil {
@ -370,13 +370,13 @@ func TestTransactionPriceNonceSort(t *testing.T) {
iPrice := txi.GasPrice() iPrice := txi.GasPrice()
nextPrice := next.GasPrice() nextPrice := next.GasPrice()
if iPrice == nil { if iPrice == nil {
iPrice = new(big.Int).Add(baseFee, txi.GasPremium()) iPrice = new(big.Int).Add(baseFee, txi.MaxMinerBribe())
if iPrice.Cmp(txi.FeeCap()) > 0 { if iPrice.Cmp(txi.FeeCap()) > 0 {
iPrice.Set(txi.FeeCap()) iPrice.Set(txi.FeeCap())
} }
} }
if nextPrice == nil { if nextPrice == nil {
nextPrice = new(big.Int).Add(baseFee, next.GasPremium()) nextPrice = new(big.Int).Add(baseFee, next.MaxMinerBribe())
if nextPrice.Cmp(next.FeeCap()) > 0 { if nextPrice.Cmp(next.FeeCap()) > 0 {
nextPrice.Set(next.FeeCap()) nextPrice.Set(next.FeeCap())
} }

View File

@ -345,13 +345,13 @@ func (t *transactionsByGasPrice) Less(i, j int) bool {
iPrice := t.txs[i].GasPrice() iPrice := t.txs[i].GasPrice()
jPrice := t.txs[j].GasPrice() jPrice := t.txs[j].GasPrice()
if iPrice == nil { if iPrice == nil {
iPrice = new(big.Int).Add(t.baseFee, t.txs[i].GasPremium()) iPrice = new(big.Int).Add(t.baseFee, t.txs[i].MaxMinerBribe())
if iPrice.Cmp(t.txs[i].FeeCap()) > 0 { if iPrice.Cmp(t.txs[i].FeeCap()) > 0 {
iPrice.Set(t.txs[i].FeeCap()) iPrice.Set(t.txs[i].FeeCap())
} }
} }
if jPrice == nil { if jPrice == nil {
jPrice = new(big.Int).Add(t.baseFee, t.txs[j].GasPremium()) jPrice = new(big.Int).Add(t.baseFee, t.txs[j].MaxMinerBribe())
if jPrice.Cmp(t.txs[j].FeeCap()) > 0 { if jPrice.Cmp(t.txs[j].FeeCap()) > 0 {
jPrice.Set(t.txs[j].FeeCap()) jPrice.Set(t.txs[j].FeeCap())
} }
@ -367,8 +367,8 @@ type transactionsByGasPremium struct {
func (t *transactionsByGasPremium) Len() int { return len(t.txs) } func (t *transactionsByGasPremium) Len() int { return len(t.txs) }
func (t *transactionsByGasPremium) Swap(i, j int) { t.txs[i], t.txs[j] = t.txs[j], t.txs[i] } func (t *transactionsByGasPremium) Swap(i, j int) { t.txs[i], t.txs[j] = t.txs[j], t.txs[i] }
func (t *transactionsByGasPremium) Less(i, j int) bool { func (t *transactionsByGasPremium) Less(i, j int) bool {
iPremium := t.txs[i].GasPremium() iPremium := t.txs[i].MaxMinerBribe()
jPremium := t.txs[j].GasPremium() jPremium := t.txs[j].MaxMinerBribe()
if iPremium == nil { if iPremium == nil {
iPremium = new(big.Int).Sub(t.txs[i].GasPrice(), t.baseFee) iPremium = new(big.Int).Sub(t.txs[i].GasPrice(), t.baseFee)
if iPremium.Cmp(common.Big0) < 0 { if iPremium.Cmp(common.Big0) < 0 {
@ -423,7 +423,7 @@ func (gpo *Oracle) getBlockPrices(ctx context.Context, signer types.Signer, bloc
} }
price := tx.GasPrice() price := tx.GasPrice()
if price == nil { if price == nil {
price = new(big.Int).Add(block.BaseFee(), tx.GasPremium()) price = new(big.Int).Add(block.BaseFee(), tx.MaxMinerBribe())
if price.Cmp(tx.FeeCap()) > 0 { if price.Cmp(tx.FeeCap()) > 0 {
price.Set(tx.FeeCap()) price.Set(tx.FeeCap())
} }
@ -455,7 +455,7 @@ func (gpo *Oracle) getBlockPremiums(ctx context.Context, signer types.Signer, bl
if err != nil || sender == block.Coinbase() { if err != nil || sender == block.Coinbase() {
continue continue
} }
premium := tx.GasPremium() premium := tx.MaxMinerBribe()
if premium == nil { if premium == nil {
premium = new(big.Int).Sub(tx.GasPrice(), block.BaseFee()) premium = new(big.Int).Sub(tx.GasPrice(), block.BaseFee())
if premium.Cmp(common.Big0) < 0 { if premium.Cmp(common.Big0) < 0 {

View File

@ -564,11 +564,11 @@ func toCallArg(msg ethereum.CallMsg) interface{} {
if msg.GasPrice != nil { if msg.GasPrice != nil {
arg["gasPrice"] = (*hexutil.Big)(msg.GasPrice) arg["gasPrice"] = (*hexutil.Big)(msg.GasPrice)
} }
if msg.GasPremium != nil { if msg.MaxMinerBribePerGas != nil {
arg["gasPremium"] = (*hexutil.Big)(msg.GasPremium) arg["maxMinerBribePerGas"] = (*hexutil.Big)(msg.MaxMinerBribePerGas)
} }
if msg.FeeCap != nil { if msg.FeeCapPerGas != nil {
arg["feeCap"] = (*hexutil.Big)(msg.FeeCap) arg["feeCapPerGas"] = (*hexutil.Big)(msg.FeeCapPerGas)
} }
return arg return arg
} }

View File

@ -119,8 +119,8 @@ type CallMsg struct {
GasPrice *big.Int // wei <-> gas exchange ratio GasPrice *big.Int // wei <-> gas exchange ratio
Value *big.Int // amount of wei sent along with the call Value *big.Int // amount of wei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation Data []byte // input data, usually an ABI-encoded contract method invocation
GasPremium *big.Int // EIP1559 gas premium paid to miners (excess of the basefee) MaxMinerBribePerGas *big.Int // EIP1559 gas premium paid to miners (excess of the basefee)
FeeCap *big.Int // Max amount of gas we can use for this trx execution FeeCapPerGas *big.Int // Max amount of gas we can use for this trx execution
} }
// A ContractCaller provides contract calls, essentially transactions that are executed by // A ContractCaller provides contract calls, essentially transactions that are executed by

View File

@ -399,7 +399,7 @@ func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args SendTxArgs
if args.Gas == nil { if args.Gas == nil {
return nil, fmt.Errorf("gas not specified") return nil, fmt.Errorf("gas not specified")
} }
if args.GasPrice == nil && (args.GasPremium == nil || args.FeeCap == nil) { if args.GasPrice == nil && (args.MaxMinerBribePerGas == nil || args.FeeCapPerGas == nil) {
return nil, fmt.Errorf("gasPrice or gasPremium+feeCap not specified") return nil, fmt.Errorf("gasPrice or gasPremium+feeCap not specified")
} }
if args.Nonce == nil { if args.Nonce == nil {
@ -754,8 +754,8 @@ type CallArgs struct {
GasPrice *hexutil.Big `json:"gasPrice"` GasPrice *hexutil.Big `json:"gasPrice"`
Value *hexutil.Big `json:"value"` Value *hexutil.Big `json:"value"`
Data *hexutil.Bytes `json:"data"` Data *hexutil.Bytes `json:"data"`
GasPremium *hexutil.Big `json:"gasPremium"` MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas"`
FeeCap *hexutil.Big `json:"feeCap"` FeeCapPerGas *hexutil.Big `json:"feeCapPerGas"`
} }
// ToMessage converts CallArgs to the Message type used by the core evm // ToMessage converts CallArgs to the Message type used by the core evm
@ -777,7 +777,7 @@ func (args *CallArgs) ToMessage(globalGasCap *big.Int) types.Message {
} }
var gasPrice *big.Int var gasPrice *big.Int
if args.GasPremium == nil { if args.MaxMinerBribePerGas == nil {
gasPrice = new(big.Int).SetUint64(defaultGasPrice) gasPrice = new(big.Int).SetUint64(defaultGasPrice)
if args.GasPrice != nil { if args.GasPrice != nil {
gasPrice = args.GasPrice.ToInt() gasPrice = args.GasPrice.ToInt()
@ -795,7 +795,7 @@ func (args *CallArgs) ToMessage(globalGasCap *big.Int) types.Message {
} }
// Create new call message // Create new call message
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, false, (*big.Int)(args.GasPremium), (*big.Int)(args.FeeCap)) msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, data, false, (*big.Int)(args.MaxMinerBribePerGas), (*big.Int)(args.FeeCapPerGas))
return msg return msg
} }
@ -822,25 +822,25 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
if eip1559 && b.CurrentBlock().BaseFee() == nil { if eip1559 && b.CurrentBlock().BaseFee() == nil {
return nil, core.ErrNoBaseFee return nil, core.ErrNoBaseFee
} }
if eip1559Finalized && (args.GasPremium == nil || args.FeeCap == nil || args.GasPrice != nil) { if eip1559Finalized && (args.MaxMinerBribePerGas == nil || args.FeeCapPerGas == nil || args.GasPrice != nil) {
return nil, core.ErrTxNotEIP1559 return nil, core.ErrTxNotEIP1559
} }
if !eip1559 && (args.GasPremium != nil || args.FeeCap != nil || args.GasPrice == nil) { if !eip1559 && (args.MaxMinerBribePerGas != nil || args.FeeCapPerGas != nil || args.GasPrice == nil) {
return nil, core.ErrTxIsEIP1559 return nil, core.ErrTxIsEIP1559
} }
if args.GasPrice != nil && (args.GasPremium != nil || args.FeeCap != nil) { if args.GasPrice != nil && (args.MaxMinerBribePerGas != nil || args.FeeCapPerGas != nil) {
return nil, core.ErrTxSetsLegacyAndEIP1559Fields return nil, core.ErrTxSetsLegacyAndEIP1559Fields
} }
if args.FeeCap != nil && args.GasPremium == nil { if args.FeeCapPerGas != nil && args.MaxMinerBribePerGas == nil {
return nil, errors.New("if FeeCap is set, GasPremium must be set") return nil, errors.New("if FeeCap is set, GasPremium must be set")
} }
if args.GasPremium != nil { if args.MaxMinerBribePerGas != nil {
if args.FeeCap == nil { if args.FeeCapPerGas == nil {
return nil, errors.New("if GasPremium is set, FeeCap must be set") return nil, errors.New("if GasPremium is set, FeeCap must be set")
} }
gasPrice := new(big.Int).Add(b.CurrentBlock().BaseFee(), args.GasPremium.ToInt()) gasPrice := new(big.Int).Add(b.CurrentBlock().BaseFee(), args.MaxMinerBribePerGas.ToInt())
if gasPrice.Cmp(args.FeeCap.ToInt()) > 0 { if gasPrice.Cmp(args.FeeCapPerGas.ToInt()) > 0 {
gasPrice.Set(args.FeeCap.ToInt()) gasPrice.Set(args.FeeCapPerGas.ToInt())
} }
if gasPrice.Cmp(b.CurrentBlock().BaseFee()) < 0 { if gasPrice.Cmp(b.CurrentBlock().BaseFee()) < 0 {
return nil, core.ErrEIP1559GasPriceLessThanBaseFee return nil, core.ErrEIP1559GasPriceLessThanBaseFee
@ -1240,8 +1240,8 @@ type RPCTransaction struct {
To *common.Address `json:"to"` To *common.Address `json:"to"`
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"` TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
Value *hexutil.Big `json:"value"` Value *hexutil.Big `json:"value"`
GasPremium *hexutil.Big `json:"gasPremium"` MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas"`
FeeCap *hexutil.Big `json:"feeCap"` FeeCapPerGas *hexutil.Big `json:"feeCapPerGas"`
V *hexutil.Big `json:"v"` V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"` R *hexutil.Big `json:"r"`
S *hexutil.Big `json:"s"` S *hexutil.Big `json:"s"`
@ -1266,8 +1266,8 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
Nonce: hexutil.Uint64(tx.Nonce()), Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(), To: tx.To(),
Value: (*hexutil.Big)(tx.Value()), Value: (*hexutil.Big)(tx.Value()),
GasPremium: (*hexutil.Big)(tx.GasPremium()), MaxMinerBribePerGas: (*hexutil.Big)(tx.MaxMinerBribe()),
FeeCap: (*hexutil.Big)(tx.FeeCap()), FeeCapPerGas: (*hexutil.Big)(tx.FeeCap()),
V: (*hexutil.Big)(v), V: (*hexutil.Big)(v),
R: (*hexutil.Big)(r), R: (*hexutil.Big)(r),
S: (*hexutil.Big)(s), S: (*hexutil.Big)(s),
@ -1507,8 +1507,8 @@ type SendTxArgs struct {
Data *hexutil.Bytes `json:"data"` Data *hexutil.Bytes `json:"data"`
Input *hexutil.Bytes `json:"input"` Input *hexutil.Bytes `json:"input"`
// EIP1559 fields // EIP1559 fields
GasPremium *hexutil.Big `json:"gasPremium"` MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas"`
FeeCap *hexutil.Big `json:"feeCap"` FeeCapPerGas *hexutil.Big `json:"feeCapPerGas"`
} }
// setDefaults is a helper function that fills in default values for unspecified tx fields. // setDefaults is a helper function that fills in default values for unspecified tx fields.
@ -1519,25 +1519,25 @@ func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
if eip1559 && b.CurrentBlock().BaseFee() == nil { if eip1559 && b.CurrentBlock().BaseFee() == nil {
return core.ErrNoBaseFee return core.ErrNoBaseFee
} }
if eip1559Finalized && (args.GasPremium == nil || args.FeeCap == nil || args.GasPrice != nil) { if eip1559Finalized && (args.MaxMinerBribePerGas == nil || args.FeeCapPerGas == nil || args.GasPrice != nil) {
return core.ErrTxNotEIP1559 return core.ErrTxNotEIP1559
} }
if !eip1559 && (args.GasPremium != nil || args.FeeCap != nil || args.GasPrice == nil) { if !eip1559 && (args.MaxMinerBribePerGas != nil || args.FeeCapPerGas != nil || args.GasPrice == nil) {
return core.ErrTxIsEIP1559 return core.ErrTxIsEIP1559
} }
if args.GasPrice != nil && (args.GasPremium != nil || args.FeeCap != nil) { if args.GasPrice != nil && (args.MaxMinerBribePerGas != nil || args.FeeCapPerGas != nil) {
return core.ErrTxSetsLegacyAndEIP1559Fields return core.ErrTxSetsLegacyAndEIP1559Fields
} }
if args.FeeCap != nil && args.GasPremium == nil { if args.FeeCapPerGas != nil && args.MaxMinerBribePerGas == nil {
return errors.New("if FeeCap is set, GasPremium must be set") return errors.New("if FeeCap is set, GasPremium must be set")
} }
if args.GasPremium != nil { if args.MaxMinerBribePerGas != nil {
if args.FeeCap == nil { if args.FeeCapPerGas == nil {
return errors.New("if GasPremium is set, FeeCap must be set") return errors.New("if GasPremium is set, FeeCap must be set")
} }
gasPrice := new(big.Int).Add(b.CurrentBlock().BaseFee(), args.GasPremium.ToInt()) gasPrice := new(big.Int).Add(b.CurrentBlock().BaseFee(), args.MaxMinerBribePerGas.ToInt())
if gasPrice.Cmp(args.FeeCap.ToInt()) > 0 { if gasPrice.Cmp(args.FeeCapPerGas.ToInt()) > 0 {
gasPrice.Set(args.FeeCap.ToInt()) gasPrice.Set(args.FeeCapPerGas.ToInt())
} }
if gasPrice.Cmp(b.CurrentBlock().BaseFee()) < 0 { if gasPrice.Cmp(b.CurrentBlock().BaseFee()) < 0 {
return core.ErrEIP1559GasPriceLessThanBaseFee return core.ErrEIP1559GasPriceLessThanBaseFee
@ -1545,7 +1545,7 @@ func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
} }
// If EIP1559 is activated but not finalized and neither a GasPrice, GasPremium, or FeeCap are provided default to suggesting a GasPrice // If EIP1559 is activated but not finalized and neither a GasPrice, GasPremium, or FeeCap are provided default to suggesting a GasPrice
if args.GasPrice == nil && args.GasPremium == nil { if args.GasPrice == nil && args.MaxMinerBribePerGas == nil {
price, err := b.SuggestPrice(ctx) price, err := b.SuggestPrice(ctx)
if err != nil { if err != nil {
return err return err
@ -1591,8 +1591,8 @@ func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
GasPrice: args.GasPrice, GasPrice: args.GasPrice,
Value: args.Value, Value: args.Value,
Data: input, Data: input,
GasPremium: args.GasPremium, MaxMinerBribePerGas: args.MaxMinerBribePerGas,
FeeCap: args.FeeCap, FeeCapPerGas: args.FeeCapPerGas,
} }
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber) pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
estimated, err := DoEstimateGas(ctx, b, callArgs, pendingBlockNr, b.RPCGasCap()) estimated, err := DoEstimateGas(ctx, b, callArgs, pendingBlockNr, b.RPCGasCap())
@ -1613,9 +1613,9 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
input = *args.Data input = *args.Data
} }
if args.To == nil { if args.To == nil {
return types.NewContractCreation(uint64(*args.Nonce), (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.GasPremium), (*big.Int)(args.FeeCap)) return types.NewContractCreation(uint64(*args.Nonce), (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.MaxMinerBribePerGas), (*big.Int)(args.FeeCapPerGas))
} }
return types.NewTransaction(uint64(*args.Nonce), *args.To, (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.GasPremium), (*big.Int)(args.FeeCap)) return types.NewTransaction(uint64(*args.Nonce), *args.To, (*big.Int)(args.Value), uint64(*args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.MaxMinerBribePerGas), (*big.Int)(args.FeeCapPerGas))
} }
// SubmitTransaction is a helper function that submits tx to txPool and logs a message. // SubmitTransaction is a helper function that submits tx to txPool and logs a message.
@ -1698,20 +1698,20 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod
if eip1559 && s.b.CurrentBlock().BaseFee() == nil { if eip1559 && s.b.CurrentBlock().BaseFee() == nil {
return common.Hash{}, core.ErrNoBaseFee return common.Hash{}, core.ErrNoBaseFee
} }
if eip1559Finalized && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { if eip1559Finalized && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) {
return common.Hash{}, core.ErrTxNotEIP1559 return common.Hash{}, core.ErrTxNotEIP1559
} }
if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { if !eip1559 && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) {
return common.Hash{}, core.ErrTxIsEIP1559 return common.Hash{}, core.ErrTxIsEIP1559
} }
if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) { if tx.GasPrice() != nil && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil) {
return common.Hash{}, core.ErrTxSetsLegacyAndEIP1559Fields return common.Hash{}, core.ErrTxSetsLegacyAndEIP1559Fields
} }
if tx.GasPrice() == nil && (tx.GasPremium() == nil || tx.FeeCap() == nil) { if tx.GasPrice() == nil && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil) {
return common.Hash{}, core.ErrMissingGasFields return common.Hash{}, core.ErrMissingGasFields
} }
if tx.GasPremium() != nil { if tx.MaxMinerBribe() != nil {
gasPrice := new(big.Int).Add(s.b.CurrentBlock().BaseFee(), tx.GasPremium()) gasPrice := new(big.Int).Add(s.b.CurrentBlock().BaseFee(), tx.MaxMinerBribe())
if gasPrice.Cmp(tx.FeeCap()) > 0 { if gasPrice.Cmp(tx.FeeCap()) > 0 {
gasPrice.Set(tx.FeeCap()) gasPrice.Set(tx.FeeCap())
} }

View File

@ -353,16 +353,16 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
if eip1559 && header.BaseFee == nil { if eip1559 && header.BaseFee == nil {
return core.ErrNoBaseFee return core.ErrNoBaseFee
} }
if eip1559Finalized && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { if eip1559Finalized && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) {
return core.ErrTxNotEIP1559 return core.ErrTxNotEIP1559
} }
if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { if !eip1559 && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) {
return core.ErrTxIsEIP1559 return core.ErrTxIsEIP1559
} }
if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) { if tx.GasPrice() != nil && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil) {
return core.ErrTxSetsLegacyAndEIP1559Fields return core.ErrTxSetsLegacyAndEIP1559Fields
} }
if tx.GasPrice() == nil && (tx.GasPremium() == nil || tx.FeeCap() == nil) { if tx.GasPrice() == nil && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil) {
return core.ErrMissingGasFields return core.ErrMissingGasFields
} }
@ -392,13 +392,13 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
if tx.GasPrice() != nil && legacyGasLimit < tx.Gas() { if tx.GasPrice() != nil && legacyGasLimit < tx.Gas() {
return core.ErrLegacyGasLimit return core.ErrLegacyGasLimit
} }
if tx.GasPremium() != nil && eip1559GasLimit < tx.Gas() { if tx.MaxMinerBribe() != nil && eip1559GasLimit < tx.Gas() {
return core.ErrEIP1559GasLimit return core.ErrEIP1559GasLimit
} }
// Derive the gasPrice from the tx.GasPremium() and tx.FeeCap() (EIP1559 transaction) to ensure it is greater than BaseFee // Derive the gasPrice from the tx.GasPremium() and tx.FeeCap() (EIP1559 transaction) to ensure it is greater than BaseFee
if tx.GasPremium() != nil { if tx.MaxMinerBribe() != nil {
gasPrice := new(big.Int).Add(pool.chain.CurrentHeader().BaseFee, tx.GasPremium()) gasPrice := new(big.Int).Add(pool.chain.CurrentHeader().BaseFee, tx.MaxMinerBribe())
if gasPrice.Cmp(tx.FeeCap()) > 0 { if gasPrice.Cmp(tx.FeeCap()) > 0 {
gasPrice.Set(tx.FeeCap()) gasPrice.Set(tx.FeeCap())
} }

View File

@ -778,10 +778,10 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
// Set which gasPool to use based on the type of transaction // Set which gasPool to use based on the type of transaction
eip1559 := false eip1559 := false
var gp *core.GasPool var gp *core.GasPool
if w.current.gp1559 != nil && tx.GasPrice() == nil && tx.GasPremium() != nil && tx.FeeCap() != nil { if w.current.gp1559 != nil && tx.GasPrice() == nil && tx.MaxMinerBribe() != nil && tx.FeeCap() != nil {
gp = w.current.gp1559 gp = w.current.gp1559
eip1559 = true eip1559 = true
} else if w.current.gasPool != nil && tx.GasPremium() == nil && tx.FeeCap() == nil && tx.GasPrice() != nil { } else if w.current.gasPool != nil && tx.MaxMinerBribe() == nil && tx.FeeCap() == nil && tx.GasPrice() != nil {
gp = w.current.gasPool gp = w.current.gasPool
} else { } else {
log.Error("Transaction does not conform with expected format (legacy or EIP1559)") log.Error("Transaction does not conform with expected format (legacy or EIP1559)")
@ -1057,8 +1057,8 @@ func (w *worker) commit(uncles []*types.Header, interval func(), update bool, st
for i, tx := range block.Transactions() { for i, tx := range block.Transactions() {
if tx.GasPrice() != nil { if tx.GasPrice() != nil {
feesWei.Add(feesWei, new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), tx.GasPrice())) feesWei.Add(feesWei, new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), tx.GasPrice()))
} else if tx.GasPremium() != nil && tx.FeeCap() != nil { } else if tx.MaxMinerBribe() != nil && tx.FeeCap() != nil {
gasPrice := new(big.Int).Add(block.BaseFee(), tx.GasPremium()) gasPrice := new(big.Int).Add(block.BaseFee(), tx.MaxMinerBribe())
if gasPrice.Cmp(tx.FeeCap()) > 0 { if gasPrice.Cmp(tx.FeeCap()) > 0 {
gasPrice.Set(tx.FeeCap()) gasPrice.Set(tx.FeeCap())
} }

View File

@ -58,8 +58,8 @@ func (msg *CallMsg) GetTo() *Address {
} }
return nil return nil
} }
func (msg *CallMsg) GetGasPremium() *BigInt { return &BigInt{msg.msg.GasPremium} } func (msg *CallMsg) GetMaxMinerBribe() *BigInt { return &BigInt{msg.msg.MaxMinerBribePerGas} }
func (msg *CallMsg) GetFeeCap() *BigInt { return &BigInt{msg.msg.FeeCap} } func (msg *CallMsg) GetFeeCap() *BigInt { return &BigInt{msg.msg.FeeCapPerGas} }
func (msg *CallMsg) SetFrom(address *Address) { msg.msg.From = address.address } func (msg *CallMsg) SetFrom(address *Address) { msg.msg.From = address.address }
func (msg *CallMsg) SetGas(gas int64) { msg.msg.Gas = uint64(gas) } func (msg *CallMsg) SetGas(gas int64) { msg.msg.Gas = uint64(gas) }
@ -73,8 +73,10 @@ func (msg *CallMsg) SetTo(address *Address) {
} }
msg.msg.To = &address.address msg.msg.To = &address.address
} }
func (msg *CallMsg) SetGasPremium(gasPremium *BigInt) { msg.msg.GasPremium = gasPremium.bigint } func (msg *CallMsg) SetMaxMinerBribe(maxMinerBribe *BigInt) {
func (msg *CallMsg) SetFeeCap(feeCap *BigInt) { msg.msg.FeeCap = feeCap.bigint } msg.msg.MaxMinerBribePerGas = maxMinerBribe.bigint
}
func (msg *CallMsg) SetFeeCap(feeCap *BigInt) { msg.msg.FeeCapPerGas = feeCap.bigint }
// SyncProgress gives progress indications when the node is synchronising with // SyncProgress gives progress indications when the node is synchronising with
// the Ethereum network. // the Ethereum network.

View File

@ -24,7 +24,7 @@ const (
VersionMajor = 1 // Major version component of the current release VersionMajor = 1 // Major version component of the current release
VersionMinor = 9 // Minor version component of the current release VersionMinor = 9 // Minor version component of the current release
VersionPatch = 15 // Patch version component of the current release VersionPatch = 15 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string VersionMeta = "eip1559-970c594cd3" // Version metadata to append to the version string
) )
// Version holds the textual version string. // Version holds the textual version string.

View File

@ -465,7 +465,7 @@ func logDiff(original *SignTxRequest, new *SignTxResponse) bool {
modified = true modified = true
log.Info("GasPrice changed by UI", "was", g0, "is", g1) log.Info("GasPrice changed by UI", "was", g0, "is", g1)
} }
gp0, gp1 := (*big.Int)(original.Transaction.GasPremium), (*big.Int)(new.Transaction.GasPremium) gp0, gp1 := (*big.Int)(original.Transaction.MaxMinerBribePerGas), (*big.Int)(new.Transaction.MaxMinerBribePerGas)
if gp0 == nil || gp1 == nil { if gp0 == nil || gp1 == nil {
if gp0 != gp1 { if gp0 != gp1 {
modified = true modified = true
@ -475,7 +475,7 @@ func logDiff(original *SignTxRequest, new *SignTxResponse) bool {
modified = true modified = true
log.Info("GasPremium changed by UI", "was", gp0, "is", gp1) log.Info("GasPremium changed by UI", "was", gp0, "is", gp1)
} }
f0, f1 := (*big.Int)(original.Transaction.FeeCap), (*big.Int)(new.Transaction.FeeCap) f0, f1 := (*big.Int)(original.Transaction.FeeCapPerGas), (*big.Int)(new.Transaction.FeeCapPerGas)
if f0 == nil || f1 == nil { if f0 == nil || f1 == nil {
if f0 != f1 { if f0 != f1 {
modified = true modified = true

View File

@ -237,8 +237,8 @@ func mkTestTx(from common.MixedcaseAddress, eip1559 bool) core.SendTxArgs {
Data: &data, Data: &data,
Nonce: nonce} Nonce: nonce}
if eip1559 { if eip1559 {
tx.GasPremium = (*hexutil.Big)(big.NewInt(1000000000)) tx.MaxMinerBribePerGas = (*hexutil.Big)(big.NewInt(1000000000))
tx.FeeCap = (*hexutil.Big)(big.NewInt(2000000000)) tx.FeeCapPerGas = (*hexutil.Big)(big.NewInt(2000000000))
} else { } else {
tx.GasPrice = (*hexutil.Big)(big.NewInt(2000000000)) tx.GasPrice = (*hexutil.Big)(big.NewInt(2000000000))
} }

View File

@ -77,8 +77,8 @@ type SendTxArgs struct {
Data *hexutil.Bytes `json:"data"` Data *hexutil.Bytes `json:"data"`
Input *hexutil.Bytes `json:"input,omitempty"` Input *hexutil.Bytes `json:"input,omitempty"`
// EIP1559 fields // EIP1559 fields
GasPremium *hexutil.Big `json:"gasPremium"` MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas"`
FeeCap *hexutil.Big `json:"feeCap"` FeeCapPerGas *hexutil.Big `json:"feeCapPerGas"`
} }
func (args SendTxArgs) String() string { func (args SendTxArgs) String() string {
@ -97,7 +97,7 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
input = *args.Input input = *args.Input
} }
if args.To == nil { if args.To == nil {
return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), uint64(args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.GasPremium), (*big.Int)(args.FeeCap)) return types.NewContractCreation(uint64(args.Nonce), (*big.Int)(&args.Value), uint64(args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.MaxMinerBribePerGas), (*big.Int)(args.FeeCapPerGas))
} }
return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.GasPremium), (*big.Int)(args.FeeCap)) return types.NewTransaction(uint64(args.Nonce), args.To.Address(), (*big.Int)(&args.Value), (uint64)(args.Gas), (*big.Int)(args.GasPrice), input, (*big.Int)(args.MaxMinerBribePerGas), (*big.Int)(args.FeeCapPerGas))
} }