Skip to content

Commit 8a7eaf8

Browse files
committed
add reset functionality to dkgState and test
1 parent ab2a2d9 commit 8a7eaf8

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Diff for: keygen.go

+12
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ func NewEmptyDKGState(n, t int) DKGState {
7878
}
7979
}
8080

81+
func (state *DKGState) Reset() {
82+
state.Coefficients = state.Coefficients[:0]
83+
84+
for index := range state.Commitments {
85+
delete(state.Commitments, index)
86+
}
87+
88+
for index := range state.Shares {
89+
delete(state.Shares, index)
90+
}
91+
}
92+
8193
func DKGStart(state *DKGState, t int, ownIndex uint16, context [32]byte) DKGMessage {
8294
state.Step = 1
8395
for index := range state.Commitments {

Diff for: keygen_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,29 @@ var _ = Describe("DKG", func() {
3030
outputs := executeDKG(players, step1Timeout)
3131
checkOutputs(outputs, n, t, indices)
3232
})
33+
34+
It("should work after restting the state", func() {
35+
n := 10
36+
t := 5
37+
38+
indices := sequentialIndices(n)
39+
context := [32]byte{}
40+
copy(context[:], []byte("context"))
41+
step1Timeout := time.Duration(500 * time.Millisecond)
42+
43+
players := createDKGPlayers(indices, t, context)
44+
45+
outputs := executeDKG(players, step1Timeout)
46+
checkOutputs(outputs, n, t, indices)
47+
48+
// Reset and run the simulation again.
49+
for i := range players {
50+
players[i].reset()
51+
}
52+
53+
outputs = executeDKG(players, step1Timeout)
54+
checkOutputs(outputs, n, t, indices)
55+
})
3356
})
3457

3558
Context("all nodes honest and some offline", func() {
@@ -142,6 +165,12 @@ func createDKGPlayers(indices []uint16, t int, context [32]byte) []dkgPlayer {
142165
return players
143166
}
144167

168+
func (player *dkgPlayer) reset() {
169+
player.state.Reset()
170+
player.online = true
171+
player.aborted = false
172+
}
173+
145174
type dkgSimOutput struct {
146175
index uint16
147176
output frost.DKGOutput

0 commit comments

Comments
 (0)