Skip to content

Commit

Permalink
fix lint (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
willscott committed Sep 30, 2020
1 parent d02bb8c commit 9b1bdef
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 41 deletions.
1 change: 0 additions & 1 deletion core/drand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ func TestDrandDKGReshareAbsent(t *testing.T) {
// the node that had stopped must not be in the group
missingPublic := dt.nodes[nodeToStop].drand.priv.Public
require.Nil(t, newGroup.Find(missingPublic), "missing public is found", missingPublic)

}

func TestDrandDKGReshareTimeout(t *testing.T) {
Expand Down
90 changes: 50 additions & 40 deletions core/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,59 @@ func (d *DrandTest2) SetupNewNodes(newNodes int) []*Node {
return d.newNodes
}

func (d *DrandTest2) runNodeReshare(n *Node, errCh chan error, force bool) {
var secret = "thisistheresharing"
leader := d.nodes[0]
// instruct to be ready for a reshare
client, err := net.NewControlClient(n.drand.opts.controlPort)
require.NoError(d.t, err)
_, err = client.InitReshare(leader.drand.priv.Public, secret, d.groupPath, force)
if err != nil {
fmt.Println("error in NON LEADER: ", err)
errCh <- err
return
}
fmt.Printf("\n\nRESHARING TEST: non-leader drand %s DONE RESHARING - %s\n", n.drand.priv.Public.Address(), n.drand.priv.Public.Key)
}

func (d *DrandTest2) runLeaderReshare(timeout time.Duration, errCh chan error, groupCh chan *key.Group) {
var secret = "thisistheresharing"
leader := d.nodes[0]
oldNode := d.group.Find(leader.drand.priv.Public)
if oldNode == nil {
panic("leader not found in old group")
}
// old root: oldNode.Index leater: leader.addr
client, err := net.NewControlClient(leader.drand.opts.controlPort)
require.NoError(d.t, err)
finalGroup, err := client.InitReshareLeader(d.newN, d.newThr, timeout, 0, secret, "", testBeaconOffset)
// Done resharing
if err != nil {
fmt.Println("error in LEADER: ", err)
errCh <- err
}
fg, err := key.GroupFromProto(finalGroup)
if err != nil {
errCh <- err
}
groupCh <- fg
}

// RunReshare runs the resharing procedure with only "oldRun" current nodes
// running, and "newRun" new nodes running (the ones created via SetupNewNodes).
// It sets the given threshold to the group.
// It stops the nodes excluded first.
func (d *DrandTest2) RunReshare(oldRun, newRun, newThr int, timeout time.Duration, force, onlyLeader bool, ignoreErrs ...bool) (*key.Group, error) {
func (d *DrandTest2) RunReshare(
oldRun, newRun, newThr int,
timeout time.Duration,
force, onlyLeader bool,
ignoreErrs ...bool) (*key.Group, error) {
var ignoreErr bool
if len(ignoreErrs) > 0 {
ignoreErr = true
}
d.Lock()
fmt.Printf(" -- Running RESHARE with %d/%d old, %d/%d new nodes\n", oldRun, len(d.nodes), newRun, len(d.newNodes))
var secret = "thisistheresharing"
// stop the exluded nodes
for _, node := range d.nodes[oldRun:] {
d.StopDrand(node.addr, false)
Expand All @@ -345,60 +386,29 @@ func (d *DrandTest2) RunReshare(oldRun, newRun, newThr int, timeout time.Duratio
leader := d.nodes[0]
errCh := make(chan error, 1)
groupCh := make(chan *key.Group, 1)
// function that each non-leader runs to start the resharing
runreshare := func(n *Node) {
if onlyLeader {
return
}
// instruct to be ready for a reshare
client, err := net.NewControlClient(n.drand.opts.controlPort)
require.NoError(d.t, err)
_, err = client.InitReshare(leader.drand.priv.Public, secret, d.groupPath, force)
if err != nil {
fmt.Println("error in NON LEADER: ", err)
errCh <- err
return
}
fmt.Printf("\n\nRESHARING TEST: non-leader drand %s DONE RESHARING - %s\n", n.drand.priv.Public.Address(), n.drand.priv.Public.Key)
}
// first run the leader, then the other nodes will send their PK to the
// leader and then the leader will answer back with the new group
go func() {
oldNode := d.group.Find(leader.drand.priv.Public)
if oldNode == nil {
panic("leader not found in old group")
}
// old root: oldNode.Index leater: leader.addr
client, err := net.NewControlClient(leader.drand.opts.controlPort)
require.NoError(d.t, err)
finalGroup, err := client.InitReshareLeader(d.newN, d.newThr, timeout, 0, secret, "", testBeaconOffset)
// Done resharing
if err != nil {
fmt.Println("error in LEADER: ", err)
errCh <- err
}
fg, err := key.GroupFromProto(finalGroup)
if err != nil {
errCh <- err
}
groupCh <- fg
}()
go d.runLeaderReshare(timeout, errCh, groupCh)
d.resharedNodes = append(d.resharedNodes, leader)
// leave some time to make sure leader is listening
time.Sleep(1 * time.Second)

// run the current nodes
for _, node := range d.nodes[1:oldRun] {
d.resharedNodes = append(d.resharedNodes, node)
go runreshare(node)
if !onlyLeader {
go d.runNodeReshare(node, errCh, force)
}
}

// run the new ones
if len(d.newNodes) > 0 {
for _, node := range d.newNodes[:newRun] {
d.resharedNodes = append(d.resharedNodes, node)
fmt.Printf("\n ++ NEW NODE running RESHARE: %s\n", node.addr)
go runreshare(node)
if !onlyLeader {
go d.runNodeReshare(node, errCh, force)
}
}
}
d.Unlock()
Expand Down

0 comments on commit 9b1bdef

Please sign in to comment.