Skip to content

Commit

Permalink
Merge pull request #107 from CudoVentures/cudos-dev-cosmos-v0.47.3-wi…
Browse files Browse the repository at this point in the history
…th-upgrade-height-parsing-limit

feat: Cudos dev cosmos v0.47.3 with upgrade height parsing limit
  • Loading branch information
kstoykov authored Nov 1, 2023
2 parents 3885a4d + 476a69b commit 3f50c93
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 204 deletions.
20 changes: 10 additions & 10 deletions cmd/bdjuno/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
groupmodule "github.com/cosmos/cosmos-sdk/x/group/module"
databasemigratecmd "github.com/forbole/bdjuno/v4/cmd/database-migrate"
migratecmd "github.com/forbole/bdjuno/v4/cmd/migrate"
parsecmd "github.com/forbole/bdjuno/v4/cmd/parse"
parsegenesiscmd "github.com/forbole/bdjuno/v4/cmd/parse-genesis"
"github.com/forbole/bdjuno/v4/workers"

Expand All @@ -37,23 +36,24 @@ func main() {
WithInitConfig(initCfg).
WithParseConfig(parseCfg)

cfgName := cfg.GetName()

// Run the command
rootCmd := cmd.RootCmd(cfg.GetName())
rootCmd := cmd.RootCmd(cfgName)

pcmd := parsecmd.NewParseCmd(cfg.GetParseConfig())
pcmd.PreRunE = workers.GetStartWorkersPrerunE(pcmd.PreRunE, cfg.GetParseConfig())
startcmd := startcmd.NewStartCmd(parseCfg)
startcmd.PreRunE = workers.GetStartWorkersPrerunE(startcmd.PreRunE, parseCfg)

rootCmd.AddCommand(
cmd.VersionCmd(),
initcmd.NewInitCmd(cfg.GetInitConfig()),
pcmd,
migratecmd.NewMigrateCmd(cfg.GetName(), cfg.GetParseConfig()),
startcmd.NewStartCmd(cfg.GetParseConfig()),
parsegenesiscmd.NewParseGenesisCmd(cfg.GetParseConfig()),
databasemigratecmd.NewDatabaseMigrateCmd(cfg.GetParseConfig()),
migratecmd.NewMigrateCmd(cfgName, parseCfg),
startcmd,
parsegenesiscmd.NewParseGenesisCmd(parseCfg),
databasemigratecmd.NewDatabaseMigrateCmd(parseCfg),
)

executor := cmd.PrepareRootCmd(cfg.GetName(), rootCmd)
executor := cmd.PrepareRootCmd(cfgName, rootCmd)
err := executor.Execute()
if err != nil {
panic(err)
Expand Down
13 changes: 0 additions & 13 deletions database/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,19 +480,6 @@ func (db *Db) DeleteSoftwareUpgradePlan(proposalID uint64) error {
return nil
}

// CheckSoftwareUpgradePlan returns true if an upgrade is scheduled at the given height
func (db *Db) CheckSoftwareUpgradePlan(upgradeHeight int64) (bool, error) {
var exist bool

stmt := `SELECT EXISTS (SELECT 1 FROM software_upgrade_plan WHERE upgrade_height=$1)`
err := db.SQL.QueryRow(stmt, upgradeHeight).Scan(&exist)
if err != nil {
return exist, fmt.Errorf("error while checking software upgrade plan existence: %s", err)
}

return exist, nil
}

// TruncateSoftwareUpgradePlan delete software upgrade plans once the upgrade height passed
func (db *Db) TruncateSoftwareUpgradePlan(height int64) error {
stmt := `DELETE FROM software_upgrade_plan WHERE upgrade_height <= $1`
Expand Down
4 changes: 2 additions & 2 deletions database/gov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,12 @@ func (suite *DbTestSuite) TestBigDipperDb_CheckSoftwareUpgradePlan() {
suite.Require().NoError(err)

// Check software upgrade plan at existing height
exist, err := suite.database.CheckSoftwareUpgradePlan(100)
exist, err := suite.database.CheckSoftwareUpgradePlan(100, 0)
suite.Require().NoError(err)
suite.Require().Equal(true, exist)

// Check software upgrade plan at non-existing height
exist, err = suite.database.CheckSoftwareUpgradePlan(11)
exist, err = suite.database.CheckSoftwareUpgradePlan(11, 0)
suite.Require().NoError(err)
suite.Require().Equal(false, exist)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ require (
// See here: https://github.com/desmos-labs/desmos/pull/1131#discussion_r1194090419
replace github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.8

replace github.com/forbole/juno/v5 => github.com/CudoVentures/juno/v5 v5.0.0-20231013114723-92245a6b696a
replace github.com/forbole/juno/v5 => github.com/CudoVentures/juno/v5 v5.0.1-0.20231031151027-8ea7bf637a02

replace github.com/cosmos/cosmos-sdk => github.com/CudoVentures/cosmos-sdk v0.47.4-0.20230717140133-df4d8422a08d

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ github.com/CudoVentures/cosmos-sdk/simapp v0.0.0-20230717140133-df4d8422a08d h1:
github.com/CudoVentures/cosmos-sdk/simapp v0.0.0-20230717140133-df4d8422a08d/go.mod h1:xbjky3L3DJEylaho6gXplkrMvJ5sFgv+qNX+Nn47bzY=
github.com/CudoVentures/cudos-node v1.1.1-0.20230821122417-31402f8ea2d9 h1:0+2Q1PuSAyjeI5txD+24+vY5NcwwcepfB7SAR4HWODE=
github.com/CudoVentures/cudos-node v1.1.1-0.20230821122417-31402f8ea2d9/go.mod h1:JqQysOSVKiSi5upBKM+dfMDEIZi4pl03/WSDEY06mNA=
github.com/CudoVentures/juno/v5 v5.0.0-20231013114723-92245a6b696a h1:xU3iYkRC2DTEJi9vgao/UToHgOTkTxYg47cidQ6fij0=
github.com/CudoVentures/juno/v5 v5.0.0-20231013114723-92245a6b696a/go.mod h1:4xgSKG+fuP3Ku//O7Sqq4IRI1V71mzEOdPxC2leuilA=
github.com/CudoVentures/juno/v5 v5.0.1-0.20231031151027-8ea7bf637a02 h1:k+V8D4F2gBAHuDLdBWbC2LEjgvIEg7Nof98biGu4pxA=
github.com/CudoVentures/juno/v5 v5.0.1-0.20231031151027-8ea7bf637a02/go.mod h1:4xgSKG+fuP3Ku//O7Sqq4IRI1V71mzEOdPxC2leuilA=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down
17 changes: 15 additions & 2 deletions modules/cudomint/handle_periodic_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package cudomint
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/forbole/bdjuno/v4/modules/utils"
junoConfig "github.com/forbole/juno/v5/types/config"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/go-co-op/gocron"
Expand Down Expand Up @@ -44,11 +46,22 @@ func (m *Module) fetchStats() error {
return err
}

if err := m.db.SaveAPR(apr, stats.APR.Height); err != nil {
// Avoid getting pass that line if upgrade height
height := stats.APR.Height
shouldErrorOnUpgrade, err := m.db.CheckSoftwareUpgradePlan(height, junoConfig.GetLastUpgradeHeight())
if err != nil {
return fmt.Errorf("error while checking software upgrade plan existence: %s", err)
}

if shouldErrorOnUpgrade {
return fmt.Errorf("upgrade height reached. not processing block %v", height)
}

if err := m.db.SaveAPR(apr, height); err != nil {
return err
}

if err := m.db.SaveAPRHistory(apr, stats.APR.Height, time.Now().UnixNano()); err != nil {
if err := m.db.SaveAPRHistory(apr, height, time.Now().UnixNano()); err != nil {
return err
}

Expand Down
11 changes: 11 additions & 0 deletions modules/staking/handle_periodic_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/rs/zerolog/log"

"github.com/forbole/bdjuno/v4/modules/utils"
"github.com/forbole/juno/v5/types/config"
)

// RegisterPeriodicOperations implements modules.PeriodicOperationsModule
Expand All @@ -32,6 +33,16 @@ func (m *Module) UpdateStakingPool() error {
log.Debug().Str("module", "staking").Int64("height", height).
Msg("updating staking pool")

// Avoid getting pass that line if upgrade height
shouldErrorOnUpgrade, err := m.db.CheckSoftwareUpgradePlan(height, config.GetLastUpgradeHeight())
if err != nil {
return fmt.Errorf("error while checking software upgrade plan existence: %s", err)
}

if shouldErrorOnUpgrade {
return fmt.Errorf("upgrade height reached. not processing block %v", height)
}

pool, err := m.GetStakingPool(height)
if err != nil {
return fmt.Errorf("error while getting staking pool: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion modules/upgrade/handle_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/forbole/juno/v5/types"
"github.com/forbole/juno/v5/types/config"

tmctypes "github.com/cometbft/cometbft/rpc/core/types"
)
Expand All @@ -21,7 +22,7 @@ func (m *Module) HandleBlock(
}

func (m *Module) refreshDataUponSoftwareUpgrade(height int64) error {
exist, err := m.db.CheckSoftwareUpgradePlan(height)
exist, err := m.db.CheckSoftwareUpgradePlan(height, config.GetLastUpgradeHeight())
if err != nil {
return fmt.Errorf("error while checking software upgrade plan existence: %s", err)
}
Expand Down
9 changes: 1 addition & 8 deletions sample_configs/aura-pool-configs/bdjuno/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ node:
insecure: true
parsing:
workers: 2
last_upgrade_height: 0
listen_new_blocks: true
parse_old_blocks: true
parse_genesis: true
Expand All @@ -39,12 +40,6 @@ parsing:
genesis_file_path: /usr/local/bdjuno/bdjuno/genesis.json
database:
url: postgres://%POSTGRES_USER%:%POSTGRES_PASSWORD%@host:5432/database-name?sslmode=disable&search_path=public
name: dev-explorer-v2
host: host.docker.internal
port: 5432
user: %POSTGRES_USER%
password: %POSTGRES_PASSWORD%
schema: public
max_open_connections: 10
max_idle_connections: 10
partition_size: 100000
Expand All @@ -66,8 +61,6 @@ distribution:
workers:
- name: fix_blocks_worker
interval: 60m
- name: migrate_nfts_worker
interval: 1m
- name: blocks_monitoring_worker
interval: 30s
cudomint:
Expand Down
3 changes: 1 addition & 2 deletions sample_configs/integration-tests-config/bdjuno/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ node:
insecure: true
parsing:
workers: 1
last_upgrade_height: 0
listen_new_blocks: true
parse_old_blocks: true
parse_genesis: true
Expand Down Expand Up @@ -58,8 +59,6 @@ distribution:
workers:
- name: fix_blocks_worker
interval: 60m
- name: migrate_nfts_worker
interval: 1m
- name: blocks_monitoring_worker
interval: 30s
cudomint:
Expand Down
11 changes: 2 additions & 9 deletions sample_configs/local-dev-configs/bdjuno/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ chain:
- bank
- consensus
- gov
- slashing
- slashing
- staking
- pricefeed
- distribution
Expand All @@ -31,6 +31,7 @@ node:
insecure: true
parsing:
workers: 1
last_upgrade_height: 101
listen_new_blocks: true
parse_old_blocks: true
parse_genesis: true
Expand All @@ -39,12 +40,6 @@ parsing:
genesis_file_path: /usr/local/bdjuno/bdjuno/genesis.json
database:
url: postgres://user:password@host:port/database-name?sslmode=disable&search_path=public
name: LocalBigDipperTestV2
host: host.docker.internal
port: 5432
user: postgres
password: passhere
schema: public
max_open_connections: 10
max_idle_connections: 10
partition_size: 100000
Expand All @@ -66,8 +61,6 @@ distribution:
workers:
- name: fix_blocks_worker
interval: 60m
- name: migrate_nfts_worker
interval: 1m
- name: blocks_monitoring_worker
interval: 30s
cudomint:
Expand Down
9 changes: 1 addition & 8 deletions sample_configs/mainnet-configs/bdjuno/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ node:
insecure: true
parsing:
workers: 5
last_upgrade_height: 0
listen_new_blocks: true
parse_old_blocks: true
parse_genesis: true
Expand All @@ -39,12 +40,6 @@ parsing:
genesis_file_path: /usr/local/bdjuno/bdjuno/genesis.json
database:
url: postgres://%POSTGRES_USER%:%POSTGRES_PASSWORD%@host:5432/database-name?sslmode=disable&search_path=public
name: explorer-v2-ui-1
host: host.docker.internal # uses gcloud sql auth proxy on localhost to connecto gcloud sql db
port: 5432
user: %POSTGRES_USER%
password: %POSTGRES_PASSWORD%
schema: public
max_open_connections: 10
max_idle_connections: 10
partition_size: 100000
Expand All @@ -66,8 +61,6 @@ distribution:
workers:
- name: fix_blocks_worker
interval: 60m
- name: migrate_nfts_worker
interval: 1m
- name: blocks_monitoring_worker
interval: 30s
cudomint:
Expand Down
9 changes: 1 addition & 8 deletions sample_configs/private-testnet-configs/bdjuno/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ node:
insecure: true
parsing:
workers: 4
last_upgrade_height: 0
listen_new_blocks: true
parse_old_blocks: true
parse_genesis: true
Expand All @@ -39,12 +40,6 @@ parsing:
genesis_file_path: /usr/local/bdjuno/bdjuno/genesis.json
database:
url: postgres://%POSTGRES_USER%:%POSTGRES_PASSWORD%@host:5432/database-name?sslmode=disable&search_path=public
name: new-private-testnet-explorer-v2
host: host.docker.internal # uses gcloud sql auth proxy on localhost to connecto gcloud sql db
port: 5432
user: %POSTGRES_USER%
password: %POSTGRES_PASSWORD%
schema: public
max_open_connections: 10
max_idle_connections: 10
partition_size: 100000
Expand All @@ -66,8 +61,6 @@ distribution:
workers:
- name: fix_blocks_worker
interval: 10m
- name: migrate_nfts_worker
interval: 1m
- name: blocks_monitoring_worker
interval: 30s
cudomint:
Expand Down
9 changes: 1 addition & 8 deletions sample_configs/public-testnet-configs/bdjuno/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ node:
insecure: true
parsing:
workers: 5
last_upgrade_height: 0
listen_new_blocks: true
parse_old_blocks: true
parse_genesis: true
Expand All @@ -39,12 +40,6 @@ parsing:
genesis_file_path: /usr/local/bdjuno/bdjuno/genesis.json
database:
url: postgres://%POSTGRES_USER%:%POSTGRES_PASSWORD%@host:5432/database-name?sslmode=disable&search_path=public
name: public-testnet-explorer-v2
host: host.docker.internal # uses gcloud sql auth proxy on localhost to connecto gcloud sql db
port: 5432
user: %POSTGRES_USER%
password: %POSTGRES_PASSWORD%
schema: public
max_open_connections: 10
max_idle_connections: 10
partition_size: 100000
Expand All @@ -66,8 +61,6 @@ distribution:
workers:
- name: fix_blocks_worker
interval: 60m
- name: migrate_nfts_worker
interval: 1m
- name: blocks_monitoring_worker
interval: 30s
cudomint:
Expand Down
2 changes: 2 additions & 0 deletions workers/blocks_monitoring_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
parsecmdtypes "github.com/forbole/juno/v5/cmd/parse/types"
"github.com/forbole/juno/v5/parser"
"github.com/jmoiron/sqlx"
"github.com/rs/zerolog/log"
)

type blocksMonitoringWorker struct {
Expand Down Expand Up @@ -72,6 +73,7 @@ func (bmw blocksMonitoringWorker) monitorBlocks(parseCfg *parsecmdtypes.Config,
}

if currentTime-lastMonitoredBlockTime > 60 {
log.Info().Str("worker", bmw.Name()).Msg("No new blocks has been parsed to the DB. exiting...")
os.Exit(-1)
}

Expand Down
Loading

0 comments on commit 3f50c93

Please sign in to comment.