Skip to content

Commit

Permalink
feat: Keep proposal/height history
Browse files Browse the repository at this point in the history
  • Loading branch information
clockworkgr committed Mar 4, 2024
1 parent d2b3ade commit ac6c142
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
25 changes: 1 addition & 24 deletions database/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,6 @@ func (db *Db) SaveTallyResults(tallys []types.TallyResult) error {
}

query = query[:len(query)-1] // Remove trailing ","
query += `
ON CONFLICT ON CONSTRAINT unique_tally_result DO UPDATE
SET yes = excluded.yes,
abstain = excluded.abstain,
no = excluded.no,
no_with_veto = excluded.no_with_veto,
height = excluded.height
WHERE proposal_tally_result.height <= excluded.height`
_, err := db.SQL.Exec(query, param...)
if err != nil {
return fmt.Errorf("error while storing tally result: %s", err)
Expand All @@ -354,13 +346,7 @@ WHERE proposal_tally_result.height <= excluded.height`
func (db *Db) SaveProposalStakingPoolSnapshot(snapshot types.ProposalStakingPoolSnapshot) error {
stmt := `
INSERT INTO proposal_staking_pool_snapshot (proposal_id, bonded_tokens, not_bonded_tokens, height)
VALUES ($1, $2, $3, $4)
ON CONFLICT ON CONSTRAINT unique_staking_pool_snapshot DO UPDATE SET
proposal_id = excluded.proposal_id,
bonded_tokens = excluded.bonded_tokens,
not_bonded_tokens = excluded.not_bonded_tokens,
height = excluded.height
WHERE proposal_staking_pool_snapshot.height <= excluded.height`
VALUES ($1, $2, $3, $4)`

_, err := db.SQL.Exec(stmt,
snapshot.ProposalID, snapshot.Pool.BondedTokens.String(), snapshot.Pool.NotBondedTokens.String(), snapshot.Pool.Height)
Expand Down Expand Up @@ -392,15 +378,6 @@ VALUES `
}

stmt = stmt[:len(stmt)-1]
stmt += `
ON CONFLICT ON CONSTRAINT unique_validator_status_snapshot DO UPDATE
SET proposal_id = excluded.proposal_id,
validator_address = excluded.validator_address,
voting_power = excluded.voting_power,
status = excluded.status,
jailed = excluded.jailed,
height = excluded.height
WHERE proposal_validator_status_snapshot.height <= excluded.height`
_, err := db.SQL.Exec(stmt, args...)
if err != nil {
return fmt.Errorf("error while storing proposal validator statuses snapshot: %s", err)
Expand Down
9 changes: 3 additions & 6 deletions database/schema/08-gov.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ CREATE TABLE proposal_tally_result
abstain TEXT NOT NULL,
no TEXT NOT NULL,
no_with_veto TEXT NOT NULL,
height BIGINT NOT NULL,
CONSTRAINT unique_tally_result UNIQUE (proposal_id)
height BIGINT NOT NULL
);
CREATE INDEX proposal_tally_result_proposal_id_index ON proposal_tally_result (proposal_id);
CREATE INDEX proposal_tally_result_height_index ON proposal_tally_result (height);
Expand All @@ -69,8 +68,7 @@ CREATE TABLE proposal_staking_pool_snapshot
proposal_id INTEGER REFERENCES proposal (id) PRIMARY KEY,
bonded_tokens TEXT NOT NULL,
not_bonded_tokens TEXT NOT NULL,
height BIGINT NOT NULL,
CONSTRAINT unique_staking_pool_snapshot UNIQUE (proposal_id)
height BIGINT NOT NULL
);
CREATE INDEX proposal_staking_pool_snapshot_proposal_id_index ON proposal_staking_pool_snapshot (proposal_id);

Expand All @@ -82,8 +80,7 @@ CREATE TABLE proposal_validator_status_snapshot
voting_power BIGINT NOT NULL,
status INT NOT NULL,
jailed BOOLEAN NOT NULL,
height BIGINT NOT NULL,
CONSTRAINT unique_validator_status_snapshot UNIQUE (proposal_id, validator_address)
height BIGINT NOT NULL
);
CREATE INDEX proposal_validator_status_snapshot_proposal_id_index ON proposal_validator_status_snapshot (proposal_id);
CREATE INDEX proposal_validator_status_snapshot_validator_address_index ON proposal_validator_status_snapshot (validator_address);

0 comments on commit ac6c142

Please sign in to comment.