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

feat: update x/gov module parsing #652

Merged
merged 40 commits into from
Oct 3, 2023

Conversation

MonikaCat
Copy link
Contributor

@MonikaCat MonikaCat commented Sep 20, 2023

Description

Closes: #XXXX
BDU-11
BDU-771
BDU-1077

Changes:
gov module:

  • Added handler on every block to check and update proposal status if active_proposal event has been emitted inside the EndBlockEvents
  • Added periodic operations to update proposal staking pool snapshots every 5 mins
  • Added periodic operations to update proposal tally results every 5 mins
  • Added handler to update tally results for given proposal on every MsgVote and MsgVoteWeighted msgs
  • Added handler for rpc error rpc error returning code = NotFound desc = proposal x doesn't exist returned from node sometimes when processing MsgSubmitProposal msg and querying the node for proposal details
  • Added amount to unique_deposit constraint to allow to store different deposits from the same address for the same proposal
  • Added weight column to proposal_vote table and added option to unique_vote constraint
  • Added handler for MsgVoteWeighted msgs to correctly store votes in db
  • Removed auth module from expected modules

staking module:

  • Added periodic operations to update validators statuses, voting power and proposal validators status snapshots every 5 mins
  • Added handler to update validators statuses, voting powers and proposals validators status snapshots when there is a VP change on MsgDelegate, MsgBeginRedelegate and MsgUndelegate msgs

Author Checklist

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 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
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

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 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)

@MonikaCat MonikaCat marked this pull request as ready for review September 20, 2023 10:52
@MonikaCat MonikaCat requested a review from zura35 September 20, 2023 10:53
@MonikaCat MonikaCat added Cat: x/gov Related to the governance module automerge Automatically merge PR once all prerequisites pass labels Sep 20, 2023
Copy link

@zura35 zura35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cuz I'm not familiar with bdjuno enough, you will see questions more than comments 😂 And wonder if there are anyone else to approve the changes but if not I can help approve if needed 🙏

modules/gov/utils_proposal.go Outdated Show resolved Hide resolved
modules/gov/utils_proposal.go Outdated Show resolved Hide resolved
modules/gov/utils_proposal.go Show resolved Hide resolved
database/auth.go Show resolved Hide resolved
database/gov.go Outdated Show resolved Hide resolved
@@ -29,7 +29,7 @@ CREATE TABLE proposal_deposit
amount COIN[],
timestamp TIMESTAMP,
height BIGINT NOT NULL,
CONSTRAINT unique_deposit UNIQUE (proposal_id, depositor_address)
CONSTRAINT unique_deposit UNIQUE (proposal_id, depositor_address, amount)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean in a proposal it is indeed not possible to have multiple deposits with the same amount from the same depositor address? Or this change is simply taking advantage of indexing? @@

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because sometimes the same address will pay the deposit in more than one txs (eg first deposit 100 DARIC, and later deposit 400 DARIC in a different tx) and right now only the latest deposit will be stored for given address inside the proposal_deposit table so by updating this constraint we can store all deposits correctly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I just updated it and added timestamp to the unique_deposit constraint to handle the edge cases where address can pay the same amount of deposit twice in different txs (eg. deposit 100 DARIC first, later deposit 100 DARIC again)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case can we also store the txHash and use it as a unique constraint? 🤔 It sounds more like a unique identifier for a proposal deposit instead of relying on timestamp and amount?

Or if txn timestamp must be unique across deposits and txns, we can remove amount from the unique constraint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I added transaction_hash to proposal_deposit table and updated unique_deposit constraint. I didn't create the reference to message table because genesis deposits doesn't contain tx hash details, so proposal deposits stored from genesis file will have empty string inside transaction_hash column

Copy link

@zura35 zura35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not change request) I see that we actually use UPSERT (i.e. INSERT ON CONFLICT UPDATE) quite intensively in this project. In general if we are certain about an operation is going to be an UPDATE, it's always better to use UPDATE statement directly so psql will not bother attempting to insert and receive an error @@

@@ -29,7 +29,7 @@ CREATE TABLE proposal_deposit
amount COIN[],
timestamp TIMESTAMP,
height BIGINT NOT NULL,
CONSTRAINT unique_deposit UNIQUE (proposal_id, depositor_address)
CONSTRAINT unique_deposit UNIQUE (proposal_id, depositor_address, amount)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case can we also store the txHash and use it as a unique constraint? 🤔 It sounds more like a unique identifier for a proposal deposit instead of relying on timestamp and amount?

Or if txn timestamp must be unique across deposits and txns, we can remove amount from the unique constraint?

@mergify mergify bot merged commit 7b4ec26 into cosmos/v0.47.x Oct 3, 2023
@mergify mergify bot deleted the dev/update-gov-module-parsing branch October 3, 2023 07:37
MonikaCat added a commit that referenced this pull request Feb 6, 2024
Closes: #XXXX
[BDU-11](https://forbole.atlassian.net/browse/BDU-11)
[BDU-771](https://forbole.atlassian.net/browse/BDU-771)
[BDU-1077](https://forbole.atlassian.net/browse/BDU-1077)

Changes:
`gov` module:
- Added handler on every block to check and update proposal status if `active_proposal` event has been emitted inside the EndBlockEvents
- Added periodic operations to update `proposal staking pool snapshots` every 5 mins
- Added periodic operations to update `proposal tally results` every 5 mins
- Added handler to update `tally results` for given proposal on every `MsgVote` and `MsgVoteWeighted` msgs
- Added handler for rpc error `rpc error returning code = NotFound desc = proposal x doesn't exist` returned from node  sometimes when processing `MsgSubmitProposal` msg and querying the node for proposal details
- Added amount to `unique_deposit` constraint to allow to store different deposits from the same address for the same proposal
- Added `weight` column to `proposal_vote` table and added `option` to `unique_vote` constraint
- Added handler for `MsgVoteWeighted` msgs to correctly store votes in db
- Removed `auth` module from expected modules

`staking` module:
- Added periodic operations to update validators statuses, voting power and proposal validators status snapshots every 5 mins
- Added handler to update validators statuses, voting powers and proposals validators status snapshots when there is a VP change on `MsgDelegate`, `MsgBeginRedelegate` and `MsgUndelegate` msgs

---

*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)

[BDU-11]: https://forbole.atlassian.net/browse/BDU-11?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[BDU-771]: https://forbole.atlassian.net/browse/BDU-771?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[BDU-1077]: https://forbole.atlassian.net/browse/BDU-1077?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge PR once all prerequisites pass Cat: x/gov Related to the governance module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants