Skip to content

Commit f673769

Browse files
committed
consensus: log rejected hashes on CV
Close #4148. Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
1 parent ef8950a commit f673769

2 files changed

Lines changed: 31 additions & 5 deletions

File tree

pkg/consensus/change_view.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ package consensus
33
import (
44
"github.com/nspcc-dev/dbft"
55
"github.com/nspcc-dev/neo-go/pkg/io"
6+
"github.com/nspcc-dev/neo-go/pkg/util"
67
)
78

89
// changeView represents dBFT ChangeView message.
910
type changeView struct {
10-
newViewNumber byte
11-
timestamp uint64
12-
reason dbft.ChangeViewReason
11+
newViewNumber byte
12+
timestamp uint64
13+
reason dbft.ChangeViewReason
14+
rejectedHashes []util.Uint256
1315
}
1416

1517
var _ dbft.ChangeView = (*changeView)(nil)
@@ -18,12 +20,18 @@ var _ dbft.ChangeView = (*changeView)(nil)
1820
func (c *changeView) EncodeBinary(w *io.BinWriter) {
1921
w.WriteU64LE(c.timestamp)
2022
w.WriteB(byte(c.reason))
23+
if c.reason == dbft.CVTxInvalid || c.reason == dbft.CVTxRejectedByPolicy {
24+
w.WriteArray(c.rejectedHashes)
25+
}
2126
}
2227

2328
// DecodeBinary implements the io.Serializable interface.
2429
func (c *changeView) DecodeBinary(r *io.BinReader) {
2530
c.timestamp = r.ReadU64LE()
2631
c.reason = dbft.ChangeViewReason(r.ReadB())
32+
if c.reason == dbft.CVTxInvalid || c.reason == dbft.CVTxRejectedByPolicy {
33+
r.ReadArray(&c.rejectedHashes)
34+
}
2735
}
2836

2937
// NewViewNumber implements the payload.ChangeView interface.

pkg/consensus/consensus.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"slices"
7+
"strings"
78
"sync/atomic"
89
"time"
910

@@ -354,12 +355,14 @@ events:
354355
zap.Uint("view", uint(v)))
355356
s.dbft.OnTimeout(h, v)
356357
case msg := <-s.messages:
358+
log := s.log.Debug
357359
fields := []zap.Field{
358360
zap.Uint8("from", msg.message.ValidatorIndex),
359361
zap.Stringer("type", msg.Type()),
360362
}
361363

362-
if msg.Type() == dbft.RecoveryMessageType {
364+
switch msg.Type() {
365+
case dbft.RecoveryMessageType:
363366
rec := msg.GetRecoveryMessage().(*recoveryMessage)
364367
if rec.preparationHash == nil {
365368
req := rec.GetPrepareRequest(&msg, s.dbft.Validators, uint16(s.dbft.PrimaryIndex))
@@ -375,9 +378,24 @@ events:
375378
zap.Int("#changeview", len(rec.changeViewPayloads)),
376379
zap.Bool("#request", rec.prepareRequest != nil),
377380
zap.Bool("#hash", rec.preparationHash != nil))
381+
case dbft.ChangeViewType:
382+
cv := msg.GetChangeView().(*changeView)
383+
if len(cv.rejectedHashes) > 0 {
384+
const maxHashes = 10
385+
var rejected strings.Builder
386+
log = s.log.Warn
387+
for _, h := range cv.rejectedHashes[:min(len(cv.rejectedHashes), maxHashes)] { // don't pollute logs with too many hashes.
388+
fmt.Fprintf(&rejected, "%s ", h.StringLE())
389+
}
390+
if len(cv.rejectedHashes) > maxHashes {
391+
rejected.WriteString("...")
392+
}
393+
fields = append(fields, zap.String("rejected", rejected.String()))
394+
}
395+
default:
378396
}
379397

380-
s.log.Debug("received message", fields...)
398+
log("received message", fields...)
381399
s.dbft.OnReceive(&msg)
382400
case tx := <-s.transactions:
383401
s.dbft.OnTransaction(tx)

0 commit comments

Comments
 (0)