Skip to content

Commit

Permalink
Merge branch 'ibc-alpha' of https://github.com/cosmos/cosmos-sdk into…
Browse files Browse the repository at this point in the history
… ibc-alpha
  • Loading branch information
AdityaSripal committed Nov 12, 2019
2 parents e12d247 + ae8ea8f commit 2de199f
Show file tree
Hide file tree
Showing 157 changed files with 5,730 additions and 1,041 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ if the provided arguments are invalid.

### Client Breaking Changes

* (rest) [\#5270](https://github.com/cosmos/cosmos-sdk/issues/5270) All account types now implement custom JSON serialization.
* (rest) [\#4783](https://github.com/cosmos/cosmos-sdk/issues/4783) The balance field in the DelegationResponse type is now sdk.Coin instead of sdk.Int
* (x/auth) [\#5006](https://github.com/cosmos/cosmos-sdk/pull/5006) The gas required to pass the `AnteHandler` has
increased significantly due to modular `AnteHandler` support. Increase GasLimit accordingly.

### Features

* (x/evidence) [\#5240](https://github.com/cosmos/cosmos-sdk/pull/5240) Initial implementation of the `x/evidence` module.
* (cli) [\#5212](https://github.com/cosmos/cosmos-sdk/issues/5212) The `q gov proposals` command now supports pagination.
* (store) [\#4724](https://github.com/cosmos/cosmos-sdk/issues/4724) Multistore supports substore migrations upon load. New `rootmulti.Store.LoadLatestVersionAndUpgrade` method in
`Baseapp` supports `StoreLoader` to enable various upgrade strategies. It no
Expand All @@ -98,6 +100,7 @@ upgrade via: `sudo rm -rf /Library/Developer/CommandLineTools; xcode-select --in
correct version via: `pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`.
* (keys) [\#5097](https://github.com/cosmos/cosmos-sdk/pull/5097) New `keys migrate` command to assist users migrate their keys
to the new keyring.
* (modules) [\#4233](https://github.com/cosmos/cosmos-sdk/pull/4233) Add upgrade module that coordinates software upgrades of live chains.
* [\#4486](https://github.com/cosmos/cosmos-sdk/issues/4486) Introduce new `PeriodicVestingAccount` vesting account type
that allows for arbitrary vesting periods.
* (baseapp) [\#5196](https://github.com/cosmos/cosmos-sdk/pull/5196) Baseapp has a new `runTxModeReCheck` to allow applications to skip expensive and unnecessary re-checking of transactions.
Expand Down Expand Up @@ -182,6 +185,7 @@ to detail this new feature and how state transitions occur.

### Bug Fixes

* (iavl) [\#5276](https://github.com/cosmos/cosmos-sdk/issues/5276) Fix potential race condition in `iavlIterator#Close`.
* (cli) [\#4763](https://github.com/cosmos/cosmos-sdk/issues/4763) Fix flag `--min-self-delegation` for staking `EditValidator`
* (keys) Fix ledger custom coin type support bug
* (x/gov) [\#5107](https://github.com/cosmos/cosmos-sdk/pull/5107) Sum validator operator's all voting power when tally votes
Expand Down
2 changes: 1 addition & 1 deletion client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func NewCLIContextWithFrom(from string) CLIContext {
return ctx.WithVerifier(verifier)
}

// NewCLIContextIBC takes additional arguements
// NewCLIContextIBC takes additional arguments
func NewCLIContextIBC(from string, chainID string, nodeURI string) CLIContext {
var rpc rpcclient.Client

Expand Down
24 changes: 11 additions & 13 deletions client/context/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,18 @@ func (ctx CLIContext) GetFromName() string {
return ctx.FromName
}

func (ctx CLIContext) queryABCI(req abci.RequestQuery) (resp abci.ResponseQuery, err error) {

func (ctx CLIContext) queryABCI(req abci.RequestQuery) (abci.ResponseQuery, error) {
node, err := ctx.GetNode()
if err != nil {
return resp, err
return abci.ResponseQuery{}, err
}

// When a client did not provide a query height, manually query for it so it can
// be injected downstream into responses.
if ctx.Height == 0 {
status, err := node.Status()
if err != nil {
return resp, err
return abci.ResponseQuery{}, err
}
ctx = ctx.WithHeight(status.SyncInfo.LatestBlockHeight)
}
Expand All @@ -153,26 +152,25 @@ func (ctx CLIContext) queryABCI(req abci.RequestQuery) (resp abci.ResponseQuery,

result, err := node.ABCIQueryWithOptions(req.Path, req.Data, opts)
if err != nil {
return
return abci.ResponseQuery{}, err
}

resp = result.Response
if !resp.IsOK() {
err = errors.New(resp.Log)
return
if !result.Response.IsOK() {
err = errors.New(result.Response.Log)
return abci.ResponseQuery{}, err
}

// data from trusted node or subspace query doesn't need verification
if ctx.TrustNode || !isQueryStoreWithProof(req.Path) {
return resp, nil
return result.Response, nil
}

err = ctx.verifyProof(req.Path, resp)
err = ctx.verifyProof(req.Path, result.Response)
if err != nil {
return
return abci.ResponseQuery{}, err
}

return
return result.Response, nil
}

// query performs a query to a Tendermint node with the provided store name
Expand Down
185 changes: 185 additions & 0 deletions client/debug/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package debug

import (
"encoding/base64"
"encoding/hex"
"fmt"
"strconv"
"strings"

"github.com/spf13/cobra"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
)

func Cmd(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "debug",
Short: "Tool for helping with debugging your application",
RunE: client.ValidateCmd,
}

cmd.AddCommand(PubkeyCmd(cdc))
cmd.AddCommand(AddrCmd())
cmd.AddCommand(RawBytesCmd())

return cmd
}

func PubkeyCmd(cdc *codec.Codec) *cobra.Command {
return &cobra.Command{
Use: "pubkey [pubkey]",
Short: "Decode a pubkey from hex, base64, or bech32",
Long: fmt.Sprintf(`Decode a pubkey from hex, base64, or bech32.
Example:
$ %s debug pubkey TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
$ %s debug pubkey cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
`, version.ClientName, version.ClientName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

pubkeyString := args[0]
var pubKeyI crypto.PubKey

// try hex, then base64, then bech32
pubkeyBytes, err := hex.DecodeString(pubkeyString)
if err != nil {
var err2 error
pubkeyBytes, err2 = base64.StdEncoding.DecodeString(pubkeyString)
if err2 != nil {
var err3 error
pubKeyI, err3 = sdk.GetAccPubKeyBech32(pubkeyString)
if err3 != nil {
var err4 error
pubKeyI, err4 = sdk.GetValPubKeyBech32(pubkeyString)

if err4 != nil {
var err5 error
pubKeyI, err5 = sdk.GetConsPubKeyBech32(pubkeyString)
if err5 != nil {
return fmt.Errorf("expected hex, base64, or bech32. Got errors: hex: %v, base64: %v, bech32 Acc: %v, bech32 Val: %v, bech32 Cons: %v",
err, err2, err3, err4, err5)
}

}
}

}
}

var pubKey ed25519.PubKeyEd25519
if pubKeyI == nil {
copy(pubKey[:], pubkeyBytes)
} else {
pubKey = pubKeyI.(ed25519.PubKeyEd25519)
pubkeyBytes = pubKey[:]
}

pubKeyJSONBytes, err := cdc.MarshalJSON(pubKey)
if err != nil {
return err
}
accPub, err := sdk.Bech32ifyAccPub(pubKey)
if err != nil {
return err
}
valPub, err := sdk.Bech32ifyValPub(pubKey)
if err != nil {
return err
}

consenusPub, err := sdk.Bech32ifyConsPub(pubKey)
if err != nil {
return err
}
cmd.Println("Address:", pubKey.Address())
cmd.Printf("Hex: %X\n", pubkeyBytes)
cmd.Println("JSON (base64):", string(pubKeyJSONBytes))
cmd.Println("Bech32 Acc:", accPub)
cmd.Println("Bech32 Validator Operator:", valPub)
cmd.Println("Bech32 Validator Consensus:", consenusPub)
return nil
},
}
}

func AddrCmd() *cobra.Command {
return &cobra.Command{
Use: "addr [address]",
Short: "Convert an address between hex and bech32",
Long: fmt.Sprintf(`Convert an address between hex encoding and bech32.
Example:
$ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
`, version.ClientName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

addrString := args[0]
var addr []byte

// try hex, then bech32
var err error
addr, err = hex.DecodeString(addrString)
if err != nil {
var err2 error
addr, err2 = sdk.AccAddressFromBech32(addrString)
if err2 != nil {
var err3 error
addr, err3 = sdk.ValAddressFromBech32(addrString)

if err3 != nil {
return fmt.Errorf("expected hex or bech32. Got errors: hex: %v, bech32 acc: %v, bech32 val: %v", err, err2, err3)

}
}
}

accAddr := sdk.AccAddress(addr)
valAddr := sdk.ValAddress(addr)

cmd.Println("Address:", addr)
cmd.Printf("Address (hex): %X\n", addr)
cmd.Printf("Bech32 Acc: %s\n", accAddr)
cmd.Printf("Bech32 Val: %s\n", valAddr)
return nil
},
}
}

func RawBytesCmd() *cobra.Command {
return &cobra.Command{
Use: "raw-bytes [raw-bytes]",
Short: "Convert raw bytes output (eg. [10 21 13 255]) to hex",
Long: fmt.Sprintf(`Convert raw-bytes to hex.
Example:
$ %s debug raw-bytes [72 101 108 108 111 44 32 112 108 97 121 103 114 111 117 110 100]
`, version.ClientName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
stringBytes := args[0]
stringBytes = strings.Trim(stringBytes, "[")
stringBytes = strings.Trim(stringBytes, "]")
spl := strings.Split(stringBytes, " ")

byteArray := []byte{}
for _, s := range spl {
b, err := strconv.Atoi(s)
if err != nil {
return err
}
byteArray = append(byteArray, byte(b))
}
fmt.Printf("%X\n", byteArray)
return nil
},
}
}
13 changes: 8 additions & 5 deletions docs/architecture/adr-009-evidence-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
## Changelog

- 2019 July 31: Initial draft
- 2019 October 24: Initial implementation

## Status

Proposed
Accepted

## Context

Expand Down Expand Up @@ -55,7 +56,8 @@ type Evidence interface {
Route() string
Type() string
String() string
ValidateBasic() Error
Hash() HexBytes
ValidateBasic() error

// The consensus address of the malicious validator at time of infraction
GetConsensusAddress() ConsAddress
Expand All @@ -78,7 +80,7 @@ the `x/evidence` module. It accomplishes this through the `Router` implementatio

```go
type Router interface {
AddRoute(r string, h Handler)
AddRoute(r string, h Handler) Router
HasRoute(r string) bool
GetRoute(path string) Handler
Seal()
Expand All @@ -97,7 +99,7 @@ necessary in order for the `Handler` to make the necessary state transitions.
If no error is returned, the `Evidence` is considered valid.

```go
type Handler func(Context, Evidence) Error
type Handler func(Context, Evidence) error
```

### Submission
Expand Down Expand Up @@ -128,7 +130,7 @@ the module's router and invoking the corresponding `Handler` which may include
slashing and jailing the validator. Upon success, the submitted evidence is persisted.

```go
func (k Keeper) SubmitEvidence(ctx Context, evidence Evidence) Error {
func (k Keeper) SubmitEvidence(ctx Context, evidence Evidence) error {
handler := keeper.router.GetRoute(evidence.Route())
if err := handler(ctx, evidence); err != nil {
return ErrInvalidEvidence(keeper.codespace, err)
Expand Down Expand Up @@ -177,3 +179,4 @@ due to the inability to introduce the new evidence type's corresponding handler

- [ICS](https://github.com/cosmos/ics)
- [IBC Architecture](https://github.com/cosmos/ics/blob/master/ibc/1_IBC_ARCHITECTURE.md)
- [Tendermint Fork Accountability](https://github.com/tendermint/tendermint/blob/master/docs/spec/consensus/fork-accountability.md)
Loading

0 comments on commit 2de199f

Please sign in to comment.