-
Notifications
You must be signed in to change notification settings - Fork 211
/
util.go
56 lines (49 loc) · 1.69 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
52
53
54
55
56
package proposals
import (
"fmt"
"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
GetLegacyNumEligible = util.GetLegacyNumEligible
// ComputeWeightPerEligibility computes the ballot weight per eligibility w.r.t the active set recorded in its reference ballot.
ComputeWeightPerEligibility = util.ComputeWeightPerEligibility
)
//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
}
// SerializeVRFMessage serializes a message for generating/verifying a VRF signature.
func SerializeVRFMessage(beacon types.Beacon, epoch types.EpochID, nonce types.VRFPostIndex, counter uint32) ([]byte, error) {
m := VrfMessage{
Type: types.EligibilityVoting,
Beacon: beacon,
Epoch: epoch,
Nonce: nonce,
Counter: counter,
}
serialized, err := codec.Encode(&m)
if err != nil {
return nil, fmt.Errorf("serialize vrf message: %w", err)
}
return serialized, nil
}
// 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)
}