diff --git a/app/app.go b/app/app.go index 20dc88d..6bf6e04 100644 --- a/app/app.go +++ b/app/app.go @@ -384,6 +384,8 @@ func (app *CosmosApp) LoadHomePath() error { cmd.Env = append(os.Environ(), "COSMOVISOR_DISABLE_LOGS=true") } + cmd.Args = append(cmd.Args, "start", "--help") + out, err := cmd.CombinedOutput() if err != nil { return fmt.Errorf("failed to get output of binary: %w", err) diff --git a/engines/celestia-core-v34/celestiacore.go b/engines/celestia-core-v34/celestiacore.go index fe3044a..77b0e0e 100644 --- a/engines/celestia-core-v34/celestiacore.go +++ b/engines/celestia-core-v34/celestiacore.go @@ -5,7 +5,6 @@ import ( abciTypes "github.com/KYVENetwork/celestia-core/abci/types" cfg "github.com/KYVENetwork/celestia-core/config" cs "github.com/KYVENetwork/celestia-core/consensus" - "github.com/KYVENetwork/celestia-core/crypto" "github.com/KYVENetwork/celestia-core/crypto/ed25519" "github.com/KYVENetwork/celestia-core/evidence" "github.com/KYVENetwork/celestia-core/libs/json" @@ -44,9 +43,8 @@ type Engine struct { evidenceDB db.DB - genDoc *GenesisDoc - privValidatorKey crypto.PubKey - nodeKey *tmP2P.NodeKey + genDoc *GenesisDoc + nodeKey *tmP2P.NodeKey state tmState.State proxyApp proxy.AppConns @@ -94,15 +92,6 @@ func (engine *Engine) LoadConfig() error { engine.genDoc = genDoc - privValidatorKey, err := privval.LoadFilePVEmptyState( - engine.config.PrivValidatorKeyFile(), - engine.config.PrivValidatorStateFile(), - ).GetPubKey() - if err != nil { - return fmt.Errorf("failed to load validator key file: %w", err) - } - engine.privValidatorKey = privValidatorKey - nodeKey, err := tmP2P.LoadNodeKey(engine.config.NodeKeyFile()) if err != nil { return fmt.Errorf("loading node key file failed: %w", err) @@ -490,7 +479,7 @@ func (engine *Engine) StartRPCServer(port int64) { ConsensusState: nil, P2PPeers: nil, P2PTransport: &Transport{nodeInfo: nodeInfo}, - PubKey: engine.privValidatorKey, + PubKey: ed25519.GenPrivKey().PubKey(), GenDoc: nil, TxIndexer: nil, BlockIndexer: nil, diff --git a/engines/cometbft-v37/cometbft.go b/engines/cometbft-v37/cometbft.go index 024c3a9..8ff77b5 100644 --- a/engines/cometbft-v37/cometbft.go +++ b/engines/cometbft-v37/cometbft.go @@ -5,7 +5,6 @@ import ( abciTypes "github.com/KYVENetwork/cometbft/v37/abci/types" cfg "github.com/KYVENetwork/cometbft/v37/config" cs "github.com/KYVENetwork/cometbft/v37/consensus" - "github.com/KYVENetwork/cometbft/v37/crypto" "github.com/KYVENetwork/cometbft/v37/crypto/ed25519" "github.com/KYVENetwork/cometbft/v37/evidence" "github.com/KYVENetwork/cometbft/v37/libs/json" @@ -44,9 +43,8 @@ type Engine struct { evidenceDB db.DB - genDoc *GenesisDoc - privValidatorKey crypto.PubKey - nodeKey *cometP2P.NodeKey + genDoc *GenesisDoc + nodeKey *cometP2P.NodeKey state tmState.State proxyApp proxy.AppConns @@ -94,15 +92,6 @@ func (engine *Engine) LoadConfig() error { engine.genDoc = genDoc - privValidatorKey, err := privval.LoadFilePVEmptyState( - engine.config.PrivValidatorKeyFile(), - engine.config.PrivValidatorStateFile(), - ).GetPubKey() - if err != nil { - return fmt.Errorf("failed to load validator key file: %w", err) - } - engine.privValidatorKey = privValidatorKey - nodeKey, err := cometP2P.LoadNodeKey(engine.config.NodeKeyFile()) if err != nil { return fmt.Errorf("loading node key file failed: %w", err) @@ -486,7 +475,7 @@ func (engine *Engine) StartRPCServer(port int64) { ConsensusState: nil, P2PPeers: nil, P2PTransport: &Transport{nodeInfo: nodeInfo}, - PubKey: engine.privValidatorKey, + PubKey: ed25519.GenPrivKey().PubKey(), GenDoc: nil, TxIndexer: nil, BlockIndexer: nil, diff --git a/engines/cometbft-v38/cometbft.go b/engines/cometbft-v38/cometbft.go index a205f8e..ef97128 100644 --- a/engines/cometbft-v38/cometbft.go +++ b/engines/cometbft-v38/cometbft.go @@ -6,7 +6,6 @@ import ( abciTypes "github.com/KYVENetwork/cometbft/v38/abci/types" cfg "github.com/KYVENetwork/cometbft/v38/config" cs "github.com/KYVENetwork/cometbft/v38/consensus" - "github.com/KYVENetwork/cometbft/v38/crypto" "github.com/KYVENetwork/cometbft/v38/crypto/ed25519" "github.com/KYVENetwork/cometbft/v38/evidence" "github.com/KYVENetwork/cometbft/v38/libs/json" @@ -45,9 +44,8 @@ type Engine struct { evidenceDB db.DB - genDoc *GenesisDoc - privValidatorKey crypto.PubKey - nodeKey *cometP2P.NodeKey + genDoc *GenesisDoc + nodeKey *cometP2P.NodeKey state tmState.State proxyApp proxy.AppConns @@ -95,15 +93,6 @@ func (engine *Engine) LoadConfig() error { engine.genDoc = genDoc - privValidatorKey, err := privval.LoadFilePVEmptyState( - engine.config.PrivValidatorKeyFile(), - engine.config.PrivValidatorStateFile(), - ).GetPubKey() - if err != nil { - return fmt.Errorf("failed to load validator key file: %w", err) - } - engine.privValidatorKey = privValidatorKey - nodeKey, err := cometP2P.LoadNodeKey(engine.config.NodeKeyFile()) if err != nil { return fmt.Errorf("loading node key file failed: %w", err) @@ -498,7 +487,7 @@ func (engine *Engine) StartRPCServer(port int64) { ConsensusState: nil, P2PPeers: nil, P2PTransport: &Transport{nodeInfo: nodeInfo}, - PubKey: engine.privValidatorKey, + PubKey: ed25519.GenPrivKey().PubKey(), GenDoc: nil, TxIndexer: nil, BlockIndexer: nil, diff --git a/engines/tendermint-v34/tendermint.go b/engines/tendermint-v34/tendermint.go index 517c284..6480bba 100644 --- a/engines/tendermint-v34/tendermint.go +++ b/engines/tendermint-v34/tendermint.go @@ -6,7 +6,6 @@ import ( abciTypes "github.com/tendermint/tendermint/abci/types" cfg "github.com/tendermint/tendermint/config" cs "github.com/tendermint/tendermint/consensus" - "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/evidence" "github.com/tendermint/tendermint/libs/json" @@ -44,9 +43,8 @@ type Engine struct { evidenceDB db.DB - genDoc *GenesisDoc - privValidatorKey crypto.PubKey - nodeKey *tmP2P.NodeKey + genDoc *GenesisDoc + nodeKey *tmP2P.NodeKey state tmState.State proxyApp proxy.AppConns @@ -94,15 +92,6 @@ func (engine *Engine) LoadConfig() error { engine.genDoc = genDoc - privValidatorKey, err := privval.LoadFilePVEmptyState( - engine.config.PrivValidatorKeyFile(), - engine.config.PrivValidatorStateFile(), - ).GetPubKey() - if err != nil { - return fmt.Errorf("failed to load validator key file: %w", err) - } - engine.privValidatorKey = privValidatorKey - nodeKey, err := tmP2P.LoadNodeKey(engine.config.NodeKeyFile()) if err != nil { return fmt.Errorf("loading node key file failed: %w", err) @@ -482,7 +471,7 @@ func (engine *Engine) StartRPCServer(port int64) { ConsensusState: nil, P2PPeers: nil, P2PTransport: &Transport{nodeInfo: nodeInfo}, - PubKey: engine.privValidatorKey, + PubKey: ed25519.GenPrivKey().PubKey(), GenDoc: nil, TxIndexer: nil, BlockIndexer: nil, diff --git a/sync/blocksync/blocksync.go b/sync/blocksync/blocksync.go index 15bf974..4e17d47 100644 --- a/sync/blocksync/blocksync.go +++ b/sync/blocksync/blocksync.go @@ -11,6 +11,56 @@ import ( "github.com/KYVENetwork/ksync/utils" ) +func Start() error { + logger.Logger.Info().Msg("starting block-sync") + + app, err := app.NewCosmosApp() + if err != nil { + return fmt.Errorf("failed to init cosmos app: %w", err) + } + + if flags.Reset { + if err := app.ConsensusEngine.ResetAll(true); err != nil { + return fmt.Errorf("failed to reset cosmos app: %w", err) + } + } + + continuationHeight := app.GetContinuationHeight() + metrics.SetContinuationHeight(continuationHeight) + + blockCollector, err := getBlockCollector(app) + if err != nil { + return err + } + + if err := PerformBlockSyncValidationChecks(blockCollector, continuationHeight, flags.TargetHeight); err != nil { + return fmt.Errorf("block-sync validation checks failed: %w", err) + } + + if confirmation, err := getUserConfirmation(flags.Y, continuationHeight, flags.TargetHeight); !confirmation { + return err + } + + if err := app.AutoSelectBinaryVersion(continuationHeight); err != nil { + return fmt.Errorf("failed to auto select binary version: %w", err) + } + + if err := app.StartAll(0); err != nil { + return fmt.Errorf("failed to start app: %w", err) + } + + defer app.StopAll() + + // we only pass the snapshot collector to the block executor if we are creating + // state-sync snapshots with serve-snapshots + if err := StartBlockSyncExecutor(app, blockCollector, nil); err != nil { + return fmt.Errorf("failed to start block-sync executor: %w", err) + } + + logger.Logger.Info().Str("duration", metrics.GetSyncDuration().String()).Msgf("successfully finished block-sync by reaching target height %d", flags.TargetHeight) + return nil +} + // PerformBlockSyncValidationChecks makes boundary checks if app can be block-synced from the given // continuation height to the given target height func PerformBlockSyncValidationChecks(blockCollector types.BlockCollector, continuationHeight, targetHeight int64) error { @@ -80,53 +130,3 @@ func getUserConfirmation(y bool, continuationHeight, targetHeight int64) (bool, return utils.GetUserConfirmationInput() } - -func Start() error { - logger.Logger.Info().Msg("starting block-sync") - - app, err := app.NewCosmosApp() - if err != nil { - return fmt.Errorf("failed to init cosmos app: %w", err) - } - - if flags.Reset { - if err := app.ConsensusEngine.ResetAll(true); err != nil { - return fmt.Errorf("failed to reset cosmos app: %w", err) - } - } - - continuationHeight := app.GetContinuationHeight() - metrics.SetContinuationHeight(continuationHeight) - - blockCollector, err := getBlockCollector(app) - if err != nil { - return err - } - - if err := PerformBlockSyncValidationChecks(blockCollector, continuationHeight, flags.TargetHeight); err != nil { - return fmt.Errorf("block-sync validation checks failed: %w", err) - } - - if confirmation, err := getUserConfirmation(flags.Y, continuationHeight, flags.TargetHeight); !confirmation { - return err - } - - if err := app.AutoSelectBinaryVersion(continuationHeight); err != nil { - return fmt.Errorf("failed to auto select binary version: %w", err) - } - - if err := app.StartAll(0); err != nil { - return fmt.Errorf("failed to start app: %w", err) - } - - defer app.StopAll() - - // we only pass the snapshot collector to the block executor if we are creating - // state-sync snapshots with serve-snapshots - if err := StartBlockSyncExecutor(app, blockCollector, nil); err != nil { - return fmt.Errorf("failed to start block-sync executor: %w", err) - } - - logger.Logger.Info().Str("duration", metrics.GetSyncDuration().String()).Msgf("successfully finished block-sync by reaching target height %d", flags.TargetHeight) - return nil -} diff --git a/sync/heightsync/heightsync.go b/sync/heightsync/heightsync.go index 7980eb2..3f03a42 100644 --- a/sync/heightsync/heightsync.go +++ b/sync/heightsync/heightsync.go @@ -12,26 +12,6 @@ import ( "github.com/KYVENetwork/ksync/utils" ) -func getUserConfirmation(y, canApplySnapshot bool, snapshotHeight, continuationHeight, targetHeight int64) (bool, error) { - if y { - return true, nil - } - - if canApplySnapshot { - if targetHeight == 0 { - fmt.Printf("\u001B[36m[KSYNC]\u001B[0m no target height specified, state-sync to height %d and sync indefinitely from there [y/N]: ", snapshotHeight) - } else if snapshotHeight == targetHeight { - fmt.Printf("\u001B[36m[KSYNC]\u001B[0m should target height %d be reached by applying a snapshot at height %d [y/N]: ", targetHeight, snapshotHeight) - } else { - fmt.Printf("\u001B[36m[KSYNC]\u001B[0m should target height %d be reached by applying a snapshot at height %d and syncing the remaining %d blocks [y/N]: ", targetHeight, snapshotHeight, targetHeight-(continuationHeight-1)) - } - } else { - fmt.Printf("\u001B[36m[KSYNC]\u001B[0m should target height %d be reached by syncing from height %d [y/N]: ", targetHeight, continuationHeight-1) - } - - return utils.GetUserConfirmationInput() -} - func Start() error { logger.Logger.Info().Msg("starting height-sync") @@ -130,3 +110,23 @@ func Start() error { logger.Logger.Info().Str("duration", metrics.GetSyncDuration().String()).Msgf("successfully finished height-sync by reaching target height %d", flags.TargetHeight) return nil } + +func getUserConfirmation(y, canApplySnapshot bool, snapshotHeight, continuationHeight, targetHeight int64) (bool, error) { + if y { + return true, nil + } + + if canApplySnapshot { + if targetHeight == 0 { + fmt.Printf("\u001B[36m[KSYNC]\u001B[0m no target height specified, state-sync to height %d and sync indefinitely from there [y/N]: ", snapshotHeight) + } else if snapshotHeight == targetHeight { + fmt.Printf("\u001B[36m[KSYNC]\u001B[0m should target height %d be reached by applying a snapshot at height %d [y/N]: ", targetHeight, snapshotHeight) + } else { + fmt.Printf("\u001B[36m[KSYNC]\u001B[0m should target height %d be reached by applying a snapshot at height %d and syncing the remaining %d blocks [y/N]: ", targetHeight, snapshotHeight, targetHeight-(continuationHeight-1)) + } + } else { + fmt.Printf("\u001B[36m[KSYNC]\u001B[0m should target height %d be reached by syncing from height %d [y/N]: ", targetHeight, continuationHeight-1) + } + + return utils.GetUserConfirmationInput() +} diff --git a/sync/statesync/statesync.go b/sync/statesync/statesync.go index 7f3c383..0deaad7 100644 --- a/sync/statesync/statesync.go +++ b/sync/statesync/statesync.go @@ -11,42 +11,6 @@ import ( "github.com/KYVENetwork/ksync/utils" ) -// PerformStateSyncValidationChecks makes boundary checks for the given snapshot height -func PerformStateSyncValidationChecks(snapshotCollector types.SnapshotCollector, snapshotHeight int64) error { - earliest := snapshotCollector.GetEarliestAvailableHeight() - latest := snapshotCollector.GetLatestAvailableHeight() - - logger.Logger.Info().Msgf("retrieved snapshot boundaries, earliest complete snapshot height = %d, latest complete snapshot height %d", earliest, latest) - - if snapshotHeight < earliest { - return fmt.Errorf("requested snapshot height is %d but first available snapshot on pool is %d", snapshotHeight, earliest) - } - - if snapshotHeight > latest { - return fmt.Errorf("requested snapshot height is %d but latest available snapshot on pool is %d", snapshotHeight, latest) - } - - return nil -} - -func getUserConfirmation(y bool, snapshotHeight, targetHeight int64) (bool, error) { - if y { - return true, nil - } - - // if we found a different snapshotHeight as the requested targetHeight it means there was no snapshot - // at the requested targetHeight. Ask the user here if KSYNC should sync to the nearest height instead - if targetHeight == 0 { - fmt.Printf("\u001B[36m[KSYNC]\u001B[0m no target height specified, state-sync to latest available snapshot with height %d [y/N]: ", snapshotHeight) - } else if snapshotHeight == targetHeight { - fmt.Printf("\u001B[36m[KSYNC]\u001B[0m should snapshot with height %d be applied with state-sync [y/N]: ", snapshotHeight) - } else { - fmt.Printf("\u001B[36m[KSYNC]\u001B[0m could not find snapshot with requested height %d, state-sync to nearest available snapshot with height %d instead? [y/N]: ", targetHeight, snapshotHeight) - } - - return utils.GetUserConfirmationInput() -} - func Start() error { logger.Logger.Info().Msg("starting state-sync") @@ -107,3 +71,39 @@ func Start() error { logger.Logger.Info().Str("duration", metrics.GetSyncDuration().String()).Msgf("successfully finished state-sync by applying snapshot at height %d", snapshotHeight) return nil } + +// PerformStateSyncValidationChecks makes boundary checks for the given snapshot height +func PerformStateSyncValidationChecks(snapshotCollector types.SnapshotCollector, snapshotHeight int64) error { + earliest := snapshotCollector.GetEarliestAvailableHeight() + latest := snapshotCollector.GetLatestAvailableHeight() + + logger.Logger.Info().Msgf("retrieved snapshot boundaries, earliest complete snapshot height = %d, latest complete snapshot height %d", earliest, latest) + + if snapshotHeight < earliest { + return fmt.Errorf("requested snapshot height is %d but first available snapshot on pool is %d", snapshotHeight, earliest) + } + + if snapshotHeight > latest { + return fmt.Errorf("requested snapshot height is %d but latest available snapshot on pool is %d", snapshotHeight, latest) + } + + return nil +} + +func getUserConfirmation(y bool, snapshotHeight, targetHeight int64) (bool, error) { + if y { + return true, nil + } + + // if we found a different snapshotHeight as the requested targetHeight it means there was no snapshot + // at the requested targetHeight. Ask the user here if KSYNC should sync to the nearest height instead + if targetHeight == 0 { + fmt.Printf("\u001B[36m[KSYNC]\u001B[0m no target height specified, state-sync to latest available snapshot with height %d [y/N]: ", snapshotHeight) + } else if snapshotHeight == targetHeight { + fmt.Printf("\u001B[36m[KSYNC]\u001B[0m should snapshot with height %d be applied with state-sync [y/N]: ", snapshotHeight) + } else { + fmt.Printf("\u001B[36m[KSYNC]\u001B[0m could not find snapshot with requested height %d, state-sync to nearest available snapshot with height %d instead? [y/N]: ", targetHeight, snapshotHeight) + } + + return utils.GetUserConfirmationInput() +}