mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
eth/filters: fix the issue of wrong check on from block
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
a43785332f
commit
a374b1b6ea
1 changed files with 19 additions and 15 deletions
|
|
@ -288,18 +288,25 @@ func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.S
|
||||||
return errInvalidToBlock
|
return errInvalidToBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
switch from {
|
|
||||||
case rpc.LatestBlockNumber:
|
|
||||||
// do live filter only
|
// do live filter only
|
||||||
|
if from == rpc.LatestBlockNumber {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
from = rpc.BlockNumber(header.Number.Int64())
|
||||||
|
}
|
||||||
|
if from < 0 {
|
||||||
|
return errInvalidFromBlock
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// do historical sync first
|
// do historical sync first
|
||||||
_, err := api.histLogs(ctx, notifier, rpcSub, header.Number.Int64(), crit)
|
_, err := api.histLogs(ctx, notifier, rpcSub, int64(from), crit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -307,9 +314,6 @@ func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.S
|
||||||
api.liveLogs(ctx, notifier, rpcSub, crit)
|
api.liveLogs(ctx, notifier, rpcSub, crit)
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
default:
|
|
||||||
return errInvalidFromBlock
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// liveLogs only retrieves live logs
|
// liveLogs only retrieves live logs
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue