Fixes to sentry (#1698)

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
ledgerwatch 2021-04-08 20:07:06 +01:00 committed by GitHub
parent eb64d4738d
commit a3cf656b68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 3 deletions

View File

@ -375,6 +375,7 @@ func grpcSentryServer(ctx context.Context, sentryAddr string) (*SentryServerImpl
} }
grpcServer = grpc.NewServer(opts...) grpcServer = grpc.NewServer(opts...)
sentryServer := &SentryServerImpl{ sentryServer := &SentryServerImpl{
ctx: ctx,
receiveCh: make(chan StreamMsg, 1024), receiveCh: make(chan StreamMsg, 1024),
receiveUploadCh: 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)) peerID := string(gointerfaces.ConvertH512ToBytes(inreq.PeerId))
rwRaw, ok := ss.peerRwMap.Load(peerID) rwRaw, ok := ss.peerRwMap.Load(peerID)
if !ok { 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) rw, _ := rwRaw.(p2p.MsgReadWriter)
var msgcode uint64 var msgcode uint64

View File

@ -117,7 +117,10 @@ func (cs *ControlServerImpl) sendHeaderRequest(ctx context.Context, req *headerd
} }
func (cs *ControlServerImpl) randSentryIndex() (int, bool, func() (int, bool)) { 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 to := i
return i, true, func() (int, bool) { return i, true, func() (int, bool) {
i = (i + 1) % len(cs.sentries) i = (i + 1) % len(cs.sentries)

View File

@ -69,7 +69,7 @@ func StageLoop(
// but call .Begin() after hearer/body download stages // but call .Begin() after hearer/body download stages
var tx ethdb.DbWithPendingMutations var tx ethdb.DbWithPendingMutations
if canRunCycleInOneTransaction { if canRunCycleInOneTransaction {
tx, err = tx.Begin(context.Background(), ethdb.RW) tx, err = db.Begin(context.Background(), ethdb.RW)
if err != nil { if err != nil {
return err return err
} }