Skip to content
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

Merged
merged 43 commits into from
Aug 7, 2021
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
60d761a
WIP participation metrics.
winder Jul 30, 2021
6d46f94
Complete interface changes for storing participation metrics.
winder Aug 2, 2021
db9a420
Use a single record + type instead of separate functions. Move regist…
winder Aug 2, 2021
decdd0d
Reuse SimpleKeyManager instead of having 3 implementations of it.
winder Aug 2, 2021
bdb95b9
Another SimpleKeyManager fix.
winder Aug 2, 2021
56d4796
Missed another SimpleKeyManager
winder Aug 3, 2021
83a3065
Rename participationRegistry
winder Aug 3, 2021
626a56e
fmt and lint
winder Aug 3, 2021
53be105
Add db initialize helper and tests.
winder Aug 3, 2021
7c1c7da
Participation registry created with db initialize function.
winder Aug 3, 2021
97870ec
fmt and lint
winder Aug 3, 2021
18f060d
Fix some error names.
winder Aug 3, 2021
ad0f283
Insert, Get, GetAll
winder Aug 4, 2021
aab152f
Delete
winder Aug 4, 2021
6c111ef
Register
winder Aug 4, 2021
5ac6446
Record
winder Aug 5, 2021
ea2badf
fmt and lint
winder Aug 5, 2021
d8b8258
sql.Row.Err does not exist in go 1.14.7
winder Aug 5, 2021
608ea43
Remove unreachable code
winder Aug 5, 2021
6c97d0d
Initialize registry to a real file.
winder Aug 5, 2021
76e8a46
Don't return error in KeyManager agreement abstraction.
winder Aug 5, 2021
fe01a6f
Improve error message.
winder Aug 5, 2021
e0ab245
Use db.Pair, cleanup things.
winder Aug 5, 2021
cd22527
Fix unit test.
winder Aug 5, 2021
25e526b
Fix error
winder Aug 5, 2021
d4bd5d3
Another fix...
winder Aug 5, 2021
3fb1e2c
Use map for participation actions, more tests.
winder Aug 5, 2021
ed38e01
fmt and lint
winder Aug 5, 2021
861cb75
Move record location.
winder Aug 5, 2021
e5020d3
Add test for record function and make sure test helpers aren't in the…
winder Aug 6, 2021
1c9639f
Add closer and close resources in tests.
winder Aug 6, 2021
5bf5c05
Record -> RecordAsync
winder Aug 6, 2021
0f6a581
Add FullNode test.
winder Aug 6, 2021
07810f5
Use Start and Stop instead of manually starting the monitoring routines.
winder Aug 6, 2021
0c3cd8f
Final pass over code.
winder Aug 6, 2021
cd820eb
Fix race.
winder Aug 6, 2021
89c2a88
Fix lock
winder Aug 6, 2021
80b8f84
Don't worry about max bal lookback.
winder Aug 6, 2021
74eaa2b
Remove channel, non blocking will be done in a future PR
winder Aug 6, 2021
e6d88a0
deadlock
winder Aug 6, 2021
dd20a36
Fix import...
winder Aug 6, 2021
ef1b8c4
Add newline to imports...
winder Aug 6, 2021
8703a00
Really fix the race.
winder Aug 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fmt and lint
winder committed Aug 5, 2021
commit ea2badf5267d09a994a802866e9631c555176d9e
23 changes: 9 additions & 14 deletions data/account/participationRegistry.go
Original file line number Diff line number Diff line change
@@ -133,42 +133,37 @@ var (
insertKeysetQuery = `INSERT INTO Keysets (participationID, account, firstValidRound, lastValidRound, keyDilution) VALUES (?, ?, ?, ?, ?)`
insertRollingQuery = `INSERT INTO Rolling (pk) VALUES (?)`


// SELECT pk FROM Keysets WHERE participationID = ?
selectPK = `SELECT pk FROM Keysets WHERE participationID = ? LIMIT 1`
selectLastPK = `SELECT pk FROM Keysets ORDER BY pk DESC LIMIT 1`
selectPK = `SELECT pk FROM Keysets WHERE participationID = ? LIMIT 1`
selectLastPK = `SELECT pk FROM Keysets ORDER BY pk DESC LIMIT 1`
selectRecords = `SELECT
participationID, account, firstValidRound, lastValidRound, keyDilution,
lastVoteRound, lastBlockProposalRound, lastCompactCertificateRound,
effectiveFirstValidRound, effectiveLastValidRound
FROM Keysets, Rolling
WHERE Keysets.pk = Rolling.pk`
selectRecord = selectRecords + ` AND participationID = ?`
selectRecord = selectRecords + ` AND participationID = ?`
deleteKeysets = `DELETE FROM Keysets WHERE pk=?`
deleteRolling = `DELETE FROM Rolling WHERE pk=?`
// there should be, at most, a single record within the effective range.
// only the effectiveLastValid can change here.
clearRegistered =
`UPDATE Rolling
clearRegistered = `UPDATE Rolling
SET effectiveLastValidRound = ?1
WHERE pk IN (SELECT pk FROM Keysets WHERE account = ?2)
AND effectiveFirstValidRound < ?1
AND effectiveLastValidRound > ?1`
setRegistered =
`UPDATE Rolling
setRegistered = `UPDATE Rolling
SET effectiveFirstValidRound=?,
effectiveLastValidRound=?
WHERE pk = (SELECT pk FROM Keysets WHERE participationID = ?)`
// there should only be a single record within the effective range.
updateRollingFieldX =
`UPDATE Rolling
updateRollingFieldX = `UPDATE Rolling
SET %s=?1
WHERE effectiveFirstValidRound < ?1
AND effectiveLastValidRound > ?1
AND pk IN (SELECT pk FROM Keysets WHERE account=?2)`
)


// dbSchemaUpgrade0 initialize the tables.
func dbSchemaUpgrade0(ctx context.Context, tx *sql.Tx, newDatabase bool) error {
// Keysets is for the immutable data.
@@ -338,19 +333,19 @@ func (db *participationDB) Register(id ParticipationID, on basics.Round) error {
}

// round out of valid range.
if on + maxBalLookback > record.LastValid || on + maxBalLookback < record.FirstValid {
if on+maxBalLookback > record.LastValid || on+maxBalLookback < record.FirstValid {
return ErrInvalidRegisterRange
}

return db.store.Atomic(func(ctx context.Context, tx *sql.Tx) error {
// if the is an active key, shut it down.
_, err = tx.Exec(clearRegistered, on + maxBalLookback, record.Account[:])
_, err = tx.Exec(clearRegistered, on+maxBalLookback, record.Account[:])
if err != nil {
return fmt.Errorf("unable to clear registered key: %w", err)
}

// update id
_, err = tx.Exec(setRegistered, on + maxBalLookback, record.LastValid, id[:])
_, err = tx.Exec(setRegistered, on+maxBalLookback, record.LastValid, id[:])
if err != nil {
return fmt.Errorf("unable to update registered key: %w", err)
}
4 changes: 2 additions & 2 deletions data/account/participationRegistry_test.go
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ func TestParticipation_Register(t *testing.T) {
FirstValid: 2000000,
LastValid: 4000000,
KeyDilution: 2,
Parent: p.Parent,
Parent: p.Parent,
}

id, err := registry.Insert(p)
@@ -242,4 +242,4 @@ func TestParticipation_Record(t *testing.T) {
require.Equal(t, 0, int(record.LastCompactCertificate))
}
}
}
}