Skip to content

Commit

Permalink
shovel/jrpc2: improve error detection for 'eth backend missing logs f…
Browse files Browse the repository at this point in the history
…or block'
  • Loading branch information
ryandotsmith committed Jun 19, 2024
1 parent a7ed2dd commit 499c6f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions jrpc2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -731,15 +731,17 @@ type logResp struct {

func (c *Client) logs(ctx context.Context, url string, filter *glf.Filter, bm blockmap, start, limit uint64) error {
var (
t0 = time.Now()
lf = struct {
t0 = time.Now()
fromBlock = start
toBlock = start + limit - 1
lf = struct {
From string `json:"fromBlock"`
To string `json:"toBlock"`
Address []string `json:"address"`
Topics [][]string `json:"topics"`
}{
From: eth.EncodeUint64(start),
To: eth.EncodeUint64(start + limit - 1),
From: eth.EncodeUint64(fromBlock),
To: eth.EncodeUint64(toBlock),
Address: filter.Addresses(),
Topics: filter.Topics(),
}
Expand All @@ -753,7 +755,7 @@ func (c *Client) logs(ctx context.Context, url string, filter *glf.Filter, bm bl
ID: fmt.Sprintf("blocks-%d-%d-%x", start, limit, randbytes()),
Version: "2.0",
Method: "eth_getBlockByNumber",
Params: []any{"0x" + strconv.FormatUint(start, 16), false},
Params: []any{lf.To, false},
},
request{
ID: fmt.Sprintf("logs-%d-%d-%x", start, limit, randbytes()),
Expand All @@ -770,12 +772,12 @@ func (c *Client) logs(ctx context.Context, url string, filter *glf.Filter, bm bl
lresp = resp[1].(*logResp)
)
switch {
case hresp.Header == nil:
return fmt.Errorf("eth backend missing logs for block")
case hresp.Error.Exists():
return fmt.Errorf("rpc=eth_getLogs/eth_getBlockByNumber %w", lresp.Error)
case lresp.Error.Exists():
return fmt.Errorf("rpc=eth_getLogs %w", lresp.Error)
case hresp.Header == nil:
return fmt.Errorf("eth backend missing logs for block: %d", toBlock)
}
var logsByTx = map[key][]logResult{}
for i := range lresp.Result {
Expand Down
2 changes: 1 addition & 1 deletion jrpc2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func TestValidate_Logs_NoBlocks(t *testing.T) {
_, err = c.Get(ctx, c.NextURL().String(), &glf.Filter{UseLogs: true}, 18000000, 2)
)
tc.WantErr(t, err)
const want = "getting logs: eth backend missing logs for block"
const want = "getting logs: eth backend missing logs for block: 18000001"
tc.WantGot(t, want, err.Error())
}

Expand Down

0 comments on commit 499c6f8

Please sign in to comment.