From 7c5d23018dad080ebf975674c6c5a25e86d4c84b Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Thu, 15 Sep 2022 14:22:43 +0800 Subject: [PATCH 1/6] fix: get open proposal ids in deposit/voting period by block time instead of current time (#465) Closes: #XXXX --- *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) --- database/gov.go | 9 +++++---- database/gov_test.go | 20 ++++++++++++++++++-- modules/gov/handle_block.go | 7 ++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/database/gov.go b/database/gov.go index 26de439f2..3577e27c7 100644 --- a/database/gov.go +++ b/database/gov.go @@ -3,6 +3,7 @@ package database import ( "encoding/json" "fmt" + "time" codectypes "github.com/cosmos/cosmos-sdk/codec/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -204,8 +205,8 @@ func (db *Db) GetProposal(id uint64) (*types.Proposal, error) { return &proposal, nil } -// GetOpenProposalsIds returns all the ids of the proposals that are currently in deposit or voting period -func (db *Db) GetOpenProposalsIds() ([]uint64, error) { +// 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 stmt := `SELECT id FROM proposal WHERE status = $1 OR status = $2` err := db.Sqlx.Select(&ids, stmt, govtypes.StatusDepositPeriod.String(), govtypes.StatusVotingPeriod.String()) @@ -215,8 +216,8 @@ func (db *Db) GetOpenProposalsIds() ([]uint64, error) { // Get also the invalid status proposals due to gRPC failure but still are in deposit period or voting period var idsInvalid []uint64 - stmt = `SELECT id FROM proposal WHERE status = $1 AND (voting_end_time > NOW() OR deposit_end_time > NOW())` - err = db.Sqlx.Select(&idsInvalid, stmt, types.ProposalStatusInvalid) + stmt = `SELECT id FROM proposal WHERE status = $1 AND (voting_end_time > $2 OR deposit_end_time > $2)` + err = db.Sqlx.Select(&idsInvalid, stmt, types.ProposalStatusInvalid, blockTime) ids = append(ids, idsInvalid...) return ids, err diff --git a/database/gov_test.go b/database/gov_test.go index 51a56c09c..6bf8f5912 100644 --- a/database/gov_test.go +++ b/database/gov_test.go @@ -215,6 +215,20 @@ func (suite *DbTestSuite) TestBigDipperDb_GetOpenProposalsIds() { content1 := govtypes.NewTextProposal("title", "description") content2 := govtypes.NewTextProposal("title1", "description1") + + invalidProposal := types.NewProposal( + 6, + "proposalRoute1", + "proposalType1", + content2, + types.ProposalStatusInvalid, + time.Date(2020, 1, 2, 00, 00, 00, 000, time.UTC), + time.Date(2020, 1, 2, 01, 00, 00, 000, time.UTC), + time.Date(2020, 1, 2, 02, 00, 00, 000, time.UTC), + time.Date(2020, 1, 2, 03, 00, 00, 000, time.UTC), + proposer2.String(), + ) + input := []types.Proposal{ types.NewProposal( 1, @@ -264,14 +278,16 @@ func (suite *DbTestSuite) TestBigDipperDb_GetOpenProposalsIds() { time.Date(2020, 1, 2, 03, 00, 00, 000, time.UTC), proposer2.String(), ), + invalidProposal, } err := suite.database.SaveProposals(input) suite.Require().NoError(err) - ids, err := suite.database.GetOpenProposalsIds() + timeBeforeDepositEnd := invalidProposal.DepositEndTime.Add(-1 * time.Hour) + ids, err := suite.database.GetOpenProposalsIds(timeBeforeDepositEnd) suite.Require().NoError(err) - suite.Require().Equal([]uint64{1, 2}, ids) + suite.Require().Equal([]uint64{1, 2, 6}, ids) } func (suite *DbTestSuite) TestBigDipperDb_UpdateProposal() { diff --git a/modules/gov/handle_block.go b/modules/gov/handle_block.go index d584b48a1..76138e4e9 100644 --- a/modules/gov/handle_block.go +++ b/modules/gov/handle_block.go @@ -2,6 +2,7 @@ package gov import ( "fmt" + "time" juno "github.com/forbole/juno/v3/types" @@ -14,7 +15,7 @@ import ( func (m *Module) HandleBlock( b *tmctypes.ResultBlock, _ *tmctypes.ResultBlockResults, _ []*juno.Tx, vals *tmctypes.ResultValidators, ) error { - err := m.updateProposals(b.Block.Height, vals) + err := m.updateProposals(b.Block.Height, b.Block.Time, vals) if err != nil { log.Error().Str("module", "gov").Int64("height", b.Block.Height). Err(err).Msg("error while updating proposals") @@ -23,8 +24,8 @@ func (m *Module) HandleBlock( } // updateProposals updates the proposals -func (m *Module) updateProposals(height int64, blockVals *tmctypes.ResultValidators) error { - ids, err := m.db.GetOpenProposalsIds() +func (m *Module) updateProposals(height int64, blockTime time.Time, blockVals *tmctypes.ResultValidators) error { + ids, err := m.db.GetOpenProposalsIds(blockTime) if err != nil { log.Error().Err(err).Str("module", "gov").Msg("error while getting open ids") } From b8f8f996174de9101773dacef0868786c649062e Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Mon, 8 Aug 2022 18:36:44 +0800 Subject: [PATCH 2/6] fix: remove tombstone from `validator_status` (already exists in `validator_singing_info`) (#443) Closes: #XXXX Removing `tombstone status` from `validator_status` because: - it makes the code cleaner as `tombstone status` is already stored in `validator_singing_info` - it saves grpc calls for each validator at each block - the front-end `graphQL` does not query it from `validator_status` table anyways c.f. #411 --- *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... - [ ] 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 - [ ] targeted the correct branch - [ ] provided a link to the relevant issue or specification - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] 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) From 82e7ab78a49c6fd89ecfe9d427a02feb8dd92a5b Mon Sep 17 00:00:00 2001 From: Magic Cat <37407870+MonikaCat@users.noreply.github.com> Date: Wed, 24 Aug 2022 22:05:36 +0800 Subject: [PATCH 3/6] feat: updated staking pool values (#455) Closes: [BDU-484](https://forbole.atlassian.net/browse/BDU-484) --- *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 - [x] provided a link to the relevant issue or specification - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] 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) From ddea3ed0e115573db06be448e7010aaefae2327c Mon Sep 17 00:00:00 2001 From: Magic Cat <37407870+MonikaCat@users.noreply.github.com> Date: Fri, 26 Aug 2022 16:50:36 +0800 Subject: [PATCH 4/6] feat: add daily refetch module (#454) Closes: BDU-479 --- *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 - [x] provided a link to the relevant issue or specification - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [x] 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) From a695c1ac150cac7e23fe507ae74d28bf90dd07aa Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:28:47 +0800 Subject: [PATCH 5/6] fix: parse gov genesis with `doc.InitialHeight` instead of height 1 (#461) Closes: #XXXX jira: https://forbole.atlassian.net/browse/BDU-544 --- *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) From 87689ce63f3bdf273b75e4cc1499f0443e268c15 Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Thu, 15 Sep 2022 14:22:43 +0800 Subject: [PATCH 6/6] fix: get open proposal ids in deposit/voting period by block time instead of current time (#465) Closes: #XXXX --- *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)