-
Notifications
You must be signed in to change notification settings - Fork 523
Participation Metrics #2677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Participation Metrics #2677
Changes from all commits
60d761a
6d46f94
db9a420
decdd0d
bdb95b9
56d4796
83a3065
626a56e
53be105
7c1c7da
97870ec
18f060d
ad0f283
aab152f
6c111ef
5ac6446
ea2badf
d8b8258
608ea43
6c97d0d
76e8a46
fe01a6f
e0ab245
cd22527
25e526b
d4bd5d3
3fb1e2c
ed38e01
861cb75
e5020d3
1c9639f
5bf5c05
0f6a581
07810f5
0c3cd8f
cd820eb
89c2a88
80b8f84
74eaa2b
e6d88a0
dd20a36
ef1b8c4
8703a00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright (C) 2019-2021 Algorand, Inc. | ||
| // This file is part of go-algorand | ||
| // | ||
| // go-algorand is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // go-algorand is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with go-algorand. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| package agreement | ||
|
|
||
| import ( | ||
| "github.com/algorand/go-deadlock" | ||
|
|
||
| "github.com/algorand/go-algorand/data/account" | ||
| "github.com/algorand/go-algorand/data/basics" | ||
| ) | ||
|
|
||
| func makeRecordingKeyManager(accounts []account.Participation) *recordingKeyManager { | ||
| return &recordingKeyManager{ | ||
| keys: accounts, | ||
| recording: make(map[basics.Address]map[account.ParticipationAction]basics.Round), | ||
| } | ||
| } | ||
|
|
||
| // recordingKeyManager provides a simple implementation of a KeyManager for unit tests. | ||
| type recordingKeyManager struct { | ||
| keys []account.Participation | ||
| recording map[basics.Address]map[account.ParticipationAction]basics.Round | ||
| mutex deadlock.Mutex | ||
| } | ||
|
|
||
| // VotingKeys implements KeyManager.VotingKeys. | ||
| func (m *recordingKeyManager) VotingKeys(votingRound, _ basics.Round) []account.Participation { | ||
| var km []account.Participation | ||
| for _, acc := range m.keys { | ||
| if acc.OverlapsInterval(votingRound, votingRound) { | ||
| km = append(km, acc) | ||
| } | ||
| } | ||
| return km | ||
| } | ||
|
|
||
| // DeleteOldKeys implements KeyManager.DeleteOldKeys. | ||
| func (m *recordingKeyManager) DeleteOldKeys(r basics.Round) { | ||
| } | ||
|
|
||
| // Record implements KeyManager.Record. | ||
| func (m *recordingKeyManager) RecordAsync(acct basics.Address, round basics.Round, action account.ParticipationAction) { | ||
| m.mutex.Lock() | ||
| defer m.mutex.Unlock() | ||
| if _, ok := m.recording[acct]; !ok { | ||
| m.recording[acct] = make(map[account.ParticipationAction]basics.Round) | ||
| } | ||
| m.recording[acct][action] = round | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,10 @@ | |
| package account | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "context" | ||
| "database/sql" | ||
| "encoding/binary" | ||
| "fmt" | ||
|
|
||
| "github.com/algorand/go-algorand/config" | ||
|
|
@@ -56,6 +58,24 @@ type Participation struct { | |
| KeyDilution uint64 | ||
| } | ||
|
|
||
| // ParticipationID computes a ParticipationID. | ||
| func (part Participation) ParticipationID() ParticipationID { | ||
| data := new(bytes.Buffer) | ||
|
|
||
| data.Write(part.Parent[:]) | ||
| binary.Write(data, binary.LittleEndian, part.FirstValid) | ||
| binary.Write(data, binary.LittleEndian, part.LastValid) | ||
| binary.Write(data, binary.LittleEndian, part.KeyDilution) | ||
| if part.VRF != nil { | ||
| data.Write(part.VRF.PK[:]) | ||
| } | ||
|
|
||
| // this too? | ||
| //part.Write(part.Voting.SubKeyPK[:]) | ||
|
|
||
| return ParticipationID(crypto.Hash(data.Bytes())) | ||
| } | ||
|
Comment on lines
+62
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The common way we calculate a hash of a structure is by msgp-ing it. Are you thinking of any particular reason we shouldn't do it here ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding is that the subkeys will change over time, so this was an attempt to make sure the same keyset wouldn't produce different ParticipationIDs
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While what you just wrote is correct, it's not what I meant. serializing := Participation{
FirstValid: part.FirstValid,
...while omitting the changing parts ( i.e. Voting keys ). then return ParticipationID(crypto.Hash(serializing.Marshal(nil))) |
||
|
|
||
| // 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. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: leave this spacing line.