all: rename internal 1559 gas fields, add support for graphql (#23010)
* all: rename internal 1559 gas fields, add support for graphql * cmd/evm/testdata, core: use public 1559 gas names on API surfaces
This commit is contained in:
parent
248572ee54
commit
c503f98f6d
@ -716,8 +716,8 @@ 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) FeeCap() *big.Int { return m.CallMsg.FeeCap }
|
||||
func (m callMsg) Tip() *big.Int { return m.CallMsg.Tip }
|
||||
func (m callMsg) GasFeeCap() *big.Int { return m.CallMsg.GasFeeCap }
|
||||
func (m callMsg) GasTipCap() *big.Int { return m.CallMsg.GasTipCap }
|
||||
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 }
|
||||
|
16
cmd/evm/testdata/10/txs.json
vendored
16
cmd/evm/testdata/10/txs.json
vendored
@ -11,8 +11,8 @@
|
||||
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
|
||||
"chainId" : "0x1",
|
||||
"type" : "0x2",
|
||||
"feeCap" : "0xfa0",
|
||||
"tip" : "0x0",
|
||||
"maxFeePerGas" : "0xfa0",
|
||||
"maxPriorityFeePerGas" : "0x0",
|
||||
"accessList" : [
|
||||
]
|
||||
},
|
||||
@ -28,8 +28,8 @@
|
||||
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
|
||||
"chainId" : "0x1",
|
||||
"type" : "0x2",
|
||||
"feeCap" : "0xfa0",
|
||||
"tip" : "0x0",
|
||||
"maxFeePerGas" : "0xfa0",
|
||||
"maxPriorityFeePerGas" : "0x0",
|
||||
"accessList" : [
|
||||
]
|
||||
},
|
||||
@ -45,8 +45,8 @@
|
||||
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
|
||||
"chainId" : "0x1",
|
||||
"type" : "0x2",
|
||||
"feeCap" : "0xfa0",
|
||||
"tip" : "0x0",
|
||||
"maxFeePerGas" : "0xfa0",
|
||||
"maxPriorityFeePerGas" : "0x0",
|
||||
"accessList" : [
|
||||
]
|
||||
},
|
||||
@ -62,8 +62,8 @@
|
||||
"secretKey" : "0x41f6e321b31e72173f8ff2e292359e1862f24fba42fe6f97efaf641980eff298",
|
||||
"chainId" : "0x1",
|
||||
"type" : "0x2",
|
||||
"feeCap" : "0xfa0",
|
||||
"tip" : "0x0",
|
||||
"maxFeePerGas" : "0xfa0",
|
||||
"maxPriorityFeePerGas" : "0x0",
|
||||
"accessList" : [
|
||||
]
|
||||
}
|
||||
|
4
cmd/evm/testdata/9/txs.json
vendored
4
cmd/evm/testdata/9/txs.json
vendored
@ -1,8 +1,8 @@
|
||||
[
|
||||
{
|
||||
"gas": "0x4ef00",
|
||||
"tip": "0x2",
|
||||
"feeCap": "0x12A05F200",
|
||||
"maxPriorityFeePerGas": "0x2",
|
||||
"maxFeePerGas": "0x12A05F200",
|
||||
"chainId": "0x1",
|
||||
"input": "0x",
|
||||
"nonce": "0x0",
|
||||
|
@ -3116,13 +3116,13 @@ func TestEIP2718Transition(t *testing.T) {
|
||||
|
||||
// TestEIP1559Transition tests the following:
|
||||
//
|
||||
// 1. A tranaction whose feeCap is greater than the baseFee is valid.
|
||||
// 1. A transaction whose gasFeeCap is greater than the baseFee is valid.
|
||||
// 2. Gas accounting for access lists on EIP-1559 transactions is correct.
|
||||
// 3. Only the transaction's tip will be received by the coinbase.
|
||||
// 4. The transaction sender pays for both the tip and baseFee.
|
||||
// 5. The coinbase receives only the partially realized tip when
|
||||
// feeCap - tip < baseFee.
|
||||
// 6. Legacy transaction behave as expected (e.g. gasPrice = feeCap = tip).
|
||||
// gasFeeCap - gasTipCap < baseFee.
|
||||
// 6. Legacy transaction behave as expected (e.g. gasPrice = gasFeeCap = gasTipCap).
|
||||
func TestEIP1559Transition(t *testing.T) {
|
||||
var (
|
||||
aa = common.HexToAddress("0x000000000000000000000000000000000000aaaa")
|
||||
@ -3176,8 +3176,8 @@ func TestEIP1559Transition(t *testing.T) {
|
||||
Nonce: 0,
|
||||
To: &aa,
|
||||
Gas: 30000,
|
||||
FeeCap: newGwei(5),
|
||||
Tip: big.NewInt(2),
|
||||
GasFeeCap: newGwei(5),
|
||||
GasTipCap: big.NewInt(2),
|
||||
AccessList: accesses,
|
||||
Data: []byte{},
|
||||
}
|
||||
@ -3212,7 +3212,7 @@ func TestEIP1559Transition(t *testing.T) {
|
||||
// 3: Ensure that miner received only the tx's tip.
|
||||
actual := state.GetBalance(block.Coinbase())
|
||||
expected := new(big.Int).Add(
|
||||
new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].Tip().Uint64()),
|
||||
new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].GasTipCap().Uint64()),
|
||||
ethash.ConstantinopleBlockReward,
|
||||
)
|
||||
if actual.Cmp(expected) != 0 {
|
||||
@ -3221,7 +3221,7 @@ func TestEIP1559Transition(t *testing.T) {
|
||||
|
||||
// 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee).
|
||||
actual = new(big.Int).Sub(funds, state.GetBalance(addr1))
|
||||
expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].Tip().Uint64() + block.BaseFee().Uint64()))
|
||||
expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].GasTipCap().Uint64() + block.BaseFee().Uint64()))
|
||||
if actual.Cmp(expected) != 0 {
|
||||
t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual)
|
||||
}
|
||||
@ -3247,7 +3247,7 @@ func TestEIP1559Transition(t *testing.T) {
|
||||
|
||||
block = chain.GetBlockByNumber(2)
|
||||
state, _ = chain.State()
|
||||
effectiveTip := block.Transactions()[0].Tip().Uint64() - block.BaseFee().Uint64()
|
||||
effectiveTip := block.Transactions()[0].GasTipCap().Uint64() - block.BaseFee().Uint64()
|
||||
|
||||
// 6+5: Ensure that miner received only the tx's effective tip.
|
||||
actual = state.GetBalance(block.Coinbase())
|
||||
|
@ -74,17 +74,17 @@ var (
|
||||
|
||||
// ErrTipAboveFeeCap is a sanity error to ensure no one is able to specify a
|
||||
// transaction with a tip higher than the total fee cap.
|
||||
ErrTipAboveFeeCap = errors.New("tip higher than fee cap")
|
||||
ErrTipAboveFeeCap = errors.New("max priority fee per gas higher than max fee per gas")
|
||||
|
||||
// ErrTipVeryHigh is a sanity error to avoid extremely big numbers specified
|
||||
// in the tip field.
|
||||
ErrTipVeryHigh = errors.New("tip higher than 2^256-1")
|
||||
ErrTipVeryHigh = errors.New("max priority fee per gas higher than 2^256-1")
|
||||
|
||||
// ErrFeeCapVeryHigh is a sanity error to avoid extremely big numbers specified
|
||||
// in the fee cap field.
|
||||
ErrFeeCapVeryHigh = errors.New("fee cap higher than 2^256-1")
|
||||
ErrFeeCapVeryHigh = errors.New("max fee per gas higher than 2^256-1")
|
||||
|
||||
// ErrFeeCapTooLow is returned if the transaction fee cap is less than the
|
||||
// the base fee of the block.
|
||||
ErrFeeCapTooLow = errors.New("fee cap less than block base fee")
|
||||
ErrFeeCapTooLow = errors.New("max fee per gas less than block base fee")
|
||||
)
|
||||
|
@ -61,11 +61,11 @@ func TestStateProcessorErrors(t *testing.T) {
|
||||
tx, _ := types.SignTx(types.NewTransaction(nonce, to, amount, gasLimit, gasPrice, data), signer, testKey)
|
||||
return tx
|
||||
}
|
||||
var mkDynamicTx = func(nonce uint64, to common.Address, gasLimit uint64, tip, feeCap *big.Int) *types.Transaction {
|
||||
var mkDynamicTx = func(nonce uint64, to common.Address, gasLimit uint64, gasTipCap, gasFeeCap *big.Int) *types.Transaction {
|
||||
tx, _ := types.SignTx(types.NewTx(&types.DynamicFeeTx{
|
||||
Nonce: nonce,
|
||||
Tip: tip,
|
||||
FeeCap: feeCap,
|
||||
GasTipCap: gasTipCap,
|
||||
GasFeeCap: gasFeeCap,
|
||||
Gas: gasLimit,
|
||||
To: &to,
|
||||
Value: big.NewInt(0),
|
||||
@ -146,25 +146,25 @@ func TestStateProcessorErrors(t *testing.T) {
|
||||
txs: []*types.Transaction{
|
||||
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(0), big.NewInt(0)),
|
||||
},
|
||||
want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: fee cap less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, feeCap: 0 baseFee: 875000000",
|
||||
want: "could not apply tx 0 [0xc4ab868fef0c82ae0387b742aee87907f2d0fc528fc6ea0a021459fb0fc4a4a8]: max fee per gas less than block base fee: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas: 0 baseFee: 875000000",
|
||||
},
|
||||
{ // ErrTipVeryHigh
|
||||
txs: []*types.Transaction{
|
||||
mkDynamicTx(0, common.Address{}, params.TxGas, tooBigNumber, big.NewInt(1)),
|
||||
},
|
||||
want: "could not apply tx 0 [0x15b8391b9981f266b32f3ab7da564bbeb3d6c21628364ea9b32a21139f89f712]: tip higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tip bit length: 257",
|
||||
want: "could not apply tx 0 [0x15b8391b9981f266b32f3ab7da564bbeb3d6c21628364ea9b32a21139f89f712]: max priority fee per gas higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxPriorityFeePerGas bit length: 257",
|
||||
},
|
||||
{ // ErrFeeCapVeryHigh
|
||||
txs: []*types.Transaction{
|
||||
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(1), tooBigNumber),
|
||||
},
|
||||
want: "could not apply tx 0 [0x48bc299b83fdb345c57478f239e89814bb3063eb4e4b49f3b6057a69255c16bd]: fee cap higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, feeCap bit length: 257",
|
||||
want: "could not apply tx 0 [0x48bc299b83fdb345c57478f239e89814bb3063eb4e4b49f3b6057a69255c16bd]: max fee per gas higher than 2^256-1: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxFeePerGas bit length: 257",
|
||||
},
|
||||
{ // ErrTipAboveFeeCap
|
||||
txs: []*types.Transaction{
|
||||
mkDynamicTx(0, common.Address{}, params.TxGas, big.NewInt(2), big.NewInt(1)),
|
||||
},
|
||||
want: "could not apply tx 0 [0xf987a31ff0c71895780a7612f965a0c8b056deb54e020bb44fa478092f14c9b4]: tip higher than fee cap: address 0x71562b71999873DB5b286dF957af199Ec94617F7, tip: 1, feeCap: 2",
|
||||
want: "could not apply tx 0 [0xf987a31ff0c71895780a7612f965a0c8b056deb54e020bb44fa478092f14c9b4]: max priority fee per gas higher than max fee per gas: address 0x71562b71999873DB5b286dF957af199Ec94617F7, maxPriorityFeePerGas: 2, maxFeePerGas: 1",
|
||||
},
|
||||
{ // ErrInsufficientFunds
|
||||
// Available balance: 1000000000000000000
|
||||
|
@ -50,8 +50,8 @@ type StateTransition struct {
|
||||
msg Message
|
||||
gas uint64
|
||||
gasPrice *big.Int
|
||||
feeCap *big.Int
|
||||
tip *big.Int
|
||||
gasFeeCap *big.Int
|
||||
gasTipCap *big.Int
|
||||
initialGas uint64
|
||||
value *big.Int
|
||||
data []byte
|
||||
@ -65,8 +65,8 @@ type Message interface {
|
||||
To() *common.Address
|
||||
|
||||
GasPrice() *big.Int
|
||||
FeeCap() *big.Int
|
||||
Tip() *big.Int
|
||||
GasFeeCap() *big.Int
|
||||
GasTipCap() *big.Int
|
||||
Gas() uint64
|
||||
Value() *big.Int
|
||||
|
||||
@ -159,8 +159,8 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
|
||||
evm: evm,
|
||||
msg: msg,
|
||||
gasPrice: msg.GasPrice(),
|
||||
feeCap: msg.FeeCap(),
|
||||
tip: msg.Tip(),
|
||||
gasFeeCap: msg.GasFeeCap(),
|
||||
gasTipCap: msg.GasTipCap(),
|
||||
value: msg.Value(),
|
||||
data: msg.Data(),
|
||||
state: evm.StateDB,
|
||||
@ -190,9 +190,9 @@ func (st *StateTransition) buyGas() error {
|
||||
mgval := new(big.Int).SetUint64(st.msg.Gas())
|
||||
mgval = mgval.Mul(mgval, st.gasPrice)
|
||||
balanceCheck := mgval
|
||||
if st.feeCap != nil {
|
||||
if st.gasFeeCap != nil {
|
||||
balanceCheck = new(big.Int).SetUint64(st.msg.Gas())
|
||||
balanceCheck = balanceCheck.Mul(balanceCheck, st.feeCap)
|
||||
balanceCheck = balanceCheck.Mul(balanceCheck, st.gasFeeCap)
|
||||
}
|
||||
if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 {
|
||||
return fmt.Errorf("%w: address %v have %v want %v", ErrInsufficientFunds, st.msg.From().Hex(), have, want)
|
||||
@ -219,25 +219,25 @@ func (st *StateTransition) preCheck() error {
|
||||
st.msg.From().Hex(), msgNonce, stNonce)
|
||||
}
|
||||
}
|
||||
// Make sure that transaction feeCap is greater than the baseFee (post london)
|
||||
// Make sure that transaction gasFeeCap is greater than the baseFee (post london)
|
||||
if st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) {
|
||||
if l := st.feeCap.BitLen(); l > 256 {
|
||||
return fmt.Errorf("%w: address %v, feeCap bit length: %d", ErrFeeCapVeryHigh,
|
||||
if l := st.gasFeeCap.BitLen(); l > 256 {
|
||||
return fmt.Errorf("%w: address %v, maxFeePerGas bit length: %d", ErrFeeCapVeryHigh,
|
||||
st.msg.From().Hex(), l)
|
||||
}
|
||||
if l := st.tip.BitLen(); l > 256 {
|
||||
return fmt.Errorf("%w: address %v, tip bit length: %d", ErrTipVeryHigh,
|
||||
if l := st.gasTipCap.BitLen(); l > 256 {
|
||||
return fmt.Errorf("%w: address %v, maxPriorityFeePerGas bit length: %d", ErrTipVeryHigh,
|
||||
st.msg.From().Hex(), l)
|
||||
}
|
||||
if st.feeCap.Cmp(st.tip) < 0 {
|
||||
return fmt.Errorf("%w: address %v, tip: %s, feeCap: %s", ErrTipAboveFeeCap,
|
||||
st.msg.From().Hex(), st.feeCap, st.tip)
|
||||
if st.gasFeeCap.Cmp(st.gasTipCap) < 0 {
|
||||
return fmt.Errorf("%w: address %v, maxPriorityFeePerGas: %s, maxFeePerGas: %s", ErrTipAboveFeeCap,
|
||||
st.msg.From().Hex(), st.gasTipCap, st.gasFeeCap)
|
||||
}
|
||||
// This will panic if baseFee is nil, but basefee presence is verified
|
||||
// as part of header validation.
|
||||
if st.feeCap.Cmp(st.evm.Context.BaseFee) < 0 {
|
||||
return fmt.Errorf("%w: address %v, feeCap: %s baseFee: %s", ErrFeeCapTooLow,
|
||||
st.msg.From().Hex(), st.feeCap, st.evm.Context.BaseFee)
|
||||
if st.gasFeeCap.Cmp(st.evm.Context.BaseFee) < 0 {
|
||||
return fmt.Errorf("%w: address %v, maxFeePerGas: %s baseFee: %s", ErrFeeCapTooLow,
|
||||
st.msg.From().Hex(), st.gasFeeCap, st.evm.Context.BaseFee)
|
||||
}
|
||||
}
|
||||
return st.buyGas()
|
||||
@ -317,7 +317,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
|
||||
}
|
||||
effectiveTip := st.gasPrice
|
||||
if st.evm.ChainConfig().IsLondon(st.evm.Context.BlockNumber) {
|
||||
effectiveTip = cmath.BigMin(st.tip, new(big.Int).Sub(st.feeCap, st.evm.Context.BaseFee))
|
||||
effectiveTip = cmath.BigMin(st.gasTipCap, new(big.Int).Sub(st.gasFeeCap, st.evm.Context.BaseFee))
|
||||
}
|
||||
st.state.AddBalance(st.evm.Context.Coinbase, new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))
|
||||
|
||||
|
@ -280,13 +280,13 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
|
||||
// If there's an older better transaction, abort
|
||||
old := l.txs.Get(tx.Nonce())
|
||||
if old != nil {
|
||||
if old.FeeCapCmp(tx) >= 0 || old.TipCmp(tx) >= 0 {
|
||||
if old.GasFeeCapCmp(tx) >= 0 || old.GasTipCapCmp(tx) >= 0 {
|
||||
return false, nil
|
||||
}
|
||||
// thresholdFeeCap = oldFC * (100 + priceBump) / 100
|
||||
a := big.NewInt(100 + int64(priceBump))
|
||||
aFeeCap := new(big.Int).Mul(a, old.FeeCap())
|
||||
aTip := a.Mul(a, old.Tip())
|
||||
aFeeCap := new(big.Int).Mul(a, old.GasFeeCap())
|
||||
aTip := a.Mul(a, old.GasTipCap())
|
||||
|
||||
// thresholdTip = oldTip * (100 + priceBump) / 100
|
||||
b := big.NewInt(100)
|
||||
@ -296,7 +296,7 @@ func (l *txList) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Tran
|
||||
// Have to ensure that either the new fee cap or tip is higher than the
|
||||
// old ones as well as checking the percentage threshold to ensure that
|
||||
// this is accurate for low (Wei-level) gas price replacements
|
||||
if tx.FeeCapIntCmp(thresholdFeeCap) < 0 || tx.TipIntCmp(thresholdTip) < 0 {
|
||||
if tx.GasFeeCapIntCmp(thresholdFeeCap) < 0 || tx.GasTipCapIntCmp(thresholdTip) < 0 {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
@ -417,7 +417,7 @@ func (l *txList) LastElement() *types.Transaction {
|
||||
// priceHeap is a heap.Interface implementation over transactions for retrieving
|
||||
// price-sorted transactions to discard when the pool fills up. If baseFee is set
|
||||
// then the heap is sorted based on the effective tip based on the given base fee.
|
||||
// If baseFee is nil then the sorting is based on feeCap.
|
||||
// If baseFee is nil then the sorting is based on gasFeeCap.
|
||||
type priceHeap struct {
|
||||
baseFee *big.Int // heap should always be re-sorted after baseFee is changed
|
||||
list []*types.Transaction
|
||||
@ -440,16 +440,16 @@ func (h *priceHeap) Less(i, j int) bool {
|
||||
func (h *priceHeap) cmp(a, b *types.Transaction) int {
|
||||
if h.baseFee != nil {
|
||||
// Compare effective tips if baseFee is specified
|
||||
if c := a.EffectiveTipCmp(b, h.baseFee); c != 0 {
|
||||
if c := a.EffectiveGasTipCmp(b, h.baseFee); c != 0 {
|
||||
return c
|
||||
}
|
||||
}
|
||||
// Compare fee caps if baseFee is not specified or effective tips are equal
|
||||
if c := a.FeeCapCmp(b); c != 0 {
|
||||
if c := a.GasFeeCapCmp(b); c != 0 {
|
||||
return c
|
||||
}
|
||||
// Compare tips if effective tips and fee caps are equal
|
||||
return a.TipCmp(b)
|
||||
return a.GasTipCapCmp(b)
|
||||
}
|
||||
|
||||
func (h *priceHeap) Push(x interface{}) {
|
||||
@ -472,7 +472,7 @@ func (h *priceHeap) Pop() interface{} {
|
||||
// will be considered for tracking, sorting, eviction, etc.
|
||||
//
|
||||
// Two heaps are used for sorting: the urgent heap (based on effective tip in the next
|
||||
// block) and the floating heap (based on feeCap). Always the bigger heap is chosen for
|
||||
// block) and the floating heap (based on gasFeeCap). Always the bigger heap is chosen for
|
||||
// eviction. Transactions evicted from the urgent heap are first demoted into the floating heap.
|
||||
// In some cases (during a congestion, when blocks are full) the urgent heap can provide
|
||||
// better candidates for inclusion while in other cases (at the top of the baseFee peak)
|
||||
|
@ -434,7 +434,7 @@ func (pool *TxPool) SetGasPrice(price *big.Int) {
|
||||
pool.gasPrice = price
|
||||
// if the min miner fee increased, remove transactions below the new threshold
|
||||
if price.Cmp(old) > 0 {
|
||||
// pool.priced is sorted by FeeCap, so we have to iterate through pool.all instead
|
||||
// pool.priced is sorted by GasFeeCap, so we have to iterate through pool.all instead
|
||||
drop := pool.all.RemotesBelowTip(price)
|
||||
for _, tx := range drop {
|
||||
pool.removeTx(tx.Hash(), false)
|
||||
@ -574,14 +574,14 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||
return ErrGasLimit
|
||||
}
|
||||
// Sanity check for extremely large numbers
|
||||
if tx.FeeCap().BitLen() > 256 {
|
||||
if tx.GasFeeCap().BitLen() > 256 {
|
||||
return ErrFeeCapVeryHigh
|
||||
}
|
||||
if tx.Tip().BitLen() > 256 {
|
||||
if tx.GasTipCap().BitLen() > 256 {
|
||||
return ErrTipVeryHigh
|
||||
}
|
||||
// Ensure feeCap is greater than or equal to tip.
|
||||
if tx.FeeCapIntCmp(tx.Tip()) < 0 {
|
||||
// Ensure gasFeeCap is greater than or equal to gasTipCap.
|
||||
if tx.GasFeeCapIntCmp(tx.GasTipCap()) < 0 {
|
||||
return ErrTipAboveFeeCap
|
||||
}
|
||||
// Make sure the transaction is signed properly.
|
||||
@ -590,7 +590,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||
return ErrInvalidSender
|
||||
}
|
||||
// Drop non-local transactions under our own minimal accepted gas price or tip
|
||||
if !local && tx.TipIntCmp(pool.gasPrice) < 0 {
|
||||
if !local && tx.GasTipCapIntCmp(pool.gasPrice) < 0 {
|
||||
return ErrUnderpriced
|
||||
}
|
||||
// Ensure the transaction adheres to nonce ordering
|
||||
@ -642,7 +642,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
|
||||
if uint64(pool.all.Slots()+numSlots(tx)) > pool.config.GlobalSlots+pool.config.GlobalQueue {
|
||||
// If the new transaction is underpriced, don't accept it
|
||||
if !isLocal && pool.priced.Underpriced(tx) {
|
||||
log.Trace("Discarding underpriced transaction", "hash", hash, "tip", tx.Tip(), "feeCap", tx.FeeCap())
|
||||
log.Trace("Discarding underpriced transaction", "hash", hash, "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
|
||||
underpricedTxMeter.Mark(1)
|
||||
return false, ErrUnderpriced
|
||||
}
|
||||
@ -659,7 +659,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e
|
||||
}
|
||||
// Kick out the underpriced remote transactions.
|
||||
for _, tx := range drop {
|
||||
log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "tip", tx.Tip(), "feeCap", tx.FeeCap())
|
||||
log.Trace("Discarding freshly underpriced transaction", "hash", tx.Hash(), "gasTipCap", tx.GasTipCap(), "gasFeeCap", tx.GasFeeCap())
|
||||
underpricedTxMeter.Mark(1)
|
||||
pool.removeTx(tx.Hash(), false)
|
||||
}
|
||||
@ -1765,7 +1765,7 @@ func (t *txLookup) RemoteToLocals(locals *accountSet) int {
|
||||
func (t *txLookup) RemotesBelowTip(threshold *big.Int) types.Transactions {
|
||||
found := make(types.Transactions, 0, 128)
|
||||
t.Range(func(hash common.Hash, tx *types.Transaction, local bool) bool {
|
||||
if tx.TipIntCmp(threshold) < 0 {
|
||||
if tx.GasTipCapIntCmp(threshold) < 0 {
|
||||
found = append(found, tx)
|
||||
}
|
||||
return true
|
||||
|
@ -101,8 +101,8 @@ func dynamicFeeTx(nonce uint64, gaslimit uint64, gasFee *big.Int, tip *big.Int,
|
||||
tx, _ := types.SignNewTx(key, types.LatestSignerForChainID(params.TestChainConfig.ChainID), &types.DynamicFeeTx{
|
||||
ChainID: params.TestChainConfig.ChainID,
|
||||
Nonce: nonce,
|
||||
Tip: tip,
|
||||
FeeCap: gasFee,
|
||||
GasTipCap: tip,
|
||||
GasFeeCap: gasFee,
|
||||
Gas: gaslimit,
|
||||
To: &common.Address{},
|
||||
Value: big.NewInt(100),
|
||||
@ -2141,17 +2141,17 @@ func TestTransactionReplacementDynamicFee(t *testing.T) {
|
||||
defer sub.Unsubscribe()
|
||||
|
||||
// Add pending transactions, ensuring the minimum price bump is enforced for replacement (for ultra low prices too)
|
||||
feeCap := int64(100)
|
||||
feeCapThreshold := (feeCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100
|
||||
tip := int64(60)
|
||||
tipThreshold := (tip * (100 + int64(testTxPoolConfig.PriceBump))) / 100
|
||||
gasFeeCap := int64(100)
|
||||
feeCapThreshold := (gasFeeCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100
|
||||
gasTipCap := int64(60)
|
||||
tipThreshold := (gasTipCap * (100 + int64(testTxPoolConfig.PriceBump))) / 100
|
||||
|
||||
// Run the following identical checks for both the pending and queue pools:
|
||||
// 1. Send initial tx => accept
|
||||
// 2. Don't bump tip or fee cap => discard
|
||||
// 3. Bump both more than min => accept
|
||||
// 4. Check events match expected (2 new executable txs during pending, 0 during queue)
|
||||
// 5. Send new tx with larger tip and feeCap => accept
|
||||
// 5. Send new tx with larger tip and gasFeeCap => accept
|
||||
// 6. Bump tip max allowed so it's still underpriced => discard
|
||||
// 7. Bump fee cap max allowed so it's still underpriced => discard
|
||||
// 8. Bump tip min for acceptance => discard
|
||||
@ -2191,27 +2191,27 @@ func TestTransactionReplacementDynamicFee(t *testing.T) {
|
||||
t.Fatalf("cheap %s replacement event firing failed: %v", stage, err)
|
||||
}
|
||||
// 5. Send new tx with larger tip and feeCap => accept
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCap), big.NewInt(tip), key)
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(gasTipCap), key)
|
||||
if err := pool.addRemoteSync(tx); err != nil {
|
||||
t.Fatalf("failed to add original proper %s transaction: %v", stage, err)
|
||||
}
|
||||
// 6. Bump tip max allowed so it's still underpriced => discard
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCap), big.NewInt(tipThreshold-1), key)
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(tipThreshold-1), key)
|
||||
if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced {
|
||||
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced)
|
||||
}
|
||||
// 7. Bump fee cap max allowed so it's still underpriced => discard
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold-1), big.NewInt(tip), key)
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold-1), big.NewInt(gasTipCap), key)
|
||||
if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced {
|
||||
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced)
|
||||
}
|
||||
// 8. Bump tip min for acceptance => accept
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCap), big.NewInt(tipThreshold), key)
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(gasFeeCap), big.NewInt(tipThreshold), key)
|
||||
if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced {
|
||||
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced)
|
||||
}
|
||||
// 9. Bump fee cap min for acceptance => accept
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold), big.NewInt(tip), key)
|
||||
tx = dynamicFeeTx(nonce, 100000, big.NewInt(feeCapThreshold), big.NewInt(gasTipCap), key)
|
||||
if err := pool.AddRemote(tx); err != ErrReplaceUnderpriced {
|
||||
t.Fatalf("original proper %s transaction replacement error mismatch: have %v, want %v", stage, err, ErrReplaceUnderpriced)
|
||||
}
|
||||
|
@ -101,8 +101,8 @@ func (tx *AccessListTx) accessList() AccessList { return tx.AccessList }
|
||||
func (tx *AccessListTx) data() []byte { return tx.Data }
|
||||
func (tx *AccessListTx) gas() uint64 { return tx.Gas }
|
||||
func (tx *AccessListTx) gasPrice() *big.Int { return tx.GasPrice }
|
||||
func (tx *AccessListTx) tip() *big.Int { return tx.GasPrice }
|
||||
func (tx *AccessListTx) feeCap() *big.Int { return tx.GasPrice }
|
||||
func (tx *AccessListTx) gasTipCap() *big.Int { return tx.GasPrice }
|
||||
func (tx *AccessListTx) gasFeeCap() *big.Int { return tx.GasPrice }
|
||||
func (tx *AccessListTx) value() *big.Int { return tx.Value }
|
||||
func (tx *AccessListTx) nonce() uint64 { return tx.Nonce }
|
||||
func (tx *AccessListTx) to() *common.Address { return tx.To }
|
||||
|
@ -109,8 +109,8 @@ func TestEIP1559BlockEncoding(t *testing.T) {
|
||||
Nonce: 0,
|
||||
To: &to,
|
||||
Gas: 123457,
|
||||
FeeCap: new(big.Int).Set(block.BaseFee()),
|
||||
Tip: big.NewInt(0),
|
||||
GasFeeCap: new(big.Int).Set(block.BaseFee()),
|
||||
GasTipCap: big.NewInt(0),
|
||||
AccessList: accesses,
|
||||
Data: []byte{},
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ import (
|
||||
type DynamicFeeTx struct {
|
||||
ChainID *big.Int
|
||||
Nonce uint64
|
||||
Tip *big.Int
|
||||
FeeCap *big.Int
|
||||
GasTipCap *big.Int
|
||||
GasFeeCap *big.Int
|
||||
Gas uint64
|
||||
To *common.Address `rlp:"nil"` // nil means contract creation
|
||||
Value *big.Int
|
||||
@ -50,8 +50,8 @@ func (tx *DynamicFeeTx) copy() TxData {
|
||||
AccessList: make(AccessList, len(tx.AccessList)),
|
||||
Value: new(big.Int),
|
||||
ChainID: new(big.Int),
|
||||
Tip: new(big.Int),
|
||||
FeeCap: new(big.Int),
|
||||
GasTipCap: new(big.Int),
|
||||
GasFeeCap: new(big.Int),
|
||||
V: new(big.Int),
|
||||
R: new(big.Int),
|
||||
S: new(big.Int),
|
||||
@ -63,11 +63,11 @@ func (tx *DynamicFeeTx) copy() TxData {
|
||||
if tx.ChainID != nil {
|
||||
cpy.ChainID.Set(tx.ChainID)
|
||||
}
|
||||
if tx.Tip != nil {
|
||||
cpy.Tip.Set(tx.Tip)
|
||||
if tx.GasTipCap != nil {
|
||||
cpy.GasTipCap.Set(tx.GasTipCap)
|
||||
}
|
||||
if tx.FeeCap != nil {
|
||||
cpy.FeeCap.Set(tx.FeeCap)
|
||||
if tx.GasFeeCap != nil {
|
||||
cpy.GasFeeCap.Set(tx.GasFeeCap)
|
||||
}
|
||||
if tx.V != nil {
|
||||
cpy.V.Set(tx.V)
|
||||
@ -88,9 +88,9 @@ func (tx *DynamicFeeTx) protected() bool { return true }
|
||||
func (tx *DynamicFeeTx) accessList() AccessList { return tx.AccessList }
|
||||
func (tx *DynamicFeeTx) data() []byte { return tx.Data }
|
||||
func (tx *DynamicFeeTx) gas() uint64 { return tx.Gas }
|
||||
func (tx *DynamicFeeTx) feeCap() *big.Int { return tx.FeeCap }
|
||||
func (tx *DynamicFeeTx) tip() *big.Int { return tx.Tip }
|
||||
func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.FeeCap }
|
||||
func (tx *DynamicFeeTx) gasFeeCap() *big.Int { return tx.GasFeeCap }
|
||||
func (tx *DynamicFeeTx) gasTipCap() *big.Int { return tx.GasTipCap }
|
||||
func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap }
|
||||
func (tx *DynamicFeeTx) value() *big.Int { return tx.Value }
|
||||
func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce }
|
||||
func (tx *DynamicFeeTx) to() *common.Address { return tx.To }
|
||||
|
@ -97,8 +97,8 @@ func (tx *LegacyTx) accessList() AccessList { return nil }
|
||||
func (tx *LegacyTx) data() []byte { return tx.Data }
|
||||
func (tx *LegacyTx) gas() uint64 { return tx.Gas }
|
||||
func (tx *LegacyTx) gasPrice() *big.Int { return tx.GasPrice }
|
||||
func (tx *LegacyTx) tip() *big.Int { return tx.GasPrice }
|
||||
func (tx *LegacyTx) feeCap() *big.Int { return tx.GasPrice }
|
||||
func (tx *LegacyTx) gasTipCap() *big.Int { return tx.GasPrice }
|
||||
func (tx *LegacyTx) gasFeeCap() *big.Int { return tx.GasPrice }
|
||||
func (tx *LegacyTx) value() *big.Int { return tx.Value }
|
||||
func (tx *LegacyTx) nonce() uint64 { return tx.Nonce }
|
||||
func (tx *LegacyTx) to() *common.Address { return tx.To }
|
||||
|
@ -36,7 +36,7 @@ var (
|
||||
ErrUnexpectedProtection = errors.New("transaction type does not supported EIP-155 protected signatures")
|
||||
ErrInvalidTxType = errors.New("transaction type not valid in this context")
|
||||
ErrTxTypeNotSupported = errors.New("transaction type not supported")
|
||||
ErrFeeCapTooLow = errors.New("fee cap less than base fee")
|
||||
ErrGasFeeCapTooLow = errors.New("fee cap less than base fee")
|
||||
errEmptyTypedTx = errors.New("empty typed transaction bytes")
|
||||
)
|
||||
|
||||
@ -77,8 +77,8 @@ type TxData interface {
|
||||
data() []byte
|
||||
gas() uint64
|
||||
gasPrice() *big.Int
|
||||
tip() *big.Int
|
||||
feeCap() *big.Int
|
||||
gasTipCap() *big.Int
|
||||
gasFeeCap() *big.Int
|
||||
value() *big.Int
|
||||
nonce() uint64
|
||||
to() *common.Address
|
||||
@ -269,11 +269,11 @@ func (tx *Transaction) Gas() uint64 { return tx.inner.gas() }
|
||||
// GasPrice returns the gas price of the transaction.
|
||||
func (tx *Transaction) GasPrice() *big.Int { return new(big.Int).Set(tx.inner.gasPrice()) }
|
||||
|
||||
// Tip returns the tip per gas of the transaction.
|
||||
func (tx *Transaction) Tip() *big.Int { return new(big.Int).Set(tx.inner.tip()) }
|
||||
// GasTipCap returns the gasTipCap per gas of the transaction.
|
||||
func (tx *Transaction) GasTipCap() *big.Int { return new(big.Int).Set(tx.inner.gasTipCap()) }
|
||||
|
||||
// FeeCap returns the fee cap per gas of the transaction.
|
||||
func (tx *Transaction) FeeCap() *big.Int { return new(big.Int).Set(tx.inner.feeCap()) }
|
||||
// GasFeeCap returns the fee cap per gas of the transaction.
|
||||
func (tx *Transaction) GasFeeCap() *big.Int { return new(big.Int).Set(tx.inner.gasFeeCap()) }
|
||||
|
||||
// Value returns the ether amount of the transaction.
|
||||
func (tx *Transaction) Value() *big.Int { return new(big.Int).Set(tx.inner.value()) }
|
||||
@ -306,62 +306,62 @@ func (tx *Transaction) RawSignatureValues() (v, r, s *big.Int) {
|
||||
return tx.inner.rawSignatureValues()
|
||||
}
|
||||
|
||||
// FeeCapCmp compares the fee cap of two transactions.
|
||||
func (tx *Transaction) FeeCapCmp(other *Transaction) int {
|
||||
return tx.inner.feeCap().Cmp(other.inner.feeCap())
|
||||
// GasFeeCapCmp compares the fee cap of two transactions.
|
||||
func (tx *Transaction) GasFeeCapCmp(other *Transaction) int {
|
||||
return tx.inner.gasFeeCap().Cmp(other.inner.gasFeeCap())
|
||||
}
|
||||
|
||||
// FeeCapIntCmp compares the fee cap of the transaction against the given fee cap.
|
||||
func (tx *Transaction) FeeCapIntCmp(other *big.Int) int {
|
||||
return tx.inner.feeCap().Cmp(other)
|
||||
// GasFeeCapIntCmp compares the fee cap of the transaction against the given fee cap.
|
||||
func (tx *Transaction) GasFeeCapIntCmp(other *big.Int) int {
|
||||
return tx.inner.gasFeeCap().Cmp(other)
|
||||
}
|
||||
|
||||
// TipCmp compares the tip of two transactions.
|
||||
func (tx *Transaction) TipCmp(other *Transaction) int {
|
||||
return tx.inner.tip().Cmp(other.inner.tip())
|
||||
// GasTipCapCmp compares the gasTipCap of two transactions.
|
||||
func (tx *Transaction) GasTipCapCmp(other *Transaction) int {
|
||||
return tx.inner.gasTipCap().Cmp(other.inner.gasTipCap())
|
||||
}
|
||||
|
||||
// TipIntCmp compares the tip of the transaction against the given tip.
|
||||
func (tx *Transaction) TipIntCmp(other *big.Int) int {
|
||||
return tx.inner.tip().Cmp(other)
|
||||
// GasTipCapIntCmp compares the gasTipCap of the transaction against the given gasTipCap.
|
||||
func (tx *Transaction) GasTipCapIntCmp(other *big.Int) int {
|
||||
return tx.inner.gasTipCap().Cmp(other)
|
||||
}
|
||||
|
||||
// EffectiveTip returns the effective miner tip for the given base fee.
|
||||
// Note: if the effective tip is negative, this method returns both error
|
||||
// the actual negative value, _and_ ErrFeeCapTooLow
|
||||
func (tx *Transaction) EffectiveTip(baseFee *big.Int) (*big.Int, error) {
|
||||
// EffectiveGasTip returns the effective miner gasTipCap for the given base fee.
|
||||
// Note: if the effective gasTipCap is negative, this method returns both error
|
||||
// the actual negative value, _and_ ErrGasFeeCapTooLow
|
||||
func (tx *Transaction) EffectiveGasTip(baseFee *big.Int) (*big.Int, error) {
|
||||
if baseFee == nil {
|
||||
return tx.Tip(), nil
|
||||
return tx.GasTipCap(), nil
|
||||
}
|
||||
var err error
|
||||
feeCap := tx.FeeCap()
|
||||
if feeCap.Cmp(baseFee) == -1 {
|
||||
err = ErrFeeCapTooLow
|
||||
gasFeeCap := tx.GasFeeCap()
|
||||
if gasFeeCap.Cmp(baseFee) == -1 {
|
||||
err = ErrGasFeeCapTooLow
|
||||
}
|
||||
return math.BigMin(tx.Tip(), feeCap.Sub(feeCap, baseFee)), err
|
||||
return math.BigMin(tx.GasTipCap(), gasFeeCap.Sub(gasFeeCap, baseFee)), err
|
||||
}
|
||||
|
||||
// EffectiveTipValue is identical to EffectiveTip, but does not return an
|
||||
// error in case the effective tip is negative
|
||||
func (tx *Transaction) EffectiveTipValue(baseFee *big.Int) *big.Int {
|
||||
effectiveTip, _ := tx.EffectiveTip(baseFee)
|
||||
// EffectiveGasTipValue is identical to EffectiveGasTip, but does not return an
|
||||
// error in case the effective gasTipCap is negative
|
||||
func (tx *Transaction) EffectiveGasTipValue(baseFee *big.Int) *big.Int {
|
||||
effectiveTip, _ := tx.EffectiveGasTip(baseFee)
|
||||
return effectiveTip
|
||||
}
|
||||
|
||||
// EffectiveTipCmp compares the effective tip of two transactions assuming the given base fee.
|
||||
func (tx *Transaction) EffectiveTipCmp(other *Transaction, baseFee *big.Int) int {
|
||||
// EffectiveGasTipCmp compares the effective gasTipCap of two transactions assuming the given base fee.
|
||||
func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *big.Int) int {
|
||||
if baseFee == nil {
|
||||
return tx.TipCmp(other)
|
||||
return tx.GasTipCapCmp(other)
|
||||
}
|
||||
return tx.EffectiveTipValue(baseFee).Cmp(other.EffectiveTipValue(baseFee))
|
||||
return tx.EffectiveGasTipValue(baseFee).Cmp(other.EffectiveGasTipValue(baseFee))
|
||||
}
|
||||
|
||||
// EffectiveTipIntCmp compares the effective tip of a transaction to the given tip.
|
||||
// EffectiveTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap.
|
||||
func (tx *Transaction) EffectiveTipIntCmp(other *big.Int, baseFee *big.Int) int {
|
||||
if baseFee == nil {
|
||||
return tx.TipIntCmp(other)
|
||||
return tx.GasTipCapIntCmp(other)
|
||||
}
|
||||
return tx.EffectiveTipValue(baseFee).Cmp(other)
|
||||
return tx.EffectiveGasTipValue(baseFee).Cmp(other)
|
||||
}
|
||||
|
||||
// Hash returns the transaction hash.
|
||||
@ -449,17 +449,17 @@ func (s TxByNonce) Len() int { return len(s) }
|
||||
func (s TxByNonce) Less(i, j int) bool { return s[i].Nonce() < s[j].Nonce() }
|
||||
func (s TxByNonce) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
|
||||
|
||||
// TxWithMinerFee wraps a transaction with its gas price or effective miner tip
|
||||
// TxWithMinerFee wraps a transaction with its gas price or effective miner gasTipCap
|
||||
type TxWithMinerFee struct {
|
||||
tx *Transaction
|
||||
minerFee *big.Int
|
||||
}
|
||||
|
||||
// NewTxWithMinerFee creates a wrapped transaction, calculating the effective
|
||||
// miner tip if a base fee is provided.
|
||||
// Returns error in case of a negative effective miner tip.
|
||||
// miner gasTipCap if a base fee is provided.
|
||||
// Returns error in case of a negative effective miner gasTipCap.
|
||||
func NewTxWithMinerFee(tx *Transaction, baseFee *big.Int) (*TxWithMinerFee, error) {
|
||||
minerFee, err := tx.EffectiveTip(baseFee)
|
||||
minerFee, err := tx.EffectiveGasTip(baseFee)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -575,14 +575,14 @@ type Message struct {
|
||||
amount *big.Int
|
||||
gasLimit uint64
|
||||
gasPrice *big.Int
|
||||
feeCap *big.Int
|
||||
tip *big.Int
|
||||
gasFeeCap *big.Int
|
||||
gasTipCap *big.Int
|
||||
data []byte
|
||||
accessList AccessList
|
||||
checkNonce bool
|
||||
}
|
||||
|
||||
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, feeCap, tip *big.Int, data []byte, accessList AccessList, checkNonce bool) Message {
|
||||
func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *big.Int, gasLimit uint64, gasPrice, gasFeeCap, gasTipCap *big.Int, data []byte, accessList AccessList, checkNonce bool) Message {
|
||||
return Message{
|
||||
from: from,
|
||||
to: to,
|
||||
@ -590,8 +590,8 @@ func NewMessage(from common.Address, to *common.Address, nonce uint64, amount *b
|
||||
amount: amount,
|
||||
gasLimit: gasLimit,
|
||||
gasPrice: gasPrice,
|
||||
feeCap: feeCap,
|
||||
tip: tip,
|
||||
gasFeeCap: gasFeeCap,
|
||||
gasTipCap: gasTipCap,
|
||||
data: data,
|
||||
accessList: accessList,
|
||||
checkNonce: checkNonce,
|
||||
@ -604,8 +604,8 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
|
||||
nonce: tx.Nonce(),
|
||||
gasLimit: tx.Gas(),
|
||||
gasPrice: new(big.Int).Set(tx.GasPrice()),
|
||||
feeCap: new(big.Int).Set(tx.FeeCap()),
|
||||
tip: new(big.Int).Set(tx.Tip()),
|
||||
gasFeeCap: new(big.Int).Set(tx.GasFeeCap()),
|
||||
gasTipCap: new(big.Int).Set(tx.GasTipCap()),
|
||||
to: tx.To(),
|
||||
amount: tx.Value(),
|
||||
data: tx.Data(),
|
||||
@ -614,7 +614,7 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
|
||||
}
|
||||
// If baseFee provided, set gasPrice to effectiveGasPrice.
|
||||
if baseFee != nil {
|
||||
msg.gasPrice = math.BigMin(msg.gasPrice.Add(msg.tip, baseFee), msg.feeCap)
|
||||
msg.gasPrice = math.BigMin(msg.gasPrice.Add(msg.gasTipCap, baseFee), msg.gasFeeCap)
|
||||
}
|
||||
var err error
|
||||
msg.from, err = Sender(s, tx)
|
||||
@ -624,8 +624,8 @@ func (tx *Transaction) AsMessage(s Signer, baseFee *big.Int) (Message, error) {
|
||||
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) FeeCap() *big.Int { return m.feeCap }
|
||||
func (m Message) Tip() *big.Int { return m.tip }
|
||||
func (m Message) GasFeeCap() *big.Int { return m.gasFeeCap }
|
||||
func (m Message) GasTipCap() *big.Int { return m.gasTipCap }
|
||||
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 }
|
||||
|
@ -86,8 +86,8 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
|
||||
enc.AccessList = &tx.AccessList
|
||||
enc.Nonce = (*hexutil.Uint64)(&tx.Nonce)
|
||||
enc.Gas = (*hexutil.Uint64)(&tx.Gas)
|
||||
enc.MaxFeePerGas = (*hexutil.Big)(tx.FeeCap)
|
||||
enc.MaxPriorityFeePerGas = (*hexutil.Big)(tx.Tip)
|
||||
enc.MaxFeePerGas = (*hexutil.Big)(tx.GasFeeCap)
|
||||
enc.MaxPriorityFeePerGas = (*hexutil.Big)(tx.GasTipCap)
|
||||
enc.Value = (*hexutil.Big)(tx.Value)
|
||||
enc.Data = (*hexutil.Bytes)(&tx.Data)
|
||||
enc.To = t.To()
|
||||
@ -227,11 +227,11 @@ func (t *Transaction) UnmarshalJSON(input []byte) error {
|
||||
if dec.MaxPriorityFeePerGas == nil {
|
||||
return errors.New("missing required field 'maxPriorityFeePerGas' for txdata")
|
||||
}
|
||||
itx.Tip = (*big.Int)(dec.MaxPriorityFeePerGas)
|
||||
itx.GasTipCap = (*big.Int)(dec.MaxPriorityFeePerGas)
|
||||
if dec.MaxFeePerGas == nil {
|
||||
return errors.New("missing required field 'maxFeePerGas' for txdata")
|
||||
}
|
||||
itx.FeeCap = (*big.Int)(dec.MaxFeePerGas)
|
||||
itx.GasFeeCap = (*big.Int)(dec.MaxFeePerGas)
|
||||
if dec.Gas == nil {
|
||||
return errors.New("missing required field 'gas' for txdata")
|
||||
}
|
||||
|
@ -226,8 +226,8 @@ func (s londonSigner) Hash(tx *Transaction) common.Hash {
|
||||
[]interface{}{
|
||||
s.chainId,
|
||||
tx.Nonce(),
|
||||
tx.Tip(),
|
||||
tx.FeeCap(),
|
||||
tx.GasTipCap(),
|
||||
tx.GasFeeCap(),
|
||||
tx.Gas(),
|
||||
tx.To(),
|
||||
tx.Value(),
|
||||
|
@ -288,14 +288,14 @@ func testTransactionPriceNonceSort(t *testing.T, baseFee *big.Int) {
|
||||
count := 25
|
||||
for i := 0; i < 25; i++ {
|
||||
var tx *Transaction
|
||||
feeCap := rand.Intn(50)
|
||||
gasFeeCap := rand.Intn(50)
|
||||
if baseFee == nil {
|
||||
tx = NewTx(&LegacyTx{
|
||||
Nonce: uint64(start + i),
|
||||
To: &common.Address{},
|
||||
Value: big.NewInt(100),
|
||||
Gas: 100,
|
||||
GasPrice: big.NewInt(int64(feeCap)),
|
||||
GasPrice: big.NewInt(int64(gasFeeCap)),
|
||||
Data: nil,
|
||||
})
|
||||
} else {
|
||||
@ -304,11 +304,11 @@ func testTransactionPriceNonceSort(t *testing.T, baseFee *big.Int) {
|
||||
To: &common.Address{},
|
||||
Value: big.NewInt(100),
|
||||
Gas: 100,
|
||||
FeeCap: big.NewInt(int64(feeCap)),
|
||||
Tip: big.NewInt(int64(rand.Intn(feeCap + 1))),
|
||||
GasFeeCap: big.NewInt(int64(gasFeeCap)),
|
||||
GasTipCap: big.NewInt(int64(rand.Intn(gasFeeCap + 1))),
|
||||
Data: nil,
|
||||
})
|
||||
if count == 25 && int64(feeCap) < baseFee.Int64() {
|
||||
if count == 25 && int64(gasFeeCap) < baseFee.Int64() {
|
||||
count = i
|
||||
}
|
||||
}
|
||||
@ -345,8 +345,8 @@ func testTransactionPriceNonceSort(t *testing.T, baseFee *big.Int) {
|
||||
if i+1 < len(txs) {
|
||||
next := txs[i+1]
|
||||
fromNext, _ := Sender(signer, next)
|
||||
tip, err := txi.EffectiveTip(baseFee)
|
||||
nextTip, nextErr := next.EffectiveTip(baseFee)
|
||||
tip, err := txi.EffectiveGasTip(baseFee)
|
||||
nextTip, nextErr := next.EffectiveGasTip(baseFee)
|
||||
if err != nil || nextErr != nil {
|
||||
t.Errorf("error calculating effective tip")
|
||||
}
|
||||
|
@ -210,8 +210,8 @@ func (s *txSorter) Swap(i, j int) {
|
||||
func (s *txSorter) Less(i, j int) bool {
|
||||
// It's okay to discard the error because a tx would never be
|
||||
// accepted into a block with an invalid effective tip.
|
||||
tip1, _ := s.txs[i].EffectiveTip(s.baseFee)
|
||||
tip2, _ := s.txs[j].EffectiveTip(s.baseFee)
|
||||
tip1, _ := s.txs[i].EffectiveGasTip(s.baseFee)
|
||||
tip2, _ := s.txs[j].EffectiveGasTip(s.baseFee)
|
||||
return tip1.Cmp(tip2) < 0
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ func (gpo *Oracle) getBlockValues(ctx context.Context, signer types.Signer, bloc
|
||||
|
||||
var prices []*big.Int
|
||||
for _, tx := range sorter.txs {
|
||||
tip, _ := tx.EffectiveTip(block.BaseFee())
|
||||
tip, _ := tx.EffectiveGasTip(block.BaseFee())
|
||||
if ignoreUnder != nil && tip.Cmp(ignoreUnder) == -1 {
|
||||
continue
|
||||
}
|
||||
|
@ -84,8 +84,8 @@ func newTestBackend(t *testing.T, londonBlock *big.Int) *testBackend {
|
||||
Nonce: b.TxNonce(addr),
|
||||
To: &common.Address{},
|
||||
Gas: 30000,
|
||||
FeeCap: big.NewInt(100 * params.GWei),
|
||||
Tip: big.NewInt(int64(i+1) * params.GWei),
|
||||
GasFeeCap: big.NewInt(100 * params.GWei),
|
||||
GasTipCap: big.NewInt(int64(i+1) * params.GWei),
|
||||
Data: []byte{},
|
||||
}
|
||||
tx = types.NewTx(txdata)
|
||||
|
@ -21,12 +21,14 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum"
|
||||
"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/core/rawdb"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
@ -218,7 +220,50 @@ func (t *Transaction) GasPrice(ctx context.Context) (hexutil.Big, error) {
|
||||
if err != nil || tx == nil {
|
||||
return hexutil.Big{}, err
|
||||
}
|
||||
switch tx.Type() {
|
||||
case types.AccessListTxType:
|
||||
return hexutil.Big(*tx.GasPrice()), nil
|
||||
case types.DynamicFeeTxType:
|
||||
if t.block != nil {
|
||||
if baseFee, _ := t.block.BaseFeePerGas(ctx); baseFee != nil {
|
||||
// price = min(tip, gasFeeCap - baseFee) + baseFee
|
||||
return (hexutil.Big)(*math.BigMin(new(big.Int).Add(tx.GasTipCap(), baseFee.ToInt()), tx.GasFeeCap())), nil
|
||||
}
|
||||
}
|
||||
return hexutil.Big(*tx.GasPrice()), nil
|
||||
default:
|
||||
return hexutil.Big(*tx.GasPrice()), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Transaction) MaxFeePerGas(ctx context.Context) (*hexutil.Big, error) {
|
||||
tx, err := t.resolve(ctx)
|
||||
if err != nil || tx == nil {
|
||||
return nil, err
|
||||
}
|
||||
switch tx.Type() {
|
||||
case types.AccessListTxType:
|
||||
return nil, nil
|
||||
case types.DynamicFeeTxType:
|
||||
return (*hexutil.Big)(tx.GasFeeCap()), nil
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Transaction) MaxPriorityFeePerGas(ctx context.Context) (*hexutil.Big, error) {
|
||||
tx, err := t.resolve(ctx)
|
||||
if err != nil || tx == nil {
|
||||
return nil, err
|
||||
}
|
||||
switch tx.Type() {
|
||||
case types.AccessListTxType:
|
||||
return nil, nil
|
||||
case types.DynamicFeeTxType:
|
||||
return (*hexutil.Big)(tx.GasTipCap()), nil
|
||||
default:
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Transaction) Value(ctx context.Context) (hexutil.Big, error) {
|
||||
@ -517,6 +562,17 @@ func (b *Block) GasUsed(ctx context.Context) (Long, error) {
|
||||
return Long(header.GasUsed), nil
|
||||
}
|
||||
|
||||
func (b *Block) BaseFeePerGas(ctx context.Context) (*hexutil.Big, error) {
|
||||
header, err := b.resolveHeader(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if header.BaseFee == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return (*hexutil.Big)(header.BaseFee), nil
|
||||
}
|
||||
|
||||
func (b *Block) Parent(ctx context.Context) (*Block, error) {
|
||||
// If the block header hasn't been fetched, and we'll need it, fetch it.
|
||||
if b.numberOrHash == nil && b.header == nil {
|
||||
@ -837,6 +893,8 @@ type CallData struct {
|
||||
To *common.Address // The Ethereum address the call is to.
|
||||
Gas *hexutil.Uint64 // The amount of gas provided for the call.
|
||||
GasPrice *hexutil.Big // The price of each unit of gas, in wei.
|
||||
MaxFeePerGas *hexutil.Big // The max price of each unit of gas, in wei (1559).
|
||||
MaxPriorityFeePerGas *hexutil.Big // The max tip of each unit of gas, in wei (1559).
|
||||
Value *hexutil.Big // The value sent along with the call.
|
||||
Data *hexutil.Bytes // Any data sent with the call.
|
||||
}
|
||||
|
@ -94,6 +94,10 @@ const schema string = `
|
||||
value: BigInt!
|
||||
# GasPrice is the price offered to miners for gas, in wei per unit.
|
||||
gasPrice: BigInt!
|
||||
# MaxFeePerGas is the maximum fee per gas offered to include a transaction, in wei.
|
||||
maxFeePerGas: BigInt
|
||||
# MaxPriorityFeePerGas is the maximum miner tip per gas offered to include a transaction, in wei.
|
||||
maxPriorityFeePerGas: BigInt
|
||||
# Gas is the maximum amount of gas this transaction can consume.
|
||||
gas: Long!
|
||||
# InputData is the data supplied to the target of the transaction.
|
||||
@ -176,6 +180,8 @@ const schema string = `
|
||||
gasLimit: Long!
|
||||
# GasUsed is the amount of gas that was used executing transactions in this block.
|
||||
gasUsed: Long!
|
||||
# BaseFeePerGas is the fee perunit of gas burned by the protocol in this block.
|
||||
baseFeePerGas: BigInt
|
||||
# Timestamp is the unix timestamp at which this block was mined.
|
||||
timestamp: Long!
|
||||
# LogsBloom is a bloom filter that can be used to check if a block may
|
||||
@ -231,6 +237,10 @@ const schema string = `
|
||||
gas: Long
|
||||
# GasPrice is the price, in wei, offered for each unit of gas.
|
||||
gasPrice: BigInt
|
||||
# MaxFeePerGas is the maximum fee per gas offered, in wei.
|
||||
maxFeePerGas: BigInt
|
||||
# MaxPriorityFeePerGas is the maximum miner tip per gas offered, in wei.
|
||||
maxPriorityFeePerGas: BigInt
|
||||
# Value is the value, in wei, sent along with the call.
|
||||
value: BigInt
|
||||
# Data is the data sent to the callee.
|
||||
|
@ -117,12 +117,11 @@ type CallMsg struct {
|
||||
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
|
||||
GasFeeCap *big.Int // EIP-1559 fee cap per gas.
|
||||
GasTipCap *big.Int // EIP-1559 tip per gas.
|
||||
Value *big.Int // amount of wei sent along with the call
|
||||
Data []byte // input data, usually an ABI-encoded contract method invocation
|
||||
|
||||
FeeCap *big.Int // EIP-1559 fee cap per gas.
|
||||
Tip *big.Int // EIP-1559 tip per gas.
|
||||
|
||||
AccessList types.AccessList // EIP-2930 access list.
|
||||
}
|
||||
|
||||
|
@ -1198,8 +1198,8 @@ type RPCTransaction struct {
|
||||
From common.Address `json:"from"`
|
||||
Gas hexutil.Uint64 `json:"gas"`
|
||||
GasPrice *hexutil.Big `json:"gasPrice"`
|
||||
FeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
|
||||
Tip *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
|
||||
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
|
||||
GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
|
||||
Hash common.Hash `json:"hash"`
|
||||
Input hexutil.Bytes `json:"input"`
|
||||
Nonce hexutil.Uint64 `json:"nonce"`
|
||||
@ -1257,12 +1257,12 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
|
||||
al := tx.AccessList()
|
||||
result.Accesses = &al
|
||||
result.ChainID = (*hexutil.Big)(tx.ChainId())
|
||||
result.FeeCap = (*hexutil.Big)(tx.FeeCap())
|
||||
result.Tip = (*hexutil.Big)(tx.Tip())
|
||||
result.GasFeeCap = (*hexutil.Big)(tx.GasFeeCap())
|
||||
result.GasTipCap = (*hexutil.Big)(tx.GasTipCap())
|
||||
// if the transaction has been mined, compute the effective gas price
|
||||
if baseFee != nil && blockHash != (common.Hash{}) {
|
||||
// price = min(tip, feeCap - baseFee) + baseFee
|
||||
price := math.BigMin(new(big.Int).Add(tx.Tip(), baseFee), tx.FeeCap())
|
||||
// price = min(tip, gasFeeCap - baseFee) + baseFee
|
||||
price := math.BigMin(new(big.Int).Add(tx.GasTipCap(), baseFee), tx.GasFeeCap())
|
||||
result.GasPrice = (*hexutil.Big)(price)
|
||||
} else {
|
||||
result.GasPrice = nil
|
||||
|
@ -38,8 +38,8 @@ type TransactionArgs struct {
|
||||
To *common.Address `json:"to"`
|
||||
Gas *hexutil.Uint64 `json:"gas"`
|
||||
GasPrice *hexutil.Big `json:"gasPrice"`
|
||||
FeeCap *hexutil.Big `json:"maxFeePerGas"`
|
||||
Tip *hexutil.Big `json:"maxPriorityFeePerGas"`
|
||||
MaxFeePerGas *hexutil.Big `json:"maxFeePerGas"`
|
||||
MaxPriorityFeePerGas *hexutil.Big `json:"maxPriorityFeePerGas"`
|
||||
Value *hexutil.Big `json:"value"`
|
||||
Nonce *hexutil.Uint64 `json:"nonce"`
|
||||
|
||||
@ -75,31 +75,31 @@ func (arg *TransactionArgs) data() []byte {
|
||||
|
||||
// setDefaults fills in default values for unspecified tx fields.
|
||||
func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
|
||||
if args.GasPrice != nil && (args.FeeCap != nil || args.Tip != nil) {
|
||||
if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) {
|
||||
return errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
|
||||
}
|
||||
// After london, default to 1559 unless gasPrice is set
|
||||
head := b.CurrentHeader()
|
||||
if b.ChainConfig().IsLondon(head.Number) && args.GasPrice == nil {
|
||||
if args.Tip == nil {
|
||||
if args.MaxPriorityFeePerGas == nil {
|
||||
tip, err := b.SuggestGasTipCap(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args.Tip = (*hexutil.Big)(tip)
|
||||
args.MaxPriorityFeePerGas = (*hexutil.Big)(tip)
|
||||
}
|
||||
if args.FeeCap == nil {
|
||||
feeCap := new(big.Int).Add(
|
||||
(*big.Int)(args.Tip),
|
||||
if args.MaxFeePerGas == nil {
|
||||
gasFeeCap := new(big.Int).Add(
|
||||
(*big.Int)(args.MaxPriorityFeePerGas),
|
||||
new(big.Int).Mul(head.BaseFee, big.NewInt(2)),
|
||||
)
|
||||
args.FeeCap = (*hexutil.Big)(feeCap)
|
||||
args.MaxFeePerGas = (*hexutil.Big)(gasFeeCap)
|
||||
}
|
||||
if args.FeeCap.ToInt().Cmp(args.Tip.ToInt()) < 0 {
|
||||
return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.FeeCap, args.Tip)
|
||||
if args.MaxFeePerGas.ToInt().Cmp(args.MaxPriorityFeePerGas.ToInt()) < 0 {
|
||||
return fmt.Errorf("maxFeePerGas (%v) < maxPriorityFeePerGas (%v)", args.MaxFeePerGas, args.MaxPriorityFeePerGas)
|
||||
}
|
||||
} else {
|
||||
if args.FeeCap != nil || args.Tip != nil {
|
||||
if args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil {
|
||||
return errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet")
|
||||
}
|
||||
if args.GasPrice == nil {
|
||||
@ -137,8 +137,8 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
|
||||
From: args.From,
|
||||
To: args.To,
|
||||
GasPrice: args.GasPrice,
|
||||
FeeCap: args.FeeCap,
|
||||
Tip: args.Tip,
|
||||
MaxFeePerGas: args.MaxFeePerGas,
|
||||
MaxPriorityFeePerGas: args.MaxPriorityFeePerGas,
|
||||
Value: args.Value,
|
||||
Data: args.Data,
|
||||
AccessList: args.AccessList,
|
||||
@ -161,7 +161,7 @@ func (args *TransactionArgs) setDefaults(ctx context.Context, b Backend) error {
|
||||
// ToMessage converts TransactionArgs to the Message type used by the core evm
|
||||
func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (types.Message, error) {
|
||||
// Reject invalid combinations of pre- and post-1559 fee styles
|
||||
if args.GasPrice != nil && (args.FeeCap != nil || args.Tip != nil) {
|
||||
if args.GasPrice != nil && (args.MaxFeePerGas != nil || args.MaxPriorityFeePerGas != nil) {
|
||||
return types.Message{}, errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
|
||||
}
|
||||
// Set sender address or use zero address if none specified.
|
||||
@ -181,8 +181,8 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
|
||||
}
|
||||
var (
|
||||
gasPrice *big.Int
|
||||
feeCap *big.Int
|
||||
tip *big.Int
|
||||
gasFeeCap *big.Int
|
||||
gasTipCap *big.Int
|
||||
)
|
||||
if baseFee == nil {
|
||||
// If there's no basefee, then it must be a non-1559 execution
|
||||
@ -190,22 +190,22 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
|
||||
if args.GasPrice != nil {
|
||||
gasPrice = args.GasPrice.ToInt()
|
||||
}
|
||||
feeCap, tip = gasPrice, gasPrice
|
||||
gasFeeCap, gasTipCap = gasPrice, gasPrice
|
||||
} else {
|
||||
// A basefee is provided, necessitating 1559-type execution
|
||||
if args.GasPrice != nil {
|
||||
gasPrice = args.GasPrice.ToInt()
|
||||
feeCap, tip = gasPrice, gasPrice
|
||||
gasFeeCap, gasTipCap = gasPrice, gasPrice
|
||||
} else {
|
||||
feeCap = new(big.Int)
|
||||
if args.FeeCap != nil {
|
||||
feeCap = args.FeeCap.ToInt()
|
||||
gasFeeCap = new(big.Int)
|
||||
if args.MaxFeePerGas != nil {
|
||||
gasFeeCap = args.MaxFeePerGas.ToInt()
|
||||
}
|
||||
tip = new(big.Int)
|
||||
if args.Tip != nil {
|
||||
tip = args.Tip.ToInt()
|
||||
gasTipCap = new(big.Int)
|
||||
if args.MaxPriorityFeePerGas != nil {
|
||||
gasTipCap = args.MaxPriorityFeePerGas.ToInt()
|
||||
}
|
||||
gasPrice = math.BigMin(new(big.Int).Add(tip, baseFee), feeCap)
|
||||
gasPrice = math.BigMin(new(big.Int).Add(gasTipCap, baseFee), gasFeeCap)
|
||||
}
|
||||
}
|
||||
value := new(big.Int)
|
||||
@ -217,7 +217,7 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
|
||||
if args.AccessList != nil {
|
||||
accessList = *args.AccessList
|
||||
}
|
||||
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, feeCap, tip, data, accessList, false)
|
||||
msg := types.NewMessage(addr, args.To, 0, value, gas, gasPrice, gasFeeCap, gasTipCap, data, accessList, false)
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
@ -226,7 +226,7 @@ func (args *TransactionArgs) ToMessage(globalGasCap uint64, baseFee *big.Int) (t
|
||||
func (args *TransactionArgs) toTransaction() *types.Transaction {
|
||||
var data types.TxData
|
||||
switch {
|
||||
case args.FeeCap != nil:
|
||||
case args.MaxFeePerGas != nil:
|
||||
al := types.AccessList{}
|
||||
if args.AccessList != nil {
|
||||
al = *args.AccessList
|
||||
@ -236,8 +236,8 @@ func (args *TransactionArgs) toTransaction() *types.Transaction {
|
||||
ChainID: (*big.Int)(args.ChainID),
|
||||
Nonce: uint64(*args.Nonce),
|
||||
Gas: uint64(*args.Gas),
|
||||
FeeCap: (*big.Int)(args.FeeCap),
|
||||
Tip: (*big.Int)(args.Tip),
|
||||
GasFeeCap: (*big.Int)(args.MaxFeePerGas),
|
||||
GasTipCap: (*big.Int)(args.MaxPriorityFeePerGas),
|
||||
Value: (*big.Int)(args.Value),
|
||||
Data: args.data(),
|
||||
AccessList: al,
|
||||
|
@ -155,7 +155,7 @@ func makeTransaction(nonce uint64, privKey *ecdsa.PrivateKey, signer types.Signe
|
||||
// larger buffer for creating both valid and invalid transactions.
|
||||
var buf = make([]byte, 32+5)
|
||||
rand.Read(buf)
|
||||
tip := new(big.Int).SetBytes(buf)
|
||||
gasTipCap := new(big.Int).SetBytes(buf)
|
||||
|
||||
// If the given base fee is nil(the 1559 is still not available),
|
||||
// generate a fake base fee in order to create 1559 tx forcibly.
|
||||
@ -163,18 +163,18 @@ func makeTransaction(nonce uint64, privKey *ecdsa.PrivateKey, signer types.Signe
|
||||
baseFee = new(big.Int).SetInt64(int64(rand.Int31()))
|
||||
}
|
||||
// Generate the feecap, 75% valid feecap and 25% unguaranted.
|
||||
var feeCap *big.Int
|
||||
var gasFeeCap *big.Int
|
||||
if rand.Intn(4) == 0 {
|
||||
rand.Read(buf)
|
||||
feeCap = new(big.Int).SetBytes(buf)
|
||||
gasFeeCap = new(big.Int).SetBytes(buf)
|
||||
} else {
|
||||
feeCap = new(big.Int).Add(baseFee, tip)
|
||||
gasFeeCap = new(big.Int).Add(baseFee, gasTipCap)
|
||||
}
|
||||
return types.MustSignNewTx(privKey, signer, &types.DynamicFeeTx{
|
||||
ChainID: signer.ChainID(),
|
||||
Nonce: nonce,
|
||||
Tip: tip,
|
||||
FeeCap: feeCap,
|
||||
GasTipCap: gasTipCap,
|
||||
GasFeeCap: gasFeeCap,
|
||||
Gas: 21000,
|
||||
To: &recipient,
|
||||
Value: big.NewInt(100),
|
||||
|
@ -1052,7 +1052,7 @@ func (w *worker) postSideBlock(event core.ChainSideEvent) {
|
||||
func totalFees(block *types.Block, receipts []*types.Receipt) *big.Float {
|
||||
feesWei := new(big.Int)
|
||||
for i, tx := range block.Transactions() {
|
||||
minerFee, _ := tx.EffectiveTip(block.BaseFee())
|
||||
minerFee, _ := tx.EffectiveGasTip(block.BaseFee())
|
||||
feesWei.Add(feesWei, new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), minerFee))
|
||||
}
|
||||
return new(big.Float).Quo(new(big.Float).SetInt(feesWei), new(big.Float).SetInt(big.NewInt(params.Ether)))
|
||||
|
Loading…
Reference in New Issue
Block a user