|
5 | 5 | "errors"
|
6 | 6 | "fmt"
|
7 | 7 | "sync"
|
| 8 | + "time" |
8 | 9 |
|
| 10 | + "github.com/ledgerwatch/erigon-lib/gointerfaces/grpcutil" |
9 | 11 | "github.com/ledgerwatch/erigon-lib/gointerfaces/sentinel"
|
10 | 12 | "github.com/ledgerwatch/erigon/cl/clparams"
|
11 | 13 | "github.com/ledgerwatch/erigon/cl/cltypes"
|
@@ -46,20 +48,35 @@ func (c *ChainTipSubscriber) StartLoop() {
|
46 | 48 | }
|
47 | 49 | log.Info("[LightClient Gossip] Started Gossip")
|
48 | 50 | c.started = true
|
| 51 | + |
| 52 | +Retry: |
| 53 | + for { |
| 54 | + if err := c.subscribeGossip(); err != nil { |
| 55 | + if errors.Is(err, context.Canceled) { |
| 56 | + return |
| 57 | + } |
| 58 | + if grpcutil.IsRetryLater(err) || grpcutil.IsEndOfStream(err) { |
| 59 | + time.Sleep(3 * time.Second) |
| 60 | + continue Retry |
| 61 | + } |
| 62 | + |
| 63 | + log.Warn("[Lightclient] could not read gossip :/", "reason", err) |
| 64 | + time.Sleep(time.Second) |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | +func (c *ChainTipSubscriber) subscribeGossip() error { |
49 | 70 | stream, err := c.sentinel.SubscribeGossip(c.ctx, &sentinel.EmptyMessage{})
|
50 | 71 | if err != nil {
|
51 |
| - log.Warn("could not start lightclient", "reason", err) |
52 |
| - return |
| 72 | + return err |
53 | 73 | }
|
54 | 74 | defer stream.CloseSend()
|
55 | 75 |
|
56 | 76 | for {
|
57 | 77 | data, err := stream.Recv()
|
58 | 78 | if err != nil {
|
59 |
| - if !errors.Is(err, context.Canceled) { |
60 |
| - log.Debug("[Lightclient] could not read gossip :/", "reason", err) |
61 |
| - } |
62 |
| - continue |
| 79 | + return err |
63 | 80 | }
|
64 | 81 | if err := c.handleGossipData(data); err != nil {
|
65 | 82 | log.Warn("could not process new gossip",
|
|
0 commit comments