From 9d4632b80cb8d1c50874151f37e42c699f2ecb3b Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 3 Nov 2022 11:37:54 +0000 Subject: [PATCH 01/22] ci: Fix syntax error in DOCR push --- .github/workflows/release.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 41a319d99..14e05d095 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,9 +4,6 @@ on: defaults: run: shell: bash -permissions: - contents: write - packages: write jobs: @@ -131,3 +128,18 @@ jobs: - name: Push Hasura CLI image run: docker image push --all-tags registry.digitalocean.com/${{ env.IMAGE_NAME }} + + cache-purge: + name: "Purge branch Actions cache" + needs: [release-bdjuno, release-hasuracli] + if: ${{ github.event_name == 'pull_request' }} + runs-on: ubuntu-latest + + steps: + + - name: "Delete Branch Cache Action" + uses: snnaplab/delete-branch-cache-action@v1.0.0 + with: + # Specify explicitly because the ref at the time of merging will be a branch name such as 'main', 'develop' + ref: refs/pull/${{ github.event.number }}/merge + github-token: ${{ secrets.GITHUB_TOKEN }} From 690ef81d8aaeeb80538b1af44ede8ed8c848a8c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:05:49 +0000 Subject: [PATCH 02/22] chore(deps): Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0 (#60) chore(deps): Bump github.com/prometheus/client_golang Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.14.0. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.13.0...v1.14.0) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 4 ++-- go.sum | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 202fe48a7..b019df2e2 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/jmoiron/sqlx v1.3.5 github.com/lib/pq v1.10.7 github.com/pelletier/go-toml v1.9.5 - github.com/prometheus/client_golang v1.13.0 + github.com/prometheus/client_golang v1.14.0 github.com/proullon/ramsql v0.0.0-20181213202341-817cee58a244 github.com/rs/zerolog v1.28.0 github.com/spf13/cobra v1.6.1 @@ -108,7 +108,7 @@ require ( github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_model v0.2.0 // indirect + github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.37.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect github.com/rakyll/statik v0.1.7 // indirect diff --git a/go.sum b/go.sum index 6a14077c6..dc211ebf9 100644 --- a/go.sum +++ b/go.sum @@ -589,15 +589,16 @@ github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP github.com/prometheus/client_golang v1.8.0/go.mod h1:O9VU6huf47PktckDQfMTX0Y8tY0/7TSWwj+ITvv0TnM= github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= -github.com/prometheus/client_golang v1.13.0 h1:b71QUfeo5M8gq2+evJdTPfZhYMAU0uKPkyPJ7TPsloU= -github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ= +github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw= +github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= +github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= From cb2270884a04d5e91494c0f19c60912eed7a460b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Nov 2022 03:38:30 +0000 Subject: [PATCH 03/22] build(deps): bump github.com/prometheus/client_golang from 1.13.0 to 1.13.1 (#493) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.13.1.
Release notes

Sourced from github.com/prometheus/client_golang's releases.

1.13.1 / 2022-11-02

  • [BUGFIX] Fix race condition with Exemplar in Counter. #1146
  • [BUGFIX] Fix CumulativeCount value of +Inf bucket created from exemplar. #1148
  • [BUGFIX] Fix double-counting bug in promhttp.InstrumentRoundTripperCounter. #1118

Full Changelog: https://github.com/prometheus/client_golang/compare/v1.13.0...v1.13.1

Changelog

Sourced from github.com/prometheus/client_golang's changelog.

1.13.1 / 2022-11-01

  • [BUGFIX] Fix race condition with Exemplar in Counter. #1146
  • [BUGFIX] Fix CumulativeCount value of +Inf bucket created from exemplar. #1148
  • [BUGFIX] Fix double-counting bug in promhttp.InstrumentRoundTripperCounter. #1118
