Skip to content

Commit

Permalink
Merge pull request #656 from oasisprotocol/andrew7234/vote-round-time…
Browse files Browse the repository at this point in the history
…stamp

[consensus] add height/timestamp to governance votes
  • Loading branch information
Andrew7234 authored Mar 8, 2024
2 parents d4f20a1 + 15ba34e commit a619fde
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 184 deletions.
1 change: 1 addition & 0 deletions analyzer/consensus/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ func (m *processor) queueVotes(batch *storage.QueryBatch, data *governanceData)
vote.ID,
vote.Submitter.String(),
vote.Vote,
data.Height,
)
}

Expand Down
7 changes: 4 additions & 3 deletions analyzer/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,11 @@ var (
WHERE id = $1`

ConsensusVoteUpsert = `
INSERT INTO chain.votes (proposal, voter, vote)
VALUES ($1, $2, $3)
INSERT INTO chain.votes (proposal, voter, vote, height)
VALUES ($1, $2, $3, $4)
ON CONFLICT (proposal, voter) DO UPDATE SET
vote = excluded.vote;`
vote = excluded.vote,
height = excluded.height;`

RuntimeBlockInsert = `
INSERT INTO chain.runtime_blocks (runtime, round, version, timestamp, block_hash, prev_block_hash, io_root, state_root, messages_hash, in_messages_hash, num_transactions, gas_used, size)
Expand Down
10 changes: 10 additions & 0 deletions api/spec/v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,16 @@ components:
type: string
description: The vote cast.
example: 'yes'
height:
type: integer
format: int64
description: The block height at which this vote was recorded.
example: *block_height_1
timestamp:
type: string
format: date-time
description: The second-granular consensus time of the block in which this vote was cast.
example: *iso_timestamp_1

RuntimeBlockList:
allOf:
Expand Down
2 changes: 2 additions & 0 deletions storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,8 @@ func (c *StorageClient) ProposalVotes(ctx context.Context, proposalID uint64, p
if err := res.rows.Scan(
&v.Address,
&v.Vote,
&v.Height,
&v.Timestamp,
); err != nil {
return nil, wrapError(err)
}
Expand Down
7 changes: 4 additions & 3 deletions storage/client/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,11 @@ const (
WHERE id = $1::bigint`

ProposalVotes = `
SELECT voter, vote
FROM chain.votes
SELECT votes.voter, votes.vote, votes.height, blocks.time
FROM chain.votes as votes
LEFT JOIN chain.blocks as blocks ON votes.height = blocks.height
WHERE proposal = $1::bigint
ORDER BY proposal DESC
ORDER BY height DESC, voter ASC
LIMIT $2::bigint
OFFSET $3::bigint`

Expand Down
6 changes: 6 additions & 0 deletions storage/migrations/11_governance_votes.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

ALTER TABLE chain.votes
ADD COLUMN height UINT63; -- Can be NULL; when the vote comes from a genesis file, height is unknown.

COMMIT;
Loading

0 comments on commit a619fde

Please sign in to comment.