PUBLISHERS BELOW SendToReplicas() directly send a bft message to each validator in a set (committee)
(replicas lib.ValidatorSet, msg lib.Signable)
| 457 | |
| 458 | // SendToReplicas() directly send a bft message to each validator in a set (committee) |
| 459 | func (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 |
| 496 | func (c *Controller) SendToProposer(msg lib.Signable) { |