From 72aa44efe669e5d1f1b10f93fe1b153b63b82952 Mon Sep 17 00:00:00 2001 From: Krishna Upadhyaya Date: Thu, 11 Aug 2022 23:10:08 +0530 Subject: [PATCH] Fix EOF error in gRPC state-sync (#489) * Fix EOF error in gRPC state-sync * linters Co-authored-by: Evgeny Danienko <6655321@bk.ru> --- consensus/bor/heimdallgrpc/state_sync.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/consensus/bor/heimdallgrpc/state_sync.go b/consensus/bor/heimdallgrpc/state_sync.go index 910fb6c4ee..a3bbb80aae 100644 --- a/consensus/bor/heimdallgrpc/state_sync.go +++ b/consensus/bor/heimdallgrpc/state_sync.go @@ -2,11 +2,13 @@ package heimdallgrpc import ( "context" - - proto "github.com/maticnetwork/polyproto/heimdall" + "errors" + "io" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus/bor/clerk" + + proto "github.com/maticnetwork/polyproto/heimdall" ) func (h *HeimdallGRPCClient) StateSyncEvents(ctx context.Context, fromID uint64, to int64) ([]*clerk.EventRecordWithTime, error) { @@ -31,8 +33,12 @@ func (h *HeimdallGRPCClient) StateSyncEvents(ctx context.Context, fromID uint64, for { events, err = res.Recv() + if errors.Is(err, io.EOF) { + return eventRecords, nil + } + if err != nil { - break + return nil, err } for _, event := range events.Result { @@ -50,6 +56,4 @@ func (h *HeimdallGRPCClient) StateSyncEvents(ctx context.Context, fromID uint64, eventRecords = append(eventRecords, eventRecord) } } - - return eventRecords, err }