From 5e427d6240a577a9017e5210acf3b06c2e1805d1 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Mon, 30 Oct 2023 17:52:22 +0200 Subject: [PATCH 1/8] add: upgrade-height-limit --- database/gov.go | 13 ------------- database/gov_test.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- modules/upgrade/handle_block.go | 3 ++- sample_configs/aura-pool-configs/bdjuno/config.yaml | 7 +------ .../integration-tests-config/bdjuno/config.yaml | 1 + sample_configs/local-dev-configs/bdjuno/config.yaml | 9 ++------- sample_configs/mainnet-configs/bdjuno/config.yaml | 7 +------ .../private-testnet-configs/bdjuno/config.yaml | 7 +------ .../public-testnet-configs/bdjuno/config.yaml | 7 +------ 11 files changed, 14 insertions(+), 50 deletions(-) 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..7d47b6855 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.20231030142926-dc29ed9043f2 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..912946f2f 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.20231030142926-dc29ed9043f2 h1:kLE3KQ8pF3fNAUhdVn3pQLdc5IyAKIWNSzvZi+Y1uaE= +github.com/CudoVentures/juno/v5 v5.0.1-0.20231030142926-dc29ed9043f2/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/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..aa9cbfba2 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 diff --git a/sample_configs/integration-tests-config/bdjuno/config.yaml b/sample_configs/integration-tests-config/bdjuno/config.yaml index a952c4989..3f51fd681 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 diff --git a/sample_configs/local-dev-configs/bdjuno/config.yaml b/sample_configs/local-dev-configs/bdjuno/config.yaml index be4f80b87..e03a8dd28 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 diff --git a/sample_configs/mainnet-configs/bdjuno/config.yaml b/sample_configs/mainnet-configs/bdjuno/config.yaml index ec3aa96b2..773637efb 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 diff --git a/sample_configs/private-testnet-configs/bdjuno/config.yaml b/sample_configs/private-testnet-configs/bdjuno/config.yaml index eeac3f567..e628811d3 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 diff --git a/sample_configs/public-testnet-configs/bdjuno/config.yaml b/sample_configs/public-testnet-configs/bdjuno/config.yaml index f75300cd5..3fd6e82a4 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 From bfbc029fdc3c50e2b7e24e7a0afee93e8c80b851 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Tue, 31 Oct 2023 12:30:39 +0200 Subject: [PATCH 2/8] add: mint, staking, nft_worker to limit at upgrade --- modules/cudomint/handle_periodic_operations.go | 17 +++++++++++++++-- modules/staking/handle_periodic_operations.go | 11 +++++++++++ workers/migrate_nfts_worker.go | 12 ++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) 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/workers/migrate_nfts_worker.go b/workers/migrate_nfts_worker.go index 9851e76cf..881657afa 100644 --- a/workers/migrate_nfts_worker.go +++ b/workers/migrate_nfts_worker.go @@ -12,6 +12,8 @@ import ( parsecmdtypes "github.com/forbole/juno/v5/cmd/parse/types" "github.com/forbole/juno/v5/parser" "github.com/rs/zerolog/log" + + "github.com/forbole/juno/v5/types/config" ) type migrateNftsWorker struct { @@ -93,6 +95,16 @@ func (mnw migrateNftsWorker) migrateNfts(parseCfg *parsecmdtypes.Config, parseCt 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)) + // Avoid getting pass that line if upgrade height + shouldErrorOnUpgrade, err := parseCtx.Database.CheckSoftwareUpgradePlan(currentHeight, 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", currentHeight) + } + block, err := parseCtx.Node.Block(currentHeight) if err != nil { return fmt.Errorf("failed to get block from node: %s", err) From 2aaba6b652496cfa66cc738d8cc46f6be97dce3a Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Tue, 31 Oct 2023 13:11:02 +0200 Subject: [PATCH 3/8] =?UTF-8?q?fix:=20CUDOS-=C2=A02626-workers-malfunction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/bdjuno/main.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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) From 6244033363fb1fc8345b12c02d96ded9b062ac37 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Tue, 31 Oct 2023 15:31:24 +0200 Subject: [PATCH 4/8] remove: migrate_nfts_worker --- database/scheme/010-nft-uniq-id.sql | 3 - .../aura-pool-configs/bdjuno/config.yaml | 2 - .../bdjuno/config.yaml | 2 - .../mainnet-configs/bdjuno/config.yaml | 2 - .../bdjuno/config.yaml | 2 - .../public-testnet-configs/bdjuno/config.yaml | 2 - workers/migrate_nfts_worker.go | 141 ------------------ workers/workers.go | 1 - 8 files changed, 155 deletions(-) delete mode 100644 workers/migrate_nfts_worker.go diff --git a/database/scheme/010-nft-uniq-id.sql b/database/scheme/010-nft-uniq-id.sql index e8255363d..e90ff23ee 100644 --- a/database/scheme/010-nft-uniq-id.sql +++ b/database/scheme/010-nft-uniq-id.sql @@ -7,6 +7,3 @@ CREATE INDEX marketplace_nft_buy_history_uniq_id_index ON marketplace_nft_buy_hi CREATE INDEX nft_transfer_history_uniq_id_index ON nft_transfer_history (uniq_id); CREATE INDEX nft_nft_uniq_id_index ON nft_nft (uniq_id); CREATE INDEX marketplace_nft_uniq_id_index ON marketplace_nft (uniq_id); - -DELETE FROM workers_storage WHERE key = 'migrate_nfts_worker_nft_migrate_current_height'; -DELETE FROM workers_storage WHERE key = 'migrate_nfts_worker_nft_migrate_until_height'; diff --git a/sample_configs/aura-pool-configs/bdjuno/config.yaml b/sample_configs/aura-pool-configs/bdjuno/config.yaml index aa9cbfba2..0b2b3911f 100755 --- a/sample_configs/aura-pool-configs/bdjuno/config.yaml +++ b/sample_configs/aura-pool-configs/bdjuno/config.yaml @@ -61,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 3f51fd681..8980abf92 100755 --- a/sample_configs/integration-tests-config/bdjuno/config.yaml +++ b/sample_configs/integration-tests-config/bdjuno/config.yaml @@ -59,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/mainnet-configs/bdjuno/config.yaml b/sample_configs/mainnet-configs/bdjuno/config.yaml index 773637efb..d60b889c5 100755 --- a/sample_configs/mainnet-configs/bdjuno/config.yaml +++ b/sample_configs/mainnet-configs/bdjuno/config.yaml @@ -61,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 e628811d3..c889f8d7b 100755 --- a/sample_configs/private-testnet-configs/bdjuno/config.yaml +++ b/sample_configs/private-testnet-configs/bdjuno/config.yaml @@ -61,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 3fd6e82a4..63dc369f1 100755 --- a/sample_configs/public-testnet-configs/bdjuno/config.yaml +++ b/sample_configs/public-testnet-configs/bdjuno/config.yaml @@ -61,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/migrate_nfts_worker.go b/workers/migrate_nfts_worker.go deleted file mode 100644 index 881657afa..000000000 --- a/workers/migrate_nfts_worker.go +++ /dev/null @@ -1,141 +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" - - "github.com/forbole/juno/v5/types/config" -) - -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)) - - // Avoid getting pass that line if upgrade height - shouldErrorOnUpgrade, err := parseCtx.Database.CheckSoftwareUpgradePlan(currentHeight, 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", 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{}, } From b36a35f6454f011789dfd43e354e3ea945dc76dc Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Tue, 31 Oct 2023 15:32:23 +0200 Subject: [PATCH 5/8] update: remove migrate_nft_worker config --- sample_configs/local-dev-configs/bdjuno/config.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/sample_configs/local-dev-configs/bdjuno/config.yaml b/sample_configs/local-dev-configs/bdjuno/config.yaml index e03a8dd28..dcd88219f 100755 --- a/sample_configs/local-dev-configs/bdjuno/config.yaml +++ b/sample_configs/local-dev-configs/bdjuno/config.yaml @@ -61,8 +61,6 @@ distribution: workers: - name: fix_blocks_worker interval: 60m - - name: migrate_nfts_worker - interval: 1m - name: blocks_monitoring_worker interval: 30s cudomint: From 6fe647e9ae0a15e8dd08460b45843fc8bba5e50e Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Tue, 31 Oct 2023 15:56:32 +0200 Subject: [PATCH 6/8] add: info to blocks_monitoring_worker exiting --- workers/blocks_monitoring_worker.go | 2 ++ 1 file changed, 2 insertions(+) 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) } From db2c6a111a8da9ddb77fa3501a7d61e8b220fb04 Mon Sep 17 00:00:00 2001 From: SpaghettiOverload Date: Tue, 31 Oct 2023 18:22:21 +0200 Subject: [PATCH 7/8] update: go.mod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7d47b6855..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.1-0.20231030142926-dc29ed9043f2 +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 912946f2f..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.1-0.20231030142926-dc29ed9043f2 h1:kLE3KQ8pF3fNAUhdVn3pQLdc5IyAKIWNSzvZi+Y1uaE= -github.com/CudoVentures/juno/v5 v5.0.1-0.20231030142926-dc29ed9043f2/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= From 476a69b93cfb3199c9c5d83b0994351492eeb70d Mon Sep 17 00:00:00 2001 From: Kamen Stoykov Date: Wed, 1 Nov 2023 09:08:58 +0000 Subject: [PATCH 8/8] restore migration --- database/scheme/010-nft-uniq-id.sql | 3 +++ 1 file changed, 3 insertions(+) diff --git a/database/scheme/010-nft-uniq-id.sql b/database/scheme/010-nft-uniq-id.sql index e90ff23ee..e8255363d 100644 --- a/database/scheme/010-nft-uniq-id.sql +++ b/database/scheme/010-nft-uniq-id.sql @@ -7,3 +7,6 @@ CREATE INDEX marketplace_nft_buy_history_uniq_id_index ON marketplace_nft_buy_hi CREATE INDEX nft_transfer_history_uniq_id_index ON nft_transfer_history (uniq_id); CREATE INDEX nft_nft_uniq_id_index ON nft_nft (uniq_id); CREATE INDEX marketplace_nft_uniq_id_index ON marketplace_nft (uniq_id); + +DELETE FROM workers_storage WHERE key = 'migrate_nfts_worker_nft_migrate_current_height'; +DELETE FROM workers_storage WHERE key = 'migrate_nfts_worker_nft_migrate_until_height';