From 65d7e766c3ddbd6010749ecbc0e5c16a5c406d4b Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Mon, 14 Nov 2022 10:50:43 +0800 Subject: [PATCH] fix: check if proposal has passed voting end time before marking it as invalid (#499) Closes: #XXXX jira: https://forbole.atlassian.net/browse/BDU-693 --- *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch - [ ] provided a link to the relevant issue or specification - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [x] confirmed all CI checks have passed *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) --- cmd/parse/gov/proposal.go | 3 ++- modules/gov/handle_block.go | 2 +- modules/gov/utils_proposal.go | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/parse/gov/proposal.go b/cmd/parse/gov/proposal.go index f4d0859c1..151f6cd89 100644 --- a/cmd/parse/gov/proposal.go +++ b/cmd/parse/gov/proposal.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "fmt" "strconv" + "time" modulestypes "github.com/forbole/bdjuno/v3/modules/types" "github.com/rs/zerolog/log" @@ -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.Now(), proposalID) if err != nil { return err } diff --git a/modules/gov/handle_block.go b/modules/gov/handle_block.go index 76138e4e9..9a279eafa 100644 --- a/modules/gov/handle_block.go +++ b/modules/gov/handle_block.go @@ -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) } diff --git a/modules/gov/utils_proposal.go b/modules/gov/utils_proposal.go index 61e9fa793..18b987e0a 100644 --- a/modules/gov/utils_proposal.go +++ b/modules/gov/utils_proposal.go @@ -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" @@ -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) }