@@ -13,7 +13,9 @@ import (
1313 "github.com/prysmaticlabs/prysm/shared/slotutil"
1414 "github.com/sirupsen/logrus"
1515 "go.opencensus.io/trace"
16+ "google.golang.org/grpc"
1617 "google.golang.org/grpc/codes"
18+ "google.golang.org/grpc/connectivity"
1719 "google.golang.org/grpc/status"
1820)
1921
@@ -46,7 +48,7 @@ func (bs *Service) ReceiveBlocks(ctx context.Context) {
4648 if err != nil {
4749 if e , ok := status .FromError (err ); ok {
4850 switch e .Code () {
49- case codes .Canceled :
51+ case codes .Canceled , codes . Internal :
5052 stream , err = bs .restartBlockStream (ctx )
5153 if err != nil {
5254 log .WithError (err ).Error ("Could not restart stream" )
@@ -109,7 +111,7 @@ func (bs *Service) ReceiveAttestations(ctx context.Context) {
109111 if err != nil {
110112 if e , ok := status .FromError (err ); ok {
111113 switch e .Code () {
112- case codes .Canceled :
114+ case codes .Canceled , codes . Internal :
113115 stream , err = bs .restartIndexedAttestationStream (ctx )
114116 if err != nil {
115117 log .WithError (err ).Error ("Could not restart stream" )
@@ -179,6 +181,16 @@ func (bs *Service) restartIndexedAttestationStream(ctx context.Context) (ethpb.B
179181 select {
180182 case <- ticker .C :
181183 log .Info ("Context closed, attempting to restart attestation stream" )
184+ conn , err := grpc .DialContext (bs .ctx , bs .provider , bs .beaconDialOptions ... )
185+ if err != nil {
186+ log .Debug ("Failed to dial beacon node" )
187+ continue
188+ }
189+ log .Debugf ("connection status %v" , conn .GetState ())
190+ if conn .GetState () == connectivity .TransientFailure || conn .GetState () == connectivity .Idle {
191+ log .Debug ("Beacon node is still down" )
192+ continue
193+ }
182194 stream , err := bs .beaconClient .StreamIndexedAttestations (ctx , & ptypes.Empty {})
183195 if err != nil {
184196 continue
@@ -199,6 +211,16 @@ func (bs *Service) restartBlockStream(ctx context.Context) (ethpb.BeaconChain_St
199211 select {
200212 case <- ticker .C :
201213 log .Info ("Context closed, attempting to restart block stream" )
214+ conn , err := grpc .DialContext (bs .ctx , bs .provider , bs .beaconDialOptions ... )
215+ if err != nil {
216+ log .Debug ("Failed to dial beacon node" )
217+ continue
218+ }
219+ log .Debugf ("connection status %v" , conn .GetState ())
220+ if conn .GetState () == connectivity .TransientFailure || conn .GetState () == connectivity .Idle {
221+ log .Debug ("Beacon node is still down" )
222+ continue
223+ }
202224 stream , err := bs .beaconClient .StreamBlocks (ctx , & ptypes.Empty {})
203225 if err != nil {
204226 continue
0 commit comments