Skip to content

Commit

Permalink
Only pass limit argument to z_getsubtreesbyindex if maxEntries > 0
Browse files Browse the repository at this point in the history
We also remove the `i < maxEntries` bound on returned results, as the
`limit` parameter already causes `zcashd` to bound its returned entries.

Closes #444.
  • Loading branch information
str4d authored and LarryRuane committed Jul 11, 2023
1 parent ab90099 commit b805382
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions frontend/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,14 +689,16 @@ func (s *lwdStreamer) GetSubtreeRoots(arg *walletrpc.GetSubtreeRootsArg, resp wa
if err != nil {
return errors.New("bad startIndex")
}
maxEntriesJSON, err := json.Marshal(arg.MaxEntries)
if err != nil {
return errors.New("bad maxEntries")
}
params := []json.RawMessage{
protocol,
startIndexJSON,
maxEntriesJSON,
}
if arg.MaxEntries > 0 {
maxEntriesJSON, err := json.Marshal(arg.MaxEntries)
if err != nil {
return errors.New("bad maxEntries")
}
params = append(params, maxEntriesJSON)
}
result, rpcErr := common.RawRequest("z_getsubtreesbyindex", params)

Expand All @@ -708,7 +710,7 @@ func (s *lwdStreamer) GetSubtreeRoots(arg *walletrpc.GetSubtreeRootsArg, resp wa
if err != nil {
return err
}
for i := 0; i < int(arg.MaxEntries) && i < len(reply.Subtrees); i++ {
for i := 0; i < len(reply.Subtrees); i++ {
subtree := reply.Subtrees[i]
block, err := common.GetBlock(s.cache, subtree.End_height)
if block == nil {
Expand Down

0 comments on commit b805382

Please sign in to comment.