Skip to content

Commit

Permalink
update docs :D
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups committed Sep 12, 2024
1 parent 189d48b commit 07c93de
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ The expected result should be:
}
```

Your network is now running and you have successfully set and resolved a name! 🎉

:::note
When you are ready to stop the testnet, you can use `ctrl + c` or `killall -9 rolld`.
:::


Your network is now running and you have successfully set and resolved a name! 🎉
4 changes: 2 additions & 2 deletions docs/versioned_docs/version-v0.50.x/03-demos/01-demo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "IBC Demo"
sidebar_label: "IBC Demo"
title: "IBC Transfers"
sidebar_label: "IBC Transfer Demo"
sidebar_position: 1
slug: /demo/ibc
---
Expand Down
113 changes: 82 additions & 31 deletions docs/versioned_docs/version-v0.50.x/03-demos/02-ibc-module.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,63 @@
---
title: "IBC Module"
sidebar_label: "IBC Module"
sidebar_label: "IBC NameService Module"
sidebar_position: 1
slug: /demo/ibc-module
---

# IBC Module
# IBC NameService Module

In this tutorial, we'll build on the nameservice tutorial and add an IBC module to the chain. This will allow us to sent our name on another network.
In this tutorial, you will build on the [nameservice tutorial](../02-build-your-chain/01-nameservice.md) to add cross chain functionality. This will allow you to sent a name from another network.

## Prerequisites
- [System Setup](../01-setup/01-system-setup.md)
- [Install Spawn](../01-setup/02-install-spawn.md)
- [Build Your Name Service Chain](../02-build-your-chain/01-nameservice.md)
- [Build Your Name Service Chain Turotial](../02-build-your-chain/01-nameservice.md)

## Create your chain

You should already have a network called `rollchain` with the nameservice module enabled from the [nameservice tutorial](../02-build-your-chain/01-nameservice.md). If you do not, complete that tutorial now.
You should already have a network, `rollchain`, with the nameservice module from the [nameservice tutorial](../02-build-your-chain/01-nameservice.md). If you do not, complete that tutorial now.

:::note warning
Make sure you do not have the previous testnet still running by stopping it with: `killall -9 rolld`
:::

## Scaffold the IBC Module

```bash
# if not already in the rollchain directory
# if you are not already in the chain directory:
cd rollchain

# scaffolds your new nameService IBC module
# scaffold the base IBC module for The
# cross chain name service
spawn module new nsibc --ibc-module
```

## Add reference to the previous Name Service keeper
## Import the other NameService Module

You now reference the nameservice module you built within this new IBC module. This will allow you to save the name mapping on the name service, making it available for both IBC and native chain interactions.

```go title="x/nsibc/keeper/keeper.go"
import (
...
nameservicekeeper "github.com/rollchains/rollchain/x/nameservice/keeper"
)

