misc fixes

This commit is contained in:
Ian Norden
2020-07-03 14:36:06 -05:00
parent 8ff850db74
commit d7aa9ccf9f
14 changed files with 63 additions and 55 deletions
+9 -5
View File
@@ -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) {
+8 -8
View File
@@ -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)
+13 -16
View File
@@ -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 {
+1 -1
View File
@@ -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"
)
+1 -1
View File
@@ -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"
+2 -2
View File
@@ -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())
+6 -4
View File
@@ -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
+2 -5
View File
@@ -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)
+12 -6
View File
@@ -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) {
+5 -3
View File
@@ -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) {
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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},
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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{