eth/filters: use a sole context

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2023-06-08 07:19:48 +00:00
parent dc6a5b1b3d
commit 870bf640aa

View file

@ -275,6 +275,9 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
) )
syncHistLogs := func(n int64) error { syncHistLogs := func(n int64) error {
// the ctx will be canceled after this function is called
// and we are run in a background goroutine, use a new context instead
cctx := context.Background()
for { for {
// get the latest block header // get the latest block header
head := api.sys.backend.CurrentHeader().Number.Int64() head := api.sys.backend.CurrentHeader().Number.Int64()
@ -284,7 +287,7 @@ func (api *FilterAPI) Logs(ctx context.Context, crit FilterCriteria) (*rpc.Subsc
// do historical sync from n to head // do historical sync from n to head
f := api.sys.NewRangeFilter(n, head, crit.Addresses, crit.Topics) f := api.sys.NewRangeFilter(n, head, crit.Addresses, crit.Topics)
logChan, errChan := f.rangeLogsAsync(ctx) logChan, errChan := f.rangeLogsAsync(cctx)
// subscribe rmLogs // subscribe rmLogs
query := ethereum.FilterQuery{FromBlock: big.NewInt(n), ToBlock: big.NewInt(head), Addresses: crit.Addresses, Topics: crit.Topics} query := ethereum.FilterQuery{FromBlock: big.NewInt(n), ToBlock: big.NewInt(head), Addresses: crit.Addresses, Topics: crit.Topics}