// Keeper defines the module keeper.
type Keeper struct {
...
NameServiceKeeper *nameservicekeeper.Keeper
}
```
![View](https://github.com/user-attachments/assets/4dd3e50d-1528-4ae4-91a2-a27612bf69d7)

<details>
<summary>Keeper Setup Image</summary>

![View](https://github.com/user-attachments/assets/4dd3e50d-1528-4ae4-91a2-a27612bf69d7)
</details>


```go title="x/nsibc/keeper/keeper.go"
// NewKeeper creates a new swap Keeper instance.
// NewKeeper creates a new Keeper instance.
func NewKeeper(
...
nsk *nameservicekeeper.Keeper,
Expand All @@ -57,11 +69,17 @@ func NewKeeper(
NameServiceKeeper: nsk,
}
```
![View](https://github.com/user-attachments/assets/7639e468-a354-468d-8368-6bedd3c142a7)
<details>
<summary>NewKeeper Image</summary>
![View](https://github.com/user-attachments/assets/7639e468-a354-468d-8368-6bedd3c142a7)
</details>
## Update it in the application
## Provide NameService to the IBC Module
Ensure that `app.NameserviceKeeper` comes before the `app.NsibcKeeper` in the `app/app.go` file. Then fix the `nsibckeeper.NewKeeper` function to use the nameservice keeper logic.
You must now give the IBC module access to nameservice keeper. It needs this reference so that the logic and connections can be shared. This is done in the `app/app.go` file. Find where the EvidenceKeeper line is, and overwrite the current lines with the following.
This moves the `NameserviceKeeper` above the IBC keeper (since you need to set that first so you can use it), and adds the `&app.NameserviceKeeper,` to the IBC Name Service keeper.
```go title="app/app.go"
// If evidence needs to be handled for the app, set routes in router here and seal
Expand All @@ -86,11 +104,18 @@ Ensure that `app.NameserviceKeeper` comes before the `app.NsibcKeeper` in the `a
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
```
![View](https://github.com/user-attachments/assets/af456634-d7b7-475f-b468-7c14411803da)
## Use NameService Logic
<details>
<summary>Application NameService Reference Image</summary>
![View](https://github.com/user-attachments/assets/af456634-d7b7-475f-b468-7c14411803da)
</details>
The `OnRecvPacket` method in this file has a placeholder for where your logic should run. Find the `OnRecvPacket` in the ibc_module.go file, then find where the `handleOnRecvLogic` method resides
## Set Name on IBC Packet
Now that the IBC module has access to the nameservice, you can add the logic to set a name received from another chain (called the counterparty). To implement, the `OnRecvPacket` method has a placeholder for where the logic should run called `handleOnRecvLogic`. Find the `OnRecvPacket` in the ibc_module.go file, then find where the `handleOnRecvLogic` method resides.
```go title="x/nsibc/ibc_module.go"
// Find this method in the file
Expand All @@ -99,24 +124,31 @@ func (im ExampleIBCModule) handleOnRecvLogic(ctx context.Context, data types.Exa
return nil
}
```
![View](https://github.com/user-attachments/assets/011cb6cb-6664-47b9-a09e-fe1b62862987)
Once found, remove the lines within it and replace it with the following.
<details>
<summary>handleOnRecvLogic location</summary>
![View](https://github.com/user-attachments/assets/011cb6cb-6664-47b9-a09e-fe1b62862987)
</details>
Once found, remove the lines within and replace with the following return.
```go title="x/nsibc/ibc_module.go"
func (im ExampleIBCModule) handleOnRecvLogic(ctx context.Context, data types.ExamplePacketData) error {
return im.keeper.NameServiceKeeper.NameMapping.Set(ctx, data.Sender, data.SomeData)
}
```
This will set the name mapping, from the sender to some data (the name) in the original nameservice module.
This sets the name mapping from the sender to some data (the name) in the original nameservice module.
::note
:::note
This is for example to show cross module interaction / extension with IBC.
You could just as easily write the NameMapping in the ibc keeper store as well.
:::
## Running testnet
## Start Testnet
```bash
# build chain binary
Expand All @@ -128,38 +160,57 @@ rolld
# build docker image
make local-image

# run testnet between itself
# run testnet between itself and an IBC relayer
# this will take a minute
local-ic start self-ibc
```
# Connect New IBC Module
## Import Testnet Helpers
Pasting the following lines in your terminal will import helper functions to interact with the testnet.
The source is publicly available on GitHub to review.
```bash
# Import the testnet interaction helper functions
# for local-interchain
source <(curl -s https://raw.githubusercontent.com/strangelove-ventures/interchaintest/main/local-interchain/bash/source.bash)
API_ADDR="http://localhost:8080"

# Waits for the testnet to start
ICT_POLL_FOR_START $API_ADDR 50 && echo "Testnet started"
```
# only 1 channel (ics-20) is auto created on start of the testnet
echo `ICT_RELAYER_CHANNELS $API_ADDR "localchain-1"`
## Connect Your IBC Modules
# We will then create a new channel between localchain-1 and localchain-2
# Using the new nameservice module we just created.
You are ready to connect the two chains with your IBC module protocol. The [cosmos/relayer](https://github.com/cosmos/relayer) is already running between the 2 networks now. You will just send a command to connect the new logic.
:::note
A Channel is a connection between two chains, like a highway. A port is a specific protocol (or logic) that can connect with itself on another chain.
For example; transfer to transfer, nsibc to nsibc, but transfer to nsibc can not be done. The version is just extra information (metadata) about the connection.
These values are found in the keys.go file as the module name. By default version is just the module name + "-1".
:::
```bash
# This will take a minute.
ICT_RELAYER_EXEC $API_ADDR "localchain-1" "rly tx connect localchain-1_localchain-2 --src-port=nsibc --dst-port=nsibc --order=unordered --version=nsibc-1"

# We can then run the channels command again to verify the new channel was createds
# Running the channels command now shows 2 channels, one for `transfer`
# and 1 for `nsibc`, marked as channel-1.
echo `ICT_RELAYER_CHANNELS $API_ADDR "localchain-1"`
```
## Really Interaction
## Submit Name Service Name Over IBC
```bash
# Set the IBC name from chain 1.
# view this command in x/nsibc/client/tx.go
rolld tx nsibc example-tx nsibc channel-1 testname --from acc0 --chain-id localchain-1 --yes

# View the logs
rolld q tx 8A2009667022BE432B60158498C2256AEED0E86E9DFF79BD11CC9EA70DEC4A8A

# Verify chain 2 set the name (
# rolld keys show -a acc0 from chain-1
# `rolld keys show -a acc0` from chain-1
ICT_QUERY "http://localhost:8080" "localchain-2" "nameservice resolve roll1hj5fveer5cjtn4wd6wstzugjfdxzl0xpg2te87"
```
2 changes: 1 addition & 1 deletion simapp/x/ibcmiddleware/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Keeper struct {
ics4Wrapper porttypes.ICS4Wrapper
}

// NewKeeper creates a new swap Keeper instance.
// NewKeeper creates a new Keeper instance.
func NewKeeper(
cdc codec.BinaryCodec,
msgServiceRouter *baseapp.MsgServiceRouter,
Expand Down
2 changes: 1 addition & 1 deletion simapp/x/ibcmodule/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Keeper struct {
authority string
}

// NewKeeper creates a new swap Keeper instance.
// NewKeeper creates a new Keeper instance.
func NewKeeper(
appCodec codec.BinaryCodec,
storeService store.KVStoreService,
Expand Down

0 comments on commit 07c93de

Please sign in to comment.