-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into realu/devgas-cli
- Loading branch information
Showing
7 changed files
with
439 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,12 @@ | |
- [What is Chaosnet?](#what-is-chaosnet) | ||
- [How to run "chaosnet"](#how-to-run-chaosnet) | ||
- [How to force pull images from the registry](#how-to-force-pull-images-from-the-registry) | ||
- [IBC Commands](#ibc-commands) | ||
- [Endpoints](#endpoints) | ||
- [FAQ](#faq) | ||
- [`make chaosnet` says that "Additional property name is not allowed"](#make-chaosnet-says-that-additional-property-name-is-not-allowed) | ||
- [Does data persist between runs?](#does-data-persist-between-runs) | ||
- [My `make chaosnet` takes forever to run](#my-make-chaosnet-takes-forever-to-run) | ||
|
||
## What is Chaosnet? | ||
|
||
|
@@ -36,6 +38,8 @@ Enter your GitHub username for the `username` field, and your personal access to | |
|
||
4. Run `make chaosnet` | ||
|
||
Note that this will take a while the first time you run it, as it will need to pull all the images from the registry, build the chaonset image locally, and set up the IBC channel (which has a lot of round trip packet commits). | ||
|
||
## How to force pull images from the registry | ||
|
||
By default, most images (heart-monitor, liquidator, etc.) are cached locally and won't re-fetch from upstream registries. To force a pull, you can run | ||
|
@@ -44,13 +48,185 @@ By default, most images (heart-monitor, liquidator, etc.) are cached locally and | |
make chaosnet-build | ||
``` | ||
|
||
## IBC Commands | ||
|
||
To send an IBC transfer from nibiru-0 to nibiru-1, run: | ||
|
||
1. SSH into nibiru-0 | ||
|
||
```sh | ||
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml exec -it nibiru-0 /bin/ash | ||
``` | ||
|
||
2. Transfer tokens from nibiru-0 to nibiru-1 | ||
|
||
```sh | ||
nibid tx ibc-transfer transfer transfer \ | ||
channel-0 \ | ||
nibi18mxturdh0mjw032c3zslgkw63cukkl4q5skk8g \ | ||
1000000unibi \ | ||
--from validator \ | ||
--fees 5000unibi \ | ||
--yes | jq | ||
``` | ||
|
||
3. In a new shell, SSH into nibiru-1 | ||
|
||
```sh | ||
docker compose -f ./contrib/docker-compose/docker-compose-chaosnet.yml exec -it nibiru-1 /bin/ash | ||
``` | ||
|
||
4. Query the balance of nibiru-1 | ||
|
||
```sh | ||
# set the config since nibiru-1 has different ports | ||
nibid config node "http://localhost:36657" | ||
nibid q bank balances $(nibid keys show validator -a) | jq | ||
``` | ||
|
||
Output: | ||
|
||
```json | ||
{ | ||
"balances": [ | ||
{ | ||
"denom": "ibc/9BEE732637B12723D26E365D19CCB624587CE6254799EEE7C5F77B587BD677B0", | ||
"amount": "1000000" | ||
}, | ||
{ | ||
"denom": "unibi", | ||
"amount": "9999100000000" | ||
} | ||
], | ||
"pagination": { | ||
"next_key": null, | ||
"total": "0" | ||
} | ||
} | ||
``` | ||
|
||
5. Send tokens from nibiru-1 to nibiru-0 | ||
|
||
```sh | ||
nibid tx ibc-transfer transfer transfer \ | ||
channel-0 \ | ||
nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl \ | ||
5555unibi \ | ||
--from validator \ | ||
--fees 5000unibi \ | ||
--yes | jq | ||
``` | ||
|
||
6. Go back to the nibiru-0 and query the balance | ||
|
||
```sh | ||
nibid q bank balances $(nibid keys show validator -a) | jq | ||
``` | ||
|
||
Output: | ||
|
||
```json | ||
{ | ||
"balances": [ | ||
{ | ||
"denom": "ibc/9BEE732637B12723D26E365D19CCB624587CE6254799EEE7C5F77B587BD677B0", | ||
"amount": "5555" | ||
}, | ||
{ | ||
"denom": "unibi", | ||
"amount": "9999098995000" | ||
} | ||
], | ||
"pagination": { | ||
"next_key": null, | ||
"total": "0" | ||
} | ||
} | ||
``` | ||
|
||
7. Send IBC tokens back to nibiru-1 | ||
|
||
```sh | ||
nibid tx ibc-transfer transfer transfer \ | ||
channel-0 \ | ||
nibi18mxturdh0mjw032c3zslgkw63cukkl4q5skk8g \ | ||
5555ibc/9BEE732637B12723D26E365D19CCB624587CE6254799EEE7C5F77B587BD677B0 \ | ||
--from validator \ | ||
--fees 5000unibi \ | ||
--yes | jq | ||
``` | ||
|
||
8. Verify tokens are sent | ||
|
||
```sh | ||
nibid q bank balances $(nibid keys show validator -a) | jq | ||
``` | ||
|
||
Output: | ||
|
||
```json | ||
{ | ||
"balances": [ | ||
{ | ||
"denom": "unibi", | ||
"amount": "9999098990000" | ||
} | ||
], | ||
"pagination": { | ||
"next_key": null, | ||
"total": "0" | ||
} | ||
} | ||
``` | ||
|
||
9. Back in the nibiru-1 shell, send tokens back to nibiru-0 | ||
|
||
```sh | ||
nibid tx ibc-transfer transfer transfer \ | ||
channel-0 \ | ||
nibi1zaavvzxez0elundtn32qnk9lkm8kmcsz44g7xl \ | ||
1000000ibc/9BEE732637B12723D26E365D19CCB624587CE6254799EEE7C5F77B587BD677B0 \ | ||
--from validator \ | ||
--fees 5000unibi \ | ||
--yes | jq | ||
``` | ||
|
||
10. Verify tokens are sent | ||
|
||
```sh | ||
nibid q bank balances $(nibid keys show validator -a) | jq | ||
``` | ||
|
||
Output: | ||
|
||
```json | ||
{ | ||
"balances": [ | ||
{ | ||
"denom": "unibi", | ||
"amount": "9999099990000" | ||
} | ||
], | ||
"pagination": { | ||
"next_key": null, | ||
"total": "0" | ||
} | ||
} | ||
``` | ||
|
||
## Endpoints | ||
|
||
- `http://localhost:5555` -> GraphQL server | ||
- `http://localhost:26657` -> Tendermint RPC server | ||
- `tcp://localhost:9090` -> Cosmos SDK gRPC server | ||
- `http://localhost:1317` -> Cosmos SDK LCD (REST) server | ||
- `http://localhost:8000` -> Faucet server (HTTP POST only) | ||
- | ||
- `http://localhost:26657` -> nibiru-0 Tendermint RPC server | ||
- `tcp://localhost:9090` -> nibiru-0 Cosmos SDK gRPC server | ||
- `http://localhost:1317` -> nibiru-0 Cosmos SDK LCD (REST) server | ||
- | ||
- `http://localhost:36657` -> nibiru-1 Tendermint RPC server | ||
- `tcp://localhost:19090` -> nibiru-1 Cosmos SDK gRPC server | ||
- `http://localhost:11317` -> nibiru-1 Cosmos SDK LCD (REST) server | ||
|
||
## FAQ | ||
|
||
|
@@ -61,3 +237,7 @@ Make sure to update your docker application to version >=23.0.1 | |
### Does data persist between runs? | ||
|
||
No, all volumes are deleted and recreated every time you run `make chaosnet`. This is to ensure that you always start with a clean network. | ||
|
||
### My `make chaosnet` takes forever to run | ||
|
||
It usually takes a few minutes to set everything up and create the IBC channels. If it takes more than 5 minutes, then check the logs of the chaosnet containers to see if any step failed. Reach out to <[email protected]> for help. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
sdkcodec "github.com/cosmos/cosmos-sdk/codec" | ||
|
||
wasmvm "github.com/CosmWasm/wasmvm/types" | ||
) | ||
|
||
// YieldStargateMsgs parses the JSON and sends wasmvm.StargateMsg objects to a channel | ||
func YieldStargateMsgs(jsonBz []byte) ([]wasmvm.StargateMsg, error) { | ||
var data interface{} | ||
if err := json.Unmarshal(jsonBz, &data); err != nil { | ||
return nil, err | ||
} | ||
|
||
var msgs []wasmvm.StargateMsg | ||
parseStargateMsgs(data, &msgs) | ||
return msgs, nil | ||
} | ||
|
||
func parseStargateMsgs(jsonData any, msgs *[]wasmvm.StargateMsg) { | ||
switch v := jsonData.(type) { | ||
case map[string]interface{}: | ||
if typeURL, ok := v["type_url"].(string); ok { | ||
if value, ok := v["value"].(string); ok { | ||
*msgs = append(*msgs, wasmvm.StargateMsg{ | ||
TypeURL: typeURL, | ||
Value: []byte(value), | ||
}) | ||
} | ||
} | ||
for _, value := range v { | ||
parseStargateMsgs(value, msgs) | ||
} | ||
case []interface{}: | ||
for _, value := range v { | ||
parseStargateMsgs(value, msgs) | ||
} | ||
} | ||
} | ||
|
||
type StargateMsgDecoded struct { | ||
TypeURL string `json:"type_url"` | ||
Value string `json:"value"` | ||
} | ||
|
||
func DecodeBase64StargateMsgs( | ||
jsonBz []byte, context client.Context, | ||
) (newSgMsgs []StargateMsgDecoded, err error) { | ||
codec := context.Codec | ||
|
||
var data interface{} | ||
if err := json.Unmarshal(jsonBz, &data); err != nil { | ||
return []StargateMsgDecoded{}, err | ||
} | ||
|
||
sgMsgs, err := YieldStargateMsgs(jsonBz) | ||
if err != nil { | ||
return | ||
} | ||
for _, sgMsg := range sgMsgs { | ||
valueStr := string(sgMsg.Value) | ||
value := strings.Replace(string(sgMsg.Value), `\"`, `"`, -1) | ||
value = strings.Replace(value, `"{`, `{`, -1) | ||
value = strings.Replace(value, `}"`, `}`, -1) | ||
|
||
if _, err := base64.StdEncoding.DecodeString(valueStr); err == nil { | ||
protoMsg, err := context.InterfaceRegistry.Resolve(sgMsg.TypeURL) | ||
if err != nil { | ||
return newSgMsgs, err | ||
} | ||
|
||
decodedBz, _ := base64.StdEncoding.Strict().DecodeString(string(sgMsg.Value)) | ||
concrete := protoMsg.(sdkcodec.ProtoMarshaler) | ||
|
||
err = codec.Unmarshal(decodedBz, concrete) | ||
if err != nil { | ||
return newSgMsgs, err | ||
} | ||
|
||
outBytes, err := codec.MarshalJSON(concrete) | ||
if err != nil { | ||
return newSgMsgs, err | ||
} | ||
|
||
newSgMsgs = append(newSgMsgs, StargateMsgDecoded{sgMsg.TypeURL, string(outBytes)}) | ||
} else if _, err := json.Marshal(value); err == nil { | ||
newSgMsgs = append(newSgMsgs, StargateMsgDecoded{sgMsg.TypeURL, string(sgMsg.Value)}) | ||
} else { | ||
return newSgMsgs, fmt.Errorf( | ||
"parse error: encountered wasmvm.StargateMsg with unexpected format: %s", sgMsg) | ||
} | ||
} | ||
return newSgMsgs, nil | ||
} | ||
|
||
// DecodeBase64Cmd creates a cobra command for base64 decoding. | ||
func DecodeBase64Cmd(defaultNodeHome string) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "base64-decode", | ||
Short: "Decode a base64-encoded protobuf message", | ||
Long: `Decode a base64-encoded protobuf message from JSON input. | ||
The input should be a JSON object with 'type_url' and 'value' fields.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
clientCtx := client.GetClientContextFromCmd(cmd) | ||
|
||
outMessage, err := DecodeBase64StargateMsgs([]byte(args[0]), clientCtx) | ||
fmt.Println(outMessage) | ||
|
||
return err | ||
}, | ||
} | ||
|
||
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") | ||
|
||
return cmd | ||
} |
Oops, something went wrong.