Skip to content

Commit

Permalink
Coreth 0.8.16 rc2 (#216)
Browse files Browse the repository at this point in the history
* Unwrap ETHChain

* hook in vm.ethConfig

* statesync for subnet-evm

* remove unused configJSON

* add err check

* add synchronization

* add default config values

* delay initialization of gossiper

* Revert "add synchronization"

This reverts commit 6234a1b5a6f944ba5d2e15d3a3ae49a12fca0910.

* fix test

* fix statesync code prefix issue

* fix comment

* wip

* wip2

* add coreth changes

* Merge branch 'master' into coreth-0.8.16-rc2

* updates

* remove coreth from go.mod

* fix linter

* fix

* update gas prices (?)

* fix tracer test

* move dependabot yml to upper file

* more changes ported in from coreth 0.8.16

* Update sync/README.md

Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>

* Update sync/README.md

Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>

* Update sync/README.md

Co-authored-by: Ceyhun Onur <ceyhun.onur@avalabs.org>

* Update core/rawdb/accessors_state_sync.go

* port missing file from coreth

* fix-import

* subscribe before goroutine

* Rebase apply coreth diff onto statesync

* fix EOF in tests

* Nits (#265)

* Nits

* Add EIP-1559 link to readme

* Fix linting introduced by merge
  • Loading branch information
ceyonur authored Sep 22, 2022
1 parent 8e7895d commit 0770479
Show file tree
Hide file tree
Showing 205 changed files with 4,508 additions and 2,483 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "gomod" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ linters:
- misspell
- unconvert
- varcheck
- whitespace

linters-settings:
gofmt:
Expand Down
23 changes: 4 additions & 19 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
case "constructor":
abi.Constructor = NewMethod("", "", Constructor, field.StateMutability, field.Constant, field.Payable, field.Inputs, nil)
case "function":
name := overloadedName(field.Name, func(s string) bool { _, ok := abi.Methods[s]; return ok })
name := ResolveNameConflict(field.Name, func(s string) bool { _, ok := abi.Methods[s]; return ok })
abi.Methods[name] = NewMethod(name, field.Name, Function, field.StateMutability, field.Constant, field.Payable, field.Inputs, field.Outputs)
case "fallback":
// New introduced function type in v0.6.0, check more detail
Expand All @@ -254,9 +254,11 @@ func (abi *ABI) UnmarshalJSON(data []byte) error {
}
abi.Receive = NewMethod("", "", Receive, field.StateMutability, field.Constant, field.Payable, nil, nil)
case "event":
name := overloadedName(field.Name, func(s string) bool { _, ok := abi.Events[s]; return ok })
name := ResolveNameConflict(field.Name, func(s string) bool { _, ok := abi.Events[s]; return ok })
abi.Events[name] = NewEvent(name, field.Name, field.Anonymous, field.Inputs)
case "error":
// Errors cannot be overloaded or overridden but are inherited,
// no need to resolve the name conflict here.
abi.Errors[field.Name] = NewError(field.Name, field.Inputs)
default:
return fmt.Errorf("abi: could not recognize type %v of field %v", field.Type, field.Name)
Expand Down Expand Up @@ -321,20 +323,3 @@ func UnpackRevert(data []byte) (string, error) {
}
return unpacked[0].(string), nil
}

// overloadedName returns the next available name for a given thing.
// Needed since solidity allows for overloading.
//
// e.g. if the abi contains Methods send, send1
// overloadedName would return send2 for input send.
//
// overloadedName works for methods, events and errors.
func overloadedName(rawName string, isAvail func(string) bool) string {
name := rawName
ok := isAvail(name)
for idx := 0; ok; idx++ {
name = fmt.Sprintf("%s%d", rawName, idx)
ok = isAvail(name)
}
return name
}
13 changes: 6 additions & 7 deletions accounts/abi/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ var (
TupleF, _ = NewType("tuple", "struct Overloader.F", []ArgumentMarshaling{
{Name: "_f", Type: "uint256"},
{Name: "__f", Type: "uint256"},
{Name: "f", Type: "uint256"}})
{Name: "f", Type: "uint256"},
})
)

