Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rpc): fix commands handling #2515

Merged
merged 6 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cmd/celestia/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ import (
"github.com/celestiaorg/celestia-node/share"
)

var plaintext bool
var base64Flag bool

func init() {
blobCmd.AddCommand(getCmd, getAllCmd, submitCmd, getProofCmd)

getCmd.PersistentFlags().BoolVar(
&plaintext,
"plaintext",
&base64Flag,
"base64",
false,
"printed blob's data as a plain text",
"printed blob's data a base64 string",
)
getAllCmd.PersistentFlags().BoolVar(
&plaintext,
"plaintext",
&base64Flag,
"base64",
false,
"printed blob's data as a plain text",
"printed blob's data as a base64 string",
)
}

Expand Down Expand Up @@ -170,7 +170,7 @@ func printOutput(data interface{}, err error) {
data = err
}

if plaintext && err == nil {
if !base64Flag && err == nil {
data = formatData(data)
}

Expand Down
26 changes: 24 additions & 2 deletions cmd/celestia/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,17 @@ var rpcCmd = &cobra.Command{

func parseParams(method string, params []string) []interface{} {
parsedParams := make([]interface{}, len(params))

validateParamsFn := func(has, want int) error {
if has < want {
return fmt.Errorf("rpc: invalid amount of params. has=%d, want=%d", has, want)
}
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
switch method {
case "GetSharesByNamespace":
if err := validateParamsFn(len(params), 2); err != nil {
panic(err)
}
// 1. Share Root
root, err := parseJSON(params[0])
if err != nil {
Expand All @@ -134,8 +142,12 @@ func parseParams(method string, params []string) []interface{} {
panic(fmt.Sprintf("Error parsing namespace: %v", err))
}
parsedParams[1] = namespace
return parsedParams
case "QueryDelegation", "QueryUnbonding", "BalanceForAddress":
var err error
if err = validateParamsFn(len(params), 2); err != nil {
panic(err)
}
parsedParams[0], err = parseAddressFromString(params[0])
if err != nil {
panic(fmt.Errorf("error parsing address: %w", err))
Expand All @@ -155,6 +167,9 @@ func parseParams(method string, params []string) []interface{} {
case "Transfer", "Delegate", "Undelegate":
// 1. Address
var err error
if err = validateParamsFn(len(params), 4); err != nil {
panic(err)
}
parsedParams[0], err = parseAddressFromString(params[0])
if err != nil {
panic(fmt.Errorf("error parsing address: %w", err))
Expand All @@ -172,6 +187,9 @@ func parseParams(method string, params []string) []interface{} {
case "CancelUnbondingDelegation":
// 1. Validator Address
var err error
if err = validateParamsFn(len(params), 5); err != nil {
panic(err)
}
parsedParams[0], err = parseAddressFromString(params[0])
if err != nil {
panic(fmt.Errorf("error parsing address: %w", err))
Expand All @@ -186,9 +204,13 @@ func parseParams(method string, params []string) []interface{} {
panic("Error parsing gas limit: uint64 could not be parsed.")
}
parsedParams[4] = num
return parsedParams
case "BeginRedelegate":
// 1. Source Validator Address
var err error
if err = validateParamsFn(len(params), 5); err != nil {
panic(err)
}
parsedParams[0], err = parseAddressFromString(params[0])
if err != nil {
panic(fmt.Errorf("error parsing address: %w", err))
Expand All @@ -207,6 +229,7 @@ func parseParams(method string, params []string) []interface{} {
panic("Error parsing gas limit: uint64 could not be parsed.")
}
parsedParams[4] = num
return parsedParams
default:
}

Expand All @@ -228,7 +251,6 @@ func parseParams(method string, params []string) []interface{} {
parsedParams[i] = param
}
}

return parsedParams
}

Expand Down
8 changes: 7 additions & 1 deletion share/getters/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package getters
import (
"context"
"errors"
"fmt"

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -37,7 +38,12 @@ func (cg *CascadeGetter) GetShare(ctx context.Context, root *share.Root, row, co
attribute.Int("col", col),
))
defer span.End()

if row >= len(root.RowRoots) || col >= len(root.ColumnRoots) {
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
err := fmt.Errorf("cascade/get-share: invalid indexes were provided:rowIndex=%d, colIndex=%d."+
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
"rowsAmount=%d, colsAmount=%d", row, col, len(root.RowRoots), len(root.ColumnRoots))
vgonkivs marked this conversation as resolved.
Show resolved Hide resolved
span.RecordError(err)
return nil, err
}
get := func(ctx context.Context, get share.Getter) (share.Share, error) {
return get.GetShare(ctx, root, row, col)
}
Expand Down
Loading