Skip to content

Commit

Permalink
feat: check latest block if no arg in q block and q block-results (
Browse files Browse the repository at this point in the history
…#21084)

(cherry picked from commit c4de9a9)

# Conflicts:
#	server/cmt_cmds.go
  • Loading branch information
julienrbrt authored and mergify[bot] committed Jul 29, 2024
1 parent e135030 commit 80ac1fe
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions server/cmt_cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,32 +226,51 @@ $ %s query block --%s=%s <hash>
`,
version.AppName, auth.FlagType, auth.TypeHeight,
version.AppName, auth.FlagType, auth.TypeHash)),
Args: cobra.ExactArgs(1),
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

typ, _ := cmd.Flags().GetString(auth.FlagType)
if len(args) == 0 {
// do not break default v0.50 behavior of block hash
// if no args are provided, set the type to height
typ = auth.TypeHeight
}

switch typ {
case auth.TypeHeight:
<<<<<<< HEAD

Check failure on line 245 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected statement, found '<<'

Check failure on line 245 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected <<, expected case or default or }

Check failure on line 245 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected <<, expected case or default or }

Check failure on line 245 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected <<, expected case or default or }

Check failure on line 245 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected <<, expected case or default or }

if args[0] == "" {

Check failure on line 247 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected if, expected :

Check failure on line 247 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected if, expected :

Check failure on line 247 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected if, expected :

Check failure on line 247 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected if, expected :
return fmt.Errorf("argument should be a block height")
=======

Check failure on line 249 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected statement, found '=='

Check failure on line 249 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ==, expected case or default or }

Check failure on line 249 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ==, expected case or default or }

Check failure on line 249 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ==, expected case or default or }

Check failure on line 249 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expected case or default or }
var (

Check failure on line 250 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected var, expected :

Check failure on line 250 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected var, expected :

Check failure on line 250 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected var, expected :

Check failure on line 250 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected var, expected :
err error

Check failure on line 251 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected error, expected )

Check failure on line 251 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected error, expected )

Check failure on line 251 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected error, expected )

Check failure on line 251 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected error, expected )
height int64

Check failure on line 252 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected int64 at end of statement

Check failure on line 252 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected int64 at end of statement

Check failure on line 252 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected int64 at end of statement

Check failure on line 252 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected int64 at end of statement
)

Check failure on line 253 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected ), expected case or default or }

Check failure on line 253 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected ), expected case or default or }

Check failure on line 253 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected ), expected case or default or }

Check failure on line 253 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ), expected case or default or }
heightStr := ""
if len(args) > 0 {

Check failure on line 255 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected if, expected :

Check failure on line 255 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected if, expected :

Check failure on line 255 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected if, expected :

Check failure on line 255 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected if, expected :
heightStr = args[0]
>>>>>>> c4de9a970 (feat: check latest block if no arg in `q block` and `q block-results` (#21084))

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected statement, found '>>'

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found arg

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected '{', found `q block`

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found `q block-results`

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

syntax error: unexpected >>, expected case or default or }

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (02)

invalid character U+0023 '#'

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

syntax error: unexpected >>, expected case or default or }

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (03)

invalid character U+0023 '#'

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

syntax error: unexpected >>, expected case or default or }

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (01)

invalid character U+0023 '#'

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expected case or default or }

Check failure on line 257 in server/cmt_cmds.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
}

// optional height
var height *int64
if len(args) > 0 {
height, err = parseOptionalHeight(args[0])
if heightStr == "" {
cmd.Println("Falling back to latest block height:")
height, err = rpc.GetChainHeight(clientCtx)
if err != nil {
return err
return fmt.Errorf("failed to get chain height: %w", err)
}
} else {
height, err = strconv.ParseInt(heightStr, 10, 64)
if err != nil {
return fmt.Errorf("failed to parse block height: %w", err)
}
}

output, err := rpc.GetBlockByHeight(clientCtx, height)
output, err := rpc.GetBlockByHeight(clientCtx, &height)
if err != nil {
return err
}
Expand Down Expand Up @@ -311,15 +330,21 @@ func QueryBlockResultsCmd() *cobra.Command {
}

// optional height
var height *int64
var height int64
if len(args) > 0 {
height, err = parseOptionalHeight(args[0])
height, err = strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}
} else {
cmd.Println("Falling back to latest block height:")
height, err = rpc.GetChainHeight(clientCtx)
if err != nil {
return fmt.Errorf("failed to get chain height: %w", err)
}
}

blockRes, err := node.BlockResults(context.Background(), height)
blockRes, err := node.BlockResults(context.Background(), &height)
if err != nil {
return err
}
Expand All @@ -341,6 +366,7 @@ func QueryBlockResultsCmd() *cobra.Command {
return cmd
}

<<<<<<< HEAD
func parseOptionalHeight(heightStr string) (*int64, error) {
h, err := strconv.Atoi(heightStr)
if err != nil {
Expand All @@ -357,6 +383,9 @@ func parseOptionalHeight(heightStr string) (*int64, error) {
}

func BootstrapStateCmd(appCreator types.AppCreator) *cobra.Command {
=======
func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cobra.Command {
>>>>>>> c4de9a970 (feat: check latest block if no arg in `q block` and `q block-results` (#21084))
cmd := &cobra.Command{
Use: "bootstrap-state",
Short: "Bootstrap CometBFT state at an arbitrary block height using a light client",
Expand Down

0 comments on commit 80ac1fe

Please sign in to comment.