From c31421ff03ad463f0ce410bfde7641f57de5a2fe Mon Sep 17 00:00:00 2001 From: Ankur Banerjee Date: Thu, 24 Nov 2022 10:29:37 +0000 Subject: [PATCH] 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

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