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
eip1559 := b.config.IsEIP1559(block.Number())
eip1559Finalized := b.config.IsEIP1559Finalized(block.Number())
if eip1559Finalized && (call.GasPremium == nil || call.FeeCap == nil || call.GasPrice != nil) {
call.GasPremium = big.NewInt(1)
call.FeeCap = big.NewInt(10)
if eip1559Finalized && (call.MaxMinerBribePerGas == nil || call.FeeCapPerGas == nil || call.GasPrice != nil) {
call.MaxMinerBribePerGas = big.NewInt(1)
call.FeeCapPerGas = big.NewInt(10)
call.GasPrice = nil
}
// 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) {
call.GasPremium = nil
call.FeeCap = nil
if !eip1559 && (call.MaxMinerBribePerGas != nil || call.FeeCapPerGas != nil || call.GasPrice == nil) {
call.MaxMinerBribePerGas = nil
call.FeeCapPerGas = nil
call.GasPrice = big.NewInt(1)
}
// If we are in between activation and finalization
if eip1559 && !eip1559Finalized {
// 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) {
call.GasPremium = nil
call.FeeCap = nil
if (call.MaxMinerBribePerGas == nil || call.FeeCapPerGas == nil && call.GasPrice == nil) || (call.MaxMinerBribePerGas != nil || call.FeeCapPerGas != nil && call.GasPrice != nil) {
call.MaxMinerBribePerGas = nil
call.FeeCapPerGas = nil
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 {
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
}
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
}
if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) {
if tx.GasPrice() != nil && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil) {
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
}
@ -771,16 +771,16 @@ type callmsg struct {
ethereum.CallMsg
}
func (m callmsg) From() common.Address { return m.CallMsg.From }
func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.CallMsg.To }
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) GasPremium() *big.Int { return m.CallMsg.GasPremium }
func (m callmsg) FeeCap() *big.Int { return m.CallMsg.FeeCap }
func (m callmsg) From() common.Address { return m.CallMsg.From }
func (m callmsg) Nonce() uint64 { return 0 }
func (m callmsg) CheckNonce() bool { return false }
func (m callmsg) To() *common.Address { return m.CallMsg.To }
func (m callmsg) GasPrice() *big.Int { return m.CallMsg.GasPrice }
func (m callmsg) Gas() uint64 { return m.CallMsg.Gas }
func (m callmsg) Value() *big.Int { return m.CallMsg.Value }
func (m callmsg) Data() []byte { return m.CallMsg.Data }
func (m callmsg) MaxMinerBribe() *big.Int { return m.CallMsg.MaxMinerBribePerGas }
func (m callmsg) FeeCap() *big.Int { return m.CallMsg.FeeCapPerGas }
// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.

View File

