Skip to content

Commit

Permalink
fix: check if proposal has passed voting end time before marking it a…
Browse files Browse the repository at this point in the history
…s invalid (forbole#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)
  • Loading branch information
huichiaotsou authored and ankurdotb committed Nov 24, 2022
1 parent 88ac193 commit 65d7e76
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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.Now(), proposalID)
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

0 comments on commit 65d7e76

Please sign in to comment.