Skip to content

Commit

Permalink
Merge pull request #2426 from Agoric/mfig-2067-dibc-working
Browse files Browse the repository at this point in the history
Get dynamic IBC working again
  • Loading branch information
michaelfig committed Feb 15, 2021
2 parents a7d9993 + 44d4a3f commit 034b649
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 11 deletions.
10 changes: 9 additions & 1 deletion golang/cosmos/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,15 @@ func (app *GaiaApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
panic(err)
}
return app.mm.InitGenesis(ctx, app.appCodec, genesisState)
res := app.mm.InitGenesis(ctx, app.appCodec, genesisState)

// Set Historical infos in InitChain to ignore genesis params
// This is needed for IBC connections not to time out easily
stakingParams := app.StakingKeeper.GetParams(ctx)
stakingParams.HistoricalEntries = 10000
app.StakingKeeper.SetParams(ctx, stakingParams)

return res
}

// Commit tells the controller that the block is commited
Expand Down
81 changes: 81 additions & 0 deletions packages/cosmic-swingset/README-dibc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Using Dynamic IBC (dIBC)

Run `make` in the current (cosmic-swingset) directory to build the Agoric Cosmos
chain integration.

You will need the Golang Cosmos IBC relayer source code. You can clone it from
https://github.com/cosmos/relayer Don't worry about building it, that will
happen later.

```sh
cd relayer
# Initialize two Agoric chains, and say "y" when prompted to run the `connect` and
# `run` steps.
./scripts/nchainz init agoric
```

Let this run in the background until it says that the connection has been established.
It will print out something like:

```
===============================
=== All connections initialized
I[2021-02-15|09:53:02.283] ★ Connection created: [ibc0]client{07-tendermint-0}conn{connection-0} -> [ibc1]client{07-tendermint-0}conn{connection-0}
===============================
```

The `ibc0` ag-solo client can be found by running `agoric open --repl`. If you
need an `ibc1` client, then you can open it with `agoric open
--hostport=localhost:8001 --repl`.

## Echo Channel

On the `ibc0` client, send the following request to the REPL to create a channel
over `connection-0` to the other chain's (`ibc1`) echo server.

```js
c = home.ibcport[0]~.connect('/ibc-hop/connection-0/ibc-port/echo/ordered/echovsn', { infoMessage(...args) { console.log(...args) } })
```

The above command will print out instructions in the REPL about how to establish
the connection. After following them, and when the relayer has started running,
you will see the above REPL command resolve to a presence.

Then:
```js
c~.send(`Hello, world!`)
```

Watch the relayer that you started by following the "connect" instructions
above. You'll see it forwards a single packet and acknowledgement. There may
be errors, but that's par for the course with the current relayer. All that
matters is that after the acknowledgement is relayed, you'll see the above REPL
command resolve to:

```js
"Hello, world!"
```

## Fungible Token Transfer Channel

To test interoperability between the IBC transfer application and dIBC, run the
following in the `ibc0` REPL:

```js
c = home.ibcport[0]~.connect('/ibc-hop/connection-0/ibc-port/transfer/unordered/ics20-1', { infoMessage(...args) { console.log(...args) }, onReceive(c, p) { console.log('received', p) }, onOpen(c) { console.log('opened') } })
```

Again, follow the instructions printed to the REPL.

Then run the IBC transfer request, where `path-2` is the path that was printed
in the newly-started relayer:

```sh
rly tx xfer ibc1 ibc0 10000n0token $(rly keys show ibc0 testkey) -ppath-2
```

You should see an inbound message in your REPL like:

```js
{ "type": "ibc/transfer/PacketDataTransfer", "value": transfer_message }
```
27 changes: 17 additions & 10 deletions packages/cosmic-swingset/bin/ag-nchainz
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ NUM_SOLOS=1
real0=$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")
thisdir=$(cd "$(dirname -- "$real0")" && pwd -P)

PATHCONFIG=nchainz/config/paths
CLI=ag-cosmos-helper
DAEMON=ag-chain-cosmos
SOLO=$thisdir/ag-solo
Expand Down Expand Up @@ -170,12 +171,12 @@ start-relayer)
# Extract existing config.
for path in $(jq '.paths | keys | .[]' "$cfgfile"); do
rawpath=$(echo "$path" | jq -r .)
jq -r ".paths[$path]" "$cfgfile" > "nchainz/config/$rawpath.json"
jq -r ".paths[$path]" "$cfgfile" > "$PATHCONFIG/$rawpath.json"
done

jqexpr=
for fname in nchainz/config/*.json; do
[[ -z $template || $fname == "nchainz/config/$template.json" ]] || continue
for fname in $PATHCONFIG/*.json; do
[[ -z $template || $fname == "$PATHCONFIG/$template.json" ]] || continue
[[ $fname =~ $BASE_RE ]] || continue
if grep -q '"generator": "ag-nchainz"' "$fname"; then :
else
Expand All @@ -200,9 +201,9 @@ start-relayer)

if [[ -z $jqexpr ]]; then
if [[ -n $template ]]; then
echo 1>&2 "Connection ID \`$srccid' is not defined in nchainz/config/$template.json"
echo 1>&2 "Connection ID \`$srccid' is not defined in $PATHCONFIG/$template.json"
else
echo 1>&2 "Connection ID \`$srccid' is not defined in nchainz/config/*.json"
echo 1>&2 "Connection ID \`$srccid' is not defined in $PATHCONFIG/*.json"
fi
exit 1
fi
Expand All @@ -215,24 +216,30 @@ start-relayer)
echo "Replacing path \`$path'"
path=$template
jq -s "$jqexpr" \
"nchainz/config/$template.json" "$tmpfile" > "nchainz/config/$path.json"
"$PATHCONFIG/$template.json" "$tmpfile" > "$PATHCONFIG/$path.json"
else
# Create a new path.
i=0
path=path-$i
while [[ -e "nchainz/config/$path.json" ]]; do
while [[ -e "$PATHCONFIG/$path.json" ]]; do
i=$(( $i + 1 ))
path=path-$i
done

echo "Creating new path \`$path'"
jq -s "$jqexpr"' * { "generator": "ag-nchainz" }' \
"nchainz/config/$template.json" "$tmpfile" > "nchainz/config/$path.json"
"$PATHCONFIG/$template.json" "$tmpfile" > "$PATHCONFIG/$path.json"
fi

echo "$ rly config add-dir nchainz/config/"
rly config add-dir nchainz/config/
# Bottom-up relay path validation may fail if src or dst chain is not past
# block #2.
# Keep trying to add-paths until both the chains have booted up.
echo "$ rly config add-paths $PATHCONFIG/"
while ! rly config add-paths $PATHCONFIG/; do
sleep 3
done

echo "$ rly link $path --timeout=3s -d"
try=0
while ! rly tx link $path --timeout=3s -d >> "nchainz/logs/$path.log" 2>&1; do
try=$(( $try + 1 ))
Expand Down

0 comments on commit 034b649

Please sign in to comment.