-
Notifications
You must be signed in to change notification settings - Fork 11
/
quorum.go
50 lines (44 loc) · 1.59 KB
/
quorum.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
package types
import (
"bytes"
"fmt"
)
// CommitSigns is used to combine threshold signatures and quorum-hash that were used
type CommitSigns struct {
QuorumSigns
QuorumHash []byte
}
// CopyToCommit copies threshold signature to commit
//
// commit.ThresholdVoteExtensions must be initialized
func (c *CommitSigns) CopyToCommit(commit *Commit) {
commit.QuorumHash = c.QuorumHash
commit.ThresholdBlockSignature = c.BlockSign
if len(c.VoteExtensionSignatures) != len(commit.ThresholdVoteExtensions) {
panic(fmt.Sprintf("count of threshold vote extension signatures (%d) doesn't match vote extensions in commit (%d)",
len(commit.ThresholdVoteExtensions), len(c.VoteExtensionSignatures),
))
}
for i, ext := range c.VoteExtensionSignatures {
commit.ThresholdVoteExtensions[i].Signature = bytes.Clone(ext)
}
}
// QuorumSigns holds all created signatures, block, state and for each recovered vote-extensions
type QuorumSigns struct {
BlockSign []byte
// List of vote extensions signatures. Order matters.
VoteExtensionSignatures [][]byte
}
// NewQuorumSignsFromCommit creates and returns QuorumSigns using threshold signatures from a commit.
//
// Note it only uses threshold-revoverable vote extension signatures, as non-threshold signatures are not included in the commit
func NewQuorumSignsFromCommit(commit *Commit) QuorumSigns {
sigs := make([][]byte, 0, len(commit.ThresholdVoteExtensions))
for _, ext := range commit.ThresholdVoteExtensions {
sigs = append(sigs, ext.Signature)
}
return QuorumSigns{
BlockSign: commit.ThresholdBlockSignature,
VoteExtensionSignatures: sigs,
}
}