From d7aa9ccf9fd0adc8edb542c5cf57def3ff5a2665 Mon Sep 17 00:00:00 2001 From: Ian Norden Date: Sun, 2 Feb 2020 16:49:44 -0600 Subject: [PATCH] misc fixes --- accounts/abi/bind/backends/simulated.go | 14 ++++++---- accounts/abi/bind/backends/simulated_test.go | 16 +++++------ cmd/clef/main.go | 29 +++++++++----------- consensus/clique/clique.go | 2 +- consensus/ethash/consensus.go | 2 +- core/tx_list.go | 4 +-- core/tx_pool.go | 10 ++++--- core/tx_pool_test.go | 7 ++--- internal/ethapi/api.go | 18 ++++++++---- light/txpool.go | 8 ++++-- miner/worker.go | 2 +- rlp/decode_test.go | 2 +- signer/fourbyte/validation_test.go | 2 +- signer/rules/rules_test.go | 2 +- 14 files changed, 63 insertions(+), 55 deletions(-) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 4bd56a811..b932bf1a9 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -553,19 +553,21 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM // Ensure message is initialized properly. // EIP1559 guards // If we have finalized EIP1559 and do not have a properly formed EIP1559 trx, sub in default values - if b.config.IsEIP1559Finalized(block.Number()) && (call.GasPremium == nil || call.FeeCap == nil || call.GasPrice != nil) { + 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) call.GasPrice = nil } // If we have not activated EIP1559 and do not have a properly formed legacy trx, sub in default values - if !b.config.IsEIP1559(block.Number()) && (call.GasPremium != nil || call.FeeCap != nil || call.GasPrice == nil) { + if !eip1559 && (call.GasPremium != nil || call.FeeCap != nil || call.GasPrice == nil) { call.GasPremium = nil call.FeeCap = nil call.GasPrice = big.NewInt(1) } // If we are in between activation and finalization - if b.config.IsEIP1559(block.Number()) && !b.config.IsEIP1559Finalized(block.Number()) { + 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 @@ -605,10 +607,12 @@ func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transa defer b.mu.Unlock() // EIP1559 guards - if b.config.IsEIP1559Finalized(b.blockchain.CurrentBlock().Number()) && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { + eip1559 := b.config.IsEIP1559(b.blockchain.CurrentBlock().Number()) + eip1559Finalized := b.config.IsEIP1559Finalized(b.blockchain.CurrentBlock().Number()) + if eip1559Finalized && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { return core.ErrTxNotEIP1559 } - if !b.config.IsEIP1559(b.blockchain.CurrentBlock().Number()) && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { + if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { return core.ErrTxIsEIP1559 } if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) { diff --git a/accounts/abi/bind/backends/simulated_test.go b/accounts/abi/bind/backends/simulated_test.go index 2aa935faa..9fb42c305 100644 --- a/accounts/abi/bind/backends/simulated_test.go +++ b/accounts/abi/bind/backends/simulated_test.go @@ -244,7 +244,7 @@ func TestSimulatedBackend_NonceAt(t *testing.T) { } // create a signed transaction to send - tx := types.NewTransaction(nonce, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) + tx := types.NewTransaction(nonce, testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -285,7 +285,7 @@ func TestSimulatedBackend_SendTransaction(t *testing.T) { bgCtx := context.Background() // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -320,7 +320,7 @@ func TestSimulatedBackend_TransactionByHash(t *testing.T) { bgCtx := context.Background() // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -633,7 +633,7 @@ func TestSimulatedBackend_TransactionCount(t *testing.T) { } // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -688,7 +688,7 @@ func TestSimulatedBackend_TransactionInBlock(t *testing.T) { } // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -743,7 +743,7 @@ func TestSimulatedBackend_PendingNonceAt(t *testing.T) { } // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -766,7 +766,7 @@ func TestSimulatedBackend_PendingNonceAt(t *testing.T) { } // make a new transaction with a nonce of 1 - tx = types.NewTransaction(uint64(1), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) + tx = types.NewTransaction(uint64(1), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil) signedTx, err = types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) @@ -795,7 +795,7 @@ func TestSimulatedBackend_TransactionReceipt(t *testing.T) { bgCtx := context.Background() // create a signed transaction to send - tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil) + tx := types.NewTransaction(uint64(0), testAddr, big.NewInt(1000), params.TxGas, big.NewInt(1), nil, nil, nil) signedTx, err := types.SignTx(tx, types.HomesteadSigner{}, testKey) if err != nil { t.Errorf("could not sign tx: %v", err) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index 0db36357f..483c0b616 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -821,22 +821,19 @@ func testExternalUI(api *core.SignerAPI) { api.UI.ShowInfo("Please approve the next request for signing a clique header") time.Sleep(delay) cliqueHeader := types.Header{ - common.HexToHash("0000H45H"), - common.HexToHash("0000H45H"), - common.HexToAddress("0000H45H"), - common.HexToHash("0000H00H"), - common.HexToHash("0000H45H"), - common.HexToHash("0000H45H"), - types.Bloom{}, - big.NewInt(1337), - big.NewInt(1337), - 1338, - 1338, - 1338, - []byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"), - common.HexToHash("0x0000H45H"), - types.BlockNonce{}, - nil, + ParentHash: common.HexToHash("0000H45H"), + UncleHash: common.HexToHash("0000H45H"), + Coinbase: common.HexToAddress("0000H45H"), + Root: common.HexToHash("0000H00H"), + TxHash: common.HexToHash("0000H45H"), + ReceiptHash: common.HexToHash("0000H45H"), + Difficulty: big.NewInt(1337), + Number: big.NewInt(1337), + GasLimit: 1338, + GasUsed: 1338, + Time: 1338, + Extra: []byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"), + MixDigest: common.HexToHash("0x0000H45H"), } cliqueRlp, err := rlp.EncodeToBytes(cliqueHeader) if err != nil { diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index a3a696446..1f896787b 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -39,7 +39,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" - "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru" "golang.org/x/crypto/sha3" ) diff --git a/consensus/ethash/consensus.go b/consensus/ethash/consensus.go index 0240689d1..690065640 100644 --- a/consensus/ethash/consensus.go +++ b/consensus/ethash/consensus.go @@ -24,7 +24,7 @@ import ( "runtime" "time" - "github.com/deckarep/golang-set" + mapset "github.com/deckarep/golang-set" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/consensus" diff --git a/core/tx_list.go b/core/tx_list.go index edc94b85f..e7518401d 100644 --- a/core/tx_list.go +++ b/core/tx_list.go @@ -545,7 +545,7 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo } // Discard stale price points if found at the heap start for len(l.items.txs) > 0 { - head := []*types.Transaction(l.items.txs)[0] + head := l.items.txs[0] if l.all.Get(head.Hash()) == nil { l.stales-- heap.Pop(l.items) @@ -558,7 +558,7 @@ func (l *txPricedList) Underpriced(tx *types.Transaction, local *accountSet) boo log.Error("Pricing query for empty pool") // This cannot happen, print to catch programming errors return false } - cheapest := []*types.Transaction(l.items.txs)[0] + cheapest := l.items.txs[0] cheapestPrice := cheapest.GasPrice() if cheapestPrice == nil { cheapestPrice = new(big.Int).Add(l.items.baseFee, cheapest.GasPremium()) diff --git a/core/tx_pool.go b/core/tx_pool.go index 365b2cbb9..f19df6ed5 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -561,13 +561,15 @@ func (pool *TxPool) local() map[common.Address]types.Transactions { // rules and adheres to some heuristic limits of the local node (price and size). func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { // EIP1559 guards - if pool.chainconfig.IsEIP1559(pool.chain.CurrentBlock().Number()) && pool.chain.CurrentBlock().BaseFee() == nil { + eip1559 := pool.chainconfig.IsEIP1559(pool.chain.CurrentBlock().Number()) + eip1559Finalized := pool.chainconfig.IsEIP1559Finalized(pool.chain.CurrentBlock().Number()) + if eip1559 && pool.chain.CurrentBlock().BaseFee() == nil { return ErrNoBaseFee } - if pool.chainconfig.IsEIP1559Finalized(pool.chain.CurrentBlock().Number()) && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { + if eip1559Finalized && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { return ErrTxNotEIP1559 } - if !pool.chainconfig.IsEIP1559(pool.chain.CurrentBlock().Number()) && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { + if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { return ErrTxIsEIP1559 } if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) { @@ -592,7 +594,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error { return ErrOversizedData } // If the transactions gas usage is above the per-tx limit, reject it - if tx.Gas() > pool.perTxGasLimit { + if eip1559 && tx.Gas() > pool.perTxGasLimit { return ErrExceedGasLimit } // Transactions can't be negative. This may never happen using RLP decoded diff --git a/core/tx_pool_test.go b/core/tx_pool_test.go index e25649e69..8392dc2e0 100644 --- a/core/tx_pool_test.go +++ b/core/tx_pool_test.go @@ -3741,11 +3741,8 @@ func TestTransactionPoolUnderpricingEIP1559(t *testing.T) { if pending != 2 { t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 2) } - if queued != 1 { - t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 1) - } - if err := validateEvents(events, 3); err != nil { - t.Fatalf("original event firing failed: %v", err) + if queued != 2 { + t.Fatalf("queued transactions mismatched: have %d, want %d", queued, 2) } if err := validateEvents(events, 1); err != nil { t.Fatalf("additional event firing failed: %v", err) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index eb4886131..89243b52f 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -808,10 +808,12 @@ func DoCall(ctx context.Context, b Backend, args CallArgs, blockNrOrHash rpc.Blo defer func(start time.Time) { log.Debug("Executing EVM call finished", "runtime", time.Since(start)) }(time.Now()) // EIP1559 guards - if b.ChainConfig().IsEIP1559Finalized(b.CurrentBlock().Number()) && (args.GasPremium == nil || args.FeeCap == nil || args.GasPrice != nil) { + eip1559 := b.ChainConfig().IsEIP1559(b.CurrentBlock().Number()) + eip1559Finalized := b.ChainConfig().IsEIP1559Finalized(b.CurrentBlock().Number()) + if eip1559Finalized && (args.GasPremium == nil || args.FeeCap == nil || args.GasPrice != nil) { return nil, 0, false, core.ErrTxNotEIP1559 } - if !b.ChainConfig().IsEIP1559(b.CurrentBlock().Number()) && (args.GasPremium != nil || args.FeeCap != nil || args.GasPrice == nil) { + if !eip1559 && (args.GasPremium != nil || args.FeeCap != nil || args.GasPrice == nil) { return nil, 0, false, core.ErrTxIsEIP1559 } if args.GasPrice != nil && (args.GasPremium != nil || args.FeeCap != nil) { @@ -1491,10 +1493,12 @@ type SendTxArgs struct { // setDefaults is a helper function that fills in default values for unspecified tx fields. func (args *SendTxArgs) setDefaults(ctx context.Context, b Backend) error { // EIP1559 guards - if b.ChainConfig().IsEIP1559Finalized(b.CurrentBlock().Number()) && (args.GasPremium == nil || args.FeeCap == nil || args.GasPrice != nil) { + eip1559 := b.ChainConfig().IsEIP1559(b.CurrentBlock().Number()) + eip1559Finalized := b.ChainConfig().IsEIP1559Finalized(b.CurrentBlock().Number()) + if eip1559Finalized && (args.GasPremium == nil || args.FeeCap == nil || args.GasPrice != nil) { return core.ErrTxNotEIP1559 } - if !b.ChainConfig().IsEIP1559(b.CurrentBlock().Number()) && (args.GasPremium != nil || args.FeeCap != nil || args.GasPrice == nil) { + if !eip1559 && (args.GasPremium != nil || args.FeeCap != nil || args.GasPrice == nil) { return core.ErrTxIsEIP1559 } if args.GasPrice != nil && (args.GasPremium != nil || args.FeeCap != nil) { @@ -1655,10 +1659,12 @@ func (s *PublicTransactionPoolAPI) SendRawTransaction(ctx context.Context, encod return common.Hash{}, err } // EIP1559 guards - if s.b.ChainConfig().IsEIP1559Finalized(s.b.CurrentBlock().Number()) && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { + eip1559 := s.b.ChainConfig().IsEIP1559(s.b.CurrentBlock().Number()) + eip1559Finalized := s.b.ChainConfig().IsEIP1559Finalized(s.b.CurrentBlock().Number()) + if eip1559Finalized && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { return common.Hash{}, core.ErrTxNotEIP1559 } - if !s.b.ChainConfig().IsEIP1559(s.b.CurrentBlock().Number()) && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { + if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { return common.Hash{}, core.ErrTxIsEIP1559 } if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) { diff --git a/light/txpool.go b/light/txpool.go index 1db3277ac..5a204a4c1 100644 --- a/light/txpool.go +++ b/light/txpool.go @@ -346,13 +346,15 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error header := pool.chain.GetHeaderByHash(pool.head) // EIP1559 guards - if pool.config.IsEIP1559(header.Number) && header.BaseFee == nil { + eip1559 := pool.config.IsEIP1559(header.Number) + eip1559Finalized := pool.config.IsEIP1559Finalized(header.Number) + if eip1559 && header.BaseFee == nil { return core.ErrNoBaseFee } - if pool.config.IsEIP1559Finalized(header.Number) && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { + if eip1559Finalized && (tx.GasPremium() == nil || tx.FeeCap() == nil || tx.GasPrice() != nil) { return core.ErrTxNotEIP1559 } - if !pool.config.IsEIP1559(header.Number) && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { + if !eip1559 && (tx.GasPremium() != nil || tx.FeeCap() != nil || tx.GasPrice() == nil) { return core.ErrTxIsEIP1559 } if tx.GasPrice() != nil && (tx.GasPremium() != nil || tx.FeeCap() != nil) { diff --git a/miner/worker.go b/miner/worker.go index 0a754b6e2..670909bb3 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -24,7 +24,7 @@ import ( "sync/atomic" "time" - "github.com/deckarep/golang-set" + mapset "github.com/deckarep/golang-set" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/misc" diff --git a/rlp/decode_test.go b/rlp/decode_test.go index 167e9974b..9e21898b6 100644 --- a/rlp/decode_test.go +++ b/rlp/decode_test.go @@ -109,7 +109,7 @@ func TestStreamErrors(t *testing.T) { {"C8C9010101010101010101", calls{"List", "Kind"}, nil, ErrElemTooLarge}, {"C3C2010201", calls{"List", "List", "Uint", "Uint", "ListEnd", "Uint"}, nil, EOL}, {"00", calls{"ListEnd"}, nil, errNotInList}, - {"C401020304", calls{"List", "Uint", "ListEnd"}, nil, errNotAtEOL}, + {"C401020304", calls{"List", "Uint", "ListEnd"}, nil, ErrNotAtEOL}, // Non-canonical integers (e.g. leading zero bytes). {"00", calls{"Uint"}, nil, ErrCanonInt}, diff --git a/signer/fourbyte/validation_test.go b/signer/fourbyte/validation_test.go index 0e98cd88e..b088cf309 100644 --- a/signer/fourbyte/validation_test.go +++ b/signer/fourbyte/validation_test.go @@ -60,7 +60,7 @@ func dummyTxArgs(t txtestcase) *core.SendTxArgs { To: to, Value: value, Nonce: n, - GasPrice: gasPrice, + GasPrice: &gasPrice, Gas: gas, Data: data, Input: input, diff --git a/signer/rules/rules_test.go b/signer/rules/rules_test.go index f442cfa14..6c27950c9 100644 --- a/signer/rules/rules_test.go +++ b/signer/rules/rules_test.go @@ -437,7 +437,7 @@ func dummyTx(value hexutil.Big) *core.SignTxRequest { To: to, Value: value, Nonce: n, - GasPrice: gasPrice, + GasPrice: &gasPrice, Gas: gas, }, Callinfo: []core.ValidationInfo{