-
Notifications
You must be signed in to change notification settings - Fork 211
/
message.go
81 lines (64 loc) · 2.25 KB
/
message.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
package beacon
import (
"encoding/hex"
"github.com/spacemeshos/go-scale"
"go.uber.org/zap/zapcore"
"github.com/spacemeshos/go-spacemesh/common/types"
)
//go:generate scalegen
// ProposalVrfMessage is the payload for the VRF Signature in `ProposalMessage`.
type ProposalVrfMessage struct {
Type types.EligibilityType // always types.EligibilityBeacon
Nonce types.VRFPostIndex
Epoch types.EpochID
}
// ProposalMessage is a message type which is used when sending proposals.
type ProposalMessage struct {
EpochID types.EpochID
NodeID types.NodeID
VRFSignature types.VrfSignature
}
type Proposal [types.BeaconSize]byte
// EncodeScale implements scale codec interface.
func (p *Proposal) EncodeScale(e *scale.Encoder) (int, error) {
return scale.EncodeByteArray(e, p[:])
}
// DecodeScale implements scale codec interface.
func (p *Proposal) DecodeScale(d *scale.Decoder) (int, error) {
return scale.DecodeByteArray(d, p[:])
}
func (p Proposal) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddString("proposal", hex.EncodeToString(p[:]))
return nil
}
func ProposalFromVrf(vrf types.VrfSignature) Proposal {
var p Proposal
copy(p[:], vrf[:])
return p
}
// FirstVotingMessageBody is FirstVotingMessage without a signature.
type FirstVotingMessageBody struct {
EpochID types.EpochID
// number of proposals is expected to be under 100, 1000 is a safe upper bound
ValidProposals []Proposal `scale:"max=1000"`
// number of proposals is expected to be under 100, 1000 is a safe upper bound
PotentiallyValidProposals []Proposal `scale:"max=1000"`
}
// FirstVotingMessage is a message type which is used when sending first voting messages.
type FirstVotingMessage struct {
FirstVotingMessageBody
SmesherID types.NodeID
Signature types.EdSignature
}
// FollowingVotingMessageBody is FollowingVotingMessage without a signature.
type FollowingVotingMessageBody struct {
EpochID types.EpochID
RoundID types.RoundID
VotesBitVector []byte `scale:"max=128"` // 128 bytes = 1024 bits and we limit the number of proposals to 1000
}
// FollowingVotingMessage is a message type which is used when sending following voting messages.
type FollowingVotingMessage struct {
FollowingVotingMessageBody
SmesherID types.NodeID
Signature types.EdSignature
}