change transaction options, gasPremium to maxMinerBribePerGas

This commit is contained in:
Ilnur Galiev 2020-10-26 14:53:52 +03:00
parent 1bac35c4a7
commit 1b59621f1b
17 changed files with 259 additions and 263 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

@ -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,8 +167,9 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp, gp1559 *GasPool) *StateTra
isEIP1559: isEIP1559,
}
if isEIP1559 {
//ToDo1559: check it
// EP1559 gasPrice = min(BASEFEE + tx.fee_premium, tx.fee_cap)
st.eip1559GasPrice = new(big.Int).Add(evm.BaseFee, msg.GasPremium())
st.eip1559GasPrice = new(big.Int).Add(evm.BaseFee, msg.MaxMinerBribe())
if st.eip1559GasPrice.Cmp(msg.FeeCap()) > 0 {
st.eip1559GasPrice.Set(msg.FeeCap())
}
@ -248,11 +249,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 +261,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

@ -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:"max_miner_bribe_per_gas" rlp:"nil"`
FeeCapPerGas *hexutil.Big `json:"fee_cap_per_gas" 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:"max_miner_bribe_per_gas" rlp:"nil"`
FeeCapPerGas *hexutil.Big `json:"fee_cap_per_gas" 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

@ -52,8 +52,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:"max_miner_bribe_per_gas" rlp:"nil"`
FeeCapPerGas *big.Int `json:"fee_cap_per_gas" rlp:"nil"`
// Signature values
V *big.Int `json:"v" gencodec:"required"`
@ -77,15 +77,15 @@ type txdataMarshaling struct {
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 +105,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 +135,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 +196,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 +218,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 +242,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 +291,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 +340,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,10 +375,11 @@ 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)
//ToDo1559: check it
if baseFee != nil && tx.data.MaxMinerBribePerGas != nil && tx.data.FeeCapPerGas != nil {
eip1559GasPrice := new(big.Int).Add(baseFee, tx.data.MaxMinerBribePerGas)
if eip1559GasPrice.Cmp(tx.data.FeeCapPerGas) > 0 {
eip1559GasPrice.Set(tx.data.FeeCapPerGas)
}
total := new(big.Int).Mul(eip1559GasPrice, new(big.Int).SetUint64(tx.data.GasLimit))
total.Add(total, tx.data.Amount)
@ -451,20 +445,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 +547,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

@ -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["max_miner_bribe_per_gas"] = (*hexutil.Big)(msg.MaxMinerBribePerGas)
}
if msg.FeeCap != nil {
arg["feeCap"] = (*hexutil.Big)(msg.FeeCap)
if msg.FeeCapPerGas != nil {
arg["fee_cap_per_gas"] = (*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

@ -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:"gasPremium"`
FeeCapPerGas *hexutil.Big `json:"feeCap"`
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
@ -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

@ -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

@ -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:"max_miner_bribe_per_gas"`
FeeCapPerGas *hexutil.Big `json:"fee_cap_per_gas"`
}
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))
}