Skip to content

Commit

Permalink
fix: remove unnecessary threading
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Aug 28, 2024
1 parent 52f309f commit d69e31a
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions node/pkg/chain/websocketchainreader/websocketreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,14 @@ func (c *ChainReader) handleSubscription(ctx context.Context, config *SubscribeC
Addresses: []common.Address{common.HexToAddress(config.Address)},
}

headerSubChan := make(chan *types.Header, 1)
defer close(headerSubChan)
// Subscribe to new head just to keep connection alive (ignoring the results)
subNewHead, err := c.client(config.ChainType).SubscribeNewHead(ctx, headerSubChan)
subNewHead, err := c.client(config.ChainType).SubscribeNewHead(ctx, nil)
if err != nil {
log.Warn().Err(err).Msg("Failed to subscribe to new head")
} else {
defer subNewHead.Unsubscribe()
}

go func() {
for {
select {
case <-ctx.Done():
return
case <-headerSubChan:
}
}
}()

logs := make(chan types.Log)
sub, err := c.client(config.ChainType).SubscribeFilterLogs(ctx, query, logs)
if err != nil {
Expand Down

0 comments on commit d69e31a

Please sign in to comment.