Skip to content

Commit

Permalink
Geth v1.12.2 nits (#1099)
Browse files Browse the repository at this point in the history
* use upstream cmd/utils

* format nits

* accessor chain format nits

* move chain config func to extra file

* rename AvalancheRules to Rules

* add transitive deps

* remove unnecessary type checks

* remove extra lock

* remove last seen

* format: remove avalanche header

* format: add upstream go-ethereum

* prepare repo for upstream

* more cosmetic changes to reduce diff

* Revert "format: remove avalanche header"

This reverts commit ea6f31d.

* Revert "format: add upstream go-ethereum"

This reverts commit 0fdf3e8.

* Revert "prepare repo for upstream"

This reverts commit ffe9024.

* fix func name

* readd type checks

* allow cmd/utils from upstream

* fix linter

* Revert "use upstream cmd/utils"

This reverts commit 52e2adf.

* Revert "allow cmd/utils from upstream"

This reverts commit 8ed4cb8.

* split flags file

* run UT with race

* remove unneccessary const
  • Loading branch information
ceyonur authored Feb 21, 2024
1 parent 9ba495d commit 7c77dff
Show file tree
Hide file tree
Showing 42 changed files with 417 additions and 341 deletions.
20 changes: 9 additions & 11 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ import (
var (
_ bind.AcceptedContractCaller = (*SimulatedBackend)(nil)
_ bind.ContractBackend = (*SimulatedBackend)(nil)
_ bind.ContractFilterer = (*SimulatedBackend)(nil)
_ bind.ContractTransactor = (*SimulatedBackend)(nil)
_ bind.DeployBackend = (*SimulatedBackend)(nil)

_ interfaces.ChainReader = (*SimulatedBackend)(nil)
Expand Down Expand Up @@ -147,7 +145,7 @@ func (b *SimulatedBackend) Close() error {
return nil
}

// Commit imports all the pending transactions as a single block and starts a
// Commit imports all the accepted transactions as a single block and starts a
// fresh new state.
func (b *SimulatedBackend) Commit(accept bool) common.Hash {
b.mu.Lock()
Expand All @@ -171,7 +169,7 @@ func (b *SimulatedBackend) Commit(accept bool) common.Hash {
return blockHash
}

// Rollback aborts all pending transactions, reverting to the last committed state.
// Rollback aborts all accepted transactions, reverting to the last committed state.
func (b *SimulatedBackend) Rollback() {
b.mu.Lock()
defer b.mu.Unlock()
Expand Down Expand Up @@ -206,7 +204,7 @@ func (b *SimulatedBackend) Fork(ctx context.Context, parent common.Hash) error {
defer b.mu.Unlock()

if len(b.acceptedBlock.Transactions()) != 0 {
return errors.New("pending block dirty")
return errors.New("accepted block dirty")
}
block, err := b.blockByHash(ctx, parent)
if err != nil {
Expand Down Expand Up @@ -293,10 +291,10 @@ func (b *SimulatedBackend) TransactionReceipt(ctx context.Context, txHash common
return receipt, nil
}

// TransactionByHash checks the pool of pending transactions in addition to the
// blockchain. The isPending return value indicates whether the transaction has been
// TransactionByHash checks the pool of accepted transactions in addition to the
// blockchain. The isAccepted return value indicates whether the transaction has been
// mined yet. Note that the transaction may not be part of the canonical chain even if
// it's not pending.
// it's not accepted.
func (b *SimulatedBackend) TransactionByHash(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error) {
b.mu.Lock()
defer b.mu.Unlock()
Expand Down Expand Up @@ -537,7 +535,7 @@ func (b *SimulatedBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, erro
return big.NewInt(1), nil
}

// EstimateGas executes the requested code against the currently pending block/state and
// EstimateGas executes the requested code against the currently accepted block/state and
// returns the used amount of gas.
func (b *SimulatedBackend) EstimateGas(ctx context.Context, call interfaces.CallMsg) (uint64, error) {
b.mu.Lock()
Expand Down Expand Up @@ -641,7 +639,7 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call interfaces.Call
return hi, nil
}

// callContract implements common code between normal and pending contract calls.
// callContract implements common code between normal and accepted contract calls.
// state is modified during execution, make sure to copy it if necessary.
func (b *SimulatedBackend) callContract(ctx context.Context, call interfaces.CallMsg, header *types.Header, stateDB *state.StateDB) (*core.ExecutionResult, error) {
// Gas prices post 1559 need to be initialized
Expand Down Expand Up @@ -711,7 +709,7 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call interfaces.Cal
return core.ApplyMessage(vmEnv, msg, gasPool)
}

// SendTransaction updates the pending block to include the given transaction.
// SendTransaction updates the accepted block to include the given transaction.
func (b *SimulatedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error {
b.mu.Lock()
defer b.mu.Unlock()
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func BindHelper(types []string, abis []string, bytecodes []string, fsigs []map[s
normalized := original
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
// Ensure there is no duplicated identifier
identifiers := callIdentifiers
var identifiers = callIdentifiers
if !original.IsConstant() {
identifiers = transactIdentifiers
}
Expand Down
1 change: 1 addition & 0 deletions accounts/abi/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type Event struct {
// e.g. event foo(uint32 a, int b) = "foo(uint32,int256)"
// Please note that "int" is substitute for its canonical representation "int256"
Sig string

// ID returns the canonical representation of the event's signature used by the
// abi definition to identify event names and types.
ID common.Hash
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func Transaction(ctx *cli.Context) error {
r.Address = sender
}
// Check intrinsic gas
rules := chainConfig.AvalancheRules(new(big.Int), 0)
rules := chainConfig.Rules(new(big.Int), 0)
if gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, rules); err != nil {
r.Error = err
results = append(results, r)
Expand Down
45 changes: 45 additions & 0 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2014 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.

// Package utils contains internal helper functions for go-ethereum commands.
package utils

import (
"fmt"
"io"
"os"
"runtime"
)

// Fatalf formats a message to standard error and exits the program.
// The message is also printed to standard output if standard error
// is redirected to a different file.
func Fatalf(format string, args ...interface{}) {
w := io.MultiWriter(os.Stdout, os.Stderr)
if runtime.GOOS == "windows" {
// The SameFile check below doesn't work on Windows.
// stdout is unlikely to get redirected though, so just print there.
w = os.Stdout
} else {
outf, _ := os.Stdout.Stat()
errf, _ := os.Stderr.Stat()
if outf != nil && errf != nil && os.SameFile(outf, errf) {
w = os.Stderr
}
}
fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
os.Exit(1)
}
23 changes: 0 additions & 23 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,11 @@ package utils

import (
"fmt"
"io"
"os"
"runtime"
"strings"

"github.com/urfave/cli/v2"
)

// Fatalf formats a message to standard error and exits the program.
// The message is also printed to standard output if standard error
// is redirected to a different file.
func Fatalf(format string, args ...interface{}) {
w := io.MultiWriter(os.Stdout, os.Stderr)
if runtime.GOOS == "windows" {
// The SameFile check below doesn't work on Windows.
// stdout is unlikely to get redirected though, so just print there.
w = os.Stdout
} else {
outf, _ := os.Stdout.Stat()
errf, _ := os.Stderr.Stat()
if outf != nil && errf != nil && os.SameFile(outf, errf) {
w = os.Stderr
}
}
fmt.Fprintf(w, "Fatal: "+format+"\n", args...)
os.Exit(1)
}

// CheckExclusive verifies that only a single instance of the provided flags was
// set by the user. Each flag might optionally be followed by a string type to
// specialize it further.
Expand Down
4 changes: 2 additions & 2 deletions core/predicate_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestCheckPredicate(t *testing.T) {
t.Run(name, func(t *testing.T) {
require := require.New(t)
// Create the rules from TestChainConfig and update the predicates based on the test params
rules := params.TestChainConfig.AvalancheRules(common.Big0, 0)
rules := params.TestChainConfig.Rules(common.Big0, 0)
if test.createPredicates != nil {
for address, predicater := range test.createPredicates(t) {
rules.Predicaters[address] = predicater
Expand Down Expand Up @@ -423,7 +423,7 @@ func TestCheckPredicatesOutput(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
require := require.New(t)
// Create the rules from TestChainConfig and update the predicates based on the test params
rules := params.TestChainConfig.AvalancheRules(common.Big0, 0)
rules := params.TestChainConfig.Rules(common.Big0, 0)
predicater := precompileconfig.NewMockPredicater(gomock.NewController(t))
predicater.EXPECT().PredicateGas(gomock.Any()).Return(uint64(0), nil).Times(len(test.testTuple))

Expand Down
11 changes: 4 additions & 7 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type NumberHash struct {
Hash common.Hash
}

// ReadAllHashesInRange retrieves all the hashes assigned to blocks at a certain
// ReadAllHashesInRange retrieves all the hashes assigned to blocks at certain
// heights, both canonical and reorged forks included.
// This method considers both limits to be _inclusive_.
func ReadAllHashesInRange(db ethdb.Iteratee, first, last uint64) []*NumberHash {
Expand Down Expand Up @@ -205,12 +205,11 @@ func WriteHeadBlockHash(db ethdb.KeyValueWriter, hash common.Hash) {

// ReadHeaderRLP retrieves a block header in its raw RLP database encoding.
func ReadHeaderRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
// Then try to look up the data in leveldb.
data, _ := db.Get(headerKey(number, hash))
if len(data) > 0 {
return data
}
return nil // Can't find the data anywhere.
return nil
}

// HasHeader verifies the existence of a block header corresponding to the hash.
Expand Down Expand Up @@ -274,12 +273,11 @@ func deleteHeaderWithoutNumber(db ethdb.KeyValueWriter, hash common.Hash, number

// ReadBodyRLP retrieves the block body (transactions and uncles) in RLP encoding.
func ReadBodyRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
// Then try to look up the data in leveldb.
data, _ := db.Get(blockBodyKey(number, hash))
if len(data) > 0 {
return data
}
return nil // Can't find the data anywhere.
return nil
}

// ReadCanonicalBodyRLP retrieves the block body (transactions and uncles) for the canonical
Expand Down Expand Up @@ -349,12 +347,11 @@ func HasReceipts(db ethdb.Reader, hash common.Hash, number uint64) bool {

// ReadReceiptsRLP retrieves all the transaction receipts belonging to a block in RLP encoding.
func ReadReceiptsRLP(db ethdb.Reader, hash common.Hash, number uint64) rlp.RawValue {
// Then try to look up the data in leveldb.
data, _ := db.Get(blockReceiptsKey(number, hash))
if len(data) > 0 {
return data
}
return nil // Can't find the data anywhere.
return nil
}

// ReadRawReceipts retrieves all the transaction receipts belonging to a block.
Expand Down
10 changes: 0 additions & 10 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"fmt"
"io"
"math/big"
"sync"
"time"

"github.com/ava-labs/subnet-evm/core/types"
Expand Down Expand Up @@ -72,11 +71,6 @@ func (s Storage) Copy() Storage {
// - Account values as well as storages can be accessed and modified through the object.
// - Finally, call commit to return the changes of storage trie and update account data.
type stateObject struct {
// dataLock protects the [data] field to prevent a race condition
// in the transaction pool tests. TODO remove after re-implementing
// tx pool to be synchronous.
dataLock sync.RWMutex

db *StateDB
address common.Address // address of ethereum account
addrHash common.Hash // hash of ethereum address of the account
Expand Down Expand Up @@ -538,8 +532,6 @@ func (s *stateObject) SetNonce(nonce uint64) {
}

func (s *stateObject) setNonce(nonce uint64) {
s.dataLock.Lock()
defer s.dataLock.Unlock()
s.data.Nonce = nonce
}

Expand All @@ -552,7 +544,5 @@ func (s *stateObject) Balance() *big.Int {
}

func (s *stateObject) Nonce() uint64 {
s.dataLock.RLock()
defer s.dataLock.RUnlock()
return s.data.Nonce
}
2 changes: 1 addition & 1 deletion core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (s *StateDB) AddRefund(gas uint64) {
}

// SubRefund removes gas from the refund counter.
// This method will panic if the refund counter goes below zero
// This method will set the refund counter to 0 if the gas is greater than the current refund.
func (s *StateDB) SubRefund(gas uint64) {
s.journal.append(refundChange{prev: s.refund})
if gas > s.refund {
Expand Down
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
var (
msg = st.msg
sender = vm.AccountRef(msg.From)
rules = st.evm.ChainConfig().AvalancheRules(st.evm.Context.BlockNumber, st.evm.Context.Time)
rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, st.evm.Context.Time)
contractCreation = msg.To == nil
)

Expand Down
2 changes: 1 addition & 1 deletion core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ func (pool *LegacyPool) validateTx(tx *types.Transaction, local bool) error {

opts := &txpool.ValidationOptionsWithState{
State: pool.currentState,
Rules: pool.chainconfig.AvalancheRules(
Rules: pool.chainconfig.Rules(
pool.currentHead.Load().Number,
pool.currentHead.Load().Time,
),
Expand Down
2 changes: 1 addition & 1 deletion core/txpool/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func ValidateTransaction(tx *types.Transaction, blobs []kzg4844.Blob, commits []
}
// Ensure the transaction has more gas than the bare minimum needed to cover
// the transaction metadata
intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, opts.Config.AvalancheRules(head.Number, head.Time))
intrGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, opts.Config.Rules(head.Number, head.Time))
if err != nil {
return err
}
Expand Down
10 changes: 0 additions & 10 deletions core/types/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,16 +461,6 @@ func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, e
return &Transaction{inner: cpy, time: tx.time}, nil
}

// FirstSeen is the time a transaction is first seen.
func (tx *Transaction) FirstSeen() time.Time {
return tx.time
}

// SetFirstSeen sets overwrites the time a transaction is first seen.
func (tx *Transaction) SetFirstSeen(t time.Time) {
tx.time = t
}

// Transactions implements DerivableList for transactions.
type Transactions []*Transaction

Expand Down
5 changes: 3 additions & 2 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
StateDB: statedb,
Config: config,
chainConfig: chainConfig,
chainRules: chainConfig.AvalancheRules(blockCtx.BlockNumber, blockCtx.Time),
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Time),
}
evm.interpreter = NewEVMInterpreter(evm)
return evm
Expand Down Expand Up @@ -242,7 +242,8 @@ func (evm *EVM) Interpreter() *EVMInterpreter {
func (evm *EVM) SetBlockContext(blockCtx BlockContext) {
evm.Context = blockCtx
num := blockCtx.BlockNumber
evm.chainRules = evm.chainConfig.AvalancheRules(num, blockCtx.Time)
timestamp := blockCtx.Time
evm.chainRules = evm.chainConfig.Rules(num, timestamp)
}

// Call executes the contract associated with the addr with the given input as
Expand Down
1 change: 0 additions & 1 deletion core/vm/memory_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func memoryCall(stack *Stack) (uint64, bool) {
}
return y, false
}

func memoryDelegateCall(stack *Stack) (uint64, bool) {
x, overflow := calcMemSize64(stack.Back(4), stack.Back(5))
if overflow {
Expand Down
Loading

0 comments on commit 7c77dff

Please sign in to comment.