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: check if proposal has passed voting end time before marking it as invalid #499

Merged
merged 5 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- ([\#461](https://github.com/forbole/bdjuno/pull/461)) Parse `x/gov` genesis with `genesisDoc.InitialHeight` instead of the hard-coded height 1
- ([\#465](https://github.com/forbole/bdjuno/pull/465)) Get open proposal ids in deposit or voting period by block time instead of current time
- ([\#489](https://github.com/forbole/bdjuno/pull/489)) Remove block height foreign key from proposal_vote and proposal_deposit tables and add column timestamp
- ([\#499](https://github.com/forbole/bdjuno/pull/499)) Check if proposal has passed voting end time before marking it invalid

#### Daily refetch
- ([\#454](https://github.com/forbole/bdjuno/pull/454)) Added `daily refetch` module to refetch missing blocks every day
Expand Down
3 changes: 2 additions & 1 deletion cmd/parse/gov/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/hex"
"fmt"
"strconv"
"time"

modulestypes "github.com/forbole/bdjuno/v3/modules/types"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -78,7 +79,7 @@ func proposalCmd(parseConfig *parsecmdtypes.Config) *cobra.Command {
return fmt.Errorf("error while getting chain latest block height: %s", err)
}

err = govModule.UpdateProposal(height, proposalID)
err = govModule.UpdateProposal(height, time.Time{}, proposalID)
huichiaotsou marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion modules/gov/handle_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (m *Module) updateProposals(height int64, blockTime time.Time, blockVals *t
}

for _, id := range ids {
err = m.UpdateProposal(height, id)
err = m.UpdateProposal(height, blockTime, id)
if err != nil {
return fmt.Errorf("error while updating proposal: %s", err)
}
Expand Down
8 changes: 6 additions & 2 deletions modules/gov/utils_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gov
import (
"fmt"
"strings"
"time"

minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
proposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
Expand All @@ -20,11 +21,14 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)

func (m *Module) UpdateProposal(height int64, id uint64) error {
func (m *Module) UpdateProposal(height int64, blockTime time.Time, id uint64) error {
// Get the proposal
proposal, err := m.source.Proposal(height, id)
if err != nil {
if strings.Contains(err.Error(), codes.NotFound.String()) {
// Check if proposal has reached the voting end time
passedVotingPeriod := blockTime.After(proposal.VotingEndTime)

if strings.Contains(err.Error(), codes.NotFound.String()) && passedVotingPeriod {
// Handle case when a proposal is deleted from the chain (did not pass deposit period)
return m.updateDeletedProposalStatus(id)
}
Expand Down