Skip to content

Commit

Permalink
[api] fix inaccurate result of getLogs (#4334)
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Aug 21, 2024
1 parent 5a70153 commit a490d25
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -1505,12 +1505,6 @@ func (core *coreService) LogsInRange(filter *logfilter.LogFilter, start, end, pa
if err != nil {
return nil, nil, err
}
if paginationSize == 0 {
paginationSize = 1000
}
if paginationSize > 5000 {
paginationSize = 5000
}
// getLogs via range Blooom filter [start, end]
blockNumbers, err := core.bfIndexer.FilterBlocksInRange(filter, start, end, paginationSize)
if err != nil {
Expand Down Expand Up @@ -1565,7 +1559,7 @@ func (core *coreService) LogsInRange(filter *logfilter.LogFilter, start, end, pa
for j := range logsInBlk[i] {
logs = append(logs, logsInBlk[i][j])
hashes = append(hashes, HashInBlk[i])
if len(logs) >= int(paginationSize) {
if paginationSize > 0 && len(logs) >= int(paginationSize) {
return logs, hashes, nil
}
}
Expand All @@ -1575,20 +1569,24 @@ func (core *coreService) LogsInRange(filter *logfilter.LogFilter, start, end, pa
}

func (core *coreService) correctQueryRange(start, end uint64) (uint64, uint64, error) {
bfTipHeight, err := core.bfIndexer.Height()
if err != nil {
return 0, 0, err
}
if start == 0 {
start = core.bc.TipHeight()
start = bfTipHeight
}
if end == 0 {
end = core.bc.TipHeight()
end = bfTipHeight
}
if start > end {
return 0, 0, errors.New("invalid start or end height")
}
if start > core.bc.TipHeight() {
if start > bfTipHeight {
return 0, 0, errors.New("start block > tip height")
}
if end > core.bc.TipHeight() {
end = core.bc.TipHeight()
if end > bfTipHeight {
end = bfTipHeight
}
return start, end, nil
}
Expand Down

0 comments on commit a490d25

Please sign in to comment.