Commits
  • 53e51c4 Merge pull request #1157 from prometheus/cut-1.13.1
  • 79ca0eb Added tip from Björn + Grammarly.
  • 078f11f Cut 1.13.1 release (+ documenting release process).
  • ddd7f0e Fix race condition with Exemplar in Counter (#1146)
  • 1f93f64 Fix CumulativeCount value of +Inf bucket created from exemplar (#1148)
  • 8cc2b6c Fix double-counting bug in promhttp.InstrumentRoundTripperCounter (#1118)
  • See full diff in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/prometheus/client_golang&package-manager=go_modules&previous-version=1.13.0&new-version=1.13.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
From 428c61acbd32faddeac63dcbd2bbe8de6291cb74 Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Mon, 14 Nov 2022 02:45:57 +0800 Subject: [PATCH 04/22] feat: manually trigger periodic task (#492) Closes: #415 --- *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` - [ ] 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/bank/cmd.go | 20 ++++++++ cmd/parse/bank/supply.go | 46 +++++++++++++++++++ cmd/parse/distribution/cmd.go | 20 ++++++++ cmd/parse/distribution/communitypool.go | 45 ++++++++++++++++++ cmd/parse/mint/cmd.go | 20 ++++++++ cmd/parse/mint/inflation.go | 45 ++++++++++++++++++ cmd/parse/parse.go | 8 ++++ cmd/parse/pricefeed/cmd.go | 21 +++++++++ cmd/parse/pricefeed/price.go | 44 ++++++++++++++++++ cmd/parse/pricefeed/pricehistory.go | 44 ++++++++++++++++++ cmd/parse/staking/cmd.go | 1 + cmd/parse/staking/staking.go | 45 ++++++++++++++++++ database/consensus.go | 14 ++++-- modules/bank/handle_periodic_operations.go | 14 +++--- .../handle_periodic_operations.go | 6 +-- .../pricefeed/handle_periodic_operations.go | 12 ++--- modules/staking/handle_periodic_operations.go | 6 +-- 17 files changed, 387 insertions(+), 24 deletions(-) create mode 100644 cmd/parse/bank/cmd.go create mode 100644 cmd/parse/bank/supply.go create mode 100644 cmd/parse/distribution/cmd.go create mode 100644 cmd/parse/distribution/communitypool.go create mode 100644 cmd/parse/mint/cmd.go create mode 100644 cmd/parse/mint/inflation.go create mode 100644 cmd/parse/pricefeed/cmd.go create mode 100644 cmd/parse/pricefeed/price.go create mode 100644 cmd/parse/pricefeed/pricehistory.go create mode 100644 cmd/parse/staking/staking.go diff --git a/cmd/parse/bank/cmd.go b/cmd/parse/bank/cmd.go new file mode 100644 index 000000000..6ee5f0a60 --- /dev/null +++ b/cmd/parse/bank/cmd.go @@ -0,0 +1,20 @@ +package bank + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewBankCmd returns the Cobra command allowing to fix various things related to the x/bank module +func NewBankCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "bank", + Short: "Fix things related to the x/bank module", + } + + cmd.AddCommand( + supplyCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/bank/supply.go b/cmd/parse/bank/supply.go new file mode 100644 index 000000000..b9a2f87a6 --- /dev/null +++ b/cmd/parse/bank/supply.go @@ -0,0 +1,46 @@ +package bank + +import ( + "fmt" + + modulestypes "github.com/forbole/bdjuno/v3/modules/types" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/bank" +) + +// supplyCmd returns the Cobra command allowing to refresh x/bank total supply +func supplyCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "supply", + Short: "Refresh total supply", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build bank module + bankModule := bank.NewModule(nil, sources.BankSource, parseCtx.EncodingConfig.Marshaler, db) + + err = bankModule.UpdateSupply() + if err != nil { + return fmt.Errorf("error while getting latest bank supply: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/distribution/cmd.go b/cmd/parse/distribution/cmd.go new file mode 100644 index 000000000..096ad4041 --- /dev/null +++ b/cmd/parse/distribution/cmd.go @@ -0,0 +1,20 @@ +package distribution + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewDistributionCmd returns the Cobra command allowing to fix various things related to the x/distribution module +func NewDistributionCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "distribution", + Short: "Fix things related to the x/distribution module", + } + + cmd.AddCommand( + communityPoolCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/distribution/communitypool.go b/cmd/parse/distribution/communitypool.go new file mode 100644 index 000000000..eaddf56ce --- /dev/null +++ b/cmd/parse/distribution/communitypool.go @@ -0,0 +1,45 @@ +package distribution + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/distribution" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// communityPoolCmd returns the Cobra command allowing to refresh community pool +func communityPoolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "community-pool", + Short: "Refresh community pool", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build distribution module + distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Marshaler, db) + + err = distrModule.GetLatestCommunityPool() + if err != nil { + return fmt.Errorf("error while updating community pool: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/mint/cmd.go b/cmd/parse/mint/cmd.go new file mode 100644 index 000000000..b5345c8d3 --- /dev/null +++ b/cmd/parse/mint/cmd.go @@ -0,0 +1,20 @@ +package mint + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewMintCmd returns the Cobra command allowing to fix various things related to the x/mint module +func NewMintCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "mint", + Short: "Fix things related to the x/mint module", + } + + cmd.AddCommand( + inflationCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/mint/inflation.go b/cmd/parse/mint/inflation.go new file mode 100644 index 000000000..01fe772d7 --- /dev/null +++ b/cmd/parse/mint/inflation.go @@ -0,0 +1,45 @@ +package mint + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/mint" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// inflationCmd returns the Cobra command allowing to refresh x/mint inflation +func inflationCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "inflation", + Short: "Refresh inflation", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build mint module + mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Marshaler, db) + + err = mintModule.UpdateInflation() + if err != nil { + return fmt.Errorf("error while updating inflation: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/parse.go b/cmd/parse/parse.go index 5d64c551b..34061227d 100644 --- a/cmd/parse/parse.go +++ b/cmd/parse/parse.go @@ -9,8 +9,12 @@ import ( parsegenesis "github.com/forbole/juno/v3/cmd/parse/genesis" parseauth "github.com/forbole/bdjuno/v3/cmd/parse/auth" + parsebank "github.com/forbole/bdjuno/v3/cmd/parse/bank" + parsedistribution "github.com/forbole/bdjuno/v3/cmd/parse/distribution" parsefeegrant "github.com/forbole/bdjuno/v3/cmd/parse/feegrant" parsegov "github.com/forbole/bdjuno/v3/cmd/parse/gov" + parsemint "github.com/forbole/bdjuno/v3/cmd/parse/mint" + parsepricefeed "github.com/forbole/bdjuno/v3/cmd/parse/pricefeed" parsestaking "github.com/forbole/bdjuno/v3/cmd/parse/staking" parsetransaction "github.com/forbole/juno/v3/cmd/parse/transactions" ) @@ -25,10 +29,14 @@ func NewParseCmd(parseCfg *parse.Config) *cobra.Command { cmd.AddCommand( parseauth.NewAuthCmd(parseCfg), + parsebank.NewBankCmd(parseCfg), parseblocks.NewBlocksCmd(parseCfg), + parsedistribution.NewDistributionCmd(parseCfg), parsefeegrant.NewFeegrantCmd(parseCfg), parsegenesis.NewGenesisCmd(parseCfg), parsegov.NewGovCmd(parseCfg), + parsemint.NewMintCmd(parseCfg), + parsepricefeed.NewPricefeedCmd(parseCfg), parsestaking.NewStakingCmd(parseCfg), parsetransaction.NewTransactionsCmd(parseCfg), ) diff --git a/cmd/parse/pricefeed/cmd.go b/cmd/parse/pricefeed/cmd.go new file mode 100644 index 000000000..2cabf9b35 --- /dev/null +++ b/cmd/parse/pricefeed/cmd.go @@ -0,0 +1,21 @@ +package pricefeed + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewPricefeedCmd returns the Cobra command allowing to refresh pricefeed +func NewPricefeedCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "pricefeed", + Short: "Fix things related to the pricefeed module", + } + + cmd.AddCommand( + priceCmd(parseConfig), + priceHistoryCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/pricefeed/price.go b/cmd/parse/pricefeed/price.go new file mode 100644 index 000000000..4c9b77cf6 --- /dev/null +++ b/cmd/parse/pricefeed/price.go @@ -0,0 +1,44 @@ +package pricefeed + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/pricefeed" +) + +// priceCmd returns the Cobra command allowing to refresh token price +func priceCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "price", + Short: "Refresh token price", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build pricefeed module + pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) + + err = pricefeedModule.RunAdditionalOperations() + if err != nil { + return fmt.Errorf("error while storing tokens: %s", err) + } + + err = pricefeedModule.UpdatePrice() + if err != nil { + return fmt.Errorf("error while updating price: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/pricefeed/pricehistory.go b/cmd/parse/pricefeed/pricehistory.go new file mode 100644 index 000000000..bad312105 --- /dev/null +++ b/cmd/parse/pricefeed/pricehistory.go @@ -0,0 +1,44 @@ +package pricefeed + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/pricefeed" +) + +// priceHistoryCmd returns the Cobra command allowing to store token price history +func priceHistoryCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "history", + Short: "Store token price history", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build pricefeed module + pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) + + err = pricefeedModule.RunAdditionalOperations() + if err != nil { + return fmt.Errorf("error while storing tokens: %s", err) + } + + err = pricefeedModule.UpdatePricesHistory() + if err != nil { + return fmt.Errorf("error while updating price history: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/staking/cmd.go b/cmd/parse/staking/cmd.go index f6f34e4cc..46251cddc 100644 --- a/cmd/parse/staking/cmd.go +++ b/cmd/parse/staking/cmd.go @@ -13,6 +13,7 @@ func NewStakingCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { } cmd.AddCommand( + poolCmd(parseConfig), validatorsCmd(parseConfig), ) diff --git a/cmd/parse/staking/staking.go b/cmd/parse/staking/staking.go new file mode 100644 index 000000000..d3dadafd4 --- /dev/null +++ b/cmd/parse/staking/staking.go @@ -0,0 +1,45 @@ +package staking + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/staking" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// poolCmd returns the Cobra command allowing to refresh x/staking pool +func poolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "pool", + Short: "Refresh staking pool", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build staking module + stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Marshaler, db) + + err = stakingModule.UpdateStakingPool() + if err != nil { + return fmt.Errorf("error while updating staking pool: %s", err) + } + + return nil + }, + } +} diff --git a/database/consensus.go b/database/consensus.go index 7fcac0320..0845ded0d 100644 --- a/database/consensus.go +++ b/database/consensus.go @@ -27,14 +27,18 @@ func (db *Db) GetLastBlock() (*dbtypes.BlockRow, error) { // GetLastBlockHeight returns the last block height stored inside the database func (db *Db) GetLastBlockHeight() (int64, error) { - block, err := db.GetLastBlock() - if err != nil { + stmt := `SELECT height FROM block ORDER BY height DESC LIMIT 1` + + var heights []int64 + if err := db.Sqlx.Select(&heights, stmt); err != nil { return 0, err } - if block == nil { - return 0, fmt.Errorf("block table is empty") + + if len(heights) == 0 { + return 0, nil } - return block.Height, nil + + return heights[0], nil } // ------------------------------------------------------------------------------------------------------------------- diff --git a/modules/bank/handle_periodic_operations.go b/modules/bank/handle_periodic_operations.go index b8a26dc39..f15ebba16 100644 --- a/modules/bank/handle_periodic_operations.go +++ b/modules/bank/handle_periodic_operations.go @@ -14,7 +14,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { log.Debug().Str("module", "bank").Msg("setting up periodic tasks") if _, err := scheduler.Every(10).Minutes().Do(func() { - utils.WatchMethod(m.updateSupply) + utils.WatchMethod(m.UpdateSupply) }); err != nil { return fmt.Errorf("error while setting up bank periodic operation: %s", err) } @@ -22,20 +22,20 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// updateSupply updates the supply of all the tokens -func (m *Module) updateSupply() error { +// UpdateSupply updates the supply of all the tokens +func (m *Module) UpdateSupply() error { log.Trace().Str("module", "bank").Str("operation", "total supply"). Msg("updating total supply") - block, err := m.db.GetLastBlock() + height, err := m.db.GetLastBlockHeight() if err != nil { - return fmt.Errorf("error while getting last block: %s", err) + return fmt.Errorf("error while getting latest block height: %s", err) } - supply, err := m.keeper.GetSupply(block.Height) + supply, err := m.keeper.GetSupply(height) if err != nil { return err } - return m.db.SaveSupply(supply, block.Height) + return m.db.SaveSupply(supply, height) } diff --git a/modules/distribution/handle_periodic_operations.go b/modules/distribution/handle_periodic_operations.go index 00f0bb2b5..0e70c025c 100644 --- a/modules/distribution/handle_periodic_operations.go +++ b/modules/distribution/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the community pool every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.getLatestCommunityPool) + utils.WatchMethod(m.GetLatestCommunityPool) }); err != nil { return fmt.Errorf("error while scheduling distribution peridic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// getLatestCommunityPool gets the latest community pool from the chain and stores inside the database -func (m *Module) getLatestCommunityPool() error { +// GetLatestCommunityPool gets the latest community pool from the chain and stores inside the database +func (m *Module) GetLatestCommunityPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", err) diff --git a/modules/pricefeed/handle_periodic_operations.go b/modules/pricefeed/handle_periodic_operations.go index 9717db267..3615f6db1 100644 --- a/modules/pricefeed/handle_periodic_operations.go +++ b/modules/pricefeed/handle_periodic_operations.go @@ -19,14 +19,14 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Fetch the token prices every 2 mins if _, err := scheduler.Every(2).Minutes().Do(func() { - utils.WatchMethod(m.updatePrice) + utils.WatchMethod(m.UpdatePrice) }); err != nil { return fmt.Errorf("error while setting up pricefeed period operations: %s", err) } // Update the historical token prices every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.updatePricesHistory) + utils.WatchMethod(m.UpdatePricesHistory) }); err != nil { return fmt.Errorf("error while setting up history period operations: %s", err) } @@ -56,8 +56,8 @@ func (m *Module) getTokenPrices() ([]types.TokenPrice, error) { return prices, nil } -// updatePrice fetch total amount of coins in the system from RPC and store it into database -func (m *Module) updatePrice() error { +// UpdatePrice fetches the total amount of coins in the system from RPC and stores it in database +func (m *Module) UpdatePrice() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). @@ -77,9 +77,9 @@ func (m *Module) updatePrice() error { return nil } -// updatePricesHistory fetches total amount of coins in the system from RPC +// UpdatePricesHistory fetches total amount of coins in the system from RPC // and stores historical perice data inside the database -func (m *Module) updatePricesHistory() error { +func (m *Module) UpdatePricesHistory() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). diff --git a/modules/staking/handle_periodic_operations.go b/modules/staking/handle_periodic_operations.go index 2f62d2613..7212fc175 100644 --- a/modules/staking/handle_periodic_operations.go +++ b/modules/staking/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the staking pool every 5 mins if _, err := scheduler.Every(5).Minutes().Do(func() { - utils.WatchMethod(m.updateStakingPool) + utils.WatchMethod(m.UpdateStakingPool) }); err != nil { return fmt.Errorf("error while scheduling staking pool periodic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// updateStakingPool reads from the LCD the current staking pool and stores its value inside the database -func (m *Module) updateStakingPool() error { +// UpdateStakingPool reads from the LCD the current staking pool and stores its value inside the database +func (m *Module) UpdateStakingPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", err) From 0a0d1b4816424c30db709996d5fa53ec89c435de 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 05/22] 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) } From 869759423b972b31796718921d3216165bf66aa7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 24 Nov 2022 09:35:22 +0000 Subject: [PATCH 06/22] chore(deps): Bump github.com/go-co-op/gocron from 1.17.1 to 1.18.0 (#61) Bumps [github.com/go-co-op/gocron](https://github.com/go-co-op/gocron) from 1.17.1 to 1.18.0. - [Release notes](https://github.com/go-co-op/gocron/releases) - [Commits](https://github.com/go-co-op/gocron/compare/v1.17.1...v1.18.0) --- updated-dependencies: - dependency-name: github.com/go-co-op/gocron dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b019df2e2..cd7699cd6 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/cosmos/cosmos-sdk v0.45.9 github.com/cosmos/gaia/v7 v7.1.0 github.com/forbole/juno/v3 v3.4.0 - github.com/go-co-op/gocron v1.17.1 + github.com/go-co-op/gocron v1.18.0 github.com/gogo/protobuf v1.3.3 github.com/jmoiron/sqlx v1.3.5 github.com/lib/pq v1.10.7 diff --git a/go.sum b/go.sum index dc211ebf9..71978f9b9 100644 --- a/go.sum +++ b/go.sum @@ -221,8 +221,8 @@ github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmV github.com/gabriel-vasile/mimetype v1.4.1 h1:TRWk7se+TOjCYgRth7+1/OYLNiRNIotknkFtf/dnN7Q= github.com/gabriel-vasile/mimetype v1.4.1/go.mod h1:05Vi0w3Y9c/lNvJOdmIwvrrAhX3rYhfQQCaf9VJcv7M= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-co-op/gocron v1.17.1 h1:oEu3xGNVn9IGukN3JPzOsfaBoTGYmUVHtR9d1cv1cq8= -github.com/go-co-op/gocron v1.17.1/go.mod h1:IpDBSaJOVfFw7hXZuTag3SCSkqazXBBUkbQ1m1aesBs= +github.com/go-co-op/gocron v1.18.0 h1:SxTyJ5xnSN4byCq7b10LmmszFdxQlSQJod8s3gbnXxA= +github.com/go-co-op/gocron v1.18.0/go.mod h1:sD/a0Aadtw5CpflUJ/lpP9Vfdk979Wl1Sg33HPHg0FY= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= From 81660096ccbeca4c36aab996650265883dbd1e94 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 09:47:58 +0000 Subject: [PATCH 07/22] Revert "feat: manually trigger periodic task (#492)" This reverts commit 88ac193d89c7e16d720b03944bdc808fd5c3d84e. --- cmd/parse/bank/cmd.go | 20 -------- cmd/parse/bank/supply.go | 46 ------------------- cmd/parse/distribution/cmd.go | 20 -------- cmd/parse/distribution/communitypool.go | 45 ------------------ cmd/parse/mint/cmd.go | 20 -------- cmd/parse/mint/inflation.go | 45 ------------------ cmd/parse/parse.go | 8 ---- cmd/parse/pricefeed/cmd.go | 21 --------- cmd/parse/pricefeed/price.go | 44 ------------------ cmd/parse/pricefeed/pricehistory.go | 44 ------------------ cmd/parse/staking/cmd.go | 1 - cmd/parse/staking/staking.go | 45 ------------------ database/consensus.go | 14 ++---- modules/bank/handle_periodic_operations.go | 14 +++--- .../handle_periodic_operations.go | 6 +-- .../pricefeed/handle_periodic_operations.go | 12 ++--- modules/staking/handle_periodic_operations.go | 6 +-- 17 files changed, 24 insertions(+), 387 deletions(-) delete mode 100644 cmd/parse/bank/cmd.go delete mode 100644 cmd/parse/bank/supply.go delete mode 100644 cmd/parse/distribution/cmd.go delete mode 100644 cmd/parse/distribution/communitypool.go delete mode 100644 cmd/parse/mint/cmd.go delete mode 100644 cmd/parse/mint/inflation.go delete mode 100644 cmd/parse/pricefeed/cmd.go delete mode 100644 cmd/parse/pricefeed/price.go delete mode 100644 cmd/parse/pricefeed/pricehistory.go delete mode 100644 cmd/parse/staking/staking.go diff --git a/cmd/parse/bank/cmd.go b/cmd/parse/bank/cmd.go deleted file mode 100644 index 6ee5f0a60..000000000 --- a/cmd/parse/bank/cmd.go +++ /dev/null @@ -1,20 +0,0 @@ -package bank - -import ( - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/spf13/cobra" -) - -// NewBankCmd returns the Cobra command allowing to fix various things related to the x/bank module -func NewBankCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - cmd := &cobra.Command{ - Use: "bank", - Short: "Fix things related to the x/bank module", - } - - cmd.AddCommand( - supplyCmd(parseConfig), - ) - - return cmd -} diff --git a/cmd/parse/bank/supply.go b/cmd/parse/bank/supply.go deleted file mode 100644 index b9a2f87a6..000000000 --- a/cmd/parse/bank/supply.go +++ /dev/null @@ -1,46 +0,0 @@ -package bank - -import ( - "fmt" - - modulestypes "github.com/forbole/bdjuno/v3/modules/types" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/bank" -) - -// supplyCmd returns the Cobra command allowing to refresh x/bank total supply -func supplyCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "supply", - Short: "Refresh total supply", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build bank module - bankModule := bank.NewModule(nil, sources.BankSource, parseCtx.EncodingConfig.Marshaler, db) - - err = bankModule.UpdateSupply() - if err != nil { - return fmt.Errorf("error while getting latest bank supply: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/distribution/cmd.go b/cmd/parse/distribution/cmd.go deleted file mode 100644 index 096ad4041..000000000 --- a/cmd/parse/distribution/cmd.go +++ /dev/null @@ -1,20 +0,0 @@ -package distribution - -import ( - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/spf13/cobra" -) - -// NewDistributionCmd returns the Cobra command allowing to fix various things related to the x/distribution module -func NewDistributionCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - cmd := &cobra.Command{ - Use: "distribution", - Short: "Fix things related to the x/distribution module", - } - - cmd.AddCommand( - communityPoolCmd(parseConfig), - ) - - return cmd -} diff --git a/cmd/parse/distribution/communitypool.go b/cmd/parse/distribution/communitypool.go deleted file mode 100644 index eaddf56ce..000000000 --- a/cmd/parse/distribution/communitypool.go +++ /dev/null @@ -1,45 +0,0 @@ -package distribution - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/distribution" - modulestypes "github.com/forbole/bdjuno/v3/modules/types" -) - -// communityPoolCmd returns the Cobra command allowing to refresh community pool -func communityPoolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "community-pool", - Short: "Refresh community pool", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build distribution module - distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Marshaler, db) - - err = distrModule.GetLatestCommunityPool() - if err != nil { - return fmt.Errorf("error while updating community pool: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/mint/cmd.go b/cmd/parse/mint/cmd.go deleted file mode 100644 index b5345c8d3..000000000 --- a/cmd/parse/mint/cmd.go +++ /dev/null @@ -1,20 +0,0 @@ -package mint - -import ( - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/spf13/cobra" -) - -// NewMintCmd returns the Cobra command allowing to fix various things related to the x/mint module -func NewMintCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - cmd := &cobra.Command{ - Use: "mint", - Short: "Fix things related to the x/mint module", - } - - cmd.AddCommand( - inflationCmd(parseConfig), - ) - - return cmd -} diff --git a/cmd/parse/mint/inflation.go b/cmd/parse/mint/inflation.go deleted file mode 100644 index 01fe772d7..000000000 --- a/cmd/parse/mint/inflation.go +++ /dev/null @@ -1,45 +0,0 @@ -package mint - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/mint" - modulestypes "github.com/forbole/bdjuno/v3/modules/types" -) - -// inflationCmd returns the Cobra command allowing to refresh x/mint inflation -func inflationCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "inflation", - Short: "Refresh inflation", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build mint module - mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Marshaler, db) - - err = mintModule.UpdateInflation() - if err != nil { - return fmt.Errorf("error while updating inflation: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/parse.go b/cmd/parse/parse.go index 34061227d..5d64c551b 100644 --- a/cmd/parse/parse.go +++ b/cmd/parse/parse.go @@ -9,12 +9,8 @@ import ( parsegenesis "github.com/forbole/juno/v3/cmd/parse/genesis" parseauth "github.com/forbole/bdjuno/v3/cmd/parse/auth" - parsebank "github.com/forbole/bdjuno/v3/cmd/parse/bank" - parsedistribution "github.com/forbole/bdjuno/v3/cmd/parse/distribution" parsefeegrant "github.com/forbole/bdjuno/v3/cmd/parse/feegrant" parsegov "github.com/forbole/bdjuno/v3/cmd/parse/gov" - parsemint "github.com/forbole/bdjuno/v3/cmd/parse/mint" - parsepricefeed "github.com/forbole/bdjuno/v3/cmd/parse/pricefeed" parsestaking "github.com/forbole/bdjuno/v3/cmd/parse/staking" parsetransaction "github.com/forbole/juno/v3/cmd/parse/transactions" ) @@ -29,14 +25,10 @@ func NewParseCmd(parseCfg *parse.Config) *cobra.Command { cmd.AddCommand( parseauth.NewAuthCmd(parseCfg), - parsebank.NewBankCmd(parseCfg), parseblocks.NewBlocksCmd(parseCfg), - parsedistribution.NewDistributionCmd(parseCfg), parsefeegrant.NewFeegrantCmd(parseCfg), parsegenesis.NewGenesisCmd(parseCfg), parsegov.NewGovCmd(parseCfg), - parsemint.NewMintCmd(parseCfg), - parsepricefeed.NewPricefeedCmd(parseCfg), parsestaking.NewStakingCmd(parseCfg), parsetransaction.NewTransactionsCmd(parseCfg), ) diff --git a/cmd/parse/pricefeed/cmd.go b/cmd/parse/pricefeed/cmd.go deleted file mode 100644 index 2cabf9b35..000000000 --- a/cmd/parse/pricefeed/cmd.go +++ /dev/null @@ -1,21 +0,0 @@ -package pricefeed - -import ( - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/spf13/cobra" -) - -// NewPricefeedCmd returns the Cobra command allowing to refresh pricefeed -func NewPricefeedCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - cmd := &cobra.Command{ - Use: "pricefeed", - Short: "Fix things related to the pricefeed module", - } - - cmd.AddCommand( - priceCmd(parseConfig), - priceHistoryCmd(parseConfig), - ) - - return cmd -} diff --git a/cmd/parse/pricefeed/price.go b/cmd/parse/pricefeed/price.go deleted file mode 100644 index 4c9b77cf6..000000000 --- a/cmd/parse/pricefeed/price.go +++ /dev/null @@ -1,44 +0,0 @@ -package pricefeed - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/pricefeed" -) - -// priceCmd returns the Cobra command allowing to refresh token price -func priceCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "price", - Short: "Refresh token price", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build pricefeed module - pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) - - err = pricefeedModule.RunAdditionalOperations() - if err != nil { - return fmt.Errorf("error while storing tokens: %s", err) - } - - err = pricefeedModule.UpdatePrice() - if err != nil { - return fmt.Errorf("error while updating price: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/pricefeed/pricehistory.go b/cmd/parse/pricefeed/pricehistory.go deleted file mode 100644 index bad312105..000000000 --- a/cmd/parse/pricefeed/pricehistory.go +++ /dev/null @@ -1,44 +0,0 @@ -package pricefeed - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/pricefeed" -) - -// priceHistoryCmd returns the Cobra command allowing to store token price history -func priceHistoryCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "history", - Short: "Store token price history", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build pricefeed module - pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) - - err = pricefeedModule.RunAdditionalOperations() - if err != nil { - return fmt.Errorf("error while storing tokens: %s", err) - } - - err = pricefeedModule.UpdatePricesHistory() - if err != nil { - return fmt.Errorf("error while updating price history: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/staking/cmd.go b/cmd/parse/staking/cmd.go index 46251cddc..f6f34e4cc 100644 --- a/cmd/parse/staking/cmd.go +++ b/cmd/parse/staking/cmd.go @@ -13,7 +13,6 @@ func NewStakingCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { } cmd.AddCommand( - poolCmd(parseConfig), validatorsCmd(parseConfig), ) diff --git a/cmd/parse/staking/staking.go b/cmd/parse/staking/staking.go deleted file mode 100644 index d3dadafd4..000000000 --- a/cmd/parse/staking/staking.go +++ /dev/null @@ -1,45 +0,0 @@ -package staking - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/staking" - modulestypes "github.com/forbole/bdjuno/v3/modules/types" -) - -// poolCmd returns the Cobra command allowing to refresh x/staking pool -func poolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "pool", - Short: "Refresh staking pool", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build staking module - stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Marshaler, db) - - err = stakingModule.UpdateStakingPool() - if err != nil { - return fmt.Errorf("error while updating staking pool: %s", err) - } - - return nil - }, - } -} diff --git a/database/consensus.go b/database/consensus.go index 0845ded0d..7fcac0320 100644 --- a/database/consensus.go +++ b/database/consensus.go @@ -27,18 +27,14 @@ func (db *Db) GetLastBlock() (*dbtypes.BlockRow, error) { // GetLastBlockHeight returns the last block height stored inside the database func (db *Db) GetLastBlockHeight() (int64, error) { - stmt := `SELECT height FROM block ORDER BY height DESC LIMIT 1` - - var heights []int64 - if err := db.Sqlx.Select(&heights, stmt); err != nil { + block, err := db.GetLastBlock() + if err != nil { return 0, err } - - if len(heights) == 0 { - return 0, nil + if block == nil { + return 0, fmt.Errorf("block table is empty") } - - return heights[0], nil + return block.Height, nil } // ------------------------------------------------------------------------------------------------------------------- diff --git a/modules/bank/handle_periodic_operations.go b/modules/bank/handle_periodic_operations.go index f15ebba16..b8a26dc39 100644 --- a/modules/bank/handle_periodic_operations.go +++ b/modules/bank/handle_periodic_operations.go @@ -14,7 +14,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { log.Debug().Str("module", "bank").Msg("setting up periodic tasks") if _, err := scheduler.Every(10).Minutes().Do(func() { - utils.WatchMethod(m.UpdateSupply) + utils.WatchMethod(m.updateSupply) }); err != nil { return fmt.Errorf("error while setting up bank periodic operation: %s", err) } @@ -22,20 +22,20 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// UpdateSupply updates the supply of all the tokens -func (m *Module) UpdateSupply() error { +// updateSupply updates the supply of all the tokens +func (m *Module) updateSupply() error { log.Trace().Str("module", "bank").Str("operation", "total supply"). Msg("updating total supply") - height, err := m.db.GetLastBlockHeight() + block, err := m.db.GetLastBlock() if err != nil { - return fmt.Errorf("error while getting latest block height: %s", err) + return fmt.Errorf("error while getting last block: %s", err) } - supply, err := m.keeper.GetSupply(height) + supply, err := m.keeper.GetSupply(block.Height) if err != nil { return err } - return m.db.SaveSupply(supply, height) + return m.db.SaveSupply(supply, block.Height) } diff --git a/modules/distribution/handle_periodic_operations.go b/modules/distribution/handle_periodic_operations.go index 0e70c025c..00f0bb2b5 100644 --- a/modules/distribution/handle_periodic_operations.go +++ b/modules/distribution/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the community pool every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.GetLatestCommunityPool) + utils.WatchMethod(m.getLatestCommunityPool) }); err != nil { return fmt.Errorf("error while scheduling distribution peridic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// GetLatestCommunityPool gets the latest community pool from the chain and stores inside the database -func (m *Module) GetLatestCommunityPool() error { +// getLatestCommunityPool gets the latest community pool from the chain and stores inside the database +func (m *Module) getLatestCommunityPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", err) diff --git a/modules/pricefeed/handle_periodic_operations.go b/modules/pricefeed/handle_periodic_operations.go index 3615f6db1..9717db267 100644 --- a/modules/pricefeed/handle_periodic_operations.go +++ b/modules/pricefeed/handle_periodic_operations.go @@ -19,14 +19,14 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Fetch the token prices every 2 mins if _, err := scheduler.Every(2).Minutes().Do(func() { - utils.WatchMethod(m.UpdatePrice) + utils.WatchMethod(m.updatePrice) }); err != nil { return fmt.Errorf("error while setting up pricefeed period operations: %s", err) } // Update the historical token prices every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.UpdatePricesHistory) + utils.WatchMethod(m.updatePricesHistory) }); err != nil { return fmt.Errorf("error while setting up history period operations: %s", err) } @@ -56,8 +56,8 @@ func (m *Module) getTokenPrices() ([]types.TokenPrice, error) { return prices, nil } -// UpdatePrice fetches the total amount of coins in the system from RPC and stores it in database -func (m *Module) UpdatePrice() error { +// updatePrice fetch total amount of coins in the system from RPC and store it into database +func (m *Module) updatePrice() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). @@ -77,9 +77,9 @@ func (m *Module) UpdatePrice() error { return nil } -// UpdatePricesHistory fetches total amount of coins in the system from RPC +// updatePricesHistory fetches total amount of coins in the system from RPC // and stores historical perice data inside the database -func (m *Module) UpdatePricesHistory() error { +func (m *Module) updatePricesHistory() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). diff --git a/modules/staking/handle_periodic_operations.go b/modules/staking/handle_periodic_operations.go index 7212fc175..2f62d2613 100644 --- a/modules/staking/handle_periodic_operations.go +++ b/modules/staking/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the staking pool every 5 mins if _, err := scheduler.Every(5).Minutes().Do(func() { - utils.WatchMethod(m.UpdateStakingPool) + utils.WatchMethod(m.updateStakingPool) }); err != nil { return fmt.Errorf("error while scheduling staking pool periodic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// UpdateStakingPool reads from the LCD the current staking pool and stores its value inside the database -func (m *Module) UpdateStakingPool() error { +// updateStakingPool reads from the LCD the current staking pool and stores its value inside the database +func (m *Module) updateStakingPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", err) From 2d7cd3860e76bc03595a43a1d5bed5bf90feee4c Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 09:48:07 +0000 Subject: [PATCH 08/22] Revert "fix: check if proposal has passed voting end time before marking it as invalid (#499)" This reverts commit 65d7e766c3ddbd6010749ecbc0e5c16a5c406d4b. --- cmd/parse/gov/proposal.go | 3 +-- modules/gov/handle_block.go | 2 +- modules/gov/utils_proposal.go | 8 ++------ 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cmd/parse/gov/proposal.go b/cmd/parse/gov/proposal.go index 151f6cd89..f4d0859c1 100644 --- a/cmd/parse/gov/proposal.go +++ b/cmd/parse/gov/proposal.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "fmt" "strconv" - "time" modulestypes "github.com/forbole/bdjuno/v3/modules/types" "github.com/rs/zerolog/log" @@ -79,7 +78,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.Now(), proposalID) + err = govModule.UpdateProposal(height, proposalID) if err != nil { return err } diff --git a/modules/gov/handle_block.go b/modules/gov/handle_block.go index 9a279eafa..76138e4e9 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, blockTime, id) + err = m.UpdateProposal(height, 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 18b987e0a..61e9fa793 100644 --- a/modules/gov/utils_proposal.go +++ b/modules/gov/utils_proposal.go @@ -3,7 +3,6 @@ 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" @@ -21,14 +20,11 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func (m *Module) UpdateProposal(height int64, blockTime time.Time, id uint64) error { +func (m *Module) UpdateProposal(height int64, id uint64) error { // Get the proposal proposal, err := m.source.Proposal(height, id) if err != nil { - // Check if proposal has reached the voting end time - passedVotingPeriod := blockTime.After(proposal.VotingEndTime) - - if strings.Contains(err.Error(), codes.NotFound.String()) && passedVotingPeriod { + if strings.Contains(err.Error(), codes.NotFound.String()) { // Handle case when a proposal is deleted from the chain (did not pass deposit period) return m.updateDeletedProposalStatus(id) } From a3b4723e1c5ae95fa388143dac6e5350643e03eb Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 10:18:15 +0000 Subject: [PATCH 09/22] docs: Update README [skip ci] --- README.md | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ba86149ea..61bc2d64a 100644 --- a/README.md +++ b/README.md @@ -3,28 +3,36 @@ BDJuno (shorthand for BigDipper Juno) is the [Juno](https://github.com/forbole/juno) implementation for [BigDipper](https://github.com/forbole/big-dipper). -It extends the custom Juno behavior by adding different handlers and custom operations to make it easier for BigDipper -showing the data inside the UI. - All the chains' data that are queried from the RPC and gRPC endpoints are stored inside a [PostgreSQL](https://www.postgresql.org/) database on top of which [GraphQL](https://graphql.org/) APIs can then be created using [Hasura](https://hasura.io/). -## Usage +## Features specific to cheqd + +1. Indexing for [cheqd network] DIDs and Resources +2. Changes to workflows/pipelines +3. Optimised Dockerfile + +## Developer guide + +This section is reproduced as-is from upstream project. + +### Usage + To know how to setup and run BDJuno, please refer to the [docs website](https://docs.bigdipper.live/cosmos-based/parser/overview/). ## Testing + If you want to test the code, you can do so by running ```shell -$ make test-unit +make test-unit ``` **Note**: Requires [Docker](https://docker.com). This will: + 1. Create a Docker container running a PostgreSQL database. 2. Run all the tests using that database as support. - - From ab50044a1d068a1eec4c6f41f41c5f5b3a6c516a Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 10:29:37 +0000 Subject: [PATCH 10/22] feat: Sync upstream `bank` and `staking` features (#63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * build(deps): bump github.com/prometheus/client_golang from 1.13.0 to 1.13.1 (#493) Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.13.1.
Release notes

Sourced from github.com/prometheus/client_golang's releases.

1.13.1 / 2022-11-02

  • [BUGFIX] Fix race condition with Exemplar in Counter. #1146
  • [BUGFIX] Fix CumulativeCount value of +Inf bucket created from exemplar. #1148
  • [BUGFIX] Fix double-counting bug in promhttp.InstrumentRoundTripperCounter. #1118

Full Changelog: https://github.com/prometheus/client_golang/compare/v1.13.0...v1.13.1

Changelog

Sourced from github.com/prometheus/client_golang's changelog.

1.13.1 / 2022-11-01

  • [BUGFIX] Fix race condition with Exemplar in Counter. #1146
  • [BUGFIX] Fix CumulativeCount value of +Inf bucket created from exemplar. #1148
  • [BUGFIX] Fix double-counting bug in promhttp.InstrumentRoundTripperCounter. #1118
Commits
  • 53e51c4 Merge pull request #1157 from prometheus/cut-1.13.1
  • 79ca0eb Added tip from Björn + Grammarly.
  • 078f11f Cut 1.13.1 release (+ documenting release process).
  • ddd7f0e Fix race condition with Exemplar in Counter (#1146)
  • 1f93f64 Fix CumulativeCount value of +Inf bucket created from exemplar (#1148)
  • 8cc2b6c Fix double-counting bug in promhttp.InstrumentRoundTripperCounter (#1118)
  • See full diff in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/prometheus/client_golang&package-manager=go_modules&previous-version=1.13.0&new-version=1.13.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
* feat: manually trigger periodic task (#492) Closes: #415 --- *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` - [ ] 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) * 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) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Aaron <76254323+huichiaotsou@users.noreply.github.com> --- cmd/parse/bank/cmd.go | 20 ++++++++ cmd/parse/bank/supply.go | 46 +++++++++++++++++++ cmd/parse/distribution/cmd.go | 20 ++++++++ cmd/parse/distribution/communitypool.go | 45 ++++++++++++++++++ cmd/parse/gov/proposal.go | 3 +- cmd/parse/mint/cmd.go | 20 ++++++++ cmd/parse/mint/inflation.go | 45 ++++++++++++++++++ cmd/parse/parse.go | 8 ++++ cmd/parse/pricefeed/cmd.go | 21 +++++++++ cmd/parse/pricefeed/price.go | 44 ++++++++++++++++++ cmd/parse/pricefeed/pricehistory.go | 44 ++++++++++++++++++ cmd/parse/staking/cmd.go | 1 + cmd/parse/staking/staking.go | 45 ++++++++++++++++++ database/consensus.go | 14 ++++-- modules/bank/handle_periodic_operations.go | 14 +++--- .../handle_periodic_operations.go | 6 +-- modules/gov/handle_block.go | 2 +- modules/gov/utils_proposal.go | 8 +++- .../pricefeed/handle_periodic_operations.go | 12 ++--- modules/staking/handle_periodic_operations.go | 6 +-- 20 files changed, 396 insertions(+), 28 deletions(-) create mode 100644 cmd/parse/bank/cmd.go create mode 100644 cmd/parse/bank/supply.go create mode 100644 cmd/parse/distribution/cmd.go create mode 100644 cmd/parse/distribution/communitypool.go create mode 100644 cmd/parse/mint/cmd.go create mode 100644 cmd/parse/mint/inflation.go create mode 100644 cmd/parse/pricefeed/cmd.go create mode 100644 cmd/parse/pricefeed/price.go create mode 100644 cmd/parse/pricefeed/pricehistory.go create mode 100644 cmd/parse/staking/staking.go diff --git a/cmd/parse/bank/cmd.go b/cmd/parse/bank/cmd.go new file mode 100644 index 000000000..6ee5f0a60 --- /dev/null +++ b/cmd/parse/bank/cmd.go @@ -0,0 +1,20 @@ +package bank + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewBankCmd returns the Cobra command allowing to fix various things related to the x/bank module +func NewBankCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "bank", + Short: "Fix things related to the x/bank module", + } + + cmd.AddCommand( + supplyCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/bank/supply.go b/cmd/parse/bank/supply.go new file mode 100644 index 000000000..b9a2f87a6 --- /dev/null +++ b/cmd/parse/bank/supply.go @@ -0,0 +1,46 @@ +package bank + +import ( + "fmt" + + modulestypes "github.com/forbole/bdjuno/v3/modules/types" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/bank" +) + +// supplyCmd returns the Cobra command allowing to refresh x/bank total supply +func supplyCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "supply", + Short: "Refresh total supply", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build bank module + bankModule := bank.NewModule(nil, sources.BankSource, parseCtx.EncodingConfig.Marshaler, db) + + err = bankModule.UpdateSupply() + if err != nil { + return fmt.Errorf("error while getting latest bank supply: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/distribution/cmd.go b/cmd/parse/distribution/cmd.go new file mode 100644 index 000000000..096ad4041 --- /dev/null +++ b/cmd/parse/distribution/cmd.go @@ -0,0 +1,20 @@ +package distribution + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewDistributionCmd returns the Cobra command allowing to fix various things related to the x/distribution module +func NewDistributionCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "distribution", + Short: "Fix things related to the x/distribution module", + } + + cmd.AddCommand( + communityPoolCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/distribution/communitypool.go b/cmd/parse/distribution/communitypool.go new file mode 100644 index 000000000..eaddf56ce --- /dev/null +++ b/cmd/parse/distribution/communitypool.go @@ -0,0 +1,45 @@ +package distribution + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/distribution" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// communityPoolCmd returns the Cobra command allowing to refresh community pool +func communityPoolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "community-pool", + Short: "Refresh community pool", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build distribution module + distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Marshaler, db) + + err = distrModule.GetLatestCommunityPool() + if err != nil { + return fmt.Errorf("error while updating community pool: %s", err) + } + + return nil + }, + } +} 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/cmd/parse/mint/cmd.go b/cmd/parse/mint/cmd.go new file mode 100644 index 000000000..b5345c8d3 --- /dev/null +++ b/cmd/parse/mint/cmd.go @@ -0,0 +1,20 @@ +package mint + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewMintCmd returns the Cobra command allowing to fix various things related to the x/mint module +func NewMintCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "mint", + Short: "Fix things related to the x/mint module", + } + + cmd.AddCommand( + inflationCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/mint/inflation.go b/cmd/parse/mint/inflation.go new file mode 100644 index 000000000..01fe772d7 --- /dev/null +++ b/cmd/parse/mint/inflation.go @@ -0,0 +1,45 @@ +package mint + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/mint" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// inflationCmd returns the Cobra command allowing to refresh x/mint inflation +func inflationCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "inflation", + Short: "Refresh inflation", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build mint module + mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Marshaler, db) + + err = mintModule.UpdateInflation() + if err != nil { + return fmt.Errorf("error while updating inflation: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/parse.go b/cmd/parse/parse.go index 5d64c551b..34061227d 100644 --- a/cmd/parse/parse.go +++ b/cmd/parse/parse.go @@ -9,8 +9,12 @@ import ( parsegenesis "github.com/forbole/juno/v3/cmd/parse/genesis" parseauth "github.com/forbole/bdjuno/v3/cmd/parse/auth" + parsebank "github.com/forbole/bdjuno/v3/cmd/parse/bank" + parsedistribution "github.com/forbole/bdjuno/v3/cmd/parse/distribution" parsefeegrant "github.com/forbole/bdjuno/v3/cmd/parse/feegrant" parsegov "github.com/forbole/bdjuno/v3/cmd/parse/gov" + parsemint "github.com/forbole/bdjuno/v3/cmd/parse/mint" + parsepricefeed "github.com/forbole/bdjuno/v3/cmd/parse/pricefeed" parsestaking "github.com/forbole/bdjuno/v3/cmd/parse/staking" parsetransaction "github.com/forbole/juno/v3/cmd/parse/transactions" ) @@ -25,10 +29,14 @@ func NewParseCmd(parseCfg *parse.Config) *cobra.Command { cmd.AddCommand( parseauth.NewAuthCmd(parseCfg), + parsebank.NewBankCmd(parseCfg), parseblocks.NewBlocksCmd(parseCfg), + parsedistribution.NewDistributionCmd(parseCfg), parsefeegrant.NewFeegrantCmd(parseCfg), parsegenesis.NewGenesisCmd(parseCfg), parsegov.NewGovCmd(parseCfg), + parsemint.NewMintCmd(parseCfg), + parsepricefeed.NewPricefeedCmd(parseCfg), parsestaking.NewStakingCmd(parseCfg), parsetransaction.NewTransactionsCmd(parseCfg), ) diff --git a/cmd/parse/pricefeed/cmd.go b/cmd/parse/pricefeed/cmd.go new file mode 100644 index 000000000..2cabf9b35 --- /dev/null +++ b/cmd/parse/pricefeed/cmd.go @@ -0,0 +1,21 @@ +package pricefeed + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewPricefeedCmd returns the Cobra command allowing to refresh pricefeed +func NewPricefeedCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "pricefeed", + Short: "Fix things related to the pricefeed module", + } + + cmd.AddCommand( + priceCmd(parseConfig), + priceHistoryCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/pricefeed/price.go b/cmd/parse/pricefeed/price.go new file mode 100644 index 000000000..4c9b77cf6 --- /dev/null +++ b/cmd/parse/pricefeed/price.go @@ -0,0 +1,44 @@ +package pricefeed + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/pricefeed" +) + +// priceCmd returns the Cobra command allowing to refresh token price +func priceCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "price", + Short: "Refresh token price", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build pricefeed module + pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) + + err = pricefeedModule.RunAdditionalOperations() + if err != nil { + return fmt.Errorf("error while storing tokens: %s", err) + } + + err = pricefeedModule.UpdatePrice() + if err != nil { + return fmt.Errorf("error while updating price: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/pricefeed/pricehistory.go b/cmd/parse/pricefeed/pricehistory.go new file mode 100644 index 000000000..bad312105 --- /dev/null +++ b/cmd/parse/pricefeed/pricehistory.go @@ -0,0 +1,44 @@ +package pricefeed + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/pricefeed" +) + +// priceHistoryCmd returns the Cobra command allowing to store token price history +func priceHistoryCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "history", + Short: "Store token price history", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build pricefeed module + pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) + + err = pricefeedModule.RunAdditionalOperations() + if err != nil { + return fmt.Errorf("error while storing tokens: %s", err) + } + + err = pricefeedModule.UpdatePricesHistory() + if err != nil { + return fmt.Errorf("error while updating price history: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/staking/cmd.go b/cmd/parse/staking/cmd.go index f6f34e4cc..46251cddc 100644 --- a/cmd/parse/staking/cmd.go +++ b/cmd/parse/staking/cmd.go @@ -13,6 +13,7 @@ func NewStakingCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { } cmd.AddCommand( + poolCmd(parseConfig), validatorsCmd(parseConfig), ) diff --git a/cmd/parse/staking/staking.go b/cmd/parse/staking/staking.go new file mode 100644 index 000000000..d3dadafd4 --- /dev/null +++ b/cmd/parse/staking/staking.go @@ -0,0 +1,45 @@ +package staking + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/staking" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// poolCmd returns the Cobra command allowing to refresh x/staking pool +func poolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "pool", + Short: "Refresh staking pool", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build staking module + stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Marshaler, db) + + err = stakingModule.UpdateStakingPool() + if err != nil { + return fmt.Errorf("error while updating staking pool: %s", err) + } + + return nil + }, + } +} diff --git a/database/consensus.go b/database/consensus.go index 7fcac0320..0845ded0d 100644 --- a/database/consensus.go +++ b/database/consensus.go @@ -27,14 +27,18 @@ func (db *Db) GetLastBlock() (*dbtypes.BlockRow, error) { // GetLastBlockHeight returns the last block height stored inside the database func (db *Db) GetLastBlockHeight() (int64, error) { - block, err := db.GetLastBlock() - if err != nil { + stmt := `SELECT height FROM block ORDER BY height DESC LIMIT 1` + + var heights []int64 + if err := db.Sqlx.Select(&heights, stmt); err != nil { return 0, err } - if block == nil { - return 0, fmt.Errorf("block table is empty") + + if len(heights) == 0 { + return 0, nil } - return block.Height, nil + + return heights[0], nil } // ------------------------------------------------------------------------------------------------------------------- diff --git a/modules/bank/handle_periodic_operations.go b/modules/bank/handle_periodic_operations.go index b8a26dc39..f15ebba16 100644 --- a/modules/bank/handle_periodic_operations.go +++ b/modules/bank/handle_periodic_operations.go @@ -14,7 +14,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { log.Debug().Str("module", "bank").Msg("setting up periodic tasks") if _, err := scheduler.Every(10).Minutes().Do(func() { - utils.WatchMethod(m.updateSupply) + utils.WatchMethod(m.UpdateSupply) }); err != nil { return fmt.Errorf("error while setting up bank periodic operation: %s", err) } @@ -22,20 +22,20 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// updateSupply updates the supply of all the tokens -func (m *Module) updateSupply() error { +// UpdateSupply updates the supply of all the tokens +func (m *Module) UpdateSupply() error { log.Trace().Str("module", "bank").Str("operation", "total supply"). Msg("updating total supply") - block, err := m.db.GetLastBlock() + height, err := m.db.GetLastBlockHeight() if err != nil { - return fmt.Errorf("error while getting last block: %s", err) + return fmt.Errorf("error while getting latest block height: %s", err) } - supply, err := m.keeper.GetSupply(block.Height) + supply, err := m.keeper.GetSupply(height) if err != nil { return err } - return m.db.SaveSupply(supply, block.Height) + return m.db.SaveSupply(supply, height) } diff --git a/modules/distribution/handle_periodic_operations.go b/modules/distribution/handle_periodic_operations.go index 00f0bb2b5..0e70c025c 100644 --- a/modules/distribution/handle_periodic_operations.go +++ b/modules/distribution/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the community pool every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.getLatestCommunityPool) + utils.WatchMethod(m.GetLatestCommunityPool) }); err != nil { return fmt.Errorf("error while scheduling distribution peridic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// getLatestCommunityPool gets the latest community pool from the chain and stores inside the database -func (m *Module) getLatestCommunityPool() error { +// GetLatestCommunityPool gets the latest community pool from the chain and stores inside the database +func (m *Module) GetLatestCommunityPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", 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) } diff --git a/modules/pricefeed/handle_periodic_operations.go b/modules/pricefeed/handle_periodic_operations.go index 9717db267..3615f6db1 100644 --- a/modules/pricefeed/handle_periodic_operations.go +++ b/modules/pricefeed/handle_periodic_operations.go @@ -19,14 +19,14 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Fetch the token prices every 2 mins if _, err := scheduler.Every(2).Minutes().Do(func() { - utils.WatchMethod(m.updatePrice) + utils.WatchMethod(m.UpdatePrice) }); err != nil { return fmt.Errorf("error while setting up pricefeed period operations: %s", err) } // Update the historical token prices every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.updatePricesHistory) + utils.WatchMethod(m.UpdatePricesHistory) }); err != nil { return fmt.Errorf("error while setting up history period operations: %s", err) } @@ -56,8 +56,8 @@ func (m *Module) getTokenPrices() ([]types.TokenPrice, error) { return prices, nil } -// updatePrice fetch total amount of coins in the system from RPC and store it into database -func (m *Module) updatePrice() error { +// UpdatePrice fetches the total amount of coins in the system from RPC and stores it in database +func (m *Module) UpdatePrice() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). @@ -77,9 +77,9 @@ func (m *Module) updatePrice() error { return nil } -// updatePricesHistory fetches total amount of coins in the system from RPC +// UpdatePricesHistory fetches total amount of coins in the system from RPC // and stores historical perice data inside the database -func (m *Module) updatePricesHistory() error { +func (m *Module) UpdatePricesHistory() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). diff --git a/modules/staking/handle_periodic_operations.go b/modules/staking/handle_periodic_operations.go index 2f62d2613..7212fc175 100644 --- a/modules/staking/handle_periodic_operations.go +++ b/modules/staking/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the staking pool every 5 mins if _, err := scheduler.Every(5).Minutes().Do(func() { - utils.WatchMethod(m.updateStakingPool) + utils.WatchMethod(m.UpdateStakingPool) }); err != nil { return fmt.Errorf("error while scheduling staking pool periodic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// updateStakingPool reads from the LCD the current staking pool and stores its value inside the database -func (m *Module) updateStakingPool() error { +// UpdateStakingPool reads from the LCD the current staking pool and stores its value inside the database +func (m *Module) UpdateStakingPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", err) From b9d13128a57fed178e96ee85666171270865ba72 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 3 Nov 2022 11:37:54 +0000 Subject: [PATCH 11/22] ci: Fix syntax error in DOCR push From 54e722c2ebd15f519a399c1c253bd685a8cbb1e5 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Tue, 8 Nov 2022 13:16:02 +0000 Subject: [PATCH 12/22] ci: Update cache cleaning --- .github/workflows/release.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 14e05d095..daee49372 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -128,18 +128,3 @@ jobs: - name: Push Hasura CLI image run: docker image push --all-tags registry.digitalocean.com/${{ env.IMAGE_NAME }} - - cache-purge: - name: "Purge branch Actions cache" - needs: [release-bdjuno, release-hasuracli] - if: ${{ github.event_name == 'pull_request' }} - runs-on: ubuntu-latest - - steps: - - - name: "Delete Branch Cache Action" - uses: snnaplab/delete-branch-cache-action@v1.0.0 - with: - # Specify explicitly because the ref at the time of merging will be a branch name such as 'main', 'develop' - ref: refs/pull/${{ github.event.number }}/merge - github-token: ${{ secrets.GITHUB_TOKEN }} From 09374e77dc6b92fa66a338a3c34560feff9df1d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:05:49 +0000 Subject: [PATCH 13/22] chore(deps): Bump github.com/prometheus/client_golang from 1.13.0 to 1.14.0 (#60) chore(deps): Bump github.com/prometheus/client_golang Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.14.0. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.13.0...v1.14.0) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From aca95ccc6fedaf8df993f225f0ac60fc7b6e9b2b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 24 Nov 2022 09:35:22 +0000 Subject: [PATCH 14/22] chore(deps): Bump github.com/go-co-op/gocron from 1.17.1 to 1.18.0 (#61) Bumps [github.com/go-co-op/gocron](https://github.com/go-co-op/gocron) from 1.17.1 to 1.18.0. - [Release notes](https://github.com/go-co-op/gocron/releases) - [Commits](https://github.com/go-co-op/gocron/compare/v1.17.1...v1.18.0) --- updated-dependencies: - dependency-name: github.com/go-co-op/gocron dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> From f7694960392ca70c04945d8e5328984f624ddf21 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 4 Nov 2022 03:38:30 +0000 Subject: [PATCH 15/22] build(deps): bump github.com/prometheus/client_golang from 1.13.0 to 1.13.1 (#493) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.13.1.
Release notes

Sourced from github.com/prometheus/client_golang's releases.

1.13.1 / 2022-11-02

  • [BUGFIX] Fix race condition with Exemplar in Counter. #1146
  • [BUGFIX] Fix CumulativeCount value of +Inf bucket created from exemplar. #1148
  • [BUGFIX] Fix double-counting bug in promhttp.InstrumentRoundTripperCounter. #1118

Full Changelog: https://github.com/prometheus/client_golang/compare/v1.13.0...v1.13.1

Changelog

Sourced from github.com/prometheus/client_golang's changelog.

1.13.1 / 2022-11-01

  • [BUGFIX] Fix race condition with Exemplar in Counter. #1146
  • [BUGFIX] Fix CumulativeCount value of +Inf bucket created from exemplar. #1148
  • [BUGFIX] Fix double-counting bug in promhttp.InstrumentRoundTripperCounter. #1118
Commits
  • 53e51c4 Merge pull request #1157 from prometheus/cut-1.13.1
  • 79ca0eb Added tip from Björn + Grammarly.
  • 078f11f Cut 1.13.1 release (+ documenting release process).
  • ddd7f0e Fix race condition with Exemplar in Counter (#1146)
  • 1f93f64 Fix CumulativeCount value of +Inf bucket created from exemplar (#1148)
  • 8cc2b6c Fix double-counting bug in promhttp.InstrumentRoundTripperCounter (#1118)
  • See full diff in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/prometheus/client_golang&package-manager=go_modules&previous-version=1.13.0&new-version=1.13.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
From cc44ec918408b84bbbf14b29f17c8d70b314e33b Mon Sep 17 00:00:00 2001 From: Aaron <76254323+huichiaotsou@users.noreply.github.com> Date: Mon, 14 Nov 2022 02:45:57 +0800 Subject: [PATCH 16/22] feat: manually trigger periodic task (#492) Closes: #415 --- *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` - [ ] 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 8ba89e9659cf5d4bfde8a731527b883a03d750a1 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 17/22] 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) From e86fc9f1f08758a46d70d5b721818190fa0727c2 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 09:46:44 +0000 Subject: [PATCH 18/22] Merge branch 'chains/cheqd/testnet' of https://github.com/cheqd/bdjuno into chains/cheqd/testnet From a2c755ad578c4e81666c794a91807b230a56f3f3 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 09:47:58 +0000 Subject: [PATCH 19/22] Revert "feat: manually trigger periodic task (#492)" This reverts commit 88ac193d89c7e16d720b03944bdc808fd5c3d84e. --- cmd/parse/bank/cmd.go | 20 -------- cmd/parse/bank/supply.go | 46 ------------------- cmd/parse/distribution/cmd.go | 20 -------- cmd/parse/distribution/communitypool.go | 45 ------------------ cmd/parse/mint/cmd.go | 20 -------- cmd/parse/mint/inflation.go | 45 ------------------ cmd/parse/parse.go | 8 ---- cmd/parse/pricefeed/cmd.go | 21 --------- cmd/parse/pricefeed/price.go | 44 ------------------ cmd/parse/pricefeed/pricehistory.go | 44 ------------------ cmd/parse/staking/cmd.go | 1 - cmd/parse/staking/staking.go | 45 ------------------ database/consensus.go | 14 ++---- modules/bank/handle_periodic_operations.go | 14 +++--- .../handle_periodic_operations.go | 6 +-- .../pricefeed/handle_periodic_operations.go | 12 ++--- modules/staking/handle_periodic_operations.go | 6 +-- 17 files changed, 24 insertions(+), 387 deletions(-) delete mode 100644 cmd/parse/bank/cmd.go delete mode 100644 cmd/parse/bank/supply.go delete mode 100644 cmd/parse/distribution/cmd.go delete mode 100644 cmd/parse/distribution/communitypool.go delete mode 100644 cmd/parse/mint/cmd.go delete mode 100644 cmd/parse/mint/inflation.go delete mode 100644 cmd/parse/pricefeed/cmd.go delete mode 100644 cmd/parse/pricefeed/price.go delete mode 100644 cmd/parse/pricefeed/pricehistory.go delete mode 100644 cmd/parse/staking/staking.go diff --git a/cmd/parse/bank/cmd.go b/cmd/parse/bank/cmd.go deleted file mode 100644 index 6ee5f0a60..000000000 --- a/cmd/parse/bank/cmd.go +++ /dev/null @@ -1,20 +0,0 @@ -package bank - -import ( - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/spf13/cobra" -) - -// NewBankCmd returns the Cobra command allowing to fix various things related to the x/bank module -func NewBankCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - cmd := &cobra.Command{ - Use: "bank", - Short: "Fix things related to the x/bank module", - } - - cmd.AddCommand( - supplyCmd(parseConfig), - ) - - return cmd -} diff --git a/cmd/parse/bank/supply.go b/cmd/parse/bank/supply.go deleted file mode 100644 index b9a2f87a6..000000000 --- a/cmd/parse/bank/supply.go +++ /dev/null @@ -1,46 +0,0 @@ -package bank - -import ( - "fmt" - - modulestypes "github.com/forbole/bdjuno/v3/modules/types" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/bank" -) - -// supplyCmd returns the Cobra command allowing to refresh x/bank total supply -func supplyCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "supply", - Short: "Refresh total supply", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build bank module - bankModule := bank.NewModule(nil, sources.BankSource, parseCtx.EncodingConfig.Marshaler, db) - - err = bankModule.UpdateSupply() - if err != nil { - return fmt.Errorf("error while getting latest bank supply: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/distribution/cmd.go b/cmd/parse/distribution/cmd.go deleted file mode 100644 index 096ad4041..000000000 --- a/cmd/parse/distribution/cmd.go +++ /dev/null @@ -1,20 +0,0 @@ -package distribution - -import ( - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/spf13/cobra" -) - -// NewDistributionCmd returns the Cobra command allowing to fix various things related to the x/distribution module -func NewDistributionCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - cmd := &cobra.Command{ - Use: "distribution", - Short: "Fix things related to the x/distribution module", - } - - cmd.AddCommand( - communityPoolCmd(parseConfig), - ) - - return cmd -} diff --git a/cmd/parse/distribution/communitypool.go b/cmd/parse/distribution/communitypool.go deleted file mode 100644 index eaddf56ce..000000000 --- a/cmd/parse/distribution/communitypool.go +++ /dev/null @@ -1,45 +0,0 @@ -package distribution - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/distribution" - modulestypes "github.com/forbole/bdjuno/v3/modules/types" -) - -// communityPoolCmd returns the Cobra command allowing to refresh community pool -func communityPoolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "community-pool", - Short: "Refresh community pool", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build distribution module - distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Marshaler, db) - - err = distrModule.GetLatestCommunityPool() - if err != nil { - return fmt.Errorf("error while updating community pool: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/mint/cmd.go b/cmd/parse/mint/cmd.go deleted file mode 100644 index b5345c8d3..000000000 --- a/cmd/parse/mint/cmd.go +++ /dev/null @@ -1,20 +0,0 @@ -package mint - -import ( - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/spf13/cobra" -) - -// NewMintCmd returns the Cobra command allowing to fix various things related to the x/mint module -func NewMintCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - cmd := &cobra.Command{ - Use: "mint", - Short: "Fix things related to the x/mint module", - } - - cmd.AddCommand( - inflationCmd(parseConfig), - ) - - return cmd -} diff --git a/cmd/parse/mint/inflation.go b/cmd/parse/mint/inflation.go deleted file mode 100644 index 01fe772d7..000000000 --- a/cmd/parse/mint/inflation.go +++ /dev/null @@ -1,45 +0,0 @@ -package mint - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/mint" - modulestypes "github.com/forbole/bdjuno/v3/modules/types" -) - -// inflationCmd returns the Cobra command allowing to refresh x/mint inflation -func inflationCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "inflation", - Short: "Refresh inflation", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build mint module - mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Marshaler, db) - - err = mintModule.UpdateInflation() - if err != nil { - return fmt.Errorf("error while updating inflation: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/parse.go b/cmd/parse/parse.go index 34061227d..5d64c551b 100644 --- a/cmd/parse/parse.go +++ b/cmd/parse/parse.go @@ -9,12 +9,8 @@ import ( parsegenesis "github.com/forbole/juno/v3/cmd/parse/genesis" parseauth "github.com/forbole/bdjuno/v3/cmd/parse/auth" - parsebank "github.com/forbole/bdjuno/v3/cmd/parse/bank" - parsedistribution "github.com/forbole/bdjuno/v3/cmd/parse/distribution" parsefeegrant "github.com/forbole/bdjuno/v3/cmd/parse/feegrant" parsegov "github.com/forbole/bdjuno/v3/cmd/parse/gov" - parsemint "github.com/forbole/bdjuno/v3/cmd/parse/mint" - parsepricefeed "github.com/forbole/bdjuno/v3/cmd/parse/pricefeed" parsestaking "github.com/forbole/bdjuno/v3/cmd/parse/staking" parsetransaction "github.com/forbole/juno/v3/cmd/parse/transactions" ) @@ -29,14 +25,10 @@ func NewParseCmd(parseCfg *parse.Config) *cobra.Command { cmd.AddCommand( parseauth.NewAuthCmd(parseCfg), - parsebank.NewBankCmd(parseCfg), parseblocks.NewBlocksCmd(parseCfg), - parsedistribution.NewDistributionCmd(parseCfg), parsefeegrant.NewFeegrantCmd(parseCfg), parsegenesis.NewGenesisCmd(parseCfg), parsegov.NewGovCmd(parseCfg), - parsemint.NewMintCmd(parseCfg), - parsepricefeed.NewPricefeedCmd(parseCfg), parsestaking.NewStakingCmd(parseCfg), parsetransaction.NewTransactionsCmd(parseCfg), ) diff --git a/cmd/parse/pricefeed/cmd.go b/cmd/parse/pricefeed/cmd.go deleted file mode 100644 index 2cabf9b35..000000000 --- a/cmd/parse/pricefeed/cmd.go +++ /dev/null @@ -1,21 +0,0 @@ -package pricefeed - -import ( - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/spf13/cobra" -) - -// NewPricefeedCmd returns the Cobra command allowing to refresh pricefeed -func NewPricefeedCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - cmd := &cobra.Command{ - Use: "pricefeed", - Short: "Fix things related to the pricefeed module", - } - - cmd.AddCommand( - priceCmd(parseConfig), - priceHistoryCmd(parseConfig), - ) - - return cmd -} diff --git a/cmd/parse/pricefeed/price.go b/cmd/parse/pricefeed/price.go deleted file mode 100644 index 4c9b77cf6..000000000 --- a/cmd/parse/pricefeed/price.go +++ /dev/null @@ -1,44 +0,0 @@ -package pricefeed - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/pricefeed" -) - -// priceCmd returns the Cobra command allowing to refresh token price -func priceCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "price", - Short: "Refresh token price", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build pricefeed module - pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) - - err = pricefeedModule.RunAdditionalOperations() - if err != nil { - return fmt.Errorf("error while storing tokens: %s", err) - } - - err = pricefeedModule.UpdatePrice() - if err != nil { - return fmt.Errorf("error while updating price: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/pricefeed/pricehistory.go b/cmd/parse/pricefeed/pricehistory.go deleted file mode 100644 index bad312105..000000000 --- a/cmd/parse/pricefeed/pricehistory.go +++ /dev/null @@ -1,44 +0,0 @@ -package pricefeed - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/pricefeed" -) - -// priceHistoryCmd returns the Cobra command allowing to store token price history -func priceHistoryCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "history", - Short: "Store token price history", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build pricefeed module - pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) - - err = pricefeedModule.RunAdditionalOperations() - if err != nil { - return fmt.Errorf("error while storing tokens: %s", err) - } - - err = pricefeedModule.UpdatePricesHistory() - if err != nil { - return fmt.Errorf("error while updating price history: %s", err) - } - - return nil - }, - } -} diff --git a/cmd/parse/staking/cmd.go b/cmd/parse/staking/cmd.go index 46251cddc..f6f34e4cc 100644 --- a/cmd/parse/staking/cmd.go +++ b/cmd/parse/staking/cmd.go @@ -13,7 +13,6 @@ func NewStakingCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { } cmd.AddCommand( - poolCmd(parseConfig), validatorsCmd(parseConfig), ) diff --git a/cmd/parse/staking/staking.go b/cmd/parse/staking/staking.go deleted file mode 100644 index d3dadafd4..000000000 --- a/cmd/parse/staking/staking.go +++ /dev/null @@ -1,45 +0,0 @@ -package staking - -import ( - "fmt" - - parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" - "github.com/forbole/juno/v3/types/config" - "github.com/spf13/cobra" - - "github.com/forbole/bdjuno/v3/database" - "github.com/forbole/bdjuno/v3/modules/staking" - modulestypes "github.com/forbole/bdjuno/v3/modules/types" -) - -// poolCmd returns the Cobra command allowing to refresh x/staking pool -func poolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { - return &cobra.Command{ - Use: "pool", - Short: "Refresh staking pool", - RunE: func(cmd *cobra.Command, args []string) error { - parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) - if err != nil { - return err - } - - sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) - if err != nil { - return err - } - - // Get the database - db := database.Cast(parseCtx.Database) - - // Build staking module - stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Marshaler, db) - - err = stakingModule.UpdateStakingPool() - if err != nil { - return fmt.Errorf("error while updating staking pool: %s", err) - } - - return nil - }, - } -} diff --git a/database/consensus.go b/database/consensus.go index 0845ded0d..7fcac0320 100644 --- a/database/consensus.go +++ b/database/consensus.go @@ -27,18 +27,14 @@ func (db *Db) GetLastBlock() (*dbtypes.BlockRow, error) { // GetLastBlockHeight returns the last block height stored inside the database func (db *Db) GetLastBlockHeight() (int64, error) { - stmt := `SELECT height FROM block ORDER BY height DESC LIMIT 1` - - var heights []int64 - if err := db.Sqlx.Select(&heights, stmt); err != nil { + block, err := db.GetLastBlock() + if err != nil { return 0, err } - - if len(heights) == 0 { - return 0, nil + if block == nil { + return 0, fmt.Errorf("block table is empty") } - - return heights[0], nil + return block.Height, nil } // ------------------------------------------------------------------------------------------------------------------- diff --git a/modules/bank/handle_periodic_operations.go b/modules/bank/handle_periodic_operations.go index f15ebba16..b8a26dc39 100644 --- a/modules/bank/handle_periodic_operations.go +++ b/modules/bank/handle_periodic_operations.go @@ -14,7 +14,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { log.Debug().Str("module", "bank").Msg("setting up periodic tasks") if _, err := scheduler.Every(10).Minutes().Do(func() { - utils.WatchMethod(m.UpdateSupply) + utils.WatchMethod(m.updateSupply) }); err != nil { return fmt.Errorf("error while setting up bank periodic operation: %s", err) } @@ -22,20 +22,20 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// UpdateSupply updates the supply of all the tokens -func (m *Module) UpdateSupply() error { +// updateSupply updates the supply of all the tokens +func (m *Module) updateSupply() error { log.Trace().Str("module", "bank").Str("operation", "total supply"). Msg("updating total supply") - height, err := m.db.GetLastBlockHeight() + block, err := m.db.GetLastBlock() if err != nil { - return fmt.Errorf("error while getting latest block height: %s", err) + return fmt.Errorf("error while getting last block: %s", err) } - supply, err := m.keeper.GetSupply(height) + supply, err := m.keeper.GetSupply(block.Height) if err != nil { return err } - return m.db.SaveSupply(supply, height) + return m.db.SaveSupply(supply, block.Height) } diff --git a/modules/distribution/handle_periodic_operations.go b/modules/distribution/handle_periodic_operations.go index 0e70c025c..00f0bb2b5 100644 --- a/modules/distribution/handle_periodic_operations.go +++ b/modules/distribution/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the community pool every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.GetLatestCommunityPool) + utils.WatchMethod(m.getLatestCommunityPool) }); err != nil { return fmt.Errorf("error while scheduling distribution peridic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// GetLatestCommunityPool gets the latest community pool from the chain and stores inside the database -func (m *Module) GetLatestCommunityPool() error { +// getLatestCommunityPool gets the latest community pool from the chain and stores inside the database +func (m *Module) getLatestCommunityPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", err) diff --git a/modules/pricefeed/handle_periodic_operations.go b/modules/pricefeed/handle_periodic_operations.go index 3615f6db1..9717db267 100644 --- a/modules/pricefeed/handle_periodic_operations.go +++ b/modules/pricefeed/handle_periodic_operations.go @@ -19,14 +19,14 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Fetch the token prices every 2 mins if _, err := scheduler.Every(2).Minutes().Do(func() { - utils.WatchMethod(m.UpdatePrice) + utils.WatchMethod(m.updatePrice) }); err != nil { return fmt.Errorf("error while setting up pricefeed period operations: %s", err) } // Update the historical token prices every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.UpdatePricesHistory) + utils.WatchMethod(m.updatePricesHistory) }); err != nil { return fmt.Errorf("error while setting up history period operations: %s", err) } @@ -56,8 +56,8 @@ func (m *Module) getTokenPrices() ([]types.TokenPrice, error) { return prices, nil } -// UpdatePrice fetches the total amount of coins in the system from RPC and stores it in database -func (m *Module) UpdatePrice() error { +// updatePrice fetch total amount of coins in the system from RPC and store it into database +func (m *Module) updatePrice() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). @@ -77,9 +77,9 @@ func (m *Module) UpdatePrice() error { return nil } -// UpdatePricesHistory fetches total amount of coins in the system from RPC +// updatePricesHistory fetches total amount of coins in the system from RPC // and stores historical perice data inside the database -func (m *Module) UpdatePricesHistory() error { +func (m *Module) updatePricesHistory() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). diff --git a/modules/staking/handle_periodic_operations.go b/modules/staking/handle_periodic_operations.go index 7212fc175..2f62d2613 100644 --- a/modules/staking/handle_periodic_operations.go +++ b/modules/staking/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the staking pool every 5 mins if _, err := scheduler.Every(5).Minutes().Do(func() { - utils.WatchMethod(m.UpdateStakingPool) + utils.WatchMethod(m.updateStakingPool) }); err != nil { return fmt.Errorf("error while scheduling staking pool periodic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// UpdateStakingPool reads from the LCD the current staking pool and stores its value inside the database -func (m *Module) UpdateStakingPool() error { +// updateStakingPool reads from the LCD the current staking pool and stores its value inside the database +func (m *Module) updateStakingPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", err) From 4d24dc27ac6f5b94e0d8ad36100bff5c23f49175 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 09:48:07 +0000 Subject: [PATCH 20/22] Revert "fix: check if proposal has passed voting end time before marking it as invalid (#499)" This reverts commit 65d7e766c3ddbd6010749ecbc0e5c16a5c406d4b. --- cmd/parse/gov/proposal.go | 3 +-- modules/gov/handle_block.go | 2 +- modules/gov/utils_proposal.go | 8 ++------ 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cmd/parse/gov/proposal.go b/cmd/parse/gov/proposal.go index 151f6cd89..f4d0859c1 100644 --- a/cmd/parse/gov/proposal.go +++ b/cmd/parse/gov/proposal.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "fmt" "strconv" - "time" modulestypes "github.com/forbole/bdjuno/v3/modules/types" "github.com/rs/zerolog/log" @@ -79,7 +78,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.Now(), proposalID) + err = govModule.UpdateProposal(height, proposalID) if err != nil { return err } diff --git a/modules/gov/handle_block.go b/modules/gov/handle_block.go index 9a279eafa..76138e4e9 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, blockTime, id) + err = m.UpdateProposal(height, 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 18b987e0a..61e9fa793 100644 --- a/modules/gov/utils_proposal.go +++ b/modules/gov/utils_proposal.go @@ -3,7 +3,6 @@ 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" @@ -21,14 +20,11 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func (m *Module) UpdateProposal(height int64, blockTime time.Time, id uint64) error { +func (m *Module) UpdateProposal(height int64, id uint64) error { // Get the proposal proposal, err := m.source.Proposal(height, id) if err != nil { - // Check if proposal has reached the voting end time - passedVotingPeriod := blockTime.After(proposal.VotingEndTime) - - if strings.Contains(err.Error(), codes.NotFound.String()) && passedVotingPeriod { + if strings.Contains(err.Error(), codes.NotFound.String()) { // Handle case when a proposal is deleted from the chain (did not pass deposit period) return m.updateDeletedProposalStatus(id) } From 214fed8b7cf80347ead484265d096b871eb5898b Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 10:18:15 +0000 Subject: [PATCH 21/22] docs: Update README [skip ci] From f1f50e74f3387e1a93982554a5781e71c0d72236 Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 10:29:37 +0000 Subject: [PATCH 22/22] feat: Sync upstream `bank` and `staking` features (#63) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * build(deps): bump github.com/prometheus/client_golang from 1.13.0 to 1.13.1 (#493) Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.13.0 to 1.13.1.
Release notes

Sourced from github.com/prometheus/client_golang's releases.

1.13.1 / 2022-11-02

  • [BUGFIX] Fix race condition with Exemplar in Counter. #1146
  • [BUGFIX] Fix CumulativeCount value of +Inf bucket created from exemplar. #1148
  • [BUGFIX] Fix double-counting bug in promhttp.InstrumentRoundTripperCounter. #1118

Full Changelog: https://github.com/prometheus/client_golang/compare/v1.13.0...v1.13.1

Changelog

Sourced from github.com/prometheus/client_golang's changelog.

1.13.1 / 2022-11-01

  • [BUGFIX] Fix race condition with Exemplar in Counter. #1146
  • [BUGFIX] Fix CumulativeCount value of +Inf bucket created from exemplar. #1148
  • [BUGFIX] Fix double-counting bug in promhttp.InstrumentRoundTripperCounter. #1118
Commits
  • 53e51c4 Merge pull request #1157 from prometheus/cut-1.13.1
  • 79ca0eb Added tip from Björn + Grammarly.
  • 078f11f Cut 1.13.1 release (+ documenting release process).
  • ddd7f0e Fix race condition with Exemplar in Counter (#1146)
  • 1f93f64 Fix CumulativeCount value of +Inf bucket created from exemplar (#1148)
  • 8cc2b6c Fix double-counting bug in promhttp.InstrumentRoundTripperCounter (#1118)
  • See full diff in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/prometheus/client_golang&package-manager=go_modules&previous-version=1.13.0&new-version=1.13.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
* feat: manually trigger periodic task (#492) Closes: #415 --- *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` - [ ] 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) * 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) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Aaron <76254323+huichiaotsou@users.noreply.github.com> --- cmd/parse/bank/cmd.go | 20 ++++++++ cmd/parse/bank/supply.go | 46 +++++++++++++++++++ cmd/parse/distribution/cmd.go | 20 ++++++++ cmd/parse/distribution/communitypool.go | 45 ++++++++++++++++++ cmd/parse/gov/proposal.go | 3 +- cmd/parse/mint/cmd.go | 20 ++++++++ cmd/parse/mint/inflation.go | 45 ++++++++++++++++++ cmd/parse/parse.go | 8 ++++ cmd/parse/pricefeed/cmd.go | 21 +++++++++ cmd/parse/pricefeed/price.go | 44 ++++++++++++++++++ cmd/parse/pricefeed/pricehistory.go | 44 ++++++++++++++++++ cmd/parse/staking/cmd.go | 1 + cmd/parse/staking/staking.go | 45 ++++++++++++++++++ database/consensus.go | 14 ++++-- modules/bank/handle_periodic_operations.go | 14 +++--- .../handle_periodic_operations.go | 6 +-- modules/gov/handle_block.go | 2 +- modules/gov/utils_proposal.go | 8 +++- .../pricefeed/handle_periodic_operations.go | 12 ++--- modules/staking/handle_periodic_operations.go | 6 +-- 20 files changed, 396 insertions(+), 28 deletions(-) create mode 100644 cmd/parse/bank/cmd.go create mode 100644 cmd/parse/bank/supply.go create mode 100644 cmd/parse/distribution/cmd.go create mode 100644 cmd/parse/distribution/communitypool.go create mode 100644 cmd/parse/mint/cmd.go create mode 100644 cmd/parse/mint/inflation.go create mode 100644 cmd/parse/pricefeed/cmd.go create mode 100644 cmd/parse/pricefeed/price.go create mode 100644 cmd/parse/pricefeed/pricehistory.go create mode 100644 cmd/parse/staking/staking.go diff --git a/cmd/parse/bank/cmd.go b/cmd/parse/bank/cmd.go new file mode 100644 index 000000000..6ee5f0a60 --- /dev/null +++ b/cmd/parse/bank/cmd.go @@ -0,0 +1,20 @@ +package bank + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewBankCmd returns the Cobra command allowing to fix various things related to the x/bank module +func NewBankCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "bank", + Short: "Fix things related to the x/bank module", + } + + cmd.AddCommand( + supplyCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/bank/supply.go b/cmd/parse/bank/supply.go new file mode 100644 index 000000000..b9a2f87a6 --- /dev/null +++ b/cmd/parse/bank/supply.go @@ -0,0 +1,46 @@ +package bank + +import ( + "fmt" + + modulestypes "github.com/forbole/bdjuno/v3/modules/types" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/bank" +) + +// supplyCmd returns the Cobra command allowing to refresh x/bank total supply +func supplyCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "supply", + Short: "Refresh total supply", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build bank module + bankModule := bank.NewModule(nil, sources.BankSource, parseCtx.EncodingConfig.Marshaler, db) + + err = bankModule.UpdateSupply() + if err != nil { + return fmt.Errorf("error while getting latest bank supply: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/distribution/cmd.go b/cmd/parse/distribution/cmd.go new file mode 100644 index 000000000..096ad4041 --- /dev/null +++ b/cmd/parse/distribution/cmd.go @@ -0,0 +1,20 @@ +package distribution + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewDistributionCmd returns the Cobra command allowing to fix various things related to the x/distribution module +func NewDistributionCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "distribution", + Short: "Fix things related to the x/distribution module", + } + + cmd.AddCommand( + communityPoolCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/distribution/communitypool.go b/cmd/parse/distribution/communitypool.go new file mode 100644 index 000000000..eaddf56ce --- /dev/null +++ b/cmd/parse/distribution/communitypool.go @@ -0,0 +1,45 @@ +package distribution + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/distribution" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// communityPoolCmd returns the Cobra command allowing to refresh community pool +func communityPoolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "community-pool", + Short: "Refresh community pool", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build distribution module + distrModule := distribution.NewModule(sources.DistrSource, parseCtx.EncodingConfig.Marshaler, db) + + err = distrModule.GetLatestCommunityPool() + if err != nil { + return fmt.Errorf("error while updating community pool: %s", err) + } + + return nil + }, + } +} 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/cmd/parse/mint/cmd.go b/cmd/parse/mint/cmd.go new file mode 100644 index 000000000..b5345c8d3 --- /dev/null +++ b/cmd/parse/mint/cmd.go @@ -0,0 +1,20 @@ +package mint + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewMintCmd returns the Cobra command allowing to fix various things related to the x/mint module +func NewMintCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "mint", + Short: "Fix things related to the x/mint module", + } + + cmd.AddCommand( + inflationCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/mint/inflation.go b/cmd/parse/mint/inflation.go new file mode 100644 index 000000000..01fe772d7 --- /dev/null +++ b/cmd/parse/mint/inflation.go @@ -0,0 +1,45 @@ +package mint + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/mint" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// inflationCmd returns the Cobra command allowing to refresh x/mint inflation +func inflationCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "inflation", + Short: "Refresh inflation", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build mint module + mintModule := mint.NewModule(sources.MintSource, parseCtx.EncodingConfig.Marshaler, db) + + err = mintModule.UpdateInflation() + if err != nil { + return fmt.Errorf("error while updating inflation: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/parse.go b/cmd/parse/parse.go index 5d64c551b..34061227d 100644 --- a/cmd/parse/parse.go +++ b/cmd/parse/parse.go @@ -9,8 +9,12 @@ import ( parsegenesis "github.com/forbole/juno/v3/cmd/parse/genesis" parseauth "github.com/forbole/bdjuno/v3/cmd/parse/auth" + parsebank "github.com/forbole/bdjuno/v3/cmd/parse/bank" + parsedistribution "github.com/forbole/bdjuno/v3/cmd/parse/distribution" parsefeegrant "github.com/forbole/bdjuno/v3/cmd/parse/feegrant" parsegov "github.com/forbole/bdjuno/v3/cmd/parse/gov" + parsemint "github.com/forbole/bdjuno/v3/cmd/parse/mint" + parsepricefeed "github.com/forbole/bdjuno/v3/cmd/parse/pricefeed" parsestaking "github.com/forbole/bdjuno/v3/cmd/parse/staking" parsetransaction "github.com/forbole/juno/v3/cmd/parse/transactions" ) @@ -25,10 +29,14 @@ func NewParseCmd(parseCfg *parse.Config) *cobra.Command { cmd.AddCommand( parseauth.NewAuthCmd(parseCfg), + parsebank.NewBankCmd(parseCfg), parseblocks.NewBlocksCmd(parseCfg), + parsedistribution.NewDistributionCmd(parseCfg), parsefeegrant.NewFeegrantCmd(parseCfg), parsegenesis.NewGenesisCmd(parseCfg), parsegov.NewGovCmd(parseCfg), + parsemint.NewMintCmd(parseCfg), + parsepricefeed.NewPricefeedCmd(parseCfg), parsestaking.NewStakingCmd(parseCfg), parsetransaction.NewTransactionsCmd(parseCfg), ) diff --git a/cmd/parse/pricefeed/cmd.go b/cmd/parse/pricefeed/cmd.go new file mode 100644 index 000000000..2cabf9b35 --- /dev/null +++ b/cmd/parse/pricefeed/cmd.go @@ -0,0 +1,21 @@ +package pricefeed + +import ( + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/spf13/cobra" +) + +// NewPricefeedCmd returns the Cobra command allowing to refresh pricefeed +func NewPricefeedCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + cmd := &cobra.Command{ + Use: "pricefeed", + Short: "Fix things related to the pricefeed module", + } + + cmd.AddCommand( + priceCmd(parseConfig), + priceHistoryCmd(parseConfig), + ) + + return cmd +} diff --git a/cmd/parse/pricefeed/price.go b/cmd/parse/pricefeed/price.go new file mode 100644 index 000000000..4c9b77cf6 --- /dev/null +++ b/cmd/parse/pricefeed/price.go @@ -0,0 +1,44 @@ +package pricefeed + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/pricefeed" +) + +// priceCmd returns the Cobra command allowing to refresh token price +func priceCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "price", + Short: "Refresh token price", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build pricefeed module + pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) + + err = pricefeedModule.RunAdditionalOperations() + if err != nil { + return fmt.Errorf("error while storing tokens: %s", err) + } + + err = pricefeedModule.UpdatePrice() + if err != nil { + return fmt.Errorf("error while updating price: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/pricefeed/pricehistory.go b/cmd/parse/pricefeed/pricehistory.go new file mode 100644 index 000000000..bad312105 --- /dev/null +++ b/cmd/parse/pricefeed/pricehistory.go @@ -0,0 +1,44 @@ +package pricefeed + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/pricefeed" +) + +// priceHistoryCmd returns the Cobra command allowing to store token price history +func priceHistoryCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "history", + Short: "Store token price history", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build pricefeed module + pricefeedModule := pricefeed.NewModule(config.Cfg, parseCtx.EncodingConfig.Marshaler, db) + + err = pricefeedModule.RunAdditionalOperations() + if err != nil { + return fmt.Errorf("error while storing tokens: %s", err) + } + + err = pricefeedModule.UpdatePricesHistory() + if err != nil { + return fmt.Errorf("error while updating price history: %s", err) + } + + return nil + }, + } +} diff --git a/cmd/parse/staking/cmd.go b/cmd/parse/staking/cmd.go index f6f34e4cc..46251cddc 100644 --- a/cmd/parse/staking/cmd.go +++ b/cmd/parse/staking/cmd.go @@ -13,6 +13,7 @@ func NewStakingCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { } cmd.AddCommand( + poolCmd(parseConfig), validatorsCmd(parseConfig), ) diff --git a/cmd/parse/staking/staking.go b/cmd/parse/staking/staking.go new file mode 100644 index 000000000..d3dadafd4 --- /dev/null +++ b/cmd/parse/staking/staking.go @@ -0,0 +1,45 @@ +package staking + +import ( + "fmt" + + parsecmdtypes "github.com/forbole/juno/v3/cmd/parse/types" + "github.com/forbole/juno/v3/types/config" + "github.com/spf13/cobra" + + "github.com/forbole/bdjuno/v3/database" + "github.com/forbole/bdjuno/v3/modules/staking" + modulestypes "github.com/forbole/bdjuno/v3/modules/types" +) + +// poolCmd returns the Cobra command allowing to refresh x/staking pool +func poolCmd(parseConfig *parsecmdtypes.Config) *cobra.Command { + return &cobra.Command{ + Use: "pool", + Short: "Refresh staking pool", + RunE: func(cmd *cobra.Command, args []string) error { + parseCtx, err := parsecmdtypes.GetParserContext(config.Cfg, parseConfig) + if err != nil { + return err + } + + sources, err := modulestypes.BuildSources(config.Cfg.Node, parseCtx.EncodingConfig) + if err != nil { + return err + } + + // Get the database + db := database.Cast(parseCtx.Database) + + // Build staking module + stakingModule := staking.NewModule(sources.StakingSource, parseCtx.EncodingConfig.Marshaler, db) + + err = stakingModule.UpdateStakingPool() + if err != nil { + return fmt.Errorf("error while updating staking pool: %s", err) + } + + return nil + }, + } +} diff --git a/database/consensus.go b/database/consensus.go index 7fcac0320..0845ded0d 100644 --- a/database/consensus.go +++ b/database/consensus.go @@ -27,14 +27,18 @@ func (db *Db) GetLastBlock() (*dbtypes.BlockRow, error) { // GetLastBlockHeight returns the last block height stored inside the database func (db *Db) GetLastBlockHeight() (int64, error) { - block, err := db.GetLastBlock() - if err != nil { + stmt := `SELECT height FROM block ORDER BY height DESC LIMIT 1` + + var heights []int64 + if err := db.Sqlx.Select(&heights, stmt); err != nil { return 0, err } - if block == nil { - return 0, fmt.Errorf("block table is empty") + + if len(heights) == 0 { + return 0, nil } - return block.Height, nil + + return heights[0], nil } // ------------------------------------------------------------------------------------------------------------------- diff --git a/modules/bank/handle_periodic_operations.go b/modules/bank/handle_periodic_operations.go index b8a26dc39..f15ebba16 100644 --- a/modules/bank/handle_periodic_operations.go +++ b/modules/bank/handle_periodic_operations.go @@ -14,7 +14,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { log.Debug().Str("module", "bank").Msg("setting up periodic tasks") if _, err := scheduler.Every(10).Minutes().Do(func() { - utils.WatchMethod(m.updateSupply) + utils.WatchMethod(m.UpdateSupply) }); err != nil { return fmt.Errorf("error while setting up bank periodic operation: %s", err) } @@ -22,20 +22,20 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// updateSupply updates the supply of all the tokens -func (m *Module) updateSupply() error { +// UpdateSupply updates the supply of all the tokens +func (m *Module) UpdateSupply() error { log.Trace().Str("module", "bank").Str("operation", "total supply"). Msg("updating total supply") - block, err := m.db.GetLastBlock() + height, err := m.db.GetLastBlockHeight() if err != nil { - return fmt.Errorf("error while getting last block: %s", err) + return fmt.Errorf("error while getting latest block height: %s", err) } - supply, err := m.keeper.GetSupply(block.Height) + supply, err := m.keeper.GetSupply(height) if err != nil { return err } - return m.db.SaveSupply(supply, block.Height) + return m.db.SaveSupply(supply, height) } diff --git a/modules/distribution/handle_periodic_operations.go b/modules/distribution/handle_periodic_operations.go index 00f0bb2b5..0e70c025c 100644 --- a/modules/distribution/handle_periodic_operations.go +++ b/modules/distribution/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the community pool every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.getLatestCommunityPool) + utils.WatchMethod(m.GetLatestCommunityPool) }); err != nil { return fmt.Errorf("error while scheduling distribution peridic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// getLatestCommunityPool gets the latest community pool from the chain and stores inside the database -func (m *Module) getLatestCommunityPool() error { +// GetLatestCommunityPool gets the latest community pool from the chain and stores inside the database +func (m *Module) GetLatestCommunityPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", 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) } diff --git a/modules/pricefeed/handle_periodic_operations.go b/modules/pricefeed/handle_periodic_operations.go index 9717db267..3615f6db1 100644 --- a/modules/pricefeed/handle_periodic_operations.go +++ b/modules/pricefeed/handle_periodic_operations.go @@ -19,14 +19,14 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Fetch the token prices every 2 mins if _, err := scheduler.Every(2).Minutes().Do(func() { - utils.WatchMethod(m.updatePrice) + utils.WatchMethod(m.UpdatePrice) }); err != nil { return fmt.Errorf("error while setting up pricefeed period operations: %s", err) } // Update the historical token prices every 1 hour if _, err := scheduler.Every(1).Hour().Do(func() { - utils.WatchMethod(m.updatePricesHistory) + utils.WatchMethod(m.UpdatePricesHistory) }); err != nil { return fmt.Errorf("error while setting up history period operations: %s", err) } @@ -56,8 +56,8 @@ func (m *Module) getTokenPrices() ([]types.TokenPrice, error) { return prices, nil } -// updatePrice fetch total amount of coins in the system from RPC and store it into database -func (m *Module) updatePrice() error { +// UpdatePrice fetches the total amount of coins in the system from RPC and stores it in database +func (m *Module) UpdatePrice() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). @@ -77,9 +77,9 @@ func (m *Module) updatePrice() error { return nil } -// updatePricesHistory fetches total amount of coins in the system from RPC +// UpdatePricesHistory fetches total amount of coins in the system from RPC // and stores historical perice data inside the database -func (m *Module) updatePricesHistory() error { +func (m *Module) UpdatePricesHistory() error { log.Debug(). Str("module", "pricefeed"). Str("operation", "pricefeed"). diff --git a/modules/staking/handle_periodic_operations.go b/modules/staking/handle_periodic_operations.go index 2f62d2613..7212fc175 100644 --- a/modules/staking/handle_periodic_operations.go +++ b/modules/staking/handle_periodic_operations.go @@ -15,7 +15,7 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { // Update the staking pool every 5 mins if _, err := scheduler.Every(5).Minutes().Do(func() { - utils.WatchMethod(m.updateStakingPool) + utils.WatchMethod(m.UpdateStakingPool) }); err != nil { return fmt.Errorf("error while scheduling staking pool periodic operation: %s", err) } @@ -23,8 +23,8 @@ func (m *Module) RegisterPeriodicOperations(scheduler *gocron.Scheduler) error { return nil } -// updateStakingPool reads from the LCD the current staking pool and stores its value inside the database -func (m *Module) updateStakingPool() error { +// UpdateStakingPool reads from the LCD the current staking pool and stores its value inside the database +func (m *Module) UpdateStakingPool() error { height, err := m.db.GetLastBlockHeight() if err != nil { return fmt.Errorf("error while getting latest block height: %s", err)