@ -53,9 +53,9 @@ type TransactOpts struct {
GasLimit uint64 // Gas limit to set for the transaction execution (0 = estimate)
// 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
GasPremium *big.Int // Gas premium (tip) to use for EIP1559 transaction execution (
FeeCap *big.Int // Fee cap to use for EIP1559 transaction execution
GasPrice *big.Int // Gas price to use for the transaction execution
MaxMinerBribePerGas *big.Int // Gas premium (tip) 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)
}
@ -217,7 +217,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
}
// Figure out the gas allowance and gas price values
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))
if err != nil {
return nil, fmt.Errorf("failed to suggest gas price: %v", err)
@ -235,13 +235,13 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
}
// If the contract surely has code (or code is not needed), estimate the transaction
msg := ethereum.CallMsg{
From: opts.From,
To: contract,
GasPrice: gasPrice,
Value: value,
Data: input,
GasPremium: opts.GasPremium,
FeeCap: opts.FeeCap,
From: opts.From,
To: contract,
GasPrice: gasPrice,
Value: value,
Data: input,
MaxMinerBribePerGas: opts.MaxMinerBribePerGas,
FeeCapPerGas: opts.FeeCapPerGas,
}
gasLimit, err = c.transactor.EstimateGas(ensureContext(opts.Context), msg)
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
var rawTx *types.Transaction
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 {
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 {
return nil, errors.New("no signer to authorize the transaction with")

View File

@ -200,15 +200,15 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio
to = &t
}
args := &core.SendTxArgs{
Data: &data,
Nonce: hexutil.Uint64(tx.Nonce()),
Value: hexutil.Big(*tx.Value()),
Gas: hexutil.Uint64(tx.Gas()),
GasPrice: (*hexutil.Big)(tx.GasPrice()),
GasPremium: (*hexutil.Big)(tx.GasPremium()),
FeeCap: (*hexutil.Big)(tx.FeeCap()),
To: to,
From: common.NewMixedcaseAddress(account.Address),
Data: &data,
Nonce: hexutil.Uint64(tx.Nonce()),
Value: hexutil.Big(*tx.Value()),
Gas: hexutil.Uint64(tx.Gas()),
GasPrice: (*hexutil.Big)(tx.GasPrice()),
MaxMinerBribePerGas: (*hexutil.Big)(tx.MaxMinerBribe()),
FeeCapPerGas: (*hexutil.Big)(tx.FeeCap()),
To: to,
From: common.NewMixedcaseAddress(account.Address),
}
if err := api.client.Call(&res, "account_signTransaction", args); err != nil {
return nil, err

View File

@ -18,6 +18,7 @@ package misc
import (
"errors"
"math/big"
"github.com/ethereum/go-ethereum/common"
@ -59,6 +60,37 @@ func VerifyEIP1559BaseFee(config *params.ChainConfig, header, parent *types.Head
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
func CalcBaseFee(config *params.ChainConfig, parent *types.Header) *big.Int {
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)
}
parentBaseFee := parent.BaseFee
parentBlockGasUsed := new(big.Int).SetUint64(parent.GasUsed)
targetGasUsed := new(big.Int).SetUint64(parent.GasLimit)
baseFeeMaxChangeDenominator := new(big.Int).SetUint64(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 computeBaseFee(
parent.BaseFee,
parent.GasUsed,
parent.GasLimit,
config.EIP1559.EIP1559BaseFeeMaxChangeDenominator,
)
return new(big.Int).Sub(parentBaseFee, feeDelta)
}
// 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),
1000000,
10000000,
big.NewInt(1125000000),
big.NewInt(2125000000),
},
{
params.EIP1559ChainConfig,
@ -165,7 +165,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000),
500000,
10000000,
big.NewInt(1125000000),
big.NewInt(3375000000),
},
{
params.EIP1559ChainConfig,
@ -175,7 +175,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000),
1000000,
10000000,
big.NewInt(1125000000),
big.NewInt(2125000000),
},
{
params.EIP1559ChainConfig,
@ -217,7 +217,7 @@ func TestCalcBaseFee(t *testing.T) {
10000000,
big.NewInt(1013888888),
},
{
{ // 10
params.EIP1559ChainConfig,
big.NewInt(1000),
1000,
@ -225,7 +225,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000),
10000000,
10000000,
big.NewInt(999999999), // baseFee diff is -1 when usage == target
big.NewInt(1000000000), // baseFee diff is -1 when usage == target
},
{
params.EIP1559ChainConfig,
@ -235,7 +235,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1000000000),
11000000,
10000000,
big.NewInt(988636363),
big.NewInt(988636364),
},
{
params.EIP1559ChainConfig,
@ -245,7 +245,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(900000000),
1000000,
10000000,
big.NewInt(1012500000),
big.NewInt(1912500000),
},
{
params.EIP1559ChainConfig,
@ -255,7 +255,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1100000000),
1000000,
10000000,
big.NewInt(1237500000),
big.NewInt(2337500000),
},
{
params.EIP1559ChainConfig,
@ -265,7 +265,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1200000000),
1000000,
10000000,
big.NewInt(1350000000),
big.NewInt(2550000000),
},
{
params.EIP1559ChainConfig,
@ -328,7 +328,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(0),
1000000000000000,
1,
big.NewInt(1),
big.NewInt(0),
},
// parent gas usage == parent gas limit
// parent baseFee == 0
@ -355,11 +355,8 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1),
1,
1000000000000000,
big.NewInt(2),
big.NewInt(125000000000000),
},
// parent gas usage <<<< parent gas limit
// parent baseFee == 1
// as expected, decrement by 1
{
params.EIP1559ChainConfig,
big.NewInt(1000),
@ -368,11 +365,8 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1),
1000000000000000,
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,
big.NewInt(1000),
@ -381,7 +375,7 @@ func TestCalcBaseFee(t *testing.T) {
big.NewInt(1),
1,
1,
big.NewInt(0),
big.NewInt(1),
},
}
for i, test := range testConditions {

View File

@ -245,8 +245,8 @@ func generateChainDuringTransition(t *testing.T) {
if state.GetBalance(addr1).Uint64() != 989000 {
t.Fatalf("expected balance of addr1 to equal %d got %d", 989000, state.GetBalance(addr1).Uint64())
}
if state.GetBalance(addr2).Uint64() != 4901403728000 {
t.Fatalf("expected balance of addr2 to equal %d got %d", 4901403728000, state.GetBalance(addr2).Uint64())
if state.GetBalance(addr2).Uint64() != 4911639338000 {
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)
bal, _ := new(big.Int).SetString("7875000000000001000", 10)
@ -389,11 +389,11 @@ func generateChainAfterFinalization2(t *testing.T) {
if blockchain.CurrentBlock().Number().Uint64() != 5 {
t.Fatalf("expected last block to equal %d got %d", 5, blockchain.CurrentBlock().Number().Uint64())
}
if state.GetBalance(addr1).Uint64() != 7536639348000 {
t.Fatalf("expected balance of addr1 to equal %d got %d", 7536639348000, state.GetBalance(addr1).Uint64())
if state.GetBalance(addr1).Uint64() != 7536639327000 {
t.Fatalf("expected balance of addr1 to equal %d got %d", 7536639327000, state.GetBalance(addr1).Uint64())
}
if state.GetBalance(addr2).Uint64() != 4911639359000 {
t.Fatalf("expected balance of addr2 to equal %d got %d", 4911639359000, state.GetBalance(addr2).Uint64())
if state.GetBalance(addr2).Uint64() != 4911639338000 {
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)
bal, _ := new(big.Int).SetString("7875000000000001000", 10)

View File

@ -18,10 +18,10 @@ package core
import (
"errors"
"math"
"math/big"
"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/params"
)
@ -76,7 +76,7 @@ type Message interface {
CheckNonce() bool
Data() []byte
GasPremium() *big.Int
MaxMinerBribe() *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.
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{
gp: gp,
gp1559: gp1559,
@ -167,11 +167,14 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp, gp1559 *GasPool) *StateTra
isEIP1559: isEIP1559,
}
if isEIP1559 {
// EP1559 gasPrice = min(BASEFEE + tx.fee_premium, tx.fee_cap)
st.eip1559GasPrice = new(big.Int).Add(evm.BaseFee, msg.GasPremium())
if st.eip1559GasPrice.Cmp(msg.FeeCap()) > 0 {
st.eip1559GasPrice.Set(msg.FeeCap())
}
// # bribe is capped such that base fee is filled first
// bribe_per_gas = min(transaction.max_miner_bribe_per_gas, transaction.fee_cap_per_gas - block.base_fee)
// # signer pays both the bribe and the base fee
// 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
}
@ -248,11 +251,11 @@ func (st *StateTransition) preCheck() error {
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 !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
}
// 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
}
// We need a BaseFee if we are past EIP1559 activation
@ -260,7 +263,7 @@ func (st *StateTransition) preCheck() error {
return ErrNoBaseFee
}
// 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
}
// 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 {
eip1559 = true
newGasPrice := new(big.Int).Add(baseFee, tx.GasPremium())
newGasPrice := new(big.Int).Add(baseFee, tx.MaxMinerBribe())
if newGasPrice.Cmp(tx.FeeCap()) > 0 {
newGasPrice.Set(tx.FeeCap())
}
@ -274,7 +274,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64, baseFee *big.Int)
}
}
} else {
oldGasPrice := new(big.Int).Add(baseFee, old.GasPremium())
oldGasPrice := new(big.Int).Add(baseFee, old.MaxMinerBribe())
if oldGasPrice.Cmp(old.FeeCap()) > 0 {
oldGasPrice.Set(old.FeeCap())
}
@ -285,7 +285,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64, baseFee *big.Int)
}
} else {
eip1559 = true
newGasPrice := new(big.Int).Add(baseFee, tx.GasPremium())
newGasPrice := new(big.Int).Add(baseFee, tx.MaxMinerBribe())
if newGasPrice.Cmp(tx.FeeCap()) > 0 {
newGasPrice.Set(tx.FeeCap())
}
@ -335,7 +335,7 @@ func (l *txList) Filter(costLimit *big.Int, legacyGasLimit, eip1559GasLimit uint
l.eip1559GasCap = eip1559GasLimit
// Filter out all the transactions above the account's funds
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
@ -418,13 +418,13 @@ func (h priceHeap) Less(i, j int) bool {
iPrice := h.txs[i].GasPrice()
jPrice := h.txs[j].GasPrice()
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 {
iPrice.Set(h.txs[i].FeeCap())
}
}
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 {
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
gasPrice := tx.GasPrice()
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 {
gasPrice.Set(tx.FeeCap())
}
@ -560,14 +560,14 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo
cheapest := l.items.txs[0]
cheapestPrice := cheapest.GasPrice()
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 {
cheapestPrice.Set(cheapest.FeeCap())
}
}
txPrice := tx.GasPrice()
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 {
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 {
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
}
if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) {
if !eip1559 && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) {
return ErrTxIsEIP1559
}
if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) {
if tx.GasPrice() != nil && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil) {
return ErrTxSetsLegacyAndEIP1559Fields
}
if tx.GasPrice() == nil && (tx.GasPremium() == nil || tx.FeeCap() == nil) {
if tx.GasPrice() == nil && (tx.MaxMinerBribe() == nil || tx.FeeCap() == nil) {
return ErrMissingGasFields
}
// 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 {
gasPrice = tx.GasPrice()
} 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 {
gasPrice.Set(tx.FeeCap())
}

View File

@ -451,7 +451,7 @@ func TestInvalidTransactionsEIP1559(t *testing.T) {
}
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))
pool.currentState.AddBalance(from, balance)
@ -518,7 +518,7 @@ func TestInvalidTransactionsEIP1559Finalized(t *testing.T) {
}
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))
pool.currentState.AddBalance(from, balance)

