Skip to content

Commit e201406

Browse files
committed
chore_: remove CallBlockHashByTransaction workaround for bad block hash calculation
1 parent fa9eebd commit e201406

File tree

11 files changed

+19
-165
lines changed

11 files changed

+19
-165
lines changed

rpc/chain/client.go

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -783,24 +783,6 @@ func (c *ClientWithFallback) GetBaseFeeFromBlock(ctx context.Context, blockNumbe
783783
return baseGasFee, err
784784
}
785785

786-
func (c *ClientWithFallback) CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error) {
787-
rpcstats.CountCallWithTag("eth_FullTransactionByBlockNumberAndIndex", c.tag)
788-
789-
res, err := c.makeCall(
790-
ctx, c.ethClients, func(client ethclient.RPSLimitedEthClientInterface) (interface{}, error) {
791-
return client.CallBlockHashByTransaction(ctx, blockNumber, index)
792-
},
793-
)
794-
795-
c.toggleConnectionState(err)
796-
797-
if err != nil {
798-
return common.HexToHash(""), err
799-
}
800-
801-
return res.(common.Hash), nil
802-
}
803-
804786
func (c *ClientWithFallback) GetWalletNotifier() func(chainId uint64, message string) {
805787
return c.WalletNotifier
806788
}

rpc/chain/ethclient/eth_client.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ type EthClientInterface interface {
6262
GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error)
6363
bind.ContractCaller
6464
bind.ContractBackend
65-
CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error)
6665
}
6766

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

85-
// go-ethereum's `Transaction` items drop the blkHash obtained during the RPC call.
86-
// This function preserves the additional data. This is the cheapest way to obtain
87-
// the block hash for a given block number.
88-
func (ec *EthClient) CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error) {
89-
return callBlockHashByTransaction(ctx, ec.rpcClient, blockNumber, index)
90-
}
91-
9284
func (ec *EthClient) GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error) {
9385
feeHistory, err := ec.FeeHistory(ctx, 1, blockNumber, nil)
9486

rpc/chain/ethclient/rpc.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

rpc/chain/mock/client/client.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/chain/mock/client/ethclient/eth_client.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/chain/mock/client/ethclient/rps_limited_eth_client.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/wallet/balance/balance_cache.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type Reader interface {
1515
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
1616
NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
1717
HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
18-
CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error)
1918
NetworkID() uint64
2019
}
2120

services/wallet/transfer/commands_sequential_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ func (tc *TestClient) FilterLogs(ctx context.Context, q ethereum.FilterQuery) ([
232232
logs := []types.Log{}
233233
for _, transfer := range allTransfers {
234234
if transfer.block.Cmp(q.FromBlock) >= 0 && transfer.block.Cmp(q.ToBlock) <= 0 {
235+
header := getTestHeader(transfer.block)
235236
log := types.Log{
236-
BlockNumber: transfer.block.Uint64(),
237-
BlockHash: common.BigToHash(transfer.block),
237+
BlockNumber: header.Number.Uint64(),
238+
BlockHash: header.Hash(),
238239
}
239240

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

291+
func getTestHeader(number *big.Int) *types.Header {
292+
return &types.Header{
293+
Number: big.NewInt(0).Set(number),
294+
Time: 0,
295+
Difficulty: big.NewInt(0),
296+
ParentHash: common.Hash{},
297+
Nonce: types.BlockNonce{},
298+
MixDigest: common.Hash{},
299+
Extra: make([]byte, 0),
300+
}
301+
}
302+
290303
func (tc *TestClient) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) {
291304
if number == nil {
292305
number = big.NewInt(int64(tc.currentBlock))
@@ -297,22 +310,11 @@ func (tc *TestClient) HeaderByNumber(ctx context.Context, number *big.Int) (*typ
297310
return nil, err
298311
}
299312

300-
header := &types.Header{
301-
Number: number,
302-
Time: 0,
303-
}
313+
header := getTestHeader(number)
304314

305315
return header, nil
306316
}
307317

308-
func (tc *TestClient) CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error) {
309-
err := tc.countAndlog("CallBlockHashByTransaction")
310-
if err != nil {
311-
return common.Hash{}, err
312-
}
313-
return common.BigToHash(blockNumber), nil
314-
}
315-
316318
func (tc *TestClient) GetBaseFeeFromBlock(ctx context.Context, blockNumber *big.Int) (string, error) {
317319
err := tc.countAndlog("GetBaseFeeFromBlock")
318320
return "", err

services/wallet/transfer/concurrent.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,11 @@ func checkRangesWithStartBlock(parent context.Context, client balance.Reader, ca
177177
}
178178
}
179179
if new(big.Int).Sub(to, from).Cmp(one) == 0 {
180-
// WARNING: Block hash calculation from plain header returns a wrong value.
181180
header, err := client.HeaderByNumber(ctx, to)
182181
if err != nil {
183182
return err
184183
}
185-
// Obtain block hash from first transaction
186-
blockHash, err := client.CallBlockHashByTransaction(ctx, to, 0)
187-
if err != nil {
188-
return err
189-
}
190-
c.PushHeader(toDBHeader(header, blockHash, account))
184+
c.PushHeader(toDBHeader(header, account))
191185
return nil
192186
}
193187
mid := new(big.Int).Add(from, to)

services/wallet/transfer/concurrent_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ func (f balancesFixture) NetworkID() uint64 {
8181
return 0
8282
}
8383

84-
func (f balancesFixture) CallBlockHashByTransaction(ctx context.Context, blockNumber *big.Int, index uint) (common.Hash, error) {
85-
return common.HexToHash("0x0"), nil
86-
}
87-
8884
type batchesFixture [][]Transfer
8985

9086
func (f batchesFixture) GetTransfersByNumber(ctx context.Context, number *big.Int) (rst []Transfer, err error) {

0 commit comments

Comments
 (0)