From cbde0803656284ad44585f59d0462f5ea2f6ccbe Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Thu, 10 Nov 2022 19:45:50 +0800 Subject: [PATCH 1/4] check deposit end time --- 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..82e6af4a6 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.Time{}, 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 be57cb3d0..e00165866 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 deposit end time + passedDepositPeriod := blockTime.After(proposal.DepositEndTime) + + if strings.Contains(err.Error(), codes.NotFound.String()) && passedDepositPeriod { // Handle case when a proposal is deleted from the chain (did not pass deposit period) return m.updateDeletedProposalStatus(id) } From 622d929439b6f825ddec051ff9ddf2f2309666f6 Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Thu, 10 Nov 2022 19:51:40 +0800 Subject: [PATCH 2/4] change to voting period --- modules/gov/utils_proposal.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/gov/utils_proposal.go b/modules/gov/utils_proposal.go index e00165866..fe13640b7 100644 --- a/modules/gov/utils_proposal.go +++ b/modules/gov/utils_proposal.go @@ -25,10 +25,10 @@ func (m *Module) UpdateProposal(height int64, blockTime time.Time, id uint64) er // Get the proposal proposal, err := m.source.Proposal(height, id) if err != nil { - // Check if proposal has reached the deposit end time - passedDepositPeriod := blockTime.After(proposal.DepositEndTime) + // Check if proposal has reached the voting end time + passedVotingPeriod := blockTime.After(proposal.VotingEndTime) - if strings.Contains(err.Error(), codes.NotFound.String()) && passedDepositPeriod { + 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) } From cc2d5a84f2b7f29c8bebcb81932fd7b7783709ea Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Thu, 10 Nov 2022 19:54:12 +0800 Subject: [PATCH 3/4] change log --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11459b330..5a5e7ea13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 302d7111d39f5b1774a4adbd67eeecb7f7d69dc7 Mon Sep 17 00:00:00 2001 From: huichiaotsou Date: Mon, 14 Nov 2022 10:37:15 +0800 Subject: [PATCH 4/4] change to time.Now() --- cmd/parse/gov/proposal.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/parse/gov/proposal.go b/cmd/parse/gov/proposal.go index 82e6af4a6..151f6cd89 100644 --- a/cmd/parse/gov/proposal.go +++ b/cmd/parse/gov/proposal.go @@ -79,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, time.Time{}, proposalID) + err = govModule.UpdateProposal(height, time.Now(), proposalID) if err != nil { return err }