Skip to content

Commit

Permalink
Tharvik's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ineiti committed Dec 15, 2021
1 parent 55f6862 commit af3d7bf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
4 changes: 1 addition & 3 deletions blscosi/protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ func DefaultSubLeaders(nodes int) int {
if nodes == 1 {
return 1
}
// As `math.Pow` calculates `9 ** (1/2) < 3`,
// we add 0.0001 for the rounding error.
return int(math.Pow(float64(nodes-1), 1.0/2.0) + 0.0001)
return int(math.Pow(float64(nodes-1), 1.0/2.0))
}

// NewBlsCosi method is used to define the blscosi protocol.
Expand Down
29 changes: 13 additions & 16 deletions blscosi/protocol/sub_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"crypto/rand"
"errors"
"fmt"
"golang.org/x/xerrors"
"sync"
"time"

Expand Down Expand Up @@ -207,8 +208,7 @@ func (p *SubBlsCosi) dispatchRoot() error {
case err := <-subLeaderActive:
if err != nil {
p.subleaderNotResponding <- true
log.Warnf("Couldn't contact subleader: %v", err)
return nil
return xerrors.Errorf("Couldn't contact subleader: %v", err)
}
case <-p.closeChan:
return nil
Expand Down Expand Up @@ -245,7 +245,17 @@ func (p *SubBlsCosi) dispatchSubLeader() error {
return err
}

p.sendToChildren(a)
if len(p.Children()) > 0 {
for _, node := range p.Children() {
go func(node *onet.TreeNode) {
err := p.SendTo(node, a)
if err != nil {
log.Warnf("Error while sending to leaf %s: %v",
node.Name(), err)
}
}(node)
}
}

responses := make(ResponseMap)
for _, c := range p.Children() {
Expand Down Expand Up @@ -447,16 +457,3 @@ func (p *SubBlsCosi) checkIntegrity() error {

return nil
}

// sendToChildren does not collect error messages,
// but doesn't block on nodes with a non-rejecting firewall in front of them.
func (p *SubBlsCosi) sendToChildren(msg interface{}) {
for _, c := range p.Children() {
go func(tn *onet.TreeNode) {
err := p.SendTo(tn, msg)
if err != nil {
log.Warnf("Error while sending to children: %v", err)
}
}(c)
}
}
2 changes: 1 addition & 1 deletion byzcoinx/byzcoinx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func runProtocol(t *testing.T, nbrHosts int, nbrFault int, refuseIndex int, prot
log.Lvl3("Added counter", counters.size()-1, refuseIndex)

require.True(t, int(math.Pow(float64(bftCosiProto.nSubtrees),
3.0)) <= nbrHosts)
2.0)) <= nbrHosts)

// kill the leafs first
nbrFault = min(nbrFault, len(servers))
Expand Down
33 changes: 19 additions & 14 deletions messaging/propagate.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func (p *Propagate) Dispatch() error {
var gotSendData bool
var errs []error
subtreeCount := p.TreeNode().SubtreeCount()
errsChan := make(chan error, subtreeCount)

for process {
p.Lock()
Expand Down Expand Up @@ -207,7 +208,19 @@ func (p *Propagate) Dispatch() error {
process = false
}
log.Lvl3(p.ServerIdentity(), "Sending to children", p.Children())
p.sendToChildren(&msg.PropagateSendData)

// Just blindly send to the children - we don't care if they receive it or
// not. If they don't receive it, they will complain later.
for _, c := range p.Children() {
go func(tn *onet.TreeNode) {
err := p.SendTo(tn, &msg.PropagateSendData)
if err != nil {
log.Warnf("Error while sending to child %s: %v",
tn.Name(), err)
errsChan <- err
}
}(c)
}
case <-p.ChannelReply:
if !gotSendData {
log.Error("got response before send")
Expand All @@ -220,6 +233,11 @@ func (p *Propagate) Dispatch() error {
return err
}
}
errsChan <- nil
case err := <-errsChan:
if err != nil {
errs = append(errs, err)
}
// Only wait for the number of children that successfully received our message.
if received == subtreeCount-len(errs) && received >= subtreeCount-p.allowedFailures {
process = false
Expand Down Expand Up @@ -265,16 +283,3 @@ func (p *Propagate) Shutdown() error {
close(p.closing)
return nil
}

// sendToChildren does not collect error messages,
// but doesn't block on nodes with a non-rejecting firewall in front of them.
func (p *Propagate) sendToChildren(msg interface{}) {
for _, c := range p.Children() {
go func(tn *onet.TreeNode) {
err := p.SendTo(tn, msg)
if err != nil {
log.Warnf("Error while sending to children: %v", err)
}
}(c)
}
}

0 comments on commit af3d7bf

Please sign in to comment.