From a374b1b6ea2d754a493b87a4e2d292bb71965bfc Mon Sep 17 00:00:00 2001 From: jsvisa Date: Tue, 27 Jun 2023 00:46:39 +0800 Subject: [PATCH] eth/filters: fix the issue of wrong check on from block Signed-off-by: jsvisa --- eth/filters/api.go | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/eth/filters/api.go b/eth/filters/api.go index f11a5f551a..31252dcf04 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -288,28 +288,32 @@ func (api *FilterAPI) logs(ctx context.Context, notifier notifier, rpcSub *rpc.S 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) - case rpc.SafeBlockNumber, rpc.FinalizedBlockNumber: + } + + if from == rpc.SafeBlockNumber || from == rpc.FinalizedBlockNumber { header, err := api.sys.backend.HeaderByNumber(ctx, from) if err != nil { return err } - go func() { - // do historical sync first - _, err := api.histLogs(ctx, notifier, rpcSub, header.Number.Int64(), crit) - if err != nil { - return - } - // then subscribe from the header - api.liveLogs(ctx, notifier, rpcSub, crit) - }() - return nil - default: + from = rpc.BlockNumber(header.Number.Int64()) + } + if from < 0 { 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