Skip to content

Commit

Permalink
Merge branch 'develop' into feature/v3-parity
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan-Ethernal committed Nov 18, 2022
2 parents a191a54 + 3c8ccd7 commit edf9d96
Show file tree
Hide file tree
Showing 33 changed files with 593 additions and 741 deletions.
11 changes: 10 additions & 1 deletion e2e/framework/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ func NewTestServers(t *testing.T, num int, conf func(*TestServerConfig)) []*Test
}
})

logsDir, err := initLogsDir(t)
if err != nil {
t.Fatal(err)
}

// It is safe to use a dummy MultiAddr here, since this init method
// is called for the Dev consensus mode, and IBFT servers are initialized with NewIBFTServersManager.
// This method needs to be standardized in the future
Expand All @@ -471,7 +476,11 @@ func NewTestServers(t *testing.T, num int, conf func(*TestServerConfig)) []*Test
t.Fatal(err)
}

srv := NewTestServer(t, dataDir, conf)
srv := NewTestServer(t, dataDir, func(c *TestServerConfig) {
c.SetLogsDir(logsDir)
c.SetSaveLogs(true)
conf(c)
})
srv.Config.SetBootnodes(bootnodes)

srvs = append(srvs, srv)
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/klauspost/compress v1.15.5 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mitchellh/mapstructure v1.5.0
github.com/umbracle/ethgo v0.1.4-0.20220722090909-c8ac32939570
github.com/umbracle/ethgo v0.1.4-0.20221117101647-b81ef2f07953
github.com/valyala/fastjson v1.6.3 // indirect
go.uber.org/zap v1.22.0 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
Expand Down Expand Up @@ -88,7 +88,6 @@ require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/boltdb/bolt v1.3.1 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/bwesterb/go-ristretto v1.2.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.1 h1:CnwP9LM/M9xuRrGSCGeMVs9iv09uMqwsVX7EeIpgV2c=
Expand Down Expand Up @@ -739,8 +737,8 @@ github.com/tj/go-spin v1.1.0/go.mod h1:Mg1mzmePZm4dva8Qz60H2lHwmJ2loum4VIrLgVnKw
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/umbracle/ethgo v0.1.4-0.20220722090909-c8ac32939570 h1:/KyTftQQhxq0iRIVRocn0F2D4zoHmstIfB4FTDjsZbw=
github.com/umbracle/ethgo v0.1.4-0.20220722090909-c8ac32939570/go.mod h1:g9zclCLixH8liBI27Py82klDkW7Oo33AxUOr+M9lzrU=
github.com/umbracle/ethgo v0.1.4-0.20221117101647-b81ef2f07953 h1:ep+lwZyyeh1iw8UojTxslDsqPw0305Vu6lOiEebWS8k=
github.com/umbracle/ethgo v0.1.4-0.20221117101647-b81ef2f07953/go.mod h1:8QIHEG/YfGnW4I5AND2Znl9W0LU3tXR9IGqgmSieiGo=
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722 h1:10Nbw6cACsnQm7r34zlpJky+IzxVLRk6MKTS2d3Vp0E=
github.com/umbracle/fastrlp v0.0.0-20220527094140-59d5dd30e722/go.mod h1:c8J0h9aULj2i3umrfyestM6jCq0LK0U6ly6bWy96nd4=
github.com/umbracle/go-eth-bn256 v0.0.0-20190607160430-b36caf4e0f6b h1:t3nz9xXkLZJz+ZlTGFT3ixsCGO5AHx1Yift2EAfjnnc=
Expand Down
4 changes: 2 additions & 2 deletions helper/predeployment/predeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func getPredeployAccount(address types.Address, input, deployedBytecode []byte)
snapshot := st.NewSnapshot()

// Create a radix
radix := state.NewTxn(st, snapshot)
radix := state.NewTxn(snapshot)

