-
Notifications
You must be signed in to change notification settings - Fork 0
/
communicator.go
601 lines (524 loc) · 20.7 KB
/
communicator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
/*
* The Clear BSD License
*
* Copyright (c) 2019 Insolar Technologies
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of Insolar Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package phases
import (
"context"
"sync/atomic"
"github.com/pkg/errors"
"go.opencensus.io/stats"
"go.opencensus.io/tag"
"go.opencensus.io/trace"
"github.com/insolar/insolar/component"
"github.com/insolar/insolar/consensus"
"github.com/insolar/insolar/consensus/packets"
"github.com/insolar/insolar/core"
"github.com/insolar/insolar/instrumentation/inslogger"
"github.com/insolar/insolar/instrumentation/instracer"
"github.com/insolar/insolar/log"
"github.com/insolar/insolar/network"
)
// Communicator interface provides methods to exchange data between nodes
//go:generate minimock -i github.com/insolar/insolar/consensus/phases.Communicator -o . -s _mock.go
type Communicator interface {
// ExchangePhase1 used in first consensus step to exchange data between participants
ExchangePhase1(
ctx context.Context,
originClaim *packets.NodeAnnounceClaim,
participants []core.Node,
packet *packets.Phase1Packet,
) (map[core.RecordRef]*packets.Phase1Packet, error)
// ExchangePhase2 used in second consensus step to exchange data between participants
ExchangePhase2(ctx context.Context, list network.UnsyncList, participants []core.Node, packet *packets.Phase2Packet) (map[core.RecordRef]*packets.Phase2Packet, error)
// ExchangePhase21 is used between phases 2 and 3 of consensus to send additional MissingNode requests
ExchangePhase21(ctx context.Context, list network.UnsyncList, packet *packets.Phase2Packet, additionalRequests []*AdditionalRequest) ([]packets.ReferendumVote, error)
// ExchangePhase3 used in third consensus step to exchange data between participants
ExchangePhase3(ctx context.Context, participants []core.Node, packet *packets.Phase3Packet) (map[core.RecordRef]*packets.Phase3Packet, error)
component.Initer
}
type phase1Result struct {
id core.RecordRef
packet *packets.Phase1Packet
}
type phase2Result struct {
id core.RecordRef
packet *packets.Phase2Packet
}
type phase3Result struct {
id core.RecordRef
packet *packets.Phase3Packet
}
// ConsensusCommunicator is simple Communicator implementation which communicates with each participants
type ConsensusCommunicator struct {
ConsensusNetwork network.ConsensusNetwork `inject:""`
PulseHandler network.PulseHandler `inject:""`
Cryptography core.CryptographyService `inject:""`
NodeKeeper network.NodeKeeper `inject:""`
phase1result chan phase1Result
phase2result chan phase2Result
phase3result chan phase3Result
currentPulseNumber uint32
}
// NewCommunicator constructor creates new ConsensusCommunicator
func NewCommunicator() *ConsensusCommunicator {
return &ConsensusCommunicator{}
}
// Start method implements Starter interface
func (nc *ConsensusCommunicator) Init(ctx context.Context) error {
nc.phase1result = make(chan phase1Result)
nc.phase2result = make(chan phase2Result)
nc.phase3result = make(chan phase3Result)
nc.ConsensusNetwork.RegisterPacketHandler(packets.Phase1, nc.phase1DataHandler)
nc.ConsensusNetwork.RegisterPacketHandler(packets.Phase2, nc.phase2DataHandler)
nc.ConsensusNetwork.RegisterPacketHandler(packets.Phase3, nc.phase3DataHandler)
return nil
}
func (nc *ConsensusCommunicator) getPulseNumber() core.PulseNumber {
pulseNumber := atomic.LoadUint32(&nc.currentPulseNumber)
return core.PulseNumber(pulseNumber)
}
func (nc *ConsensusCommunicator) setPulseNumber(new core.PulseNumber) bool {
old := nc.getPulseNumber()
return old < new && atomic.CompareAndSwapUint32(&nc.currentPulseNumber, uint32(old), uint32(new))
}
func (nc *ConsensusCommunicator) sendRequestToNodes(ctx context.Context, participants []core.Node, packet packets.ConsensusPacket) {
for _, node := range participants {
if node.ID().Equal(nc.NodeKeeper.GetOrigin().ID()) {
continue
}
go func(ctx context.Context, n core.Node, packet packets.ConsensusPacket) {
logger := inslogger.FromContext(ctx)
logger.Debugf("Send %s request to %s", packet.GetType(), n.ID())
err := nc.ConsensusNetwork.SignAndSendPacket(packet, n.ID(), nc.Cryptography)
if err != nil {
logger.Errorf("Failed to send %s request: %s", packet.GetType(), err.Error())
return
}
err = stats.RecordWithTags(context.Background(), []tag.Mutator{tag.Upsert(consensus.TagPhase, packet.GetType().String())}, consensus.PacketsSent.M(1))
if err != nil {
logger.Warn("Failed to record metric of sent phase1 requests")
}
}(ctx, node, packet.Clone())
}
}
func (nc *ConsensusCommunicator) sendRequestToNodesWithOrigin(ctx context.Context, originClaim *packets.NodeAnnounceClaim,
participants []core.Node, packet *packets.Phase1Packet) error {
requests := make(map[core.RecordRef]packets.ConsensusPacket)
for _, participant := range participants {
if participant.ID().Equal(nc.NodeKeeper.GetOrigin().ID()) {
continue
}
err := originClaim.Update(participant.ID(), nc.Cryptography)
if err != nil {
return errors.Wrap(err, "Failed to update claims before sending in phase1")
}
requests[participant.ID()] = packet.Clone()
}
for ref, req := range requests {
go func(ctx context.Context, node core.RecordRef, consensusPacket packets.ConsensusPacket) {
logger := inslogger.FromContext(ctx)
logger.Debug("Send phase1 request with origin to %s", node)
err := nc.ConsensusNetwork.SignAndSendPacket(consensusPacket, node, nc.Cryptography)
if err != nil {
logger.Error("Failed to send phase1 request with origin: " + err.Error())
return
}
err = stats.RecordWithTags(context.Background(), []tag.Mutator{tag.Upsert(consensus.TagPhase, consensusPacket.GetType().String())}, consensus.PacketsSent.M(1))
if err != nil {
logger.Warn("Failed to record metric of sent phase1 requests")
}
}(ctx, ref, req)
}
return nil
}
func (nc *ConsensusCommunicator) generatePhase2Response(ctx context.Context, origReq, req *packets.Phase2Packet,
list network.UnsyncList) (*packets.Phase2Packet, error) {
logger := inslogger.FromContext(ctx)
answers := make([]packets.ReferendumVote, 0)
for _, vote := range req.GetVotes() {
if vote.Type() != packets.TypeMissingNode {
continue
}
v, ok := vote.(*packets.MissingNode)
if !ok {
logger.Warnf("Phase 2 MissingNode request type mismatch")
continue
}
ref, err := list.IndexToRef(int(v.NodeIndex))
if err != nil {
logger.Warnf("Phase 2 MissingNode requested index: %d, error: %s", v.NodeIndex, err.Error())
continue
}
node := list.GetActiveNode(ref)
if node == nil {
logger.Warnf("Phase 2 MissingNode requested index: %d; mapped ref %s not found", v.NodeIndex, ref)
continue
}
claim, err := packets.NodeToClaim(node)
if err != nil {
logger.Warnf("Phase 2 MissingNode requested index: %d, mapped ref: %s, convertation node -> claim error: %s",
v.NodeIndex, ref, err.Error())
continue
}
proof := list.GetProof(ref)
if proof == nil {
logger.Warnf("Phase 2 MissingNode requested index: %d, mapped ref: %s, proof not found", v.NodeIndex, ref)
continue
}
answer := packets.MissingNodeSupplementaryVote{
NodeIndex: v.NodeIndex,
NodePulseProof: *proof,
NodeClaimUnsigned: *claim,
}
answers = append(answers, &answer)
claims := list.GetClaims(ref)
for _, claim := range claims {
claimAnswer := packets.MissingNodeClaim{NodeIndex: v.NodeIndex, Claim: claim}
answers = append(answers, &claimAnswer)
}
}
response := packets.NewPhase2Packet(origReq.GetPulseNumber())
response.SetBitSet(origReq.GetBitSet())
ghs := origReq.GetGlobuleHashSignature()
err := response.SetGlobuleHashSignature(ghs[:])
if err != nil {
return nil, errors.Wrap(err, "Failed to set globule hash in phase2 response")
}
for _, answer := range answers {
response.AddVote(answer)
}
return response, nil
}
// ExchangePhase1 used in first consensus phase to exchange data between participants
func (nc *ConsensusCommunicator) ExchangePhase1(
ctx context.Context,
originClaim *packets.NodeAnnounceClaim,
participants []core.Node,
packet *packets.Phase1Packet,
) (map[core.RecordRef]*packets.Phase1Packet, error) {
_, span := instracer.StartSpan(ctx, "Communicator.ExchangePhase1")
span.AddAttributes(trace.Int64Attribute("pulse", int64(packet.GetPulseNumber())))
defer span.End()
logger := inslogger.FromContext(ctx)
result := make(map[core.RecordRef]*packets.Phase1Packet, len(participants))
result[nc.ConsensusNetwork.GetNodeID()] = packet
nc.setPulseNumber(packet.GetPulse().PulseNumber)
var request *packets.Phase1Packet
type none struct{}
sentRequests := make(map[core.RecordRef]none)
// TODO: awful, need rework
if originClaim == nil {
request = packet
} else {
request = packet.Clone().(*packets.Phase1Packet)
request.RemoveAnnounceClaim()
}
if originClaim == nil {
nc.sendRequestToNodes(ctx, participants, request)
} else {
err := nc.sendRequestToNodesWithOrigin(ctx, originClaim, participants, packet)
if err != nil {
return nil, errors.Wrap(err, "Failed to send requests")
}
}
for _, p := range participants {
sentRequests[p.ID()] = none{}
}
shouldSendResponse := func(ref core.RecordRef) bool {
_, ok := sentRequests[ref]
return !ok
}
response := request
for {
select {
case res := <-nc.phase1result:
logger.Debugf("Got phase1 request from %s", res.id)
currentPulse := nc.getPulseNumber()
if res.packet.GetPulseNumber() != currentPulse {
logger.Debugf("Filtered phase1 packet, packet pulse %d != %d (current pulse)",
res.packet.GetPulseNumber(), currentPulse)
continue
}
if res.id.IsEmpty() {
logger.Debug("Got unknown phase1 request, try to get routing info from announce claim")
claim := res.packet.GetAnnounceClaim()
if claim == nil {
logger.Warn("Could not get announce claim from phase1 packet")
continue
}
res.id = claim.NodeRef
err := nc.NodeKeeper.AddTemporaryMapping(claim.NodeRef, claim.ShortNodeID, claim.NodeAddress.Get())
if err != nil {
logger.Warn("Error adding temporary mapping: " + err.Error())
continue
}
}
if shouldSendResponse(res.id) {
// send response
logger.Debugf("Send phase1 response to %s", res.id)
err := nc.ConsensusNetwork.SignAndSendPacket(response, res.id, nc.Cryptography)
if err != nil {
logger.Error("Error sending phase1 response: " + err.Error())
}
}
if !res.id.IsEmpty() {
sentRequests[res.id] = none{}
result[res.id] = res.packet
}
// FIXME: early return is commented to have synchronized length of phases on all nodes
// if len(result) == len(participants) {
// return result, nil
// }
case <-ctx.Done():
return result, nil
}
}
}
// ExchangePhase2 used in second consensus phase to exchange data between participants
func (nc *ConsensusCommunicator) ExchangePhase2(ctx context.Context, list network.UnsyncList,
participants []core.Node, packet *packets.Phase2Packet) (map[core.RecordRef]*packets.Phase2Packet, error) {
_, span := instracer.StartSpan(ctx, "Communicator.ExchangePhase2")
span.AddAttributes(trace.Int64Attribute("pulse", int64(packet.GetPulseNumber())))
defer span.End()
logger := inslogger.FromContext(ctx)
result := make(map[core.RecordRef]*packets.Phase2Packet, len(participants))
result[nc.ConsensusNetwork.GetNodeID()] = packet
nc.sendRequestToNodes(ctx, participants, packet)
type none struct{}
sentRequests := make(map[core.RecordRef]none)
shouldSendResponse := func(p *phase2Result) bool {
_, ok := sentRequests[p.id]
return !ok || p.packet.ContainsRequests()
}
var err error
for {
select {
case res := <-nc.phase2result:
logger.Debugf("Got phase2 request from %s", res.id)
currentPulse := nc.getPulseNumber()
if res.packet.GetPulseNumber() != currentPulse {
logger.Debugf("Filtered phase2 packet, packet pulse %d != %d (current pulse)",
res.packet.GetPulseNumber(), currentPulse)
continue
}
if shouldSendResponse(&res) {
logger.Debugf("Send phase2 response to %s", res.id)
// send response
response := packet
if res.packet.ContainsRequests() {
response, err = nc.generatePhase2Response(ctx, packet, res.packet, list)
if err != nil {
logger.Warnf("Failed to generate phase 2 response packet: %s", err.Error())
continue
}
}
err := nc.ConsensusNetwork.SignAndSendPacket(response, res.id, nc.Cryptography)
if err != nil {
logger.Error("Error sending phase2 response: " + err.Error())
}
}
result[res.id] = res.packet
sentRequests[res.id] = none{}
// FIXME: early return is commented to have synchronized length of phases on all nodes
// if len(result) == len(participants) {
// return result, nil
// }
case <-ctx.Done():
return result, nil
}
}
}
func selectCandidate(candidates []core.RecordRef) core.RecordRef {
// TODO: make it random
if len(candidates) == 0 {
panic("candidates list should have at least 1 candidate (check consensus state matrix calculation routines)")
}
return candidates[0]
}
func (nc *ConsensusCommunicator) sendAdditionalRequests(ctx context.Context, origReq *packets.Phase2Packet,
additionalRequests []*AdditionalRequest) error {
logger := inslogger.FromContext(ctx)
for _, req := range additionalRequests {
newReq := *origReq
newReq.AddVote(&packets.MissingNode{NodeIndex: uint16(req.RequestIndex)})
receiver := selectCandidate(req.Candidates)
err := nc.ConsensusNetwork.SignAndSendPacket(&newReq, receiver, nc.Cryptography)
if err != nil {
return errors.Wrapf(err, "Failed to send additional phase 2.1 request for index %d to node %s", req.RequestIndex, receiver)
}
err = stats.RecordWithTags(context.Background(), []tag.Mutator{tag.Upsert(consensus.TagPhase, origReq.GetType().String())}, consensus.PacketsSent.M(1))
if err != nil {
logger.Warn("Failed to record metric of sent phase2.1 additional requests")
}
}
return nil
}
// ExchangePhase21 used in second consensus phase to exchange data between participants
func (nc *ConsensusCommunicator) ExchangePhase21(ctx context.Context, list network.UnsyncList, packet *packets.Phase2Packet,
additionalRequests []*AdditionalRequest) ([]packets.ReferendumVote, error) {
_, span := instracer.StartSpan(ctx, "Communicator.ExchangePhase21")
span.AddAttributes(trace.Int64Attribute("pulse", int64(packet.GetPulseNumber())))
defer span.End()
logger := inslogger.FromContext(ctx)
type none struct{}
incoming := make(map[core.RecordRef]none)
responsesFilter := make(map[int]none)
for _, req := range additionalRequests {
responsesFilter[req.RequestIndex] = none{}
}
shouldSendResponse := func(p *phase2Result) bool {
_, ok := incoming[p.id]
return !ok || p.packet.ContainsRequests()
}
result := make([]packets.ReferendumVote, 0)
appendResult := func(index uint16, vote packets.ReferendumVote) {
_, ok := responsesFilter[int(index)]
if !ok {
return
}
result = append(result, vote)
}
err := nc.sendAdditionalRequests(ctx, packet, additionalRequests)
if err != nil {
return nil, errors.Wrap(err, "[ ExchangePhase2.1 ] Failed to send additional phase 2.1 requests")
}
for {
select {
case res := <-nc.phase2result:
logger.Debugf("Got phase2 request from %s", res.id)
currentPulse := nc.getPulseNumber()
if res.packet.GetPulseNumber() != currentPulse {
logger.Debugf("Filtered phase2 packet, packet pulse %d != %d (current pulse)",
res.packet.GetPulseNumber(), currentPulse)
continue
}
if shouldSendResponse(&res) {
logger.Debugf("Send phase2 response to %s", res.id)
// send response
response := packet
if res.packet.ContainsRequests() {
response, err = nc.generatePhase2Response(ctx, packet, res.packet, list)
if err != nil {
logger.Warnf("Failed to generate phase 2 response packet: %s", err.Error())
continue
}
}
err := nc.ConsensusNetwork.SignAndSendPacket(response, res.id, nc.Cryptography)
if err != nil {
logger.Error("Error sending phase2 response: " + err.Error())
}
}
if res.packet.ContainsResponses() {
voteAnswers := res.packet.GetVotes()
for _, vote := range voteAnswers {
switch v := vote.(type) {
case *packets.MissingNodeSupplementaryVote:
appendResult(v.NodeIndex, v)
case *packets.MissingNodeClaim:
appendResult(v.NodeIndex, v)
}
}
}
incoming[res.id] = none{}
// FIXME: early return is commented to have synchronized length of phases on all nodes
// if len(result) == len(participants) {
// return result, nil
// }
case <-ctx.Done():
return result, nil
}
}
}
// ExchangePhase3 used in third consensus step to exchange data between participants
func (nc *ConsensusCommunicator) ExchangePhase3(ctx context.Context, participants []core.Node, packet *packets.Phase3Packet) (map[core.RecordRef]*packets.Phase3Packet, error) {
result := make(map[core.RecordRef]*packets.Phase3Packet, len(participants))
_, span := instracer.StartSpan(ctx, "Communicator.ExchangePhase3")
span.AddAttributes(trace.Int64Attribute("pulse", int64(packet.GetPulseNumber())))
defer span.End()
logger := inslogger.FromContext(ctx)
result[nc.ConsensusNetwork.GetNodeID()] = packet
nc.sendRequestToNodes(ctx, participants, packet)
type none struct{}
sentRequests := make(map[core.RecordRef]none)
shouldSendResponse := func(p *phase3Result) bool {
_, ok := sentRequests[p.id]
return !ok
}
for {
select {
case res := <-nc.phase3result:
logger.Debugf("Got phase3 request from %s", res.id)
currentPulse := nc.getPulseNumber()
if res.packet.GetPulseNumber() != currentPulse {
logger.Debugf("Filtered phase3 packet, packet pulse %d != %d (current pulse)",
res.packet.GetPulseNumber(), currentPulse)
continue
}
if shouldSendResponse(&res) {
logger.Debugf("Send phase3 response to %s", res.id)
// send response
err := nc.ConsensusNetwork.SignAndSendPacket(packet, res.id, nc.Cryptography)
if err != nil {
logger.Error("Error sending phase3 response: " + err.Error())
}
}
result[res.id] = res.packet
sentRequests[res.id] = none{}
// FIXME: early return is commented to have synchronized length of phases on all nodes
// if len(result) == len(participants) {
// return result, nil
// }
case <-ctx.Done():
return result, nil
}
}
}
func (nc *ConsensusCommunicator) phase1DataHandler(packet packets.ConsensusPacket, sender core.RecordRef) {
p, ok := packet.(*packets.Phase1Packet)
if !ok {
log.Error("invalid Phase1Packet")
return
}
newPulse := p.GetPulse()
if newPulse.PulseNumber < nc.getPulseNumber() {
log.Warn("ignore old pulse Phase1Packet")
return
}
if nc.setPulseNumber(newPulse.PulseNumber) {
go nc.PulseHandler.HandlePulse(context.Background(), newPulse)
}
nc.phase1result <- phase1Result{id: sender, packet: p}
}
func (nc *ConsensusCommunicator) phase2DataHandler(packet packets.ConsensusPacket, sender core.RecordRef) {
p, ok := packet.(*packets.Phase2Packet)
if !ok {
log.Error("invalid Phase2Packet")
return
}
pulseNumber := p.GetPulseNumber()
if pulseNumber < nc.getPulseNumber() {
log.Warn("ignore old pulse Phase2Packet")
return
}
nc.phase2result <- phase2Result{id: sender, packet: p}
}
func (nc *ConsensusCommunicator) phase3DataHandler(packet packets.ConsensusPacket, sender core.RecordRef) {
p, ok := packet.(*packets.Phase3Packet)
if !ok {
log.Warn("failed to cast a type 3 packet to phase3packet")
}
nc.phase3result <- phase3Result{id: sender, packet: p}
}