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

fix: EOF on DB update deleted proposal from chain #106

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions database/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,29 @@ func (db *Db) GetProposal(id uint64) (types.Proposal, error) {
return proposal, nil
}

// GetProposalForUpdate returns a proposal with data required by NewProposalUpdate type
func (db *Db) GetProposalForUpdate(id uint64) (types.ProposalUpdate, error) {
var proposalForUpdate types.ProposalUpdate
var rows []*dbtypes.ProposalRow

err := db.SQL.Select(&rows, `SELECT status, voting_start_time, voting_end_time FROM proposal WHERE id = $1`, id)
if err != nil {
return types.ProposalUpdate{}, err
}

if len(rows) == 0 {
return types.ProposalUpdate{}, nil
}

row := rows[0]
proposalForUpdate.ProposalID = id
proposalForUpdate.Status = row.Status
proposalForUpdate.VotingStartTime = dbtypes.NullTimeToTime(row.VotingStartTime)
proposalForUpdate.VotingEndTime = dbtypes.NullTimeToTime(row.VotingEndTime)

return proposalForUpdate, nil
}

// GetOpenProposalsIds returns all the ids of the proposals that are in deposit or voting period at the given block time
func (db *Db) GetOpenProposalsIds(blockTime time.Time) ([]uint64, error) {
var ids []uint64
Expand Down
8 changes: 4 additions & 4 deletions modules/gov/utils_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ func (m *Module) UpdateProposalStakingPoolSnapshot(height int64, blockVals *tmct
// updateDeletedProposalStatus updates the proposal having the given id by setting its status
// to the one that represents a deleted proposal
func (m *Module) updateDeletedProposalStatus(id uint64) error {
stored, err := m.db.GetProposal(id)
proposalForUpdate, err := m.db.GetProposalForUpdate(id)
if err != nil {
return err
}

return m.db.UpdateProposal(
types.NewProposalUpdate(
stored.ID,
proposalForUpdate.ProposalID,
types.ProposalStatusInvalid,
stored.VotingStartTime,
stored.VotingEndTime,
proposalForUpdate.VotingStartTime,
proposalForUpdate.VotingEndTime,
),
)
}
Expand Down
Loading