From 42dfb52e98ff5fe923ba4982fd8fbca485359b07 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 31 Jan 2020 14:31:19 +0300 Subject: [PATCH 1/5] consensus: add more logging in consensus service --- pkg/consensus/consensus.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index acbfa49d6..d63b100f5 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -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 } From e441cb1414a2704928ee754657ea105f39e79acc Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 31 Jan 2020 14:49:15 +0300 Subject: [PATCH 2/5] consensus: add preparation hash to logger --- pkg/consensus/consensus.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index d63b100f5..91dc47287 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -181,7 +181,8 @@ func (s *service) eventLoop() { zap.Int("#preparation", len(rec.preparationPayloads)), zap.Int("#commit", len(rec.commitPayloads)), zap.Int("#changeview", len(rec.changeViewPayloads)), - zap.Bool("#request", rec.prepareRequest != nil)) + zap.Bool("#request", rec.prepareRequest != nil), + zap.Bool("#hash", rec.preparationHash != nil)) } s.log.Debug("received message", fields...) From e65b5c9914db4fb41c7cb8c35219f4c58af34740 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 31 Jan 2020 15:02:03 +0300 Subject: [PATCH 3/5] consensus: fill preparation hash in recovery message --- pkg/consensus/consensus.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index 91dc47287..c6662ba10 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -177,6 +177,14 @@ func (s *service) eventLoop() { if msg.Type() == payload.RecoveryMessageType { rec := msg.GetRecoveryMessage().(*recoveryMessage) + if rec.preparationHash == nil { + req := rec.GetPrepareRequest(&msg, s.dbft.Validators, uint16(s.dbft.PrimaryIndex)) + if req != nil { + h := req.Hash() + rec.preparationHash = &h + } + } + fields = append(fields, zap.Int("#preparation", len(rec.preparationPayloads)), zap.Int("#commit", len(rec.commitPayloads)), From 9ceefe17e23321b2d3dbe930aa4d86d63bdb92a8 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 31 Jan 2020 17:22:37 +0300 Subject: [PATCH 4/5] consensus: check current chain height before processing timer The chain may already be more current than our dBFT state (like when the node has commited something at view 0, but all the other nodes changed view and accepted something at view 1), so in this case we should reinit dBFT on new height. --- pkg/consensus/consensus.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/consensus/consensus.go b/pkg/consensus/consensus.go index c6662ba10..96847d904 100644 --- a/pkg/consensus/consensus.go +++ b/pkg/consensus/consensus.go @@ -168,7 +168,14 @@ func (s *service) eventLoop() { s.log.Debug("timer fired", zap.Uint32("height", hv.Height), zap.Uint("view", uint(hv.View))) - s.dbft.OnTimeout(hv) + if s.Chain.BlockHeight() >= s.dbft.BlockIndex { + s.log.Debug("chain already advanced", + zap.Uint32("dbft index", s.dbft.BlockIndex), + zap.Uint32("chain index", s.Chain.BlockHeight())) + s.dbft.InitializeConsensus(0) + } else { + s.dbft.OnTimeout(hv) + } case msg := <-s.messages: fields := []zap.Field{ zap.Uint16("from", msg.validatorIndex), From 916b54fd602247c2e3d8df454a32fa673bfb8436 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Fri, 31 Jan 2020 12:00:22 +0300 Subject: [PATCH 5/5] go.mod: update dbft library, fix #634 and other problems --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e5730fc1f..f808f6304 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/go-redis/redis v6.10.2+incompatible github.com/go-yaml/yaml v2.1.0+incompatible github.com/mr-tron/base58 v1.1.2 - github.com/nspcc-dev/dbft v0.0.0-20200130105505-02c208d154bf + github.com/nspcc-dev/dbft v0.0.0-20200203121303-549ecf2daaa1 github.com/nspcc-dev/rfc6979 v0.2.0 github.com/pkg/errors v0.8.1 github.com/prometheus/client_golang v1.2.1