// Create the contract object for the EVM
contract := runtime.NewContractCreation(
Expand All @@ -141,7 +141,7 @@ func getPredeployAccount(address types.Address, input, deployedBytecode []byte)
config := chain.AllForksEnabled.At(0)

// Create a transition
transition := state.NewTransition(config, radix)
transition := state.NewTransition(config, snapshot, radix)

// Run the transition through the EVM
res := evm.NewEVM().Run(contract, transition, &config)
Expand Down
9 changes: 0 additions & 9 deletions jsonrpc/eth_blockchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,6 @@ func (m *mockBlockStore) GetReceiptsByHash(hash types.Hash) ([]*types.Receipt, e
return receipts, nil
}

func (m *mockBlockStore) GetHeaderByNumber(blockNumber uint64) (*types.Header, bool) {
b, ok := m.GetBlockByNumber(blockNumber, false)
if !ok {
return nil, false
}

return b.Header, true
}

func (m *mockBlockStore) GetBlockByNumber(blockNumber uint64, full bool) (*types.Block, bool) {
for _, b := range m.blocks {
if b.Number() == blockNumber {
Expand Down
28 changes: 12 additions & 16 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ type ethTxPoolStore interface {
GetPendingTx(txHash types.Hash) (*types.Transaction, bool)
}

type Account struct {
Balance *big.Int
Nonce uint64
}

type ethStateStore interface {
GetAccount(root types.Hash, addr types.Address) (*state.Account, error)
GetAccount(root types.Hash, addr types.Address) (*Account, error)
GetStorage(root types.Hash, addr types.Address, slot types.Hash) ([]byte, error)
GetForksInTime(blockNumber uint64) chain.ForksInTime
GetCode(hash types.Hash) ([]byte, error)
GetCode(root types.Hash, addr types.Address) ([]byte, error)
}

type ethBlockchainStore interface {
// Header returns the current header of the chain (genesis if empty)
Header() *types.Header

// GetHeaderByNumber returns the header by number
GetHeaderByNumber(block uint64) (*types.Header, bool)

// GetBlockByHash gets a block using the provided hash
GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool)

Expand Down Expand Up @@ -729,7 +731,7 @@ func (e *Eth) GetCode(address types.Address, filter BlockNumberOrHash) (interfac
}

emptySlice := []byte{}
acc, err := e.store.GetAccount(header.StateRoot, address)
code, err := e.store.GetCode(header.StateRoot, address)

if errors.Is(err, ErrStateNotFound) {
// If the account doesn't exist / is not initialized yet,
Expand All @@ -739,12 +741,6 @@ func (e *Eth) GetCode(address types.Address, filter BlockNumberOrHash) (interfac
return argBytesPtr(emptySlice), err
}

code, err := e.store.GetCode(types.BytesToHash(acc.CodeHash))
if err != nil {
// TODO This is just a workaround. Figure out why CodeHash is populated for regular accounts
return argBytesPtr(emptySlice), nil
}

return argBytesPtr(code), nil
}

Expand Down Expand Up @@ -779,24 +775,24 @@ func (e *Eth) getBlockHeader(number BlockNumber) (*types.Header, error) {
return e.store.Header(), nil

case EarliestBlockNumber:
header, ok := e.store.GetHeaderByNumber(uint64(0))
block, ok := e.store.GetBlockByNumber(uint64(0), false)
if !ok {
return nil, fmt.Errorf("error fetching genesis block header")
}

return header, nil
return block.Header, nil

case PendingBlockNumber:
return nil, fmt.Errorf("fetching the pending header is not supported")

default:
// Convert the block number from hex to uint64
header, ok := e.store.GetHeaderByNumber(uint64(number))
block, ok := e.store.GetBlockByNumber(uint64(number), false)
if !ok {
return nil, fmt.Errorf("error fetching block number %d header", uint64(number))
}

return header, nil
return block.Header, nil
}
}

Expand Down
9 changes: 4 additions & 5 deletions jsonrpc/eth_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"math/big"
"testing"

"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/types"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/assert"
Expand All @@ -16,7 +15,7 @@ func TestEth_DecodeTxn(t *testing.T) {

tests := []struct {
name string
accounts map[types.Address]*state.Account
accounts map[types.Address]*Account
arg *txnArgs
res *types.Transaction
err error
Expand Down Expand Up @@ -77,7 +76,7 @@ func TestEth_DecodeTxn(t *testing.T) {
},
{
name: "should set latest nonce as default",
accounts: map[types.Address]*state.Account{
accounts: map[types.Address]*Account{
addr1: {
Nonce: 10,
},
Expand Down Expand Up @@ -171,11 +170,11 @@ func TestEth_GetNextNonce(t *testing.T) {
// Set up the mock accounts
accounts := []struct {
address types.Address
account *state.Account
account *Account
}{
{
types.StringToAddress("123"),
&state.Account{
&Account{
Nonce: 5,
},
},
Expand Down
39 changes: 18 additions & 21 deletions jsonrpc/eth_state_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package jsonrpc

import (
"bytes"
"errors"
"fmt"
"math/big"
"testing"

Expand All @@ -26,7 +24,7 @@ func TestEth_State_GetBalance(t *testing.T) {
store := &mockSpecialStore{
account: &mockAccount{
address: addr0,
account: &state.Account{
account: &Account{
Balance: big.NewInt(100),
},
storage: make(map[types.Hash][]byte),
Expand Down Expand Up @@ -158,7 +156,7 @@ func TestEth_State_GetTransactionCount(t *testing.T) {
store := &mockSpecialStore{
account: &mockAccount{
address: addr0,
account: &state.Account{
account: &Account{
Balance: big.NewInt(100),
Nonce: 100,
},
Expand Down Expand Up @@ -276,10 +274,9 @@ func TestEth_State_GetCode(t *testing.T) {
store := &mockSpecialStore{
account: &mockAccount{
address: addr0,
account: &state.Account{
Balance: big.NewInt(100),
Nonce: 100,
CodeHash: types.BytesToHash(addr0.Bytes()).Bytes(),
account: &Account{
Balance: big.NewInt(100),
Nonce: 100,
},
code: code0,
},
Expand Down Expand Up @@ -401,7 +398,7 @@ func TestEth_State_GetStorageAt(t *testing.T) {
store := &mockSpecialStore{
account: &mockAccount{
address: addr0,
account: &state.Account{
account: &Account{
Balance: big.NewInt(100),
Nonce: 100,
},
Expand Down Expand Up @@ -550,7 +547,7 @@ func TestEth_State_GetStorageAt(t *testing.T) {
for addr, storage := range tt.initialStorage {
store.account = &mockAccount{
address: addr,
account: &state.Account{
account: &Account{
Balance: big.NewInt(100),
Nonce: 100,
},
Expand Down Expand Up @@ -598,7 +595,7 @@ func getExampleStore() *mockSpecialStore {
return &mockSpecialStore{
account: &mockAccount{
address: addr0,
account: &state.Account{
account: &Account{
Balance: big.NewInt(100),
Nonce: 0,
},
Expand Down Expand Up @@ -777,27 +774,27 @@ type mockSpecialStore struct {
}

func (m *mockSpecialStore) GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool) {
if m.block.Header.Hash.String() != hash.String() {
if m.block.Header.Hash != hash {
return nil, false
}

return m.block, true
}

func (m *mockSpecialStore) GetAccount(root types.Hash, addr types.Address) (*state.Account, error) {
if m.account.address.String() != addr.String() {
func (m *mockSpecialStore) GetAccount(root types.Hash, addr types.Address) (*Account, error) {
if m.account.address != addr {
return nil, ErrStateNotFound
}

return m.account.account, nil
}

func (m *mockSpecialStore) GetHeaderByNumber(blockNumber uint64) (*types.Header, bool) {
func (m *mockSpecialStore) GetBlockByNumber(blockNumber uint64, full bool) (*types.Block, bool) {
if m.block.Number() != blockNumber {
return nil, false
}

return m.block.Header, true
return m.block, true
}

func (m *mockSpecialStore) Header() *types.Header {
Expand All @@ -809,7 +806,7 @@ func (m *mockSpecialStore) GetNonce(addr types.Address) uint64 {
}

func (m *mockSpecialStore) GetStorage(root types.Hash, addr types.Address, slot types.Hash) ([]byte, error) {
if m.account.address.String() != addr.String() {
if m.account.address != addr {
return nil, ErrStateNotFound
}

Expand All @@ -823,12 +820,12 @@ func (m *mockSpecialStore) GetStorage(root types.Hash, addr types.Address, slot
return val, nil
}

func (m *mockSpecialStore) GetCode(hash types.Hash) ([]byte, error) {
if bytes.Equal(m.account.account.CodeHash, hash.Bytes()) {
return m.account.code, nil
func (m *mockSpecialStore) GetCode(root types.Hash, addr types.Address) ([]byte, error) {
if m.account.address != addr {
return nil, ErrStateNotFound
}

return nil, fmt.Errorf("code not found")
return m.account.code, nil
}

func (m *mockSpecialStore) GetForksInTime(blockNumber uint64) chain.ForksInTime {
Expand Down
5 changes: 2 additions & 3 deletions jsonrpc/eth_txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"math/big"
"testing"

"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/types"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -69,7 +68,7 @@ func (m *mockStoreTxn) AddAccount(addr types.Address) *mockAccount {

acct := &mockAccount{
address: addr,
account: &state.Account{},
account: &Account{},
storage: make(map[types.Hash][]byte),
}
m.accounts[addr] = acct
Expand All @@ -81,7 +80,7 @@ func (m *mockStoreTxn) Header() *types.Header {
return &types.Header{}
}

func (m *mockStoreTxn) GetAccount(root types.Hash, addr types.Address) (*state.Account, error) {
func (m *mockStoreTxn) GetAccount(root types.Hash, addr types.Address) (*Account, error) {
acct, ok := m.accounts[addr]
if !ok {
return nil, ErrStateNotFound
Expand Down
Loading

0 comments on commit edf9d96

Please sign in to comment.