@@ -230,36 +230,35 @@ var (
230230 createKeysets = `CREATE TABLE Keysets (
231231 pk INTEGER PRIMARY KEY NOT NULL,
232232
233- participationID BLOB,
234- account BLOB,
233+ participationID BLOB NOT NULL ,
234+ account BLOB NOT NULL ,
235235
236- firstValidRound INTEGER NOT NULL DEFAULT 0 ,
237- lastValidRound INTEGER NOT NULL DEFAULT 0 ,
238- keyDilution INTEGER NOT NULL DEFAULT 0 ,
236+ firstValidRound INTEGER NOT NULL,
237+ lastValidRound INTEGER NOT NULL,
238+ keyDilution INTEGER NOT NULL,
239239
240- vrf BLOB --* msgpack encoding of ParticipationAccount.vrf
240+ vrf BLOB, --* msgpack encoding of ParticipationAccount.vrf
241+ stateProof BLOB --* msgpack encoding of ParticipationAccount.BlockProof
241242 )`
243+
242244 createRolling = `CREATE TABLE Rolling (
243245 pk INTEGER PRIMARY KEY NOT NULL,
244246
245- lastVoteRound INTEGER NOT NULL DEFAULT 0 ,
246- lastBlockProposalRound INTEGER NOT NULL DEFAULT 0 ,
247- lastCompactCertificateRound INTEGER NOT NULL DEFAULT 0 ,
248- effectiveFirstRound INTEGER NOT NULL DEFAULT 0 ,
249- effectiveLastRound INTEGER NOT NULL DEFAULT 0 ,
247+ lastVoteRound INTEGER,
248+ lastBlockProposalRound INTEGER,
249+ lastCompactCertificateRound INTEGER,
250+ effectiveFirstRound INTEGER ,
251+ effectiveLastRound INTEGER ,
250252
251253 voting BLOB --* msgpack encoding of ParticipationAccount.voting
252-
253- -- blockProof BLOB --* msgpack encoding of ParticipationAccount.BlockProof
254254 )`
255255
256- /*
257- createBlockProof = `CREATE TABLE BlockProofKeys (
258- id INTEGER PRIMARY KEY,
259- round INTEGER, --* committed round for this key
260- key BLOB --* msgpack encoding of ParticipationAccount.BlockProof.SignatureAlgorithm
261- )`
262- */
256+ createStateProof = `CREATE TABLE StateProofKeys (
257+ pk INTEGER NOT NULL, --* join with keyset to find key for a particular participation id
258+ round INTEGER NOT NULL, --* committed round for this key
259+ key BLOB NOT NULL, --* msgpack encoding of ParticipationAccount.BlockProof.SignatureAlgorithm
260+ PRIMARY KEY (pk, round)
261+ )`
263262 insertKeysetQuery = `INSERT INTO Keysets (participationID, account, firstValidRound, lastValidRound, keyDilution, vrf) VALUES (?, ?, ?, ?, ?, ?)`
264263 insertRollingQuery = `INSERT INTO Rolling (pk, voting) VALUES (?, ?)`
265264
@@ -299,6 +298,12 @@ func dbSchemaUpgrade0(ctx context.Context, tx *sql.Tx, newDatabase bool) error {
299298 return err
300299 }
301300
301+ // For performance reasons, state proofs are in a separate table.
302+ _ , err = tx .Exec (createStateProof )
303+ if err != nil {
304+ return err
305+ }
306+
302307 return nil
303308}
304309
@@ -663,18 +668,25 @@ func scanRecords(rows *sql.Rows) ([]ParticipationRecord, error) {
663668 var rawAccount []byte
664669 var rawVRF []byte
665670 var rawVoting []byte
671+
672+ var lastVote sql.NullInt64
673+ var lastBlockProposal sql.NullInt64
674+ var lastCompactCertificate sql.NullInt64
675+ var effectiveFirst sql.NullInt64
676+ var effectiveLast sql.NullInt64
677+
666678 err := rows .Scan (
667679 & rawParticipation ,
668680 & rawAccount ,
669681 & record .FirstValid ,
670682 & record .LastValid ,
671683 & record .KeyDilution ,
672684 & rawVRF ,
673- & record . LastVote ,
674- & record . LastBlockProposal ,
675- & record . LastCompactCertificate ,
676- & record . EffectiveFirst ,
677- & record . EffectiveLast ,
685+ & lastVote ,
686+ & lastBlockProposal ,
687+ & lastCompactCertificate ,
688+ & effectiveFirst ,
689+ & effectiveLast ,
678690 & rawVoting ,
679691 )
680692 if err != nil {
@@ -700,6 +712,27 @@ func scanRecords(rows *sql.Rows) ([]ParticipationRecord, error) {
700712 }
701713 }
702714
715+ // Check optional values.
716+ if lastVote .Valid {
717+ record .LastVote = basics .Round (lastVote .Int64 )
718+ }
719+
720+ if lastBlockProposal .Valid {
721+ record .LastBlockProposal = basics .Round (lastBlockProposal .Int64 )
722+ }
723+
724+ if lastCompactCertificate .Valid {
725+ record .LastCompactCertificate = basics .Round (lastCompactCertificate .Int64 )
726+ }
727+
728+ if effectiveFirst .Valid {
729+ record .EffectiveFirst = basics .Round (effectiveFirst .Int64 )
730+ }
731+
732+ if effectiveLast .Valid {
733+ record .EffectiveLast = basics .Round (effectiveLast .Int64 )
734+ }
735+
703736 results = append (results , record )
704737 }
705738
0 commit comments