summaryrefslogtreecommitdiff
path: root/data/account/participation.go
diff options
context:
space:
mode:
Diffstat (limited to 'data/account/participation.go')
-rw-r--r--data/account/participation.go44
1 files changed, 43 insertions, 1 deletions
diff --git a/data/account/participation.go b/data/account/participation.go
index 269163c99..474f6ca5e 100644
--- a/data/account/participation.go
+++ b/data/account/participation.go
@@ -41,6 +41,7 @@ import (
// For correctness, all Roots should have no more than one Participation
// globally active at any time. If this condition is violated, the Root may
// equivocate. (Algorand tolerates a limited fraction of misbehaving accounts.)
+//msgp:ignore Participation
type Participation struct {
Parent basics.Address
@@ -56,9 +57,50 @@ type Participation struct {
KeyDilution uint64
}
+// ParticipationKeyIdentity is for msgpack encoding the participation data.
+type ParticipationKeyIdentity struct {
+ _struct struct{} `codec:",omitempty,omitemptyarray"`
+
+ Parent basics.Address `codec:"addr"`
+ VRFSK crypto.VrfPrivkey `codec:"vrfsk"`
+ VoteID crypto.OneTimeSignatureVerifier `codec:"vote-id"`
+ FirstValid basics.Round `codec:"fv"`
+ LastValid basics.Round `codec:"lv"`
+ KeyDilution uint64 `codec:"kd"`
+}
+
+// ToBeHashed implements the Hashable interface.
+func (id *ParticipationKeyIdentity) ToBeHashed() (protocol.HashID, []byte) {
+ return protocol.ParticipationKeys, protocol.Encode(id)
+}
+
+// ID creates a ParticipationID hash from the identity file.
+func (id ParticipationKeyIdentity) ID() ParticipationID {
+ return ParticipationID(crypto.HashObj(&id))
+}
+
+// ID computes a ParticipationID.
+func (part Participation) ID() ParticipationID {
+ idData := ParticipationKeyIdentity{
+ Parent: part.Parent,
+ FirstValid: part.FirstValid,
+ LastValid: part.LastValid,
+ KeyDilution: part.KeyDilution,
+ }
+ if part.VRF != nil {
+ copy(idData.VRFSK[:], part.VRF.SK[:])
+ }
+ if part.Voting != nil {
+ copy(idData.VoteID[:], part.Voting.OneTimeSignatureVerifier[:])
+ }
+
+ return idData.ID()
+}
+
// PersistedParticipation encapsulates the static state of the participation
// for a single address at any given moment, while providing the ability
// to handle persistence and deletion of secrets.
+//msgp:ignore PersistedParticipation
type PersistedParticipation struct {
Participation
@@ -164,7 +206,7 @@ func (part PersistedParticipation) PersistNewParent() error {
// FillDBWithParticipationKeys initializes the passed database with participation keys
func FillDBWithParticipationKeys(store db.Accessor, address basics.Address, firstValid, lastValid basics.Round, keyDilution uint64) (part PersistedParticipation, err error) {
if lastValid < firstValid {
- err = fmt.Errorf("FillDBWithParticipationKeys: lastValid %d is after firstValid %d", lastValid, firstValid)
+ err = fmt.Errorf("FillDBWithParticipationKeys: firstValid %d is after lastValid %d", firstValid, lastValid)
return
}