RequestBlock() sends a block request to peer(s) - `heightOnly` is a request for just the peer's max height
(heightOnly bool, recipients ...[]byte)
| 519 | |
| 520 | // RequestBlock() sends a block request to peer(s) - `heightOnly` is a request for just the peer's max height |
| 521 | func (c *Controller) RequestBlock(heightOnly bool, recipients ...[]byte) { |
| 522 | // define a convenience variable for the current height |
| 523 | height := c.FSM.Height() |
| 524 | // if the optional 'recipients' is specified |
| 525 | if len(recipients) != 0 { |
| 526 | // for each 'recipient' specified |
| 527 | for _, pk := range recipients { |
| 528 | // log the block request |
| 529 | c.log.Debugf("Requesting block %d for chain %d from %s", height, c.Config.ChainId, lib.BytesToTruncatedString(pk)) |
| 530 | // send it to exactly who was specified in the function call |
| 531 | if err := c.P2P.SendTo(pk, BlockRequest, &lib.BlockRequestMessage{ |
| 532 | ChainId: c.Config.ChainId, |
| 533 | Height: height, |
| 534 | HeightOnly: heightOnly, |
| 535 | }); err != nil { |
| 536 | // log error |
| 537 | c.log.Error(err.Error()) |
| 538 | } |
| 539 | } |
| 540 | } else { |
| 541 | // log the block request |
| 542 | c.log.Debugf("Requesting block %d for chain %d from all", height, c.Config.ChainId) |
| 543 | // send it to the peers |
| 544 | if err := c.P2P.SendToPeers(BlockRequest, &lib.BlockRequestMessage{ |
| 545 | ChainId: c.Config.ChainId, |
| 546 | Height: height, |
| 547 | HeightOnly: heightOnly, |
| 548 | }); err != nil { |
| 549 | // log error |
| 550 | c.log.Error(err.Error()) |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | // SendBlock() responds to a `blockRequest` message to a peer - always sending the self.MaxHeight and sometimes sending the actual block and supporting QC |
| 556 | func (c *Controller) SendBlock(maxHeight, vdfIterations uint64, blockAndCert *lib.QuorumCertificate, recipient []byte) { |
no test coverage detected