View File

@ -16,18 +16,18 @@ var _ = (*txdataMarshaling)(nil)
// MarshalJSON marshals as JSON.
func (t txdata) MarshalJSON() ([]byte, error) {
type txdata struct {
AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"`
Price *hexutil.Big `json:"gasPrice"`
GasLimit hexutil.Uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload hexutil.Bytes `json:"input" gencodec:"required"`
GasPremium *hexutil.Big `json:"gasPremium" rlp:"nil"`
FeeCap *hexutil.Big `json:"feeCap" rlp:"nil"`
V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" rlp:"-"`
AccountNonce hexutil.Uint64 `json:"nonce" gencodec:"required"`
Price *hexutil.Big `json:"gasPrice"`
GasLimit hexutil.Uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload hexutil.Bytes `json:"input" gencodec:"required"`
MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas" rlp:"nil"`
FeeCapPerGas *hexutil.Big `json:"feeCapPerGas" rlp:"nil"`
V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" rlp:"-"`
}
var enc txdata
enc.AccountNonce = hexutil.Uint64(t.AccountNonce)
@ -36,8 +36,8 @@ func (t txdata) MarshalJSON() ([]byte, error) {
enc.Recipient = t.Recipient
enc.Amount = (*hexutil.Big)(t.Amount)
enc.Payload = t.Payload
enc.GasPremium = (*hexutil.Big)(t.GasPremium)
enc.FeeCap = (*hexutil.Big)(t.FeeCap)
enc.MaxMinerBribePerGas = (*hexutil.Big)(t.MaxMinerBribePerGas)
enc.FeeCapPerGas = (*hexutil.Big)(t.FeeCapPerGas)
enc.V = (*hexutil.Big)(t.V)
enc.R = (*hexutil.Big)(t.R)
enc.S = (*hexutil.Big)(t.S)
@ -48,18 +48,18 @@ func (t txdata) MarshalJSON() ([]byte, error) {
// UnmarshalJSON unmarshals from JSON.
func (t *txdata) UnmarshalJSON(input []byte) error {
type txdata struct {
AccountNonce *hexutil.Uint64 `json:"nonce" gencodec:"required"`
Price *hexutil.Big `json:"gasPrice"`
GasLimit *hexutil.Uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload *hexutil.Bytes `json:"input" gencodec:"required"`
GasPremium *hexutil.Big `json:"gasPremium" rlp:"nil"`
FeeCap *hexutil.Big `json:"feeCap" rlp:"nil"`
V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" rlp:"-"`
AccountNonce *hexutil.Uint64 `json:"nonce" gencodec:"required"`
Price *hexutil.Big `json:"gasPrice"`
GasLimit *hexutil.Uint64 `json:"gas" gencodec:"required"`
Recipient *common.Address `json:"to" rlp:"nil"`
Amount *hexutil.Big `json:"value" gencodec:"required"`
Payload *hexutil.Bytes `json:"input" gencodec:"required"`
MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas" rlp:"nil"`
FeeCapPerGas *hexutil.Big `json:"feeCapPerGas" rlp:"nil"`
V *hexutil.Big `json:"v" gencodec:"required"`
R *hexutil.Big `json:"r" gencodec:"required"`
S *hexutil.Big `json:"s" gencodec:"required"`
Hash *common.Hash `json:"hash" rlp:"-"`
}
var dec txdata
if err := json.Unmarshal(input, &dec); err != nil {
@ -87,11 +87,11 @@ func (t *txdata) UnmarshalJSON(input []byte) error {
return errors.New("missing required field 'input' for txdata")
}
t.Payload = *dec.Payload
if dec.GasPremium != nil {
t.GasPremium = (*big.Int)(dec.GasPremium)
if dec.MaxMinerBribePerGas != nil {
t.MaxMinerBribePerGas = (*big.Int)(dec.MaxMinerBribePerGas)
}
if dec.FeeCap != nil {
t.FeeCap = (*big.Int)(dec.FeeCap)
if dec.FeeCapPerGas != nil {
t.FeeCapPerGas = (*big.Int)(dec.FeeCapPerGas)
}
if dec.V == nil {
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/hexutil"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
)
@ -52,8 +53,8 @@ type txdata struct {
Payload []byte `json:"input" gencodec:"required"`
// EIP1559 gas values
GasPremium *big.Int `json:"gasPremium" rlp:"nil"` // nil means legacy transaction
FeeCap *big.Int `json:"feeCap" rlp:"nil"` // nil means legacy transaction
MaxMinerBribePerGas *big.Int `json:"maxMinerBribePerGas" rlp:"nil"`
FeeCapPerGas *big.Int `json:"feeCapPerGas" rlp:"nil"`
// Signature values
V *big.Int `json:"v" gencodec:"required"`
@ -65,27 +66,27 @@ type txdata struct {
}
type txdataMarshaling struct {
AccountNonce hexutil.Uint64
Price *hexutil.Big
GasLimit hexutil.Uint64
Amount *hexutil.Big
Payload hexutil.Bytes
GasPremium *hexutil.Big
FeeCap *hexutil.Big
V *hexutil.Big
R *hexutil.Big
S *hexutil.Big
AccountNonce hexutil.Uint64
Price *hexutil.Big
GasLimit hexutil.Uint64
Amount *hexutil.Big
Payload hexutil.Bytes
MaxMinerBribePerGas *hexutil.Big
FeeCapPerGas *hexutil.Big
V *hexutil.Big
R *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 {
return newTransaction(nonce, &to, amount, gasLimit, gasPrice, data, gasPremium, feeCap)
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, maxMinerBribePerGas, feeCapPerGas)
}
func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte, gasPremium, feeCap *big.Int) *Transaction {
return newTransaction(nonce, nil, amount, gasLimit, gasPrice, data, gasPremium, feeCap)
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, 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 {
data = common.CopyBytes(data)
}
@ -105,19 +106,12 @@ func newTransaction(nonce uint64, to *common.Address, amount *big.Int, gasLimit
if gasPrice != nil {
d.Price = gasPrice
}
if gasPremium != nil {
d.GasPremium = gasPremium
if maxMinerBribePerGas != nil {
d.MaxMinerBribePerGas = maxMinerBribePerGas
}
if feeCap != nil {
d.FeeCap = feeCap
if feeCapPerGas != nil {
d.FeeCapPerGas = feeCapPerGas
}
if gasPremium != nil {
d.GasPremium = gasPremium
}
if feeCap != nil {
d.FeeCap = feeCap
}
return &Transaction{data: d}
}
@ -142,7 +136,7 @@ func isProtectedV(V *big.Int) bool {
// EncodeRLP implements rlp.Encoder
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{}{
tx.data.AccountNonce,
tx.data.Price,
@ -203,12 +197,12 @@ func (tx *Transaction) DecodeRLP(stream *rlp.Stream) error {
if err = stream.Decode(payload); err != nil {
return err
}
gasPremium := new(big.Int)
if err = stream.Decode(gasPremium); err != nil {
maxMinerBribePerGas := new(big.Int)
if err = stream.Decode(maxMinerBribePerGas); err != nil {
return err
}
feeCap := new(big.Int)
if err = stream.Decode(feeCap); err != nil {
feeCapPerGas := new(big.Int)
if err = stream.Decode(feeCapPerGas); err != nil {
return err
}
v := new(big.Int)
@ -225,8 +219,8 @@ func (tx *Transaction) DecodeRLP(stream *rlp.Stream) error {
Recipient: recipient,
Amount: amount,
Payload: *payload,
V: gasPremium,
R: feeCap,
V: maxMinerBribePerGas,
R: feeCapPerGas,
S: v,
}
tx.size.Store(common.StorageSize(rlp.ListSize(size)))
@ -249,17 +243,17 @@ func (tx *Transaction) DecodeRLP(stream *rlp.Stream) error {
return err
}
tx.data = txdata{
AccountNonce: *accountNonce,
Price: nil,
GasLimit: *gasLimit,
Recipient: recipient,
Amount: amount,
Payload: *payload,
GasPremium: gasPremium,
FeeCap: feeCap,
V: v,
R: r,
S: s,
AccountNonce: *accountNonce,
Price: nil,
GasLimit: *gasLimit,
Recipient: recipient,
Amount: amount,
Payload: *payload,
MaxMinerBribePerGas: maxMinerBribePerGas,
FeeCapPerGas: feeCapPerGas,
V: v,
R: r,
S: s,
}
tx.size.Store(common.StorageSize(rlp.ListSize(size)))
return nil
@ -298,14 +292,14 @@ func (tx *Transaction) UnmarshalJSON(input []byte) error {
return nil
}
func (tx *Transaction) Data() []byte { return common.CopyBytes(tx.data.Payload) }
func (tx *Transaction) Gas() uint64 { return tx.data.GasLimit }
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) Nonce() uint64 { return tx.data.AccountNonce }
func (tx *Transaction) CheckNonce() bool { return true }
func (tx *Transaction) GasPremium() *big.Int { return tx.data.GasPremium }
func (tx *Transaction) FeeCap() *big.Int { return tx.data.FeeCap }
func (tx *Transaction) Data() []byte { return common.CopyBytes(tx.data.Payload) }
func (tx *Transaction) Gas() uint64 { return tx.data.GasLimit }
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) Nonce() uint64 { return tx.data.AccountNonce }
func (tx *Transaction) CheckNonce() bool { return true }
func (tx *Transaction) MaxMinerBribe() *big.Int { return tx.data.MaxMinerBribePerGas }
func (tx *Transaction) FeeCap() *big.Int { return tx.data.FeeCapPerGas }
// To returns the recipient address of the transaction.
// It returns nil if the transaction is a contract creation.
@ -347,15 +341,15 @@ func (tx *Transaction) Size() common.StorageSize {
// XXX Rename message to something less arbitrary?
func (tx *Transaction) AsMessage(s Signer) (Message, error) {
msg := Message{
nonce: tx.data.AccountNonce,
gasLimit: tx.data.GasLimit,
gasPrice: tx.data.Price,
to: tx.data.Recipient,
amount: tx.data.Amount,
data: tx.data.Payload,
checkNonce: true,
gasPremium: tx.data.GasPremium,
feeCap: tx.data.FeeCap,
nonce: tx.data.AccountNonce,
gasLimit: tx.data.GasLimit,
gasPrice: tx.data.Price,
to: tx.data.Recipient,
amount: tx.data.Amount,
data: tx.data.Payload,
checkNonce: true,
maxMinerBribePerGas: tx.data.MaxMinerBribePerGas,
feeCapPerGas: tx.data.FeeCapPerGas,
}
var err error
@ -382,11 +376,15 @@ func (tx *Transaction) Cost(baseFee *big.Int) *big.Int {
total.Add(total, tx.data.Amount)
return total
}
if baseFee != nil && tx.data.GasPremium != nil && tx.data.FeeCap != nil {
eip1559GasPrice := new(big.Int).Add(baseFee, tx.data.GasPremium)
if eip1559GasPrice.Cmp(tx.data.FeeCap) > 0 {
eip1559GasPrice.Set(tx.data.FeeCap)
}
if baseFee != nil && tx.data.MaxMinerBribePerGas != nil && tx.data.FeeCapPerGas != nil {
// # bribe is capped such that base fee is filled first
// bribe_per_gas = min(transaction.max_miner_bribe_per_gas, transaction.fee_cap_per_gas - block.base_fee)
// # 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.Add(total, tx.data.Amount)
return total
@ -451,20 +449,21 @@ type TxByPrice struct {
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
func (s TxByPrice) Less(i, j int) bool {
iPrice := s.txs[i].data.Price
jPrice := s.txs[j].data.Price
if iPrice == nil {
iPrice = new(big.Int).Add(s.baseFee, s.txs[i].data.GasPremium)
if iPrice.Cmp(s.txs[i].data.FeeCap) > 0 {
iPrice.Set(s.txs[i].data.FeeCap)
iPrice = new(big.Int).Add(s.baseFee, s.txs[i].data.MaxMinerBribePerGas)
if iPrice.Cmp(s.txs[i].data.FeeCapPerGas) > 0 {
iPrice.Set(s.txs[i].data.FeeCapPerGas)
}
}
if jPrice == nil {
jPrice = new(big.Int).Add(s.baseFee, s.txs[j].data.GasPremium)
if jPrice.Cmp(s.txs[j].data.FeeCap) > 0 {
jPrice.Set(s.txs[j].data.FeeCap)
jPrice = new(big.Int).Add(s.baseFee, s.txs[j].data.MaxMinerBribePerGas)
if jPrice.Cmp(s.txs[j].data.FeeCapPerGas) > 0 {
jPrice.Set(s.txs[j].data.FeeCapPerGas)
}
}
return iPrice.Cmp(jPrice) > 0
@ -552,41 +551,41 @@ func (t *TransactionsByPriceAndNonce) Pop() {
//
// NOTE: In a future PR this will be removed.
type Message struct {
to *common.Address
from common.Address
nonce uint64
amount *big.Int
gasLimit uint64
gasPrice *big.Int
data []byte
checkNonce bool
gasPremium *big.Int
feeCap *big.Int
to *common.Address
from common.Address
nonce uint64
amount *big.Int
gasLimit uint64
gasPrice *big.Int
data []byte
checkNonce bool
maxMinerBribePerGas *big.Int
feeCapPerGas *big.Int
}
// 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{
from: from,
to: to,
nonce: nonce,
amount: amount,
gasLimit: gasLimit,
gasPrice: gasPrice,
data: data,
checkNonce: checkNonce,
gasPremium: gasPremium,
feeCap: feeCap,
from: from,
to: to,
nonce: nonce,
amount: amount,
gasLimit: gasLimit,
gasPrice: gasPrice,
data: data,
checkNonce: checkNonce,
maxMinerBribePerGas: maxMinerBribePerGas,
feeCapPerGas: feeCapPerGas,
}
}
func (m Message) From() common.Address { return m.from }
func (m Message) To() *common.Address { return m.to }
func (m Message) GasPrice() *big.Int { return m.gasPrice }
func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
func (m Message) CheckNonce() bool { return m.checkNonce }
func (m Message) GasPremium() *big.Int { return m.gasPremium }
func (m Message) FeeCap() *big.Int { return m.feeCap }
func (m Message) From() common.Address { return m.from }
func (m Message) To() *common.Address { return m.to }
func (m Message) GasPrice() *big.Int { return m.gasPrice }
func (m Message) Value() *big.Int { return m.amount }
func (m Message) Gas() uint64 { return m.gasLimit }
func (m Message) Nonce() uint64 { return m.nonce }
func (m Message) Data() []byte { return m.data }
func (m Message) CheckNonce() bool { return m.checkNonce }
func (m Message) MaxMinerBribe() *big.Int { return m.maxMinerBribePerGas }
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.Payload,
}
if tx.data.GasPremium != nil && tx.data.FeeCap != nil {
txFields = append(txFields, tx.data.GasPremium, tx.data.FeeCap)
if tx.data.MaxMinerBribePerGas != nil && tx.data.FeeCapPerGas != nil {
txFields = append(txFields, tx.data.MaxMinerBribePerGas, tx.data.FeeCapPerGas)
}
txFields = append(txFields, s.chainId, uint(0), uint(0))
return rlpHash(txFields)
@ -217,8 +217,8 @@ func (fs FrontierSigner) Hash(tx *Transaction) common.Hash {
tx.data.Amount,
tx.data.Payload,
}
if tx.data.GasPremium != nil && tx.data.FeeCap != nil {
txFields = append(txFields, tx.data.GasPremium, tx.data.FeeCap)
if tx.data.MaxMinerBribePerGas != nil && tx.data.FeeCapPerGas != nil {
txFields = append(txFields, tx.data.MaxMinerBribePerGas, tx.data.FeeCapPerGas)
}
return rlpHash(txFields)
}

View File

@ -152,10 +152,10 @@ func TestEIP1159TransactionDecode(t *testing.T) {
if err != nil {
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")
}
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")
}
if tx.data.Price != nil {
@ -370,13 +370,13 @@ func TestTransactionPriceNonceSort(t *testing.T) {
iPrice := txi.GasPrice()
nextPrice := next.GasPrice()
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 {
iPrice.Set(txi.FeeCap())
}
}
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 {
nextPrice.Set(next.FeeCap())
}

View File

@ -345,13 +345,13 @@ func (t *transactionsByGasPrice) Less(i, j int) bool {
iPrice := t.txs[i].GasPrice()
jPrice := t.txs[j].GasPrice()
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 {
iPrice.Set(t.txs[i].FeeCap())
}
}
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 {
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) Swap(i, j int) { t.txs[i], t.txs[j] = t.txs[j], t.txs[i] }
func (t *transactionsByGasPremium) Less(i, j int) bool {
iPremium := t.txs[i].GasPremium()
jPremium := t.txs[j].GasPremium()
iPremium := t.txs[i].MaxMinerBribe()
jPremium := t.txs[j].MaxMinerBribe()
if iPremium == nil {
iPremium = new(big.Int).Sub(t.txs[i].GasPrice(), t.baseFee)
if iPremium.Cmp(common.Big0) < 0 {
@ -423,7 +423,7 @@ func (gpo *Oracle) getBlockPrices(ctx context.Context, signer types.Signer, bloc
}
price := tx.GasPrice()
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 {
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() {
continue
}
premium := tx.GasPremium()
premium := tx.MaxMinerBribe()
if premium == nil {
premium = new(big.Int).Sub(tx.GasPrice(), block.BaseFee())
if premium.Cmp(common.Big0) < 0 {

View File

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

View File

@ -113,14 +113,14 @@ type ChainSyncReader interface {
// CallMsg contains parameters for contract calls.
type CallMsg struct {
From common.Address // the sender of the 'transaction'
To *common.Address // the destination contract (nil for contract creation)
Gas uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // wei <-> gas exchange ratio
Value *big.Int // amount of wei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation
GasPremium *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
From common.Address // the sender of the 'transaction'
To *common.Address // the destination contract (nil for contract creation)
Gas uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // wei <-> gas exchange ratio
Value *big.Int // amount of wei sent along with the call
Data []byte // input data, usually an ABI-encoded contract method invocation
MaxMinerBribePerGas *big.Int // EIP1559 gas premium paid to miners (excess of the basefee)
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

View File

@ -399,7 +399,7 @@ func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args SendTxArgs
if args.Gas == nil {
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")
}
if args.Nonce == nil {
@ -748,14 +748,14 @@ func (s *PublicBlockChainAPI) GetStorageAt(ctx context.Context, address common.A
// CallArgs represents the arguments for a call.
type CallArgs struct {
From *common.Address `json:"from"`
To *common.Address `json:"to"`
Gas *hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Value *hexutil.Big `json:"value"`
Data *hexutil.Bytes `json:"data"`
GasPremium *hexutil.Big `json:"gasPremium"`
FeeCap *hexutil.Big `json:"feeCap"`
From *common.Address `json:"from"`
To *common.Address `json:"to"`
Gas *hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Value *hexutil.Big `json:"value"`
Data *hexutil.Bytes `json:"data"`
MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas"`
FeeCapPerGas *hexutil.Big `json:"feeCapPerGas"`
}
// 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
if args.GasPremium == nil {
if args.MaxMinerBribePerGas == nil {
gasPrice = new(big.Int).SetUint64(defaultGasPrice)
if args.GasPrice != nil {
gasPrice = args.GasPrice.ToInt()
@ -795,7 +795,7 @@ func (args *CallArgs) ToMessage(globalGasCap *big.Int) types.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
}
@ -822,25 +822,25 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo
if eip1559 && b.CurrentBlock().BaseFee() == nil {
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
}
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
}
if args.GasPrice != nil && (args.GasPremium != nil || args.FeeCap != nil) {
if args.GasPrice != nil && (args.MaxMinerBribePerGas != nil || args.FeeCapPerGas != nil) {
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")
}
if args.GasPremium != nil {
if args.FeeCap == nil {
if args.MaxMinerBribePerGas != nil {
if args.FeeCapPerGas == nil {
return nil, errors.New("if GasPremium is set, FeeCap must be set")
}
gasPrice := new(big.Int).Add(b.CurrentBlock().BaseFee(), args.GasPremium.ToInt())
if gasPrice.Cmp(args.FeeCap.ToInt()) > 0 {
gasPrice.Set(args.FeeCap.ToInt())
gasPrice := new(big.Int).Add(b.CurrentBlock().BaseFee(), args.MaxMinerBribePerGas.ToInt())
if gasPrice.Cmp(args.FeeCapPerGas.ToInt()) > 0 {
gasPrice.Set(args.FeeCapPerGas.ToInt())
}
if gasPrice.Cmp(b.CurrentBlock().BaseFee()) < 0 {
return nil, core.ErrEIP1559GasPriceLessThanBaseFee
@ -1229,22 +1229,22 @@ func (s *PublicBlockChainAPI) rpcMarshalBlock(b *types.Block, inclTx bool, fullT
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
type RPCTransaction struct {
BlockHash *common.Hash `json:"blockHash"`
BlockNumber *hexutil.Big `json:"blockNumber"`
From common.Address `json:"from"`
Gas hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Hash common.Hash `json:"hash"`
Input hexutil.Bytes `json:"input"`
Nonce hexutil.Uint64 `json:"nonce"`
To *common.Address `json:"to"`
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
Value *hexutil.Big `json:"value"`
GasPremium *hexutil.Big `json:"gasPremium"`
FeeCap *hexutil.Big `json:"feeCap"`
V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"`
S *hexutil.Big `json:"s"`
BlockHash *common.Hash `json:"blockHash"`
BlockNumber *hexutil.Big `json:"blockNumber"`
From common.Address `json:"from"`
Gas hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Hash common.Hash `json:"hash"`
Input hexutil.Bytes `json:"input"`
Nonce hexutil.Uint64 `json:"nonce"`
To *common.Address `json:"to"`
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
Value *hexutil.Big `json:"value"`
MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas"`
FeeCapPerGas *hexutil.Big `json:"feeCapPerGas"`
V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"`
S *hexutil.Big `json:"s"`
}
// newRPCTransaction returns a transaction that will serialize to the RPC
@ -1258,19 +1258,19 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
v, r, s := tx.RawSignatureValues()
result := &RPCTransaction{
From: from,
Gas: hexutil.Uint64(tx.Gas()),
GasPrice: (*hexutil.Big)(tx.GasPrice()),
Hash: tx.Hash(),
Input: hexutil.Bytes(tx.Data()),
Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(),
Value: (*hexutil.Big)(tx.Value()),
GasPremium: (*hexutil.Big)(tx.GasPremium()),
FeeCap: (*hexutil.Big)(tx.FeeCap()),
V: (*hexutil.Big)(v),
R: (*hexutil.Big)(r),
S: (*hexutil.Big)(s),
From: from,
Gas: hexutil.Uint64(tx.Gas()),
GasPrice: (*hexutil.Big)(tx.GasPrice()),
Hash: tx.Hash(),
Input: hexutil.Bytes(tx.Data()),
Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(),
Value: (*hexutil.Big)(tx.Value()),
MaxMinerBribePerGas: (*hexutil.Big)(tx.MaxMinerBribe()),
FeeCapPerGas: (*hexutil.Big)(tx.FeeCap()),
V: (*hexutil.Big)(v),
R: (*hexutil.Big)(r),
S: (*hexutil.Big)(s),
}
if blockHash != (common.Hash{}) {
result.BlockHash = &blockHash
@ -1507,8 +1507,8 @@ type SendTxArgs struct {
Data *hexutil.Bytes `json:"data"`
Input *hexutil.Bytes `json:"input"`
// EIP1559 fields
GasPremium *hexutil.Big `json:"gasPremium"`
FeeCap *hexutil.Big `json:"feeCap"`
MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas"`
FeeCapPerGas *hexutil.Big `json:"feeCapPerGas"`
}
// 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 {
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
}
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
}
if args.GasPrice != nil && (args.GasPremium != nil || args.FeeCap != nil) {
if args.GasPrice != nil && (args.MaxMinerBribePerGas != nil || args.FeeCapPerGas != nil) {
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")
}
if args.GasPremium != nil {
if args.FeeCap == nil {
if args.MaxMinerBribePerGas != nil {
if args.FeeCapPerGas == nil {
return errors.New("if GasPremium is set, FeeCap must be set")
}
gasPrice := new(big.Int).Add(b.CurrentBlock().BaseFee(), args.GasPremium.ToInt())
if gasPrice.Cmp(args.FeeCap.ToInt()) > 0 {
gasPrice.Set(args.FeeCap.ToInt())
gasPrice := new(big.Int).Add(b.CurrentBlock().BaseFee(), args.MaxMinerBribePerGas.ToInt())
if gasPrice.Cmp(args.FeeCapPerGas.ToInt()) > 0 {
gasPrice.Set(args.FeeCapPerGas.ToInt())
}
if gasPrice.Cmp(b.CurrentBlock().BaseFee()) < 0 {
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 args.GasPrice == nil && args.GasPremium == nil {
if args.GasPrice == nil && args.MaxMinerBribePerGas == nil {
price, err := b.SuggestPrice(ctx)
if err != nil {
return err
@ -1586,13 +1586,13 @@ func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error {
input = args.Data
}
callArgs := CallArgs{
From: &args.From, // From shouldn't be nil
To: args.To,
GasPrice: args.GasPrice,
Value: args.Value,
Data: input,
GasPremium: args.GasPremium,
FeeCap: args.FeeCap,
From: &args.From, // From shouldn't be nil
To: args.To,
GasPrice: args.GasPrice,
Value: args.Value,
Data: input,
MaxMinerBribePerGas: args.MaxMinerBribePerGas,
FeeCapPerGas: args.FeeCapPerGas,
}
pendingBlockNr := rpc.BlockNumberOrHashWithNumber(rpc.PendingBlockNumber)
estimated, err := DoEstimateGas(ctx, b, callArgs, pendingBlockNr, b.RPCGasCap())
@ -1613,9 +1613,9 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
input = *args.Data
}
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.
@ -1698,20 +1698,20 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod
if eip1559 && s.b.CurrentBlock().BaseFee() == nil {
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
}
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
}
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
}
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
}
if tx.GasPremium() != nil {
gasPrice := new(big.Int).Add(s.b.CurrentBlock().BaseFee(), tx.GasPremium())
if tx.MaxMinerBribe() != nil {
gasPrice := new(big.Int).Add(s.b.CurrentBlock().BaseFee(), tx.MaxMinerBribe())
if gasPrice.Cmp(tx.FeeCap()) > 0 {
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 {
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
}
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
}
if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) {
if tx.GasPrice() != nil && (tx.MaxMinerBribe() != nil || tx.FeeCap() != nil) {
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
}
@ -392,13 +392,13 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
if tx.GasPrice() != nil && legacyGasLimit < tx.Gas() {
return core.ErrLegacyGasLimit
}
if tx.GasPremium() != nil && eip1559GasLimit < tx.Gas() {
if tx.MaxMinerBribe() != nil && eip1559GasLimit < tx.Gas() {
return core.ErrEIP1559GasLimit
}
// Derive the gasPrice from the tx.GasPremium() and tx.FeeCap() (EIP1559 transaction) to ensure it is greater than BaseFee
if tx.GasPremium() != nil {
gasPrice := new(big.Int).Add(pool.chain.CurrentHeader().BaseFee, tx.GasPremium())
if tx.MaxMinerBribe() != nil {
gasPrice := new(big.Int).Add(pool.chain.CurrentHeader().BaseFee, tx.MaxMinerBribe())
if gasPrice.Cmp(tx.FeeCap()) > 0 {
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
eip1559 := false
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
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
} else {
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() {
if tx.GasPrice() != nil {
feesWei.Add(feesWei, new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), tx.GasPrice()))
} else if tx.GasPremium() != nil && tx.FeeCap() != nil {
gasPrice := new(big.Int).Add(block.BaseFee(), tx.GasPremium())
} else if tx.MaxMinerBribe() != nil && tx.FeeCap() != nil {
gasPrice := new(big.Int).Add(block.BaseFee(), tx.MaxMinerBribe())
if gasPrice.Cmp(tx.FeeCap()) > 0 {
gasPrice.Set(tx.FeeCap())
}

View File

@ -58,8 +58,8 @@ func (msg *CallMsg) GetTo() *Address {
}
return nil
}
func (msg *CallMsg) GetGasPremium() *BigInt { return &BigInt{msg.msg.GasPremium} }
func (msg *CallMsg) GetFeeCap() *BigInt { return &BigInt{msg.msg.FeeCap} }
func (msg *CallMsg) GetMaxMinerBribe() *BigInt { return &BigInt{msg.msg.MaxMinerBribePerGas} }
func (msg *CallMsg) GetFeeCap() *BigInt { return &BigInt{msg.msg.FeeCapPerGas} }
func (msg *CallMsg) SetFrom(address *Address) { msg.msg.From = address.address }
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
}
func (msg *CallMsg) SetGasPremium(gasPremium *BigInt) { msg.msg.GasPremium = gasPremium.bigint }
func (msg *CallMsg) SetFeeCap(feeCap *BigInt) { msg.msg.FeeCap = feeCap.bigint }
func (msg *CallMsg) SetMaxMinerBribe(maxMinerBribe *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
// the Ethereum network.

View File

@ -21,10 +21,10 @@ import (
)
const (
VersionMajor = 1 // Major version component of the current release
VersionMinor = 9 // Minor 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
VersionMajor = 1 // Major version component of the current release
VersionMinor = 9 // Minor version component of the current release
VersionPatch = 15 // Patch version component of the current release
VersionMeta = "eip1559-970c594cd3" // Version metadata to append to the version string
)
// Version holds the textual version string.

View File

@ -465,7 +465,7 @@ func logDiff(original *SignTxRequest, new *SignTxResponse) bool {
modified = true
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 != gp1 {
modified = true
@ -475,7 +475,7 @@ func logDiff(original *SignTxRequest, new *SignTxResponse) bool {
modified = true
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 != f1 {
modified = true

View File

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

View File

@ -77,8 +77,8 @@ type SendTxArgs struct {
Data *hexutil.Bytes `json:"data"`
Input *hexutil.Bytes `json:"input,omitempty"`
// EIP1559 fields
GasPremium *hexutil.Big `json:"gasPremium"`
FeeCap *hexutil.Big `json:"feeCap"`
MaxMinerBribePerGas *hexutil.Big `json:"maxMinerBribePerGas"`
FeeCapPerGas *hexutil.Big `json:"feeCapPerGas"`
}
func (args SendTxArgs) String() string {
@ -97,7 +97,7 @@ func (args *SendTxArgs) toTransaction() *types.Transaction {
input = *args.Input
}
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))
}