Skip to content

Commit

Permalink
Use SelectionID to detect when to zero out StateProofID
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Jan 10, 2024
1 parent 1afb148 commit c8dd389
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions ledger/store/trackerdb/sqlitedriver/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,11 @@ func performOnlineAccountsTableMigration(ctx context.Context, e db.Executable, p
}

// We had a bug that didn't remove StateProofIDs when going offline.
// Tidy up such accounts. This would be wrong to run after the
// incentives work is complete, since voting material is retained for
// suspended accounts, which are offline. But we won't be running this
// schema upgrade on future databases.
if ba.Status != basics.Online && !ba.StateProofID.IsEmpty() {
// Tidy up such accounts. We don't zero it out based on
// `!basics.Online` because accounts can be suspended, in which case
// they are Offline, but retain their voting material. But it remains
// illegal to have a StateProofID without a SelectionID.
if ba.SelectionID.IsEmpty() && !ba.StateProofID.IsEmpty() {
// store old data for account hash update
state := acctState{old: ba, oldEnc: encodedAcctData}
ba.StateProofID = merklesignature.Commitment{}
Expand Down
12 changes: 6 additions & 6 deletions ledger/store/trackerdb/sqlitedriver/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestAccountDBTxTailLoad(t *testing.T) {
}
}

func TestRemoveOfflineStateProofID(t *testing.T) {
func TestRemoveStrayStateProofID(t *testing.T) {
partitiontest.PartitionTest(t)

accts := ledgertesting.RandomAccounts(20, true)
Expand All @@ -176,7 +176,7 @@ func TestRemoveOfflineStateProofID(t *testing.T) {
accts[addr] = acct

expectedAcct := acct
if acct.Status != basics.Online {
if acct.SelectionID.IsEmpty() {
expectedAcct.StateProofID = merklesignature.Commitment{}
}
expectedAccts[addr] = expectedAcct
Expand Down Expand Up @@ -236,8 +236,8 @@ func TestRemoveOfflineStateProofID(t *testing.T) {
var ba trackerdb.BaseAccountData
err = protocol.Decode(encodedAcctData, &ba)
require.NoError(t, err)
if expected && (ba.Status != basics.Online) {
require.Equal(t, merklesignature.Commitment{}, ba.StateProofID)
if expected && ba.SelectionID.IsEmpty() {
require.Zero(t, ba.StateProofID)
}
addHash := trackerdb.AccountHashBuilderV6(addr, &ba, encodedAcctData)
added, err := trie.Add(addHash)
Expand Down Expand Up @@ -286,8 +286,8 @@ func TestRemoveOfflineStateProofID(t *testing.T) {
var ba trackerdb.BaseAccountData
err = protocol.Decode(encodedAcctData, &ba)
require.NoError(t, err)
if ba.Status != basics.Online {
require.True(t, ba.StateProofID.IsEmpty())
if ba.SelectionID.IsEmpty() {
require.Zero(t, ba.StateProofID)
}
}
}

0 comments on commit c8dd389

Please sign in to comment.