Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

toolchain go1.21.8

replace github.com/ethereum/go-ethereum v1.10.26 => github.com/status-im/go-ethereum v1.10.25-status.16
replace github.com/ethereum/go-ethereum v1.10.26 => github.com/status-im/go-ethereum v1.10.25-status.18

replace github.com/rjeczalik/notify => github.com/status-im/notify v1.0.2-status

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2018,8 +2018,8 @@ github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/y
github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
github.com/status-im/doubleratchet v3.0.0+incompatible h1:aJ1ejcSERpSzmWZBgtfYtiU2nF0Q8ZkGyuEPYETXkCY=
github.com/status-im/doubleratchet v3.0.0+incompatible/go.mod h1:1sqR0+yhiM/bd+wrdX79AOt2csZuJOni0nUDzKNuqOU=
github.com/status-im/go-ethereum v1.10.25-status.16 h1:6CjK8qdlUc/7n42UJ743rf13x/ICSwxrh/NlDGyvmOk=
github.com/status-im/go-ethereum v1.10.25-status.16/go.mod h1:Dt4K5JYMhJRdtXJwBEyGZLZn9iz/chSOZyjVmt5ZhwQ=
github.com/status-im/go-ethereum v1.10.25-status.18 h1:nPntq/vB9Pc+GgUdnnT6BITdvsDz1+oInwBa4pAuv3Q=
github.com/status-im/go-ethereum v1.10.25-status.18/go.mod h1:Dt4K5JYMhJRdtXJwBEyGZLZn9iz/chSOZyjVmt5ZhwQ=
github.com/status-im/go-sqlcipher/v4 v4.5.4-status.3 h1:/73h1w1hUfb3wVyTlNrUIwahZxatgesCHa6lwO57C2M=
github.com/status-im/go-sqlcipher/v4 v4.5.4-status.3/go.mod h1:mF2UmIpBnzFeBdu/ypTDb/LdbS0nk0dfSN1WUsWTjMA=
github.com/status-im/gomoji v1.1.3-0.20220213022530-e5ac4a8732d4 h1:CtobZoiNdHpx+xurFxnuJ1xsGm3oKMfcZkB3vmomJmA=
Expand Down
18 changes: 0 additions & 18 deletions rpc/chain/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,24 +783,6 @@ func (c *ClientWithFallback) GetBaseFeeFromBlock(ctx context.Context, blockNumbe
return baseGasFee, err
}

func (c *ClientWithFallback) CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error) {
rpcstats.CountCallWithTag("eth_FullTransactionByBlockNumberAndIndex", c.tag)

res, err := c.makeCall(
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
return client.CallBlockHashByTransaction(ctx, blockNumber, index)
},
)

c.toggleConnectionState(err)

if err != nil {
return common.HexToHash(""), err
}

return res.(common.Hash), nil
}

func (c *ClientWithFallback) GetWalletNotifier() func(chainId uint64, message string) {
return c.WalletNotifier
}
Expand Down
8 changes: 0 additions & 8 deletions rpc/chain/ethclient/eth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type EthClientInterface interface {
GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error)
bind.ContractCaller
bind.ContractBackend
CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error)
}

// EthClient implements EthClientInterface
Expand All @@ -82,13 +81,6 @@ func (ec *EthClient) BatchCallContext(ctx context.Context, b []rpc.BatchElem) er
return ec.rpcClient.BatchCallContext(ctx, b)
}

// go-ethereum's `Transaction` items drop the blkHash obtained during the RPC call.
// This function preserves the additional data. This is the cheapest way to obtain
// the block hash for a given block number.
func (ec *EthClient) CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error) {
return callBlockHashByTransaction(ctx, ec.rpcClient, blockNumber, index)
}

