-
Notifications
You must be signed in to change notification settings - Fork 0
/
round_2.go
81 lines (70 loc) · 1.93 KB
/
round_2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (C) 2020-2021 AnySwap Ltd. All rights reserved.
* Copyright (C) 2020-2021 haijun.cai@anyswap.exchange
*
* This library is free software; you can redistribute it and/or
* modify it under the Apache License, Version 2.0.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package signing
import (
"errors"
"fmt"
"github.com/deltaswapio/gsmpc/smpc-lib/smpc"
)
// Start broacast zkR
func (round *round2) Start() error {
if round.started {
fmt.Printf("============= round2.start fail =======\n")
return errors.New("ed sign,round2 already started")
}
round.number = 2
round.started = true
round.ResetOK()
curIndex, err := round.GetDNodeIDIndex(round.kgid)
if err != nil {
return err
}
srm := &SignRound2Message{
SignRoundMessage: new(SignRoundMessage),
ZkR: round.temp.zkR,
}
srm.SetFromID(round.kgid)
srm.SetFromIndex(curIndex)
round.temp.signRound2Messages[curIndex] = srm
round.out <- srm
//fmt.Printf("============= ed sign,round2.start success, current node id = %v =======\n", round.kgid)
return nil
}
// CanAccept is it legal to receive this message
func (round *round2) CanAccept(msg smpc.Message) bool {
if _, ok := msg.(*SignRound2Message); ok {
return msg.IsBroadcast()
}
return false
}
// Update is the message received and ready for the next round?
func (round *round2) Update() (bool, error) {
for j, msg := range round.temp.signRound2Messages {
if round.ok[j] {
continue
}
if msg == nil || !round.CanAccept(msg) {
return false, nil
}
round.ok[j] = true
}
return true, nil
}
// NextRound enter next round
func (round *round2) NextRound() smpc.Round {
round.started = false
return &round3{round}
}