Git Product home page Git Product logo

gaia's Introduction

Cosmos Hub

banner

license LoC

This branch contains a modified version of Gaia that references a version of cosmos-sdk with an additional IBC module which enables uploading and running of light client as a WASM smart contract.

Note: Requires Go 1.14+

Installation & Running

For installation, just run make install. This will install gaiad and gaiacli in $GOPATH/bin. To run local testnet/node you can follow instructions from here.

Upload wasm bytecode of substrate light client

Once you have gaia up and running, we need to upload substrate_light_client's build using gaiacli.

gaiacli tx ibc wasm store "target/wasm32-unknown-unknown/release/substrate_client.wasm"  --gas=2000000  --from=<account with $ for gas> --chain-id "<your chain id>" --yes

Start Gaia light client daemon

Quantum tunnel interacts with light client daemon instead of interacting with gaia daemon directly. So, we also need to start Gaia LCD locally.

gaiacli rest-server --chain-id="<your chain id>" --laddr=tcp://localhost:1317  --node tcp://localhost:26657 --read-timeout 10000 --write-timeout 10000

Submit a transaction to the light client:

  1. Creating a light client: To create light client, message of type ibc/client/MsgCreateWasmClient needs to be submitted. Example of such message:
{
  "type": "ibc/client/MsgCreateWasmClient",
  "value": {
    "address": "cosmos1xccsl78jz98ydsfahrnluxefyvcnavuy4g3wd5",
    "client_id": "mtnzosnstn",
    "header": {
      "authority_set": "<Initial authority set>",
      "block": "<scale codec serialized SignedBlockWithAuthoritySet>",
      "max_headers_allowed_between_justifications": 512,
      "max_headers_allowed_to_store": 256,
      "set_id": 0
    },
    "max_clock_drift": "30000000000",
    "trusting_period": "2592000000000000",
    "unbonding_period": "2595600000000000",
    "wasm_id": "1"
  }
}

Here, wasm_id is Id of the wasm contract. max_headers_allowed_between_justifications is require that user must submit justification after stipulated blocks. This is to prevent an attack where attacker just feed non-finalized fork without submitting any justification.

  1. Update a light client: To update light client, message of type ibc/client/MsgUpdateWasmClient needs to be submitted. Example of such message:
{
  "type": "ibc/client/MsgUpdateWasmClient",
  "value": {
    "address": "cosmos1xccsl78jz98ydsfahrnluxefyvcnavuy4g3wd5",
    "client_id": "mtnzosnstn",
    "header": {
      "authority_set": "<authority set>",
      "block": "<scale codec serialized SignedBlockWithAuthoritySet>",
      "set_id": 0
    }
  }
}

Here, client_id needs to be previously referenced by MsgCreateWasmClient. authority_set and set_id are no-op for current version of light client.

Check status of the client:

There are two rpc endpoints available in Gaia LCD to query status of light client instances:

  1. http://localhost:1317/ibc/clients: Gives array of all clients exist in the system. Sample response:
{
  "height": "76",
  "result": [
    {
      "type": "ibc/client/wasm/ClientState",
      "value": {
        "id": "vffykhgkrc",
        "trusting_period": "2592000000000000",
        "unbonding_period": "2595600000000000",
        "MaxClockDrift": "30000000000",
        "frozen_height": "0",
        "last_header": {
          "Data": "<last header data>"
        },
        "validity_predicate_address": "Q4GAgIAQAAAAAAAAAAAAAAAAAAA="
      }
    },
    {
      "type": "ibc/client/wasm/ClientState",
      "value": {
        "id": "bggehqndmp",
        "trusting_period": "43230005550666000",
        "unbonding_period": "5323600000000000",
        "MaxClockDrift": "30000000000",
        "frozen_height": "0",
        "last_header": {
          "Data": "<last header data>"
        },
        "validity_predicate_address": "EpGAgIAQgBABAghAIAGAAAgAAEA="
      }
    }
  ]
}
  1. http://localhost:1317/ibc/wasm/client/{client_id}: Gets status of a particular client referred by its id.

For example, Let's take first client with id vffykhgkrc from the sample response of 1st api call. In that case, url would be: http://localhost:1317/ibc/wasm/client/vffykhgkrc and response would be:

{
  "height": "200",
  "result": "{\"best_header_height\":165,\"best_header_hash\":[130,154,171,213,11,253,140,13,103,86,2,142,169,186,243,243,198,245,76,49,38,231,98,156,110,21,70,169,224,206,174,141],\"last_finalized_header_hash\":[],\"best_header_commitment_root\":[83,250,120,181,184,202,74,105,205,244,131,140,177,137,88,254,157,92,224,21,93,231,252,89,60,56,164,212,16,9,86,122],\"current_authority_set\":\"LightAuthoritySet { set_id: 0, authorities: [(Public(88dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee (5FA9nQDV...)), 1)] }\"}"
}

You can parse the stringified json to get the data about light client for example: best header, last finalized header, current authority set etc etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.