func (ec *EthClient) GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error) {
feeHistory, err := ec.FeeHistory(ctx, 1, blockNumber, nil)

Expand Down
13 changes: 13 additions & 0 deletions rpc/chain/ethclient/geth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ethclient

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestGeth_HeaderHash(t *testing.T) {
number, hash, header := getTestBlockHeader()
require.Equal(t, number.String(), header.Number.String())
require.Equal(t, hash, header.Hash())
}
28 changes: 28 additions & 0 deletions rpc/chain/ethclient/geth_test_data.go

Large diffs are not rendered by default.

66 changes: 0 additions & 66 deletions rpc/chain/ethclient/rpc.go

This file was deleted.

15 changes: 0 additions & 15 deletions rpc/chain/mock/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions rpc/chain/mock/client/ethclient/eth_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions rpc/chain/mock/client/ethclient/rps_limited_eth_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion services/wallet/balance/balance_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Reader interface {
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error)
NetworkID() uint64
}

Expand Down
30 changes: 16 additions & 14 deletions services/wallet/transfer/commands_sequential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ func (tc *TestClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([
logs := []types.Log{}
for _, transfer := range allTransfers {
if transfer.block.Cmp(q.FromBlock) >= 0 && transfer.block.Cmp(q.ToBlock) <= 0 {
header := getTestHeader(transfer.block)
log := types.Log{
BlockNumber: transfer.block.Uint64(),
BlockHash: common.BigToHash(transfer.block),
BlockNumber: header.Number.Uint64(),
BlockHash: header.Hash(),
}

// Use the address at least in one any(from/to) topic to trick the implementation
Expand Down Expand Up @@ -287,6 +288,18 @@ func (tc *TestClient) tokenBalanceAt(account common.Address, token common.Addres
return balance
}

func getTestHeader(number *big.Int) *types.Header {
return &types.Header{
Number: big.NewInt(0).Set(number),
Time: 0,
Difficulty: big.NewInt(0),
ParentHash: common.Hash{},
Nonce: types.BlockNonce{},
MixDigest: common.Hash{},
Extra: make([]byte, 0),
}
}

func (tc *TestClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
if number == nil {
number = big.NewInt(int64(tc.currentBlock))
Expand All @@ -297,22 +310,11 @@ func (tc *TestClient) HeaderByNumber(ctx context.Context, number *big.Int) (*typ
return nil, err
}

header := &types.Header{
Number: number,
Time: 0,
}
header := getTestHeader(number)

return header, nil
}

func (tc *TestClient) CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error) {
err := tc.countAndlog("CallBlockHashByTransaction")
if err != nil {
return common.Hash{}, err
}
return common.BigToHash(blockNumber), nil
}

func (tc *TestClient) GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error) {
err := tc.countAndlog("GetBaseFeeFromBlock")
return "", err
Expand Down
8 changes: 1 addition & 7 deletions services/wallet/transfer/concurrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,11 @@ func checkRangesWithStartBlock(parent context.Context, client balance.Reader, ca
}
}
if new(big.Int).Sub(to, from).Cmp(one) == 0 {
// WARNING: Block hash calculation from plain header returns a wrong value.
header, err := client.HeaderByNumber(ctx, to)
if err != nil {
return err
}
// Obtain block hash from first transaction
blockHash, err := client.CallBlockHashByTransaction(ctx, to, 0)
if err != nil {
return err
}
c.PushHeader(toDBHeader(header, blockHash, account))
c.PushHeader(toDBHeader(header, account))
return nil
}
mid := new(big.Int).Add(from, to)
Expand Down
4 changes: 0 additions & 4 deletions services/wallet/transfer/concurrent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ func (f balancesFixture) NetworkID() uint64 {
return 0
}

func (f balancesFixture) CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error) {
return common.HexToHash("0x0"), nil
}

type batchesFixture [][]Transfer

func (f batchesFixture) GetTransfersByNumber(ctx context.Context, number *big.Int) (rst []Transfer, err error) {
Expand Down
4 changes: 2 additions & 2 deletions services/wallet/transfer/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ type DBHeader struct {
Loaded bool
}

func toDBHeader(header *types.Header, blockHash common.Hash, account common.Address) *DBHeader {
func toDBHeader(header *types.Header, account common.Address) *DBHeader {
return &DBHeader{
Hash: blockHash,
Hash: header.Hash(),
Number: header.Number,
Timestamp: header.Time,
Loaded: false,
Expand Down
Loading