eth/filters: fix the issue of wrong check on from block

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-06-27 00:46:39 +08:00
parent a43785332f
commit a374b1b6ea

View file

@ -288,28 +288,32 @@ func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.S
return errInvalidToBlock return errInvalidToBlock
} }
switch from { // do live filter only
case rpc.LatestBlockNumber: if from == rpc.LatestBlockNumber {
// do live filter only
return api.liveLogs(ctx, notifier, rpcSub, crit) return api.liveLogs(ctx, notifier, rpcSub, crit)
case rpc.SafeBlockNumber, rpc.FinalizedBlockNumber: }
if from == rpc.SafeBlockNumber || from == rpc.FinalizedBlockNumber {
header, err := api.sys.backend.HeaderByNumber(ctx, from) header, err := api.sys.backend.HeaderByNumber(ctx, from)
if err != nil { if err != nil {
return err return err
} }
go func() { from = rpc.BlockNumber(header.Number.Int64())
// do historical sync first }
_, err := api.histLogs(ctx, notifier, rpcSub, header.Number.Int64(), crit) if from < 0 {
if err != nil {
return
}
// then subscribe from the header
api.liveLogs(ctx, notifier, rpcSub, crit)
}()
return nil
default:
return errInvalidFromBlock return errInvalidFromBlock
} }
go func() {
// do historical sync first
_, err := api.histLogs(ctx, notifier, rpcSub, int64(from), crit)
if err != nil {
return
}
// then subscribe from the header
api.liveLogs(ctx, notifier, rpcSub, crit)
}()
return nil
} }
// liveLogs only retrieves live logs // liveLogs only retrieves live logs