consensus: add more logging in consensus service

This commit is contained in:
Evgenii Stratonikov 2020-01-31 14:31:19 +03:00 committed by Roman Khimov
parent 9374c5e7c2
commit 42dfb52e98

View file

@ -170,7 +170,21 @@ func (s *service) eventLoop() {
zap.Uint("view", uint(hv.View)))
s.dbft.OnTimeout(hv)
case msg := <-s.messages:
s.log.Debug("received message", zap.Uint16("from", msg.validatorIndex))
fields := []zap.Field{
zap.Uint16("from", msg.validatorIndex),
zap.Stringer("type", msg.Type()),
}
if msg.Type() == payload.RecoveryMessageType {
rec := msg.GetRecoveryMessage().(*recoveryMessage)
fields = append(fields,
zap.Int("#preparation", len(rec.preparationPayloads)),
zap.Int("#commit", len(rec.commitPayloads)),
zap.Int("#changeview", len(rec.changeViewPayloads)),
zap.Bool("#request", rec.prepareRequest != nil))
}
s.log.Debug("received message", fields...)
s.dbft.OnReceive(&msg)
case tx := <-s.transactions:
s.dbft.OnTransaction(tx)
@ -212,7 +226,12 @@ func (s *service) getKeyPair(pubs []crypto.PublicKey) (int, crypto.PrivateKey, c
// OnPayload handles Payload receive.
func (s *service) OnPayload(cp *Payload) {
if !s.validatePayload(cp) || s.cache.Has(cp.Hash()) {
log := s.log.With(zap.Stringer("hash", cp.Hash()), zap.Stringer("type", cp.Type()))
if !s.validatePayload(cp) {
log.Debug("can't validate payload")
return
} else if s.cache.Has(cp.Hash()) {
log.Debug("payload is already in cache")
return
}
@ -220,6 +239,7 @@ func (s *service) OnPayload(cp *Payload) {
s.cache.Add(cp)
if s.dbft == nil {
log.Debug("dbft is nil")
return
}