From a3cf656b68dde16b52788d98feaa981f69cd6827 Mon Sep 17 00:00:00 2001 From: ledgerwatch Date: Thu, 8 Apr 2021 20:07:06 +0100 Subject: [PATCH] Fixes to sentry (#1698) Co-authored-by: Alexey Sharp --- cmd/headers/download/sentry.go | 3 ++- cmd/headers/download/sentry_api.go | 5 ++++- turbo/stages/stageloop.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/headers/download/sentry.go b/cmd/headers/download/sentry.go index 5b78ee6e6..6b203241b 100644 --- a/cmd/headers/download/sentry.go +++ b/cmd/headers/download/sentry.go @@ -375,6 +375,7 @@ func grpcSentryServer(ctx context.Context, sentryAddr string) (*SentryServerImpl } grpcServer = grpc.NewServer(opts...) sentryServer := &SentryServerImpl{ + ctx: ctx, receiveCh: make(chan StreamMsg, 1024), receiveUploadCh: make(chan StreamMsg, 1024), } @@ -545,7 +546,7 @@ func (ss *SentryServerImpl) SendMessageById(_ context.Context, inreq *proto_sent peerID := string(gointerfaces.ConvertH512ToBytes(inreq.PeerId)) rwRaw, ok := ss.peerRwMap.Load(peerID) if !ok { - return &proto_sentry.SentPeers{}, fmt.Errorf("peer not found: %s", inreq.PeerId) + return &proto_sentry.SentPeers{}, fmt.Errorf("peer not found: %s", peerID) } rw, _ := rwRaw.(p2p.MsgReadWriter) var msgcode uint64 diff --git a/cmd/headers/download/sentry_api.go b/cmd/headers/download/sentry_api.go index 13f4fb527..a6be60506 100644 --- a/cmd/headers/download/sentry_api.go +++ b/cmd/headers/download/sentry_api.go @@ -117,7 +117,10 @@ func (cs *ControlServerImpl) sendHeaderRequest(ctx context.Context, req *headerd } func (cs *ControlServerImpl) randSentryIndex() (int, bool, func() (int, bool)) { - i := rand.Intn(len(cs.sentries) - 1) + var i int + if len(cs.sentries) > 1 { + i = rand.Intn(len(cs.sentries) - 1) + } to := i return i, true, func() (int, bool) { i = (i + 1) % len(cs.sentries) diff --git a/turbo/stages/stageloop.go b/turbo/stages/stageloop.go index 035b65aa8..4cf23dddb 100644 --- a/turbo/stages/stageloop.go +++ b/turbo/stages/stageloop.go @@ -69,7 +69,7 @@ func StageLoop( // but call .Begin() after hearer/body download stages var tx ethdb.DbWithPendingMutations if canRunCycleInOneTransaction { - tx, err = tx.Begin(context.Background(), ethdb.RW) + tx, err = db.Begin(context.Background(), ethdb.RW) if err != nil { return err }