Skip to content

Commit df2cc3f

Browse files
committed
Make Sbft log messages better
Change-Id: I601e4375a947458f34fd46f6dc013050a3ce8959 Signed-off-by: Gabor Hosszu <[email protected]>
1 parent 2c22539 commit df2cc3f

12 files changed

+62
-60
lines changed

orderer/sbft/simplebft/backlog.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ limitations under the License.
1616

1717
package simplebft
1818

19+
import "fmt"
20+
1921
const maxBacklogSeq = 4
2022
const msgPerSeq = 3 // (pre)prepare, commit, checkpoint
2123

@@ -53,7 +55,7 @@ func (s *SBFT) testBacklogMessage(m *Msg, src uint64) bool {
5355

5456
func (s *SBFT) recordBacklogMsg(m *Msg, src uint64) {
5557
if src == s.id {
56-
panic("should never have to backlog my own message")
58+
panic(fmt.Sprintf("should never have to backlog my own message (replica ID: %d)", src))
5759
}
5860

5961
s.replicaState[src].backLog = append(s.replicaState[src].backLog, m)
@@ -86,7 +88,7 @@ func (s *SBFT) processBacklog() {
8688
}
8789
state.backLog = rest
8890

89-
log.Debugf("processing stored message from %d: %s", src, m)
91+
log.Debugf("replica %d: processing stored message from %d: %s", s.id, src, m)
9092

9193
s.handleQueueableMessage(m, src)
9294
processed = true

orderer/sbft/simplebft/checkpoint.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ func (s *SBFT) handleCheckpoint(c *Checkpoint, src uint64) {
4747

4848
err := s.checkBytesSig(c.Digest, src, c.Signature)
4949
if err != nil {
50-
log.Infof("checkpoint signature invalid for %d from %d", c.Seq, src)
50+
log.Infof("replica %d: checkpoint signature invalid for %d from %d", s.id, c.Seq, src)
5151
return
5252
}
5353

5454
// TODO should we always accept checkpoints?
5555
if c.Seq != s.cur.subject.Seq.Seq {
56-
log.Infof("checkpoint does not match expected subject %v, got %v", &s.cur.subject, c)
56+
log.Infof("replica %d: checkpoint does not match expected subject %v, got %v", s.id, &s.cur.subject, c)
5757
return
5858
}
5959
if _, ok := s.cur.checkpoint[src]; ok {
60-
log.Infof("duplicate checkpoint for %d from %d", c.Seq, src)
60+
log.Infof("replica %d: duplicate checkpoint for %d from %d", s.id, c.Seq, src)
6161
}
6262
s.cur.checkpoint[src] = c
6363

@@ -89,8 +89,8 @@ func (s *SBFT) handleCheckpoint(c *Checkpoint, src uint64) {
8989
c = s.cur.checkpoint[replicas[0]]
9090

9191
if !reflect.DeepEqual(c.Digest, s.cur.subject.Digest) {
92-
log.Fatalf("weak checkpoint %x does not match our state %x",
93-
c.Digest, s.cur.subject.Digest)
92+
log.Fatalf("replica %d: weak checkpoint %x does not match our state %x",
93+
s.id, c.Digest, s.cur.subject.Digest)
9494
// NOT REACHED
9595
}
9696

@@ -100,7 +100,7 @@ func (s *SBFT) handleCheckpoint(c *Checkpoint, src uint64) {
100100
s.deliverBatch(&batch)
101101

102102
s.cur.timeout.Cancel()
103-
log.Infof("request %s %s completed on %d", s.cur.subject.Seq, hash2str(s.cur.subject.Digest), s.id)
103+
log.Infof("replica %d: request %s %s completed on %d", s.id, s.cur.subject.Seq, hash2str(s.cur.subject.Digest), s.id)
104104

105105
s.maybeSendNextBatch()
106106
s.processBacklog()

orderer/sbft/simplebft/commit.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ func (s *SBFT) handleCommit(c *Subject, src uint64) {
3939
}
4040

4141
if !reflect.DeepEqual(c, &s.cur.subject) {
42-
log.Warningf("commit does not match expected subject %v %x, got %v %x",
43-
s.cur.subject.Seq, s.cur.subject.Digest, c.Seq, c.Digest)
42+
log.Warningf("replica %d: commit does not match expected subject %v %x, got %v %x",
43+
s.id, s.cur.subject.Seq, s.cur.subject.Digest, c.Seq, c.Digest)
4444
return
4545
}
4646
if _, ok := s.cur.commit[src]; ok {
47-
log.Infof("duplicate commit for %v from %d", *c.Seq, src)
47+
log.Infof("replica %d: duplicate commit for %v from %d", s.id, *c.Seq, src)
4848
return
4949
}
5050
s.cur.commit[src] = c

orderer/sbft/simplebft/connection.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (s *SBFT) Connection(replica uint64) {
6767
func (s *SBFT) handleHello(h *Hello, src uint64) {
6868
bh, err := s.checkBatch(h.Batch, false, true)
6969
if err != nil {
70-
log.Warningf("invalid hello batch from %d: %s", src, err)
70+
log.Warningf("replica %d: invalid hello batch from %d: %s", s.id, src, err)
7171
return
7272
}
7373

@@ -77,19 +77,19 @@ func (s *SBFT) handleHello(h *Hello, src uint64) {
7777

7878
if h.NewView != nil {
7979
if s.primaryIDView(h.NewView.View) != src {
80-
log.Warningf("invalid hello with new view from non-primary %d", src)
80+
log.Warningf("replica %d: invalid hello with new view from non-primary %d", s.id, src)
8181
return
8282
}
8383

8484
vcs, err := s.checkNewViewSignatures(h.NewView)
8585
if err != nil {
86-
log.Warningf("invalid hello new view from %d: %s", src, err)
86+
log.Warningf("replica %d: invalid hello new view from %d: %s", s.id, src, err)
8787
return
8888
}
8989

9090
_, _, ok := s.makeXset(vcs)
9191
if !ok {
92-
log.Warningf("invalid hello new view xset from %d", src)
92+
log.Warningf("replica %d: invalid hello new view xset from %d", s.id, src)
9393
return
9494
}
9595

orderer/sbft/simplebft/execute.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (s *SBFT) maybeExecute() {
2121
return
2222
}
2323
s.cur.executed = true
24-
log.Noticef("%d is executing %v %x", s.id, s.cur.subject.Seq, s.cur.subject.Digest)
24+
log.Noticef("replica %d: executing %v %x", s.id, s.cur.subject.Seq, s.cur.subject.Digest)
2525

2626
s.sys.Persist("execute", &s.cur.subject)
2727

orderer/sbft/simplebft/newview.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (s *SBFT) maybeSendNewView() {
3939

4040
xset, _, ok := s.makeXset(vcs)
4141
if !ok {
42-
log.Debug("xset not yet sufficient")
42+
log.Debugf("replica %d: xset not yet sufficient", s.id)
4343
return
4444
}
4545

@@ -49,7 +49,7 @@ func (s *SBFT) maybeSendNewView() {
4949
} else if reflect.DeepEqual(s.cur.subject.Digest, xset.Digest) {
5050
batch = s.cur.preprep.Batch
5151
} else {
52-
log.Warningf("forfeiting primary - do not have request in store for %d %x", xset.Seq.Seq, xset.Digest)
52+
log.Warningf("replica %d: forfeiting primary - do not have request in store for %d %x", s.id, xset.Seq.Seq, xset.Digest)
5353
xset = nil
5454
}
5555

@@ -60,7 +60,7 @@ func (s *SBFT) maybeSendNewView() {
6060
Batch: batch,
6161
}
6262

63-
log.Noticef("sending new view for %d", nv.View)
63+
log.Noticef("replica %d: sending new view for %d", s.id, nv.View)
6464
s.lastNewViewSent = nv
6565
s.broadcast(&Msg{&Msg_NewView{nv}})
6666
}
@@ -87,48 +87,48 @@ func (s *SBFT) checkNewViewSignatures(nv *NewView) ([]*ViewChange, error) {
8787

8888
func (s *SBFT) handleNewView(nv *NewView, src uint64) {
8989
if src != s.primaryIDView(nv.View) {
90-
log.Warningf("invalid new view from %d for %d", src, nv.View)
90+
log.Warningf("replica %d: invalid new view from %d for %d", s.id, src, nv.View)
9191
return
9292
}
9393

9494
if onv := s.replicaState[s.primaryIDView(nv.View)].newview; onv != nil && onv.View >= nv.View {
95-
log.Debugf("discarding duplicate new view for %d", nv.View)
95+
log.Debugf("replica %d: discarding duplicate new view for %d", s.id, nv.View)
9696
return
9797
}
9898

9999
vcs, err := s.checkNewViewSignatures(nv)
100100
if err != nil {
101-
log.Warningf("invalid new view from %d: %s", src, err)
101+
log.Warningf("replica %d: invalid new view from %d: %s", s.id, src, err)
102102
s.sendViewChange()
103103
return
104104
}
105105

106106
xset, _, ok := s.makeXset(vcs)
107107

108108
if !ok || !reflect.DeepEqual(nv.Xset, xset) {
109-
log.Warningf("invalid new view from %d: xset incorrect: %v, %v", src, nv.Xset, xset)
109+
log.Warningf("replica %d: invalid new view from %d: xset incorrect: %v, %v", s.id, src, nv.Xset, xset)
110110
s.sendViewChange()
111111
return
112112
}
113113

114114
if nv.Xset == nil {
115115
if nv.Batch != nil {
116-
log.Warningf("invalid new view from %d: null request should come with null batch", src)
116+
log.Warningf("replica %d: invalid new view from %d: null request should come with null batch", s.id, src)
117117
s.sendViewChange()
118118
return
119119
}
120120
} else if nv.Batch == nil || !bytes.Equal(nv.Batch.Hash(), nv.Xset.Digest) {
121-
log.Warningf("invalid new view from %d: batch head hash does not match xset: %x, %x, %v",
122-
src, hash(nv.Batch.Header), nv.Xset.Digest, nv)
121+
log.Warningf("replica %d: invalid new view from %d: batch head hash does not match xset: %x, %x, %v",
122+
s.id, src, hash(nv.Batch.Header), nv.Xset.Digest, nv)
123123
s.sendViewChange()
124124
return
125125
}
126126

127127
if nv.Batch != nil {
128128
_, err = s.checkBatch(nv.Batch, true, false)
129129
if err != nil {
130-
log.Warningf("invalid new view from %d: invalid batch, %s",
131-
src, err)
130+
log.Warningf("replica %d: invalid new view from %d: invalid batch, %s",
131+
s.id, src, err)
132132
s.sendViewChange()
133133
return
134134
}
@@ -175,7 +175,7 @@ func (s *SBFT) processNewView() {
175175

176176
s.handleCheckedPreprepare(pp)
177177
} else {
178-
log.Debugf("%+v", s)
178+
log.Debugf("replica %d: %+v", s.id, s)
179179
s.cancelViewChangeTimer()
180180
s.maybeSendNextBatch()
181181
}

orderer/sbft/simplebft/prepare.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ func (s *SBFT) handlePrepare(p *Subject, src uint64) {
3030
}
3131

3232
if !reflect.DeepEqual(p, &s.cur.subject) {
33-
log.Infof("prepare does not match expected subject %v, got %v", &s.cur.subject, p)
33+
log.Infof("replica %d: prepare does not match expected subject %v, got %v", s.id, &s.cur.subject, p)
3434
return
3535
}
3636
if _, ok := s.cur.prep[src]; ok {
37-
log.Infof("duplicate prepare for %v from %d", *p.Seq, src)
37+
log.Infof("replica %d: duplicate prepare for %v from %d", s.id, *p.Seq, src)
3838
return
3939
}
4040
s.cur.prep[src] = p

orderer/sbft/simplebft/preprepare.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,36 @@ func (s *SBFT) sendPreprepare(batch []*Request) {
4343

4444
func (s *SBFT) handlePreprepare(pp *Preprepare, src uint64) {
4545
if src == s.id {
46-
log.Infof("Ignoring preprepare from self: %d", src)
46+
log.Infof("replica %d: ignoring preprepare from self: %d", s.id, src)
4747
return
4848
}
4949
if src != s.primaryID() {
50-
log.Infof("preprepare from non-primary %d", src)
50+
log.Infof("replica %d: preprepare from non-primary %d", s.id, src)
5151
return
5252
}
5353
nextSeq := s.nextSeq()
5454
if *pp.Seq != nextSeq {
55-
log.Infof("preprepare does not match expected %v, got %v", nextSeq, *pp.Seq)
55+
log.Infof("replica %d: preprepare does not match expected %v, got %v", s.id, nextSeq, *pp.Seq)
5656
return
5757
}
5858
if s.cur.subject.Seq.Seq == pp.Seq.Seq {
59-
log.Infof("duplicate preprepare for %v", *pp.Seq)
59+
log.Infof("replica %d: duplicate preprepare for %v", s.id, *pp.Seq)
6060
return
6161
}
6262
if pp.Batch == nil {
63-
log.Infof("preprepare without batch")
63+
log.Infof("replica %d: preprepare without batch", s.id)
6464
return
6565
}
6666

6767
batchheader, err := s.checkBatch(pp.Batch, true, false)
6868
if err != nil || batchheader.Seq != pp.Seq.Seq {
69-
log.Infof("preprepare %v batch head inconsistent from %d: %s", pp.Seq, src, err)
69+
log.Infof("replica %d: preprepare %v batch head inconsistent from %d: %s", s.id, pp.Seq, src, err)
7070
return
7171
}
7272

7373
prevhash := s.sys.LastBatch().Hash()
7474
if !bytes.Equal(batchheader.PrevHash, prevhash) {
75-
log.Infof("preprepare batch prev hash does not match expected %s, got %s", hash2str(batchheader.PrevHash), hash2str(prevhash))
75+
log.Infof("replica %d: preprepare batch prev hash does not match expected %s, got %s", s.id, hash2str(batchheader.PrevHash), hash2str(prevhash))
7676
return
7777
}
7878

@@ -82,7 +82,7 @@ func (s *SBFT) handlePreprepare(pp *Preprepare, src uint64) {
8282
func (s *SBFT) acceptPreprepare(pp *Preprepare) {
8383
sub := Subject{Seq: pp.Seq, Digest: pp.Batch.Hash()}
8484

85-
log.Infof("accepting preprepare for %v, %x", sub.Seq, sub.Digest)
85+
log.Infof("replica %d: accepting preprepare for %v, %x", s.id, sub.Seq, sub.Digest)
8686
s.sys.Persist("preprepare", pp)
8787

8888
s.cur = reqInfo{
@@ -107,6 +107,6 @@ func (s *SBFT) handleCheckedPreprepare(pp *Preprepare) {
107107
////////////////////////////////////////////////
108108

109109
func (s *SBFT) requestTimeout() {
110-
log.Infof("request timed out: %s", s.cur.subject.Seq)
110+
log.Infof("replica %d: request timed out: %s", s.id, s.cur.subject.Seq)
111111
s.sendViewChange()
112112
}

orderer/sbft/simplebft/request.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (s *SBFT) Request(req []byte) {
2525

2626
func (s *SBFT) handleRequest(req *Request, src uint64) {
2727
key := hash2str(hash(req.Payload))
28-
log.Infof("replica %d inserting %x into pending", s.id, key)
28+
log.Infof("replica %d: inserting %x into pending", s.id, key)
2929
s.pending[key] = req
3030
if s.isPrimary() && s.activeView {
3131
s.batch = append(s.batch, req)

orderer/sbft/simplebft/simplebft.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (s *SBFT) broadcast(m *Msg) {
186186

187187
// Receive is the ingress method for SBFT messages.
188188
func (s *SBFT) Receive(m *Msg, src uint64) {
189-
log.Debugf("received message from %d: %s", src, m)
189+
log.Debugf("replica %d: received message from %d: %s", s.id, src, m)
190190

191191
if h := m.GetHello(); h != nil {
192192
s.handleHello(h, src)
@@ -203,7 +203,7 @@ func (s *SBFT) Receive(m *Msg, src uint64) {
203203
}
204204

205205
if s.testBacklog(m, src) {
206-
log.Debugf("message for future seq, storing for later")
206+
log.Debugf("replica %d: message for future seq, storing for later", s.id)
207207
s.recordBacklogMsg(m, src)
208208
return
209209
}
@@ -226,15 +226,15 @@ func (s *SBFT) handleQueueableMessage(m *Msg, src uint64) {
226226
return
227227
}
228228

229-
log.Warningf("received invalid message from %d", src)
229+
log.Warningf("replica %d: received invalid message from %d", s.id, src)
230230
}
231231

232232
func (s *SBFT) deliverBatch(batch *Batch) {
233233
s.sys.Deliver(batch)
234234

235235
for _, req := range batch.Payloads {
236236
key := hash2str(hash(req))
237-
log.Infof("replica %d attempting to remove %x from pending", s.id, key)
237+
log.Infof("replica %d: attempting to remove %x from pending", s.id, key)
238238
delete(s.pending, key)
239239
}
240240
}

orderer/sbft/simplebft/viewchange.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (s *SBFT) sendViewChange() {
2828
state.viewchange = nil
2929
}
3030
}
31-
log.Noticef("sending viewchange for view %d", s.view)
31+
log.Noticef("replica %d: sending viewchange for view %d", s.id, s.view)
3232

3333
var q, p []*Subject
3434
if s.cur.sentCommit {
@@ -67,19 +67,19 @@ func (s *SBFT) handleViewChange(svc *Signed, src uint64) {
6767
_, err = s.checkBatch(vc.Checkpoint, false, true)
6868
}
6969
if err != nil {
70-
log.Noticef("invalid viewchange: %s", err)
70+
log.Noticef("replica %d: invalid viewchange: %s", s.id, err)
7171
return
7272
}
7373
if vc.View < s.view {
74-
log.Debugf("old view change from %d for view %d, we are in view %d", src, vc.View, s.view)
74+
log.Debugf("replica %d: old view change from %d for view %d, we are in view %d", s.id, src, vc.View, s.view)
7575
return
7676
}
7777
if ovc := s.replicaState[src].viewchange; ovc != nil && vc.View <= ovc.View {
78-
log.Noticef("duplicate view change for %d from %d", vc.View, src)
78+
log.Noticef("replica %d: duplicate view change for %d from %d", s.id, vc.View, src)
7979
return
8080
}
8181

82-
log.Infof("viewchange from %d: %v", src, vc)
82+
log.Infof("replica %d: viewchange from %d: %v", s.id, src, vc)
8383
s.replicaState[src].viewchange = vc
8484
s.replicaState[src].signedViewchange = svc
8585

@@ -97,18 +97,18 @@ func (s *SBFT) handleViewChange(svc *Signed, src uint64) {
9797
if quorum == s.oneCorrectQuorum() {
9898
// catch up to the minimum view
9999
if s.view < min {
100-
log.Notice("we are behind on view change, resending for newer view")
100+
log.Noticef("replica %d: we are behind on view change, resending for newer view", s.id)
101101
s.view = min - 1
102102
s.sendViewChange()
103103
return
104104
}
105105
}
106106

107107
if quorum == s.noFaultyQuorum() {
108-
log.Notice("received 2f+1 view change messages, starting view change timer")
108+
log.Noticef("replica %d: received 2f+1 view change messages, starting view change timer", s.id)
109109
s.viewChangeTimer = s.sys.Timer(s.viewChangeTimeout, func() {
110110
s.viewChangeTimeout *= 2
111-
log.Notice("view change timed out, sending next")
111+
log.Noticef("replica %d: view change timed out, sending next", s.id)
112112
s.sendViewChange()
113113
})
114114
}

0 commit comments

Comments
 (0)