From 7f90a0fff7a9fa5f956c27e57f333eb86b4c2871 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Thu, 11 Sep 2025 15:58:46 +0800 Subject: [PATCH] ethclient: set from block to nil if q.from is nil --- ethclient/ethclient.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index f4b4a33ee1..ffe5d79075 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -479,6 +479,10 @@ func (ec *Client) SubscribeFilterLogs(ctx context.Context, q ethereum.FilterQuer // TODO(s1na): Log subscription prohibits ToBlock being set. // This will be later re-allowed once it supports historical-only queries. arg["toBlock"] = nil + // For subscriptions, if FromBlock is nil, we want only live logs, not historical logs from genesis + if q.FromBlock == nil { + arg["fromBlock"] = "latest" + } sub, err := ec.c.EthSubscribe(ctx, ch, "logs", arg) if err != nil { // Defensively prefer returning nil interface explicitly on error-path, instead