Skip to content

Commit

Permalink
RPC-compat hive fixes (#13617)
Browse files Browse the repository at this point in the history
Set of minor changes to align with hive's `rpc-compat` tests
Also reverts #8337
  • Loading branch information
somnathb1 authored Jan 31, 2025
1 parent dcb4ec2 commit a1449e1
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
8 changes: 7 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
ChangeLog
---------

## v3.0.0-beta1 (in development)
## v3.0.0-beta2 (in development)

### Breaking changes
- Reverts Optimize gas by default in eth_createAccessList #8337


## v3.0.0-beta1

### Breaking changes

Expand Down
8 changes: 8 additions & 0 deletions turbo/jsonrpc/eth_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package jsonrpc

import (
"context"
"errors"
"fmt"
"math/big"

Expand Down Expand Up @@ -120,6 +121,13 @@ func (api *APIImpl) GetCode(ctx context.Context, address libcommon.Address, bloc
// GetStorageAt implements eth_getStorageAt. Returns the value from a storage position at a given address.
func (api *APIImpl) GetStorageAt(ctx context.Context, address libcommon.Address, index string, blockNrOrHash rpc.BlockNumberOrHash) (string, error) {
var empty []byte
indexBytes := hexutility.FromHex(index)
if len(indexBytes) < 32 {
return "", errors.New("unable to decode storage key: hex string invalid")
}
if len(indexBytes) > 32 {
return "", errors.New("unable to decode storage key: hex string too long, want at most 32 bytes")
}

tx, err1 := api.db.BeginTemporalRo(ctx)
if err1 != nil {
Expand Down
14 changes: 7 additions & 7 deletions turbo/jsonrpc/eth_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestGetStorageAt_ByBlockNumber_WithRequireCanonicalDefault(t *testing.T) {
api := NewEthAPI(newBaseApiForTest(m), m.DB, nil, nil, nil, 5000000, ethconfig.Defaults.RPCTxFeeCap, 100_000, false, 100_000, 128, log.New())
addr := common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")

result, err := api.GetStorageAt(context.Background(), addr, "0x0", rpc.BlockNumberOrHashWithNumber(0))
result, err := api.GetStorageAt(context.Background(), addr, common.HexToHash("0x0").String(), rpc.BlockNumberOrHashWithNumber(0))
if err != nil {
t.Errorf("calling GetStorageAt: %v", err)
}
Expand All @@ -110,7 +110,7 @@ func TestGetStorageAt_ByBlockHash_WithRequireCanonicalDefault(t *testing.T) {
api := NewEthAPI(newBaseApiForTest(m), m.DB, nil, nil, nil, 5000000, ethconfig.Defaults.RPCTxFeeCap, 100_000, false, 100_000, 128, log.New())
addr := common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")

result, err := api.GetStorageAt(context.Background(), addr, "0x0", rpc.BlockNumberOrHashWithHash(m.Genesis.Hash(), false))
result, err := api.GetStorageAt(context.Background(), addr, common.HexToHash("0x0").String(), rpc.BlockNumberOrHashWithHash(m.Genesis.Hash(), false))
if err != nil {
t.Errorf("calling GetStorageAt: %v", err)
}
Expand All @@ -124,7 +124,7 @@ func TestGetStorageAt_ByBlockHash_WithRequireCanonicalTrue(t *testing.T) {
api := NewEthAPI(newBaseApiForTest(m), m.DB, nil, nil, nil, 5000000, ethconfig.Defaults.RPCTxFeeCap, 100_000, false, 100_000, 128, log.New())
addr := common.HexToAddress("0x71562b71999873db5b286df957af199ec94617f7")

result, err := api.GetStorageAt(context.Background(), addr, "0x0", rpc.BlockNumberOrHashWithHash(m.Genesis.Hash(), true))
result, err := api.GetStorageAt(context.Background(), addr, common.HexToHash("0x0").String(), rpc.BlockNumberOrHashWithHash(m.Genesis.Hash(), true))
if err != nil {
t.Errorf("calling GetStorageAt: %v", err)
}
Expand All @@ -144,7 +144,7 @@ func TestGetStorageAt_ByBlockHash_WithRequireCanonicalDefault_BlockNotFoundError
}
offChainBlock := offChain.Blocks[0]

if _, err := api.GetStorageAt(context.Background(), addr, "0x0", rpc.BlockNumberOrHashWithHash(offChainBlock.Hash(), false)); err != nil {
if _, err := api.GetStorageAt(context.Background(), addr, common.HexToHash("0x0").String(), rpc.BlockNumberOrHashWithHash(offChainBlock.Hash(), false)); err != nil {
if fmt.Sprintf("%v", err) != fmt.Sprintf("block %s not found", offChainBlock.Hash().String()[2:]) {
t.Errorf("wrong error: %v", err)
}
Expand All @@ -165,7 +165,7 @@ func TestGetStorageAt_ByBlockHash_WithRequireCanonicalTrue_BlockNotFoundError(t
}
offChainBlock := offChain.Blocks[0]

if _, err := api.GetStorageAt(context.Background(), addr, "0x0", rpc.BlockNumberOrHashWithHash(offChainBlock.Hash(), true)); err != nil {
if _, err := api.GetStorageAt(context.Background(), addr, common.HexToHash("0x0").String(), rpc.BlockNumberOrHashWithHash(offChainBlock.Hash(), true)); err != nil {
if fmt.Sprintf("%v", err) != fmt.Sprintf("block %s not found", offChainBlock.Hash().String()[2:]) {
t.Errorf("wrong error: %v", err)
}
Expand All @@ -182,7 +182,7 @@ func TestGetStorageAt_ByBlockHash_WithRequireCanonicalDefault_NonCanonicalBlock(

orphanedBlock := orphanedChain[0].Blocks[0]

result, err := api.GetStorageAt(context.Background(), addr, "0x0", rpc.BlockNumberOrHashWithHash(orphanedBlock.Hash(), false))
result, err := api.GetStorageAt(context.Background(), addr, common.HexToHash("0x0").String(), rpc.BlockNumberOrHashWithHash(orphanedBlock.Hash(), false))
if err != nil {
if fmt.Sprintf("%v", err) != fmt.Sprintf("hash %s is not currently canonical", orphanedBlock.Hash().String()[2:]) {
t.Errorf("wrong error: %v", err)
Expand All @@ -201,7 +201,7 @@ func TestGetStorageAt_ByBlockHash_WithRequireCanonicalTrue_NonCanonicalBlock(t *

orphanedBlock := orphanedChain[0].Blocks[0]

if _, err := api.GetStorageAt(context.Background(), addr, "0x0", rpc.BlockNumberOrHashWithHash(orphanedBlock.Hash(), true)); err != nil {
if _, err := api.GetStorageAt(context.Background(), addr, common.HexToHash("0x0").String(), rpc.BlockNumberOrHashWithHash(orphanedBlock.Hash(), true)); err != nil {
if fmt.Sprintf("%v", err) != fmt.Sprintf("hash %s is not currently canonical", orphanedBlock.Hash().String()[2:]) {
t.Errorf("wrong error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion turbo/jsonrpc/eth_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ func (api *APIImpl) CreateAccessList(ctx context.Context, args ethapi2.CallArgs,
errString = res.Err.Error()
}
accessList := &accessListResult{Accesslist: &accessList, Error: errString, GasUsed: hexutil.Uint64(res.UsedGas)}
if optimizeGas == nil || *optimizeGas { // optimize gas unless explicitly told not to
if optimizeGas != nil && *optimizeGas {
optimizeWarmAddrInAccessList(accessList, *args.From)
optimizeWarmAddrInAccessList(accessList, to)
optimizeWarmAddrInAccessList(accessList, header.Coinbase)
Expand Down
3 changes: 3 additions & 0 deletions turbo/jsonrpc/eth_receipts.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ func (api *APIImpl) GetBlockReceipts(ctx context.Context, numberOrHash rpc.Block
defer tx.Rollback()
blockNum, blockHash, _, err := rpchelper.GetBlockNumber(ctx, numberOrHash, tx, api._blockReader, api.filters)
if err != nil {
if errors.Is(err, rpchelper.BlockNotFoundErr{Hash: blockHash}) {
return nil, nil
}
return nil, err
}
block, err := api.blockWithSenders(ctx, tx, blockHash, blockNum)
Expand Down
10 changes: 9 additions & 1 deletion turbo/rpchelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ func (e nonCanonocalHashError) Error() string {
return fmt.Sprintf("hash %x is not currently canonical", e.hash)
}

type BlockNotFoundErr struct {
Hash libcommon.Hash
}

func (e BlockNotFoundErr) Error() string {
return fmt.Sprintf("block %x not found", e.Hash)
}

func GetBlockNumber(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash, tx kv.Tx, br services.FullBlockReader, filters *Filters) (uint64, libcommon.Hash, bool, error) {
bn, bh, latest, _, err := _GetBlockNumber(ctx, blockNrOrHash.RequireCanonical, blockNrOrHash, tx, br, filters)
return bn, bh, latest, err
Expand Down Expand Up @@ -121,7 +129,7 @@ func _GetBlockNumber(ctx context.Context, requireCanonical bool, blockNrOrHash r
return 0, libcommon.Hash{}, false, false, err
}
if number == nil {
return 0, libcommon.Hash{}, false, false, fmt.Errorf("block %x not found", hash)
return 0, libcommon.Hash{}, false, false, BlockNotFoundErr{Hash: hash}
}
blockNumber = *number

Expand Down

0 comments on commit a1449e1

Please sign in to comment.