MCPcopy
hub / github.com/canopy-network/canopy / SendToReplicas

Method SendToReplicas

controller/consensus.go:459–493  ·  view source on GitHub ↗

PUBLISHERS BELOW SendToReplicas() directly send a bft message to each validator in a set (committee)

(replicas lib.ValidatorSet, msg lib.Signable)

Source from the content-addressed store, hash-verified

457
458// SendToReplicas() directly send a bft message to each validator in a set (committee)
459func (c *Controller) SendToReplicas(replicas lib.ValidatorSet, msg lib.Signable) {
460 // log the initialization of the send process
461 c.log.Debugf("Sending to %d replicas", replicas.NumValidators)
462 // sign the consensus message
463 if err := msg.Sign(c.PrivateKey); err != nil {
464 // log the error
465 c.log.Error(err.Error())
466 // exit
467 return
468 }
469 // send the message to self right away using internal routing
470 if err := c.P2P.SelfSend(c.PublicKey, Cons, msg); err != nil {
471 // log the error
472 c.log.Error(err.Error())
473 }
474 // if gossip mode is set, no need to send to replicas, the SelfSend will propagate to all the peers
475 if c.P2P.GossipMode() {
476 return
477 }
478 // for each replica (validator) in the set
479 for _, replica := range replicas.ValidatorSet.ValidatorSet {
480 // skip self
481 if bytes.Equal(replica.PublicKey, c.PublicKey) {
482 continue
483 } else {
484 // if not self, send directly to peer using P2P
485 if err := c.P2P.SendTo(replica.PublicKey, Cons, msg); err != nil {
486 // log the error (warning is used in case 'some' replicas are not reachable)
487 // for the case of gossiping, it is guaranteed that this warning will
488 // happen as not all peers will be reachable
489 c.log.Warn(err.Error())
490 }
491 }
492 }
493}
494
495// SendToProposer() sends a bft message to the leader of the Consensus round
496func (c *Controller) SendToProposer(msg lib.Signable) {

Callers

nothing calls this directly

Calls 8

SelfSendMethod · 0.80
GossipModeMethod · 0.80
EqualMethod · 0.80
SendToMethod · 0.80
DebugfMethod · 0.65
SignMethod · 0.65
ErrorMethod · 0.65
WarnMethod · 0.65

Tested by

no test coverage detected