Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/v3-parity
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Nov 30, 2022
2 parents a219437 + 7d8338f commit 82fd78d
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 80 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/deploy.devnet.eph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ jobs:
pandoras_box_eoa:
uses: ./.github/workflows/pandoras_box.yml
name: Pandora's Box
name: Pandora's Box EOA
needs: deploy_eph_devnet
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
Expand All @@ -183,8 +183,8 @@ jobs:
mode: EOA
pandoras_box_erc20:
uses: ./.github/workflows/pandoras_box.yml
name: Pandora's Box
needs: pandoras_box_eoa
name: Pandora's Box ERC20
needs: deploy_eph_devnet
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
PANDORAS_TARGET: ${{ secrets.PANDORAS_TARGET }}
Expand All @@ -197,8 +197,8 @@ jobs:
mode: ERC20
pandoras_box_erc721:
uses: ./.github/workflows/pandoras_box.yml
name: Pandora's Box
needs: pandoras_box_erc20
name: Pandora's Box ERC721
needs: deploy_eph_devnet
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
PANDORAS_TARGET: ${{ secrets.PANDORAS_TARGET }}
Expand Down
28 changes: 14 additions & 14 deletions .github/workflows/deploy.devnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,23 @@ jobs:
transaction_count: '10000'
mode: EOA
pandoras_box_erc20:
uses: ./.github/workflows/pandoras_box.yml
name: Pandora's Box ERC20
needs: pandoras_box_eoa
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
PANDORAS_TARGET: ${{ secrets.PANDORAS_TARGET }}
PANDORAS_MNEMONIC: ${{ secrets.PANDORAS_MNEMONIC }}
with:
runner: devnet
environment: devnet
transaction_batch: '200'
transaction_count: '10000'
mode: ERC20
uses: ./.github/workflows/pandoras_box.yml
name: Pandora's Box ERC20
needs: deploy_devnet
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
PANDORAS_TARGET: ${{ secrets.PANDORAS_TARGET }}
PANDORAS_MNEMONIC: ${{ secrets.PANDORAS_MNEMONIC }}
with:
runner: devnet
environment: devnet
transaction_batch: '200'
transaction_count: '10000'
mode: ERC20
pandoras_box_erc721:
uses: ./.github/workflows/pandoras_box.yml
name: Pandora's Box ERC721
needs: pandoras_box_erc20
needs: deploy_devnet
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
PANDORAS_TARGET: ${{ secrets.PANDORAS_TARGET }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy.testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ jobs:
pandoras_box_erc20:
uses: ./.github/workflows/pandoras_box.yml
name: Pandora's Box ERC20
needs: pandoras_box_eoa
needs: deploy_testnet
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
PANDORAS_TARGET: ${{ secrets.PANDORAS_TARGET }}
Expand All @@ -191,7 +191,7 @@ jobs:
pandoras_box_erc721:
uses: ./.github/workflows/pandoras_box.yml
name: Pandora's Box ERC721
needs: pandoras_box_erc20
needs: deploy_testnet
secrets:
SLACK_PERFORMANCE_WEBHOOK_URL: ${{ secrets.SLACK_PERFORMANCE_WEBHOOK_URL }}
PANDORAS_TARGET: ${{ secrets.PANDORAS_TARGET }}
Expand Down
6 changes: 2 additions & 4 deletions jsonrpc/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ func stringToBlockNumber(str string) (BlockNumber, error) {

str = strings.Trim(str, "\"")
switch str {
case "pending":
return PendingBlockNumber, nil
case "latest":
case pending, latest:
return LatestBlockNumber, nil
case "earliest":
case earliest:
return EarliestBlockNumber, nil
}

Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func TestDispatcherFuncDecode(t *testing.T) {
{
"filter",
`[{"fromBlock": "pending", "toBlock": "earliest"}]`,
LogQuery{fromBlock: PendingBlockNumber, toBlock: EarliestBlockNumber},
LogQuery{fromBlock: LatestBlockNumber, toBlock: EarliestBlockNumber}, // pending = latest
},
}

Expand Down
11 changes: 2 additions & 9 deletions jsonrpc/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
var (
ErrHeaderNotFound = errors.New("header not found")
ErrLatestNotFound = errors.New("latest header not found")
ErrPendingBlockNumber = errors.New("fetching the pending header is not supported")
ErrNegativeBlockNumber = errors.New("invalid argument 0: block number must not be negative")
ErrFailedFetchGenesis = errors.New("error fetching genesis block header")
ErrNoDataInContractCreation = errors.New("contract creation without data provided")
Expand All @@ -24,7 +23,7 @@ type latestHeaderGetter interface {
// GetNumericBlockNumber returns block number based on current state or specified number
func GetNumericBlockNumber(number BlockNumber, store latestHeaderGetter) (uint64, error) {
switch number {
case LatestBlockNumber:
case LatestBlockNumber, PendingBlockNumber:
latest := store.Header()
if latest == nil {
return 0, ErrLatestNotFound
Expand All @@ -35,9 +34,6 @@ func GetNumericBlockNumber(number BlockNumber, store latestHeaderGetter) (uint64
case EarliestBlockNumber:
return 0, nil

case PendingBlockNumber:
return 0, ErrPendingBlockNumber

default:
if number < 0 {
return 0, ErrNegativeBlockNumber
Expand All @@ -55,7 +51,7 @@ type headerGetter interface {
// GetBlockHeader returns a header using the provided number
func GetBlockHeader(number BlockNumber, store headerGetter) (*types.Header, error) {
switch number {
case LatestBlockNumber:
case PendingBlockNumber, LatestBlockNumber:
return store.Header(), nil

case EarliestBlockNumber:
Expand All @@ -66,9 +62,6 @@ func GetBlockHeader(number BlockNumber, store headerGetter) (*types.Header, erro

return header, nil

case PendingBlockNumber:
return nil, ErrPendingBlockNumber

default:
// Convert the block number from hex to uint64
header, ok := store.GetHeaderByNumber(uint64(number))
Expand Down
56 changes: 45 additions & 11 deletions jsonrpc/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestGetNumericBlockNumber(t *testing.T) {
err error
}{
{
name: "should return the latest block's number if latest is given",
name: "should return the latest block's number if it is found",
num: LatestBlockNumber,
store: &debugEndpointMockStore{
headerFn: func() *types.Header {
Expand All @@ -85,7 +85,7 @@ func TestGetNumericBlockNumber(t *testing.T) {
err: nil,
},
{
name: "should return the latest block's number if latest is given",
name: "should return error if the latest block's number is not found",
num: LatestBlockNumber,
store: &debugEndpointMockStore{
headerFn: func() *types.Header {
Expand All @@ -103,11 +103,41 @@ func TestGetNumericBlockNumber(t *testing.T) {
err: nil,
},
{
name: "should return error if pending is given",
num: PendingBlockNumber,
store: &debugEndpointMockStore{},
name: "should return latest if found and pending is given",
num: PendingBlockNumber,
store: &debugEndpointMockStore{
headerFn: func() *types.Header {
return &types.Header{
Number: 10,
}
},
},
expected: 10,
err: nil,
},
{
name: "should return error if given pending and the latest block's number is not found",
num: PendingBlockNumber,
store: &debugEndpointMockStore{
headerFn: func() *types.Header {
return nil
},
},
expected: 0,
err: ErrPendingBlockNumber,
err: ErrLatestNotFound,
},
{
name: "should return error for latest if not found and pending is given",
num: PendingBlockNumber,
store: &debugEndpointMockStore{
headerFn: func() *types.Header {
return &types.Header{
Number: 10,
}
},
},
expected: 10,
err: nil,
},
{
name: "should return error if negative number is given",
Expand Down Expand Up @@ -187,11 +217,15 @@ func TestGetBlockHeader(t *testing.T) {
err: ErrFailedFetchGenesis,
},
{
name: "should return error if pending is given",
num: PendingBlockNumber,
store: &debugEndpointMockStore{},
expected: nil,
err: ErrPendingBlockNumber,
name: "should return latest if pending is given",
num: PendingBlockNumber,
store: &debugEndpointMockStore{
headerFn: func() *types.Header {
return testLatestHeader
},
},
expected: testLatestHeader,
err: nil,
},
{
name: "should return header at arbitrary height",
Expand Down
2 changes: 1 addition & 1 deletion jsonrpc/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestFilterDecode(t *testing.T) {
"toBlock": "earliest"
}`,
&LogQuery{
fromBlock: PendingBlockNumber,
fromBlock: LatestBlockNumber, // pending = latest
toBlock: EarliestBlockNumber,
},
},
Expand Down
56 changes: 23 additions & 33 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,28 @@ type txpoolHub struct {
*blockchain.Blockchain
}

func (t *txpoolHub) GetNonce(root types.Hash, addr types.Address) uint64 {
// TODO: Use a function that returns only Account
snap, err := t.state.NewSnapshotAt(root)
// getAccountImpl is used for fetching account state from both TxPool and JSON-RPC
func getAccountImpl(state state.State, root types.Hash, addr types.Address) (*state.Account, error) {
snap, err := state.NewSnapshotAt(root)
if err != nil {
return 0
return nil, fmt.Errorf("unable to get snapshot for root '%s': %w", root, err)
}

account, err := snap.GetAccount(addr)
if err != nil {
return nil, err
}

if account == nil {
return nil, jsonrpc.ErrStateNotFound
}

return account, nil
}

func (t *txpoolHub) GetNonce(root types.Hash, addr types.Address) uint64 {
account, err := getAccountImpl(t.state, root, addr)

if err != nil {
return 0
}
Expand All @@ -320,12 +334,8 @@ func (t *txpoolHub) GetNonce(root types.Hash, addr types.Address) uint64 {
}

func (t *txpoolHub) GetBalance(root types.Hash, addr types.Address) (*big.Int, error) {
snap, err := t.state.NewSnapshotAt(root)
if err != nil {
return nil, fmt.Errorf("unable to get snapshot for root, %w", err)
}
account, err := getAccountImpl(t.state, root, addr)

account, err := snap.GetAccount(addr)
if err != nil {
return big.NewInt(0), err
}
Expand Down Expand Up @@ -433,32 +443,12 @@ type jsonRPCHub struct {
consensus.BridgeDataProvider
}

// HELPER + WRAPPER METHODS //

func (j *jsonRPCHub) GetPeers() int {
return len(j.Server.Peers())
}

func (j *jsonRPCHub) getAccountImpl(root types.Hash, addr types.Address) (*state.Account, error) {
snap, err := j.state.NewSnapshotAt(root)
if err != nil {
return nil, err
}

account, err := snap.GetAccount(addr)
if err != nil {
return nil, err
}

if account == nil {
return nil, jsonrpc.ErrStateNotFound
}

return account, nil
}

func (j *jsonRPCHub) GetAccount(root types.Hash, addr types.Address) (*jsonrpc.Account, error) {
acct, err := j.getAccountImpl(root, addr)
acct, err := getAccountImpl(j.state, root, addr)
if err != nil {
return nil, err
}
Expand All @@ -477,7 +467,7 @@ func (j *jsonRPCHub) GetForksInTime(blockNumber uint64) chain.ForksInTime {
}

func (j *jsonRPCHub) GetStorage(stateRoot types.Hash, addr types.Address, slot types.Hash) ([]byte, error) {
account, err := j.getAccountImpl(stateRoot, addr)
account, err := getAccountImpl(j.state, stateRoot, addr)
if err != nil {
return nil, err
}
Expand All @@ -493,12 +483,12 @@ func (j *jsonRPCHub) GetStorage(stateRoot types.Hash, addr types.Address, slot t
}

func (j *jsonRPCHub) GetCode(root types.Hash, addr types.Address) ([]byte, error) {
account, err := j.getAccountImpl(root, addr)
account, err := getAccountImpl(j.state, root, addr)
if err != nil {
return nil, err
}

code, ok := j.state.GetCode(account.Root)
code, ok := j.state.GetCode(types.BytesToHash(account.CodeHash))
if !ok {
return nil, fmt.Errorf("unable to fetch code")
}
Expand Down

0 comments on commit 82fd78d

Please sign in to comment.