Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: eth_subscribe with geth open ended range #2027

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions evmrpc/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ func (a *SubscriptionAPI) Logs(ctx context.Context, filter *filters.FilterCriter
if filter == nil {
filter = &filters.FilterCriteria{}
}

// when fromBlock is 0 and toBlock is latest, adjust the filter
// to unbounded filter
if filter.FromBlock != nil && filter.FromBlock.Int64() == 0 &&
filter.ToBlock != nil && filter.ToBlock.Int64() < 0 {
unboundedFilter := &filters.FilterCriteria{
FromBlock: filter.FromBlock, // keep "0x0" to fetch historical logs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The desired behavior in this scenario is not to fetch historic logs, just stream any new logs.

Copy link
Contributor

@cordt-sei cordt-sei Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looking through the relevant geth docs, toBlock and fromBlock are not even valid parameters for this method in any context so it's very confusing as to why they are being passed there in the first place.

ToBlock: nil, // set to nil to continue listening
Addresses: filter.Addresses,
Topics: filter.Topics,
}
filter = unboundedFilter
}

rpcSub := notifier.CreateSubscription()

if filter.BlockHash != nil {
Expand Down
Loading