Skip to content

Commit

Permalink
fix: engine selection & target-height (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
troykessler authored Jul 16, 2024
1 parent bb46411 commit 1f18f03
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cmd/ksync/commands/blocksync.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func init() {
blockSyncCmd.Flags().StringVarP(&engine, "engine", "e", utils.DefaultEngine, fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))
blockSyncCmd.Flags().StringVarP(&engine, "engine", "e", "", fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))

blockSyncCmd.Flags().StringVarP(&binaryPath, "binary", "b", "", "binary path of node to be synced")
if err := blockSyncCmd.MarkFlagRequired("binary"); err != nil {
Expand Down
15 changes: 14 additions & 1 deletion cmd/ksync/commands/heightsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"
"github.com/KYVENetwork/ksync/blocksync"
blocksyncHelpers "github.com/KYVENetwork/ksync/blocksync/helpers"
"github.com/KYVENetwork/ksync/engines"
"github.com/KYVENetwork/ksync/heightsync"
"github.com/KYVENetwork/ksync/sources"
Expand All @@ -13,7 +14,7 @@ import (
)

func init() {
heightSyncCmd.Flags().StringVarP(&engine, "engine", "e", utils.DefaultEngine, fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))
heightSyncCmd.Flags().StringVarP(&engine, "engine", "e", "", fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))

heightSyncCmd.Flags().StringVarP(&binaryPath, "binary", "b", "", "binary path of node to be synced")
if err := heightSyncCmd.MarkFlagRequired("binary"); err != nil {
Expand Down Expand Up @@ -74,6 +75,18 @@ var heightSyncCmd = &cobra.Command{
os.Exit(1)
}

_, _, blockEndHeight, err := blocksyncHelpers.GetBlockBoundaries(chainRest, nil, &bId)
if err != nil {
logger.Error().Msg(fmt.Sprintf("failed to get block boundaries: %s", err))
os.Exit(1)
}

// if target height was not specified we sync to the latest available height
if targetHeight == 0 {
targetHeight = blockEndHeight
logger.Info().Msg(fmt.Sprintf("target height not specified, searching for latest available block height"))
}

// perform validation checks before booting state-sync process
snapshotBundleId, snapshotHeight, err := heightsync.PerformHeightSyncValidationChecks(defaultEngine, chainRest, sId, &bId, targetHeight, !y)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ksync/commands/resetall.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func init() {
resetCmd.Flags().StringVarP(&engine, "engine", "e", utils.DefaultEngine, fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))
resetCmd.Flags().StringVarP(&engine, "engine", "e", "", fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))

resetCmd.Flags().StringVar(&homePath, "home", "", "home directory")
if err := resetCmd.MarkFlagRequired("home"); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ksync/commands/serveblocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func init() {
serveBlocksCmd.Flags().StringVarP(&engine, "engine", "e", utils.DefaultEngine, fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))
serveBlocksCmd.Flags().StringVarP(&engine, "engine", "e", "", fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))

serveBlocksCmd.Flags().StringVarP(&binaryPath, "binary", "b", "", "binary path of node to be synced")
if err := serveBlocksCmd.MarkFlagRequired("binary"); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ksync/commands/servesnapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func init() {
servesnapshotsCmd.Flags().StringVarP(&engine, "engine", "e", utils.DefaultEngine, fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))
servesnapshotsCmd.Flags().StringVarP(&engine, "engine", "e", "", fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))

servesnapshotsCmd.Flags().StringVarP(&binaryPath, "binary", "b", "", "binary path of node to be synced")
if err := servesnapshotsCmd.MarkFlagRequired("binary"); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/ksync/commands/statesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func init() {
stateSyncCmd.Flags().StringVarP(&engine, "engine", "e", utils.DefaultEngine, fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))
stateSyncCmd.Flags().StringVarP(&engine, "engine", "e", "", fmt.Sprintf("consensus engine of the binary by default %s is used, list all engines with \"ksync engines\"", utils.DefaultEngine))

stateSyncCmd.Flags().StringVarP(&binaryPath, "binary", "b", "", "binary path of node to be synced")
if err := stateSyncCmd.MarkFlagRequired("binary"); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion engines/engines.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func EngineSourceFactory(engine, registryUrl, source string, continuationHeight
func EngineFactory(engine string) types.Engine {
switch engine {
case "":
return &tendermint_v34.Engine{}
return &cometbft_v38.Engine{}
case utils.EngineTendermintV34:
return &tendermint_v34.Engine{}
case utils.EngineCometBFTV37:
Expand Down
13 changes: 0 additions & 13 deletions heightsync/heightsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package heightsync
import (
"fmt"
"github.com/KYVENetwork/ksync/blocksync"
blocksyncHelpers "github.com/KYVENetwork/ksync/blocksync/helpers"
"github.com/KYVENetwork/ksync/bootstrap"
"github.com/KYVENetwork/ksync/statesync"
"github.com/KYVENetwork/ksync/types"
Expand All @@ -20,18 +19,6 @@ var (
// PerformHeightSyncValidationChecks checks if the targetHeight lies in the range of available blocks and checks
// if a state-sync snapshot is available right before the targetHeight
func PerformHeightSyncValidationChecks(engine types.Engine, chainRest string, snapshotPoolId int64, blockPoolId *int64, targetHeight int64, userInput bool) (snapshotBundleId, snapshotHeight int64, err error) {
_, _, blockEndHeight, err := blocksyncHelpers.GetBlockBoundaries(chainRest, nil, blockPoolId)
if err != nil {
logger.Error().Msg(fmt.Sprintf("failed to get block boundaries: %s", err))
os.Exit(1)
}

// if target height was not specified we sync to the latest available height
if targetHeight == 0 {
targetHeight = blockEndHeight
logger.Info().Msg(fmt.Sprintf("target height not specified, searching for latest available block height"))
}

if _, err := blocksync.PerformBlockSyncValidationChecks(engine, chainRest, nil, blockPoolId, targetHeight, true, false); err != nil {
logger.Error().Msg(fmt.Sprintf("block-sync validation checks failed: %s", err))
os.Exit(1)
Expand Down
6 changes: 4 additions & 2 deletions statesync/statesync.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ func PerformStateSyncValidationChecks(chainRest string, snapshotPoolId, targetHe
return snapshotBundleId, snapshotHeight, fmt.Errorf("requested snapshot height %d but first available snapshot on pool is %d", targetHeight, startHeight)
}

// limit snapshot search height by latest available snapshot height
snapshotSearchHeight := targetHeight
if targetHeight > endHeight {
return snapshotBundleId, snapshotHeight, fmt.Errorf("requested snapshot height %d but last available snapshot on pool is %d", targetHeight, endHeight)
snapshotSearchHeight = endHeight
}

snapshotBundleId, snapshotHeight, err = snapshots.FindNearestSnapshotBundleIdByHeight(chainRest, snapshotPoolId, targetHeight)
snapshotBundleId, snapshotHeight, err = snapshots.FindNearestSnapshotBundleIdByHeight(chainRest, snapshotPoolId, snapshotSearchHeight)
if err != nil {
return
}
Expand Down

0 comments on commit 1f18f03

Please sign in to comment.