Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: StdTx #52

Closed
wants to merge 9 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@ default = ["paths-cosmos"]
paths-cosmos = []

[dependencies]
tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "tendermint/v0.33" }
tendermint = { path = "../../tendermint-rs/tendermint/" }
#tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "tendermint/v0.33" }

anomaly = "0.2.0"
thiserror = "1.0.11"
1 change: 1 addition & 0 deletions relayer/cli/src/commands.rs
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ mod config;
mod light;
mod query;
mod start;
mod tx;
mod utils;
mod version;

9 changes: 8 additions & 1 deletion relayer/relay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -9,17 +9,24 @@ authors = [

[dependencies]
relayer-modules = { path = "../../modules" }
tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "tendermint/v0.33" }
tendermint = { path = "../../../tendermint-rs/tendermint/" }
#tendermint = { git = "https://github.com/informalsystems/tendermint-rs.git", branch = "tendermint/v0.33" }
anomaly = "0.2.0"
async-trait = "0.1.24"
humantime-serde = "1.0.0"
prost-amino = { path = "../../../../tendermint/amino_rs" } # "0.5"
prost-amino-derive= { path = "../../../../tendermint/amino_rs/prost-amino-derive" } # "0.5"
serde = "1.0.97"
serde_json = "1"
serde_cbor = "0.11.1"
serde_derive = "1.0"
sled = { version = "0.31.0", features = ["no_metrics", "no_logs"] }
thiserror = "1.0.11"
toml = "0.5"
tracing = "0.1.13"
stdtx = { path = "../../../../iqlusioninc/crates/stdtx" } # "0.1.0"
subtle-encoding = { version = "0.5", features = ["bech32-preview"] }


[dev-dependencies]
tokio = { version = "0.2.13", features = ["macros"] }
57 changes: 57 additions & 0 deletions relayer/relay/src/amino.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"fmt"
"io/ioutil"

"github.com/cosmos/cosmos-sdk/codec"
codecstd "github.com/cosmos/cosmos-sdk/codec/std"
"github.com/cosmos/cosmos-sdk/x/auth"
ibc "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
"github.com/cosmos/gaia/app"
)

// NOTE: this should be run from within the gaia repo, on branch ibc-alpha

func main() {
b, err := ioutil.ReadFile("signed.json")
if err != nil {
panic(err)
}

cdc := codecstd.MakeCodec(app.ModuleBasics)

var stdtx auth.StdTx
err = cdc.UnmarshalJSON(b, &stdtx)
if err != nil {
panic(err)
}

msg := stdtx.Msgs[0].(ibc.MsgCreateClient)
hcv := msg.Header
header := hcv.SignedHeader.Header
commit := hcv.SignedHeader.Commit
vals := hcv.ValidatorSet

printer(cdc, "header", header)
printer(cdc, "commit", commit)
printer(cdc, "vals", vals)
printer(cdc, "hcv", hcv)
printer(cdc, "sh", hcv.SignedHeader)
printer(cdc, "msg", msg)
printer(cdc, "client", msg.ClientID)
printer(cdc, "trusting_period", msg.TrustingPeriod)
printer(cdc, "unbonding_period", msg.UnbondingPeriod)
printer(cdc, "address", msg.Signer)

}

func printer(cdc *codec.Codec, name string, o interface{}) {
b, err := cdc.MarshalBinaryBare(o)
if err != nil {
panic(err)
}
fmt.Printf("%s --------------------------------------------\n", name)
fmt.Printf("%x\n", b)

}
233 changes: 233 additions & 0 deletions relayer/relay/src/amino.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
use crate::tx;
use prost_amino_derive::Message;

use std::time::Duration;

use tendermint::{amino_types, block, validator};

#[derive(Clone, Message)]
pub struct Version {
#[prost_amino(uint64, tag = "1")]
pub block: u64,
#[prost_amino(uint64)]
pub app: u64,
}

#[derive(Clone, Message)]
pub struct Header {
#[prost_amino(message, tag = "1")]
pub version: Option<Version>,
#[prost_amino(string)]
pub chain_id: String,
#[prost_amino(int64)]
pub height: i64,
#[prost_amino(message)]
pub time: Option<amino_types::time::TimeMsg>,
#[prost_amino(message)]
pub last_block_id: Option<amino_types::BlockId>,
#[prost_amino(bytes)]
pub last_commit_hash: Vec<u8>,
#[prost_amino(bytes)]
pub data_hash: Vec<u8>,
#[prost_amino(bytes)]
pub validators_hash: Vec<u8>,
#[prost_amino(bytes)]
pub next_validators_hash: Vec<u8>,
#[prost_amino(bytes)]
pub consensus_hash: Vec<u8>,
#[prost_amino(bytes)]
pub app_hash: Vec<u8>,
#[prost_amino(bytes)]
pub last_results_hash: Vec<u8>,
#[prost_amino(bytes)]
pub evidence_hash: Vec<u8>,
#[prost_amino(bytes)]
pub proposer_address: Vec<u8>,
}

impl From<&block::Header> for Header {
fn from(header: &block::Header) -> Header {
Header {
version: Some(Version {
block: header.version.block,
app: header.version.app,
}),
chain_id: header.chain_id.as_str().to_string(),
height: i64::from(header.height),
time: Some(amino_types::time::TimeMsg::from(header.time)),
last_block_id: match &header.last_block_id {
Some(id) => Some(amino_types::block_id::BlockId::from(id)),
None => None,
},
last_commit_hash: option_hash(header.last_commit_hash),
data_hash: option_hash(header.data_hash),
validators_hash: hash(header.validators_hash),
next_validators_hash: hash(header.next_validators_hash),
consensus_hash: hash(header.consensus_hash),
app_hash: header.app_hash.clone(), // XXX
last_results_hash: option_hash(header.last_results_hash),
evidence_hash: option_hash(header.evidence_hash),
proposer_address: header.proposer_address.as_bytes().to_vec(),
}
}
}

