Skip to content

Commit 18ad562

Browse files
authored
cmd/rpctest: fix debug_accountRange bench encoding and start key size (erigontech#21774)
## Summary - `request_generator.go`: replace `base64.StdEncoding.EncodeToString` with `hexutil.Encode` for the `start` parameter — the server expects a `0x`-prefixed hex string, not base64 - `bench1.go`, `bench3.go`, `bench9.go`, `account_range_verify.go`: replace the initial page cursor from `common.Hash{}[:]` (32 bytes, rejected by the server) to `common.Address{}[:]` (20 bytes) - `request_generator_test.go`: update test cases to use 20-byte addresses and hex-encoded expected strings ## Test plan - [ ] `go test ./cmd/rpctest/rpctest/... -run TestRequestGenerator_accountRange` passes - [ ] `go test ./rpc/jsonrpc/... -run TestAccountRange` passes - [ ] `make lint` clean
1 parent 78e767e commit 18ad562

6 files changed

Lines changed: 24 additions & 27 deletions

File tree

cmd/rpctest/rpctest/account_range_verify.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ func CompareAccountRange(logger log.Logger, erigonURL, gethURL, tmpDataDir, geth
8888
f := func(url string, db kv.RwTx) error {
8989
i := uint64(0)
9090
reqGen := &RequestGenerator{}
91-
next := []byte{}
91+
var nextAddr common.Address
92+
next := nextAddr[:]
9293
for {
9394
ar := DebugAccountRange{}
9495
req := reqGen.accountRange(blockFrom, next, 256)

cmd/rpctest/rpctest/bench1.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ func Bench1(erigonURL, gethURL string, needCompare bool, fullTest bool, blockFro
255255
}
256256
fmt.Printf("Done blocks %d-%d, modified accounts: %d\n", prevBn, bn, len(mag.Result))
257257

258-
zeroHash := common.Hash{}
259-
page := zeroHash[:]
260-
pageGeth := zeroHash[:]
258+
zeroAddr := common.Address{}
259+
page := zeroAddr[:]
260+
pageGeth := zeroAddr[:]
261261

262262
var accRangeErigon map[common.Address]state.DumpAccount
263263
var accRangeGeth map[common.Address]state.DumpAccount

cmd/rpctest/rpctest/bench3.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package rpctest
1818

1919
import (
20-
"encoding/base64"
2120
"errors"
2221
"fmt"
2322
"maps"
2423

2524
"github.com/erigontech/erigon/common"
25+
"github.com/erigontech/erigon/common/hexutil"
2626
"github.com/erigontech/erigon/execution/state"
2727
)
2828

@@ -35,15 +35,14 @@ func Bench3(erigon_url, geth_url string) error {
3535
req_id++
3636
template := `{ "jsonrpc": "2.0", "method": "debug_accountRange", "params": ["0x1", "%s", %d, true, true, true], "id":%d}`
3737

38-
zeroHash := common.Hash{}
39-
page := zeroHash[:]
38+
zeroAddr := common.Address{}
39+
page := zeroAddr[:]
4040

4141
accRangeTG := make(map[common.Address]state.DumpAccount)
4242

4343
for len(page) > 0 {
44-
encodedKey := base64.StdEncoding.EncodeToString(page)
4544
var sr DebugAccountRange
46-
if err := post(client, erigon_url, fmt.Sprintf(template, encodedKey, pageSize, req_id), &sr); err != nil {
45+
if err := post(client, erigon_url, fmt.Sprintf(template, hexutil.Encode(page), pageSize, req_id), &sr); err != nil {
4746
return fmt.Errorf("Could not get accountRange: %v\n", err)
4847
}
4948
if sr.Error != nil {
@@ -57,19 +56,18 @@ func Bench3(erigon_url, geth_url string) error {
5756

5857
accRangeGeth := make(map[common.Address]state.DumpAccount)
5958

60-
page = zeroHash[:]
59+
page = zeroAddr[:]
6160
for len(page) > 0 {
62-
encodedKey := base64.StdEncoding.EncodeToString(page)
6361
var sr DebugAccountRange
64-
if err := post(client, geth_url, fmt.Sprintf(template, encodedKey, pageSize, req_id), &sr); err != nil {
62+
if err := post(client, geth_url, fmt.Sprintf(template, hexutil.Encode(page), pageSize, req_id), &sr); err != nil {
6563
return fmt.Errorf("Could not get accountRange: %v\n", err)
6664
}
6765
if sr.Error != nil {
6866
fmt.Printf("Error getting accountRange: %d %s\n", sr.Error.Code, sr.Error.Message)
6967
break
7068
} else {
7169
page = sr.Result.Next
72-
maps.Copy(accRangeTG, sr.Result.Accounts)
70+
maps.Copy(accRangeGeth, sr.Result.Accounts)
7371
}
7472
}
7573

cmd/rpctest/rpctest/bench9.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func Bench9(erigonURL, gethURL string, needCompare, latest bool) error {
4343
fmt.Printf("Last block: %d\n", lastBlock)
4444
// Go back 256 blocks
4545
bn := uint64(lastBlock) - 256
46-
zeroHash := common.Hash{}
47-
page := zeroHash[:]
46+
zeroAddr := common.Address{}
47+
page := zeroAddr[:]
4848

4949
var resultsCh chan CallResult = nil
5050
if !needCompare {

cmd/rpctest/rpctest/request_generator.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package rpctest
1818

1919
import (
20-
"encoding/base64"
2120
"fmt"
2221
"net/http"
2322
"strings"
@@ -179,8 +178,7 @@ func (g *RequestGenerator) getOverlayLogs2(prevBn uint64, bn uint64, account com
179178

180179
func (g *RequestGenerator) accountRange(bn uint64, page []byte, num int) string { //nolint
181180
const template = `{ "jsonrpc": "2.0", "method": "debug_accountRange", "params": ["0x%x", "%s", %d, false, false], "id":%d}`
182-
encodedKey := base64.StdEncoding.EncodeToString(page)
183-
return fmt.Sprintf(template, bn, encodedKey, num, g.reqID.Add(1))
181+
return fmt.Sprintf(template, bn, hexutil.Encode(page), num, g.reqID.Add(1))
184182
}
185183

186184
func (g *RequestGenerator) getProof(bn uint64, account common.Address, storageList []common.Hash) string {

cmd/rpctest/rpctest/request_generator_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@ func TestRequestGenerator_getLogs2(t *testing.T) {
414414
}
415415

416416
func TestRequestGenerator_accountRange(t *testing.T) {
417-
hash1 := common.HexToHash("0x6f9e34c00812a80fa87df26208bbe69411e36d6a9f00b35444ef4181f6c483ca")
418-
hash2 := common.HexToHash("0x1cfe7ce95a1694d8969365cb472ce4a0d3eed812c540fd7708bbe6941e34c4de")
419-
hash3 := common.HexToHash("0x1cd73c7adf5b31f3cf94c67b9e251e699559d91c27664463fb5978b97f8b2d1b")
417+
addr1 := common.HexToAddress("0x6f9e34c00812a80fa87df26208bbe69411e36d6a")
418+
addr2 := common.HexToAddress("0x1cfe7ce95a1694d8969365cb472ce4a0d3eed812")
419+
addr3 := common.HexToAddress("0x1cd73c7adf5b31f3cf94c67b9e251e699559d91c")
420420
testCases := []struct {
421421
reqId int
422422
blockNum uint64
@@ -427,23 +427,23 @@ func TestRequestGenerator_accountRange(t *testing.T) {
427427
{
428428
1,
429429
4756370,
430-
hash1[:],
430+
addr1[:],
431431
1,
432-
`{ "jsonrpc": "2.0", "method": "debug_accountRange", "params": ["0x489392", "b540wAgSqA+offJiCLvmlBHjbWqfALNURO9BgfbEg8o=", 1, false, false], "id":1}`,
432+
`{ "jsonrpc": "2.0", "method": "debug_accountRange", "params": ["0x489392", "0x6f9e34c00812a80fa87df26208bbe69411e36d6a", 1, false, false], "id":1}`,
433433
},
434434
{
435435
2,
436436
0,
437-
hash2[:],
437+
addr2[:],
438438
2,
439-
`{ "jsonrpc": "2.0", "method": "debug_accountRange", "params": ["0x0", "HP586VoWlNiWk2XLRyzkoNPu2BLFQP13CLvmlB40xN4=", 2, false, false], "id":2}`,
439+
`{ "jsonrpc": "2.0", "method": "debug_accountRange", "params": ["0x0", "0x1cfe7ce95a1694d8969365cb472ce4a0d3eed812", 2, false, false], "id":2}`,
440440
},
441441
{
442442
3,
443443
1234567,
444-
hash3[:],
444+
addr3[:],
445445
3,
446-
`{ "jsonrpc": "2.0", "method": "debug_accountRange", "params": ["0x12d687", "HNc8et9bMfPPlMZ7niUeaZVZ2RwnZkRj+1l4uX+LLRs=", 3, false, false], "id":3}`,
446+
`{ "jsonrpc": "2.0", "method": "debug_accountRange", "params": ["0x12d687", "0x1cd73c7adf5b31f3cf94c67b9e251e699559d91c", 3, false, false], "id":3}`,
447447
},
448448
}
449449

0 commit comments

Comments
 (0)