diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 41a319d99..daee49372 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: 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. - - 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/go.mod b/go.mod index 202fe48a7..cd7699cd6 100644 --- a/go.mod +++ b/go.mod @@ -7,12 +7,12 @@ 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 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..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= @@ -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= 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)