fn option_hash(oh: Option<tendermint::Hash>) -> Vec<u8> {
match oh {
Some(h) => hash(h),
None => Vec::new(),
}
}

fn hash(h: tendermint::Hash) -> Vec<u8> {
h.as_bytes().to_vec()
}

#[derive(Clone, Message)]
pub struct CommitSig {
#[prost_amino(uint32, tag = "1")]
pub block_id_flag: u32,
#[prost_amino(bytes)]
pub validator_address: Vec<u8>,
#[prost_amino(message)]
pub timestamp: Option<amino_types::time::TimeMsg>,
#[prost_amino(bytes)]
pub signature: Vec<u8>,
}

impl From<&block::CommitSig> for CommitSig {
fn from(cs: &block::CommitSig) -> Self {
CommitSig {
block_id_flag: cs.block_id_flag.to_u32(),
validator_address: match cs.validator_address {
Some(addr) => addr.as_bytes().to_vec(),
None => Vec::new(),
},
timestamp: Some(amino_types::time::TimeMsg::from(cs.timestamp)),
signature: match &cs.signature {
Some(sig) => sig.as_bytes().to_vec(),
None => Vec::new(),
},
}
}
}

#[derive(Clone, Message)]
pub struct Commit {
#[prost_amino(int64, tag = "1")]
pub height: i64,
#[prost_amino(int64)]
pub round: i64,
#[prost_amino(message)]
pub block_id: Option<amino_types::BlockId>,
#[prost_amino(message, repeated)]
pub signatures: Vec<CommitSig>,
}

impl From<&block::Commit> for Commit {
fn from(commit: &block::Commit) -> Commit {
let mut sigs = Vec::new();
for sig in commit.signatures.iter() {
sigs.push(CommitSig::from(sig))
}
Commit {
height: i64::from(commit.height),
round: commit.round as i64, // XXX
block_id: Some(amino_types::block_id::BlockId::from(&commit.block_id)),
signatures: sigs,
}
}
}

#[derive(Clone, Message)]
pub struct Validator {
#[prost_amino(bytes, tag = "1")]
pub address: Vec<u8>,
#[prost_amino(bytes)]
pub pub_key: Vec<u8>,
#[prost_amino(int64)]
pub voting_power: i64,
// XXX: the Go version also has ProposerPriority!
}

impl From<&validator::Info> for Validator {
fn from(val: &validator::Info) -> Self {
Validator {
address: val.address.as_bytes().to_vec(),
pub_key: val.pub_key.to_amino_bytes(),
voting_power: val.voting_power.value() as i64, // XXX
}
}
}

#[derive(Clone, Message)]
pub struct ValidatorSet {
#[prost_amino(message, repeated, tag = "1")]
pub validators: Vec<Validator>,
// XXX: the Go version also has the proposer
}

impl From<&validator::Set> for ValidatorSet {
fn from(valset: &validator::Set) -> Self {
let mut vals = Vec::new();
for val in valset.validators().iter() {
vals.push(Validator::from(val));
}
ValidatorSet { validators: vals }
}
}

#[derive(Clone, Message)]
pub struct SignedHeader {
#[prost_amino(message, tag = "1")]
pub header: Option<Header>,
#[prost_amino(message)]
pub commit: Option<Commit>,
}

#[derive(Clone, Message)]
#[amino_name = "ibc/client/tendermint/Header"]
pub struct SignedHeaderVals {
#[prost_amino(message, tag = "1")]
pub SignedHeader: Option<SignedHeader>,
#[prost_amino(message)]
pub validator_set: Option<ValidatorSet>,
}

#[derive(Clone, Message)]
pub struct MsgCreateClient {
#[prost_amino(string, tag = "1")]
pub client_id: String,
#[prost_amino(message)]
pub header: Option<SignedHeaderVals>,
#[prost_amino(message)]
pub trusting_period: Option<amino_types::time::TimeMsg>,
#[prost_amino(message)]
pub unbonding_period: Option<amino_types::time::TimeMsg>,
#[prost_amino(bytes)]
pub address: Vec<u8>,
}

impl From<&tx::MsgCreateClientInner> for MsgCreateClient {
fn from(msg: &tx::MsgCreateClientInner) -> Self {
MsgCreateClient {
client_id: msg.client_id.clone(),
header: Some(SignedHeaderVals {
SignedHeader: Some(SignedHeader {
header: Some(Header::from(&msg.header.SignedHeader.header)),
commit: Some(Commit::from(&msg.header.SignedHeader.commit)),
}),
validator_set: Some(ValidatorSet::from(&msg.header.validator_set)),
}),
trusting_period: Some(duration(msg.trusting_period)),
unbonding_period: Some(duration(msg.unbonding_period)),
address: msg.address.as_ref().to_vec(),
}
}
}

fn duration(d: Duration) -> amino_types::time::TimeMsg {
let seconds = d.as_secs() as i64;
let nanos = d.subsec_nanos() as i32;
amino_types::time::TimeMsg { seconds, nanos }
}
2 changes: 2 additions & 0 deletions relayer/relay/src/lib.rs
Original file line number Diff line number Diff line change
@@ -11,10 +11,12 @@

//! IBC Relayer implementation

pub mod amino;
pub mod chain;
pub mod client;
pub mod config;
pub mod error;
pub mod query;
pub mod store;
pub mod tx;
pub mod util;
Loading