-
Notifications
You must be signed in to change notification settings - Fork 211
/
util.go
51 lines (45 loc) · 1.23 KB
/
util.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
package proposals
import (
"github.com/spacemeshos/go-spacemesh/codec"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/proposals/util"
)
var (
CalcEligibleLayer = util.CalcEligibleLayer
GetNumEligibleSlots = util.GetNumEligibleSlots
)
func MustGetNumEligibleSlots(
weight, minWeight, totalWeight uint64,
committeeSize, layersPerEpoch uint32,
) uint32 {
slots, err := GetNumEligibleSlots(weight, minWeight, totalWeight, committeeSize, layersPerEpoch)
if err != nil {
panic(err)
}
return slots
}
//go:generate scalegen -types VrfMessage
// VrfMessage is a verification message. It is the payload for the signature in `VotingEligibility`.
type VrfMessage struct {
Type types.EligibilityType // always types.EligibilityVoting
Beacon types.Beacon
Epoch types.EpochID
Nonce types.VRFPostIndex
Counter uint32
}
// MustSerializeVRFMessage serializes a message for generating/verifying a VRF signature.
func MustSerializeVRFMessage(
beacon types.Beacon,
epoch types.EpochID,
nonce types.VRFPostIndex,
counter uint32,
) []byte {
m := VrfMessage{
Type: types.EligibilityVoting,
Beacon: beacon,
Epoch: epoch,
Nonce: nonce,
Counter: counter,
}
return codec.MustEncode(&m)
}