var methods = map[string]Method{
Expand Down Expand Up @@ -884,12 +885,12 @@ func TestUnpackMethodIntoMap(t *testing.T) {

func TestUnpackIntoMapNamingConflict(t *testing.T) {
// Two methods have the same name
var abiJSON = `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"get","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"send","outputs":[{"name":"amount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"get","outputs":[{"name":"hash","type":"bytes"}],"payable":true,"stateMutability":"payable","type":"function"}]`
abiJSON := `[{"constant":false,"inputs":[{"name":"memo","type":"bytes"}],"name":"get","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[],"name":"send","outputs":[{"name":"amount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"get","outputs":[{"name":"hash","type":"bytes"}],"payable":true,"stateMutability":"payable","type":"function"}]`
abi, err := JSON(strings.NewReader(abiJSON))
if err != nil {
t.Fatal(err)
}
var hexdata = `00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158`
hexdata := `00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000158`
data, err := hex.DecodeString(hexdata)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -1048,9 +1049,7 @@ func TestABI_EventById(t *testing.T) {
}
if event == nil {
t.Errorf("We should find a event for topic %s, test #%d", topicID.Hex(), testnum)
}

if event.ID != topicID {
} else if event.ID != topicID {
t.Errorf("Event id %s does not match topic %s, test #%d", event.ID.Hex(), topicID.Hex(), testnum)
}

Expand Down Expand Up @@ -1143,7 +1142,7 @@ func TestUnnamedEventParam(t *testing.T) {
func TestUnpackRevert(t *testing.T) {
t.Parallel()

var cases = []struct {
cases := []struct {
input string
expect string
expectErr error
Expand Down
15 changes: 8 additions & 7 deletions accounts/abi/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package abi

import (
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -88,8 +89,8 @@ func (arguments Arguments) isTuple() bool {
// Unpack performs the operation hexdata -> Go format.
func (arguments Arguments) Unpack(data []byte) ([]interface{}, error) {
if len(data) == 0 {
if len(arguments) != 0 {
return nil, fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
if len(arguments.NonIndexed()) != 0 {
return nil, errors.New("abi: attempting to unmarshall an empty string while arguments are expected")
}
return make([]interface{}, 0), nil
}
Expand All @@ -100,11 +101,11 @@ func (arguments Arguments) Unpack(data []byte) ([]interface{}, error) {
func (arguments Arguments) UnpackIntoMap(v map[string]interface{}, data []byte) error {
// Make sure map is not nil
if v == nil {
return fmt.Errorf("abi: cannot unpack into a nil map")
return errors.New("abi: cannot unpack into a nil map")
}
if len(data) == 0 {
if len(arguments) != 0 {
return fmt.Errorf("abi: attempting to unmarshall an empty string while arguments are expected")
if len(arguments.NonIndexed()) != 0 {
return errors.New("abi: attempting to unmarshall an empty string while arguments are expected")
}
return nil // Nothing to unmarshal, return
}
Expand All @@ -125,8 +126,8 @@ func (arguments Arguments) Copy(v interface{}, values []interface{}) error {
return fmt.Errorf("abi: Unpack(non-pointer %T)", v)
}
if len(values) == 0 {
if len(arguments) != 0 {
return fmt.Errorf("abi: attempting to copy no values while %d arguments are expected", len(arguments))
if len(arguments.NonIndexed()) != 0 {
return errors.New("abi: attempting to copy no values while arguments are expected")
}
return nil // Nothing to copy, return
}
Expand Down
5 changes: 2 additions & 3 deletions accounts/abi/bind/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"crypto/ecdsa"
"errors"
"io"
"io/ioutil"
"math/big"

"github.com/ava-labs/subnet-evm/accounts"
Expand All @@ -55,7 +54,7 @@ var ErrNotAuthorized = errors.New("not authorized to sign this account")
// Deprecated: Use NewTransactorWithChainID instead.
func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
log.Warn("WARNING: NewTransactor has been deprecated in favour of NewTransactorWithChainID")
json, err := ioutil.ReadAll(keyin)
json, err := io.ReadAll(keyin)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -116,7 +115,7 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
// NewTransactorWithChainID is a utility method to easily create a transaction signer from
// an encrypted json key stream and the associated passphrase.
func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) {
json, err := ioutil.ReadAll(keyin)
json, err := io.ReadAll(keyin)
if err != nil {
return nil, err
}
Expand Down
17 changes: 11 additions & 6 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func NewSimulatedBackendWithDatabase(database ethdb.Database, alloc core.Genesis
database: database,
blockchain: blockchain,
config: genesis.Config,
events: filters.NewEventSystem(&filterBackend{database, blockchain}, false),
}
backend.events = filters.NewEventSystem(&filterBackend{database, blockchain, backend}, false)
backend.rollback(blockchain.CurrentBlock())
return backend
}
Expand All @@ -138,7 +138,7 @@ func (b *SimulatedBackend) Close() error {

// Commit imports all the pending transactions as a single block and starts a
// fresh new state.
func (b *SimulatedBackend) Commit(accept bool) {
func (b *SimulatedBackend) Commit(accept bool) common.Hash {
b.mu.Lock()
defer b.mu.Unlock()

Expand All @@ -151,9 +151,13 @@ func (b *SimulatedBackend) Commit(accept bool) {
}
b.blockchain.DrainAcceptorQueue()
}
blockHash := b.acceptedBlock.Hash()

// Using the last inserted block here makes it possible to build on a side
// chain after a fork.
b.rollback(b.acceptedBlock)

return blockHash
}

// Rollback aborts all pending transactions, reverting to the last committed state.
Expand Down Expand Up @@ -724,7 +728,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query interfaces.Filt
var filter *filters.Filter
if query.BlockHash != nil {
// Block filter requested, construct a single-shot filter
filter = filters.NewBlockFilter(&filterBackend{b.database, b.blockchain}, *query.BlockHash, query.Addresses, query.Topics)
filter = filters.NewBlockFilter(&filterBackend{b.database, b.blockchain, b}, *query.BlockHash, query.Addresses, query.Topics)
} else {
// Initialize unset filter boundaries to run from genesis to chain head
from := int64(0)
Expand All @@ -736,7 +740,7 @@ func (b *SimulatedBackend) FilterLogs(ctx context.Context, query interfaces.Filt
to = query.ToBlock.Int64()
}
// Construct the range filter
filter, _ = filters.NewRangeFilter(&filterBackend{b.database, b.blockchain}, from, to, query.Addresses, query.Topics)
filter, _ = filters.NewRangeFilter(&filterBackend{b.database, b.blockchain, b}, from, to, query.Addresses, query.Topics)
}
// Run the filter and return all the logs
logs, err := filter.Logs(ctx)
Expand Down Expand Up @@ -857,8 +861,9 @@ func (m callMsg) AccessList() types.AccessList { return m.CallMsg.AccessList }
// filterBackend implements filters.Backend to support filtering for logs without
// taking bloom-bits acceleration structures into account.
type filterBackend struct {
db ethdb.Database
bc *core.BlockChain
db ethdb.Database
bc *core.BlockChain
backend *SimulatedBackend
}

func (fb *filterBackend) SubscribeChainAcceptedEvent(ch chan<- core.ChainEvent) event.Subscription {
Expand Down
42 changes: 40 additions & 2 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ func TestHeaderByNumber(t *testing.T) {
}
if latestBlockHeader == nil {
t.Errorf("received a nil block header")
}
if latestBlockHeader.Number.Uint64() != uint64(0) {
} else if latestBlockHeader.Number.Uint64() != uint64(0) {
t.Errorf("expected block header number 0, instead got %v", latestBlockHeader.Number.Uint64())
}

Expand Down Expand Up @@ -1362,3 +1361,42 @@ contract Callable {
// t.Errorf("TX included in wrong block: %d", h)
// }
// }

func TestCommitReturnValue(t *testing.T) {
testAddr := crypto.PubkeyToAddress(testKey.PublicKey)
sim := simTestBackend(testAddr)
defer sim.Close()

startBlockHeight := sim.blockchain.CurrentBlock().NumberU64()

// Test if Commit returns the correct block hash
h1 := sim.Commit(true)
if h1 != sim.blockchain.CurrentBlock().Hash() {
t.Error("Commit did not return the hash of the last block.")
}

// Create a block in the original chain (containing a transaction to force different block hashes)
head, _ := sim.HeaderByNumber(context.Background(), nil) // Should be child's, good enough
gasPrice := new(big.Int).Add(head.BaseFee, big.NewInt(1))
_tx := types.NewTransaction(0, testAddr, big.NewInt(1000), params.TxGas, gasPrice, nil)
tx, _ := types.SignTx(_tx, types.HomesteadSigner{}, testKey)
sim.SendTransaction(context.Background(), tx)
h2 := sim.Commit(false)

// Create another block in the original chain
sim.Commit(false)

// Fork at the first bock
if err := sim.Fork(context.Background(), h1); err != nil {
t.Errorf("forking: %v", err)
}

// Test if Commit returns the correct block hash after the reorg
h2fork := sim.Commit(false)
if h2 == h2fork {
t.Error("The block in the fork and the original block are the same block!")
}
if sim.blockchain.GetHeader(h2fork, startBlockHeight+2) == nil {
t.Error("Could not retrieve the just created block (side-chain)")
}
}
5 changes: 4 additions & 1 deletion accounts/abi/bind/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func (c *BoundContract) Call(opts *CallOpts, results *[]interface{}, method stri
return ErrNoAcceptedState
}
output, err = pb.AcceptedCallContract(ctx, msg)
if err == nil && len(output) == 0 {
if err != nil {
return err
}
if len(output) == 0 {
// Make sure we have a contract to operate on, and bail out otherwise.
if code, err = pb.AcceptedCodeAt(ctx, c.address); err != nil {
return err
Expand Down
Loading

0 comments on commit 0770479

Please sign in to comment.