diff --git a/cmd/bdjuno/main.go b/cmd/bdjuno/main.go index f809dfaa8..549a71944 100644 --- a/cmd/bdjuno/main.go +++ b/cmd/bdjuno/main.go @@ -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" @@ -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) diff --git a/database/gov.go b/database/gov.go index ee87aaa60..3b1ddc965 100644 --- a/database/gov.go +++ b/database/gov.go @@ -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` diff --git a/database/gov_test.go b/database/gov_test.go index 907f7f5f8..ff2116eaf 100644 --- a/database/gov_test.go +++ b/database/gov_test.go @@ -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) } diff --git a/go.mod b/go.mod index 2d424f11d..de4dd3cf1 100644 --- a/go.mod +++ b/go.mod @@ -321,7 +321,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 diff --git a/go.sum b/go.sum index 0dd032587..18817e853 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/modules/cudomint/handle_periodic_operations.go b/modules/cudomint/handle_periodic_operations.go index 48fe05c1b..5ae1a9ebc 100644 --- a/modules/cudomint/handle_periodic_operations.go +++ b/modules/cudomint/handle_periodic_operations.go @@ -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" @@ -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 } diff --git a/modules/staking/handle_periodic_operations.go b/modules/staking/handle_periodic_operations.go index 352ad8cab..91fa28703 100644 --- a/modules/staking/handle_periodic_operations.go +++ b/modules/staking/handle_periodic_operations.go @@ -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 @@ -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) diff --git a/modules/upgrade/handle_block.go b/modules/upgrade/handle_block.go index c5ca62fd8..0c56733a3 100644 --- a/modules/upgrade/handle_block.go +++ b/modules/upgrade/handle_block.go @@ -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" ) @@ -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) } diff --git a/sample_configs/aura-pool-configs/bdjuno/config.yaml b/sample_configs/aura-pool-configs/bdjuno/config.yaml index 73617ddeb..0b2b3911f 100755 --- a/sample_configs/aura-pool-configs/bdjuno/config.yaml +++ b/sample_configs/aura-pool-configs/bdjuno/config.yaml @@ -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 @@ -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 @@ -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: diff --git a/sample_configs/integration-tests-config/bdjuno/config.yaml b/sample_configs/integration-tests-config/bdjuno/config.yaml index a952c4989..8980abf92 100755 --- a/sample_configs/integration-tests-config/bdjuno/config.yaml +++ b/sample_configs/integration-tests-config/bdjuno/config.yaml @@ -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 @@ -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: diff --git a/sample_configs/local-dev-configs/bdjuno/config.yaml b/sample_configs/local-dev-configs/bdjuno/config.yaml index be4f80b87..dcd88219f 100755 --- a/sample_configs/local-dev-configs/bdjuno/config.yaml +++ b/sample_configs/local-dev-configs/bdjuno/config.yaml @@ -7,7 +7,7 @@ chain: - bank - consensus - gov - - slashing + - slashing - staking - pricefeed - distribution @@ -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 @@ -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 @@ -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: diff --git a/sample_configs/mainnet-configs/bdjuno/config.yaml b/sample_configs/mainnet-configs/bdjuno/config.yaml index ec3aa96b2..d60b889c5 100755 --- a/sample_configs/mainnet-configs/bdjuno/config.yaml +++ b/sample_configs/mainnet-configs/bdjuno/config.yaml @@ -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 @@ -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 @@ -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: diff --git a/sample_configs/private-testnet-configs/bdjuno/config.yaml b/sample_configs/private-testnet-configs/bdjuno/config.yaml index eeac3f567..c889f8d7b 100755 --- a/sample_configs/private-testnet-configs/bdjuno/config.yaml +++ b/sample_configs/private-testnet-configs/bdjuno/config.yaml @@ -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 @@ -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 @@ -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: diff --git a/sample_configs/public-testnet-configs/bdjuno/config.yaml b/sample_configs/public-testnet-configs/bdjuno/config.yaml index f75300cd5..63dc369f1 100755 --- a/sample_configs/public-testnet-configs/bdjuno/config.yaml +++ b/sample_configs/public-testnet-configs/bdjuno/config.yaml @@ -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 @@ -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 @@ -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: diff --git a/workers/blocks_monitoring_worker.go b/workers/blocks_monitoring_worker.go index 50a71cd9a..7a9bb9216 100644 --- a/workers/blocks_monitoring_worker.go +++ b/workers/blocks_monitoring_worker.go @@ -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 { @@ -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) } diff --git a/workers/migrate_nfts_worker.go b/workers/migrate_nfts_worker.go deleted file mode 100644 index 9851e76cf..000000000 --- a/workers/migrate_nfts_worker.go +++ /dev/null @@ -1,129 +0,0 @@ -package workers - -import ( - "context" - "fmt" - "strconv" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/forbole/bdjuno/v4/database" - "github.com/forbole/bdjuno/v4/modules/nft" - parsecmdtypes "github.com/forbole/juno/v5/cmd/parse/types" - "github.com/forbole/juno/v5/parser" - "github.com/rs/zerolog/log" -) - -type migrateNftsWorker struct { - baseWorker -} - -func (mnw migrateNftsWorker) Name() string { - return "migrate_nfts_worker" -} - -func (mnw migrateNftsWorker) Start(ctx context.Context, parseCfg *parsecmdtypes.Config, parseCtx *parser.Context, storage keyValueStorage, interval time.Duration) { - mnw.baseWorker.Start(ctx, mnw.Name(), mnw.migrateNfts, parseCfg, parseCtx, storage, interval) -} - -func (mnw migrateNftsWorker) migrateNfts(parseCfg *parsecmdtypes.Config, parseCtx *parser.Context, storage keyValueStorage) error { - currentHeightVal, err := storage.GetOrDefaultValue(nftMigrationCurrentHeightKey, "0") - if err != nil { - return fmt.Errorf("error while getting worker storage key '%s': %s", nftMigrationCurrentHeightKey, err) - } - - currentHeight, err := strconv.ParseInt(currentHeightVal, 10, 64) - if err != nil { - return fmt.Errorf("error while parsing current height string value '%s': %s", currentHeightVal, err) - } - - if currentHeight == 0 { - currentHeight, err = getGenesisMaxInitialHeight(parseCtx) - if err != nil { - return fmt.Errorf("error while getting genesis max initial height: %s", err) - } - } - - untilHeightVal, err := storage.GetOrDefaultValue(nftMigrateUntilHeightKey, "0") - if err != nil { - return fmt.Errorf("error while getting worker storage key '%s': %s", nftMigrateUntilHeightKey, err) - } - - untilHeight, err := strconv.ParseInt(untilHeightVal, 10, 64) - if err != nil { - return fmt.Errorf("error while parsing until height string value '%s': %s", untilHeightVal, err) - } - - if untilHeight == 0 { - untilHeight, err = parseCtx.Node.LatestHeight() - if err != nil { - return fmt.Errorf("error while getting chain latest block height: %s", err) - } - - latestHeightVal := strconv.FormatInt(untilHeight, 10) - - if err := storage.SetValue(nftMigrateUntilHeightKey, latestHeightVal); err != nil { - return fmt.Errorf("error while storing migrate until value '%s': %s", latestHeightVal, err) - } - } - - if currentHeight >= untilHeight { - // Processing finished - return nil - } - - nftModule := nft.NewModule(parseCtx.EncodingConfig.Codec, database.Cast(parseCtx.Database)) - - for i := 0; i < 10000; i++ { - if err := mnw.processBlock(nftModule, parseCtx, currentHeight); err != nil { - return fmt.Errorf("error while processing block at height '%d': %s", currentHeight, err) - } - - currentHeight++ - } - - currentHeightVal = strconv.FormatInt(currentHeight, 10) - if err := storage.SetValue(nftMigrationCurrentHeightKey, currentHeightVal); err != nil { - return fmt.Errorf("error while storing migration current height value '%s': %s", currentHeightVal, err) - } - - return nil -} - -func (mnw migrateNftsWorker) processBlock(module *nft.Module, parseCtx *parser.Context, currentHeight int64) error { - log.Debug().Str("worker", "migrate_nft_worker").Msg(fmt.Sprintf("Processing block at height %d", currentHeight)) - - block, err := parseCtx.Node.Block(currentHeight) - if err != nil { - return fmt.Errorf("failed to get block from node: %s", err) - } - - txs, err := parseCtx.Node.Txs(block) - if err != nil { - return fmt.Errorf("failed to get transactions for block: %s", err) - } - - for _, tx := range txs { - log.Debug().Str("worker", "migrate_nft_worker").Msg(fmt.Sprintf("Processing TX hash: %s at height %d", tx.TxHash, currentHeight)) - msgIndex := 0 - for _, msg := range tx.Body.Messages { - var stdMsg sdk.Msg - if err := parseCtx.EncodingConfig.Codec.UnpackAny(msg, &stdMsg); err != nil { - return fmt.Errorf("error while unpacking message: %s", err) - } - - if err := module.HandleMsg(msgIndex, stdMsg, tx); err != nil { - return fmt.Errorf("error while nft module handle msg: %s", err) - } - - msgIndex++ - } - } - - return nil -} - -const ( - nftMigrationCurrentHeightKey = "nft_migrate_current_height" - nftMigrateUntilHeightKey = "nft_migrate_until_height" -) diff --git a/workers/workers.go b/workers/workers.go index c385cf1d2..b338953ac 100644 --- a/workers/workers.go +++ b/workers/workers.go @@ -24,7 +24,6 @@ var cancelWorkersCtx context.CancelFunc var workers = []worker{ fixBlocksWorker{}, - migrateNftsWorker{}, blocksMonitoringWorker{}, }