Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 13 additions & 9 deletions core/src/ibc/client_02/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ impl<'a> Manager<'a> {

pub fn verify_connection_state(
&self,
id: IdentifierSlice,
client_identifier: IdentifierSlice,
proof_height: BlockNumber,
proof: Bytes,
connection_identifier: IdentifierSlice,
counterparty_connection_identifier: IdentifierSlice,
connection_end: &ConnectionEnd,
) -> Result<(), String> {
let path = ibc::connection_03::path(connection_identifier);
let path = ibc::connection_03::path(counterparty_connection_identifier);
let value_enc = rlp::encode(connection_end);
self.verify_common_presence(id, proof_height, proof, path, value_enc)
self.verify_common_presence(client_identifier, proof_height, proof, path, value_enc)
.map_err(|e| format!("{} : connection_state", e))
}

Expand All @@ -169,10 +169,10 @@ impl<'a> Manager<'a> {
proof_height: BlockNumber,
proof: Bytes,
port_identifier: IdentifierSlice,
channel_identifier: IdentifierSlice,
counterparty_channel_identifier: IdentifierSlice,
channel_end: &ChannelEnd,
) -> Result<(), String> {
let path = ibc::channel_04::channel_path(port_identifier, channel_identifier);
let path = ibc::channel_04::channel_path(port_identifier, counterparty_channel_identifier);
let value_enc = rlp::encode(channel_end);
self.verify_common_presence(id, proof_height, proof, path, value_enc)
.map_err(|e| format!("{} : channel_state", e))
Expand All @@ -183,12 +183,16 @@ impl<'a> Manager<'a> {
id: IdentifierSlice,
proof_height: BlockNumber,
proof: Bytes,
port_identifier: IdentifierSlice,
channel_identifier: IdentifierSlice,
counterparty_port_identifier: IdentifierSlice,
counterparty_channel_identifier: IdentifierSlice,
sequence: &Sequence,
packet_commitment: &PacketCommitment,
) -> Result<(), String> {
let path = ibc::channel_04::packet_commitment_path(port_identifier, channel_identifier, sequence);
let path = ibc::channel_04::packet_commitment_path(
counterparty_port_identifier,
counterparty_channel_identifier,
sequence,
);
let value_enc = rlp::encode(&packet_commitment.hash());
self.verify_common_presence(id, proof_height, proof, path, value_enc)
.map_err(|e| format!("{} : packet_data", e))
Expand Down
14 changes: 7 additions & 7 deletions core/src/ibc/connection_03/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,18 @@ impl<'a> Manager<'a> {

let connection = ConnectionEnd {
state: ConnectionState::TRYOPEN,
counterparty_connection_identifier: counterparty_client_identifier.clone(),
counterparty_connection_identifier: counterparty_connection_identifier.clone(),
counterparty_prefix: counterparty_prefix.clone(),
client_identifier: client_identifier.clone(),
counterparty_client_identifier: counterparty_client_identifier.clone(),
};

let client_manager = ClientManager::new(self.ctx);
client_manager.verify_connection_state(
&counterparty_client_identifier,
&client_identifier,
proof_height,
proof_init,
&desired_identifier,
&counterparty_connection_identifier,
&expected,
)?;

Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'a> Manager<'a> {
&connection.client_identifier,
proof_height,
proof_try,
&identifier,
&connection.counterparty_connection_identifier,
&expected,
)?;

Expand Down Expand Up @@ -200,7 +200,7 @@ impl<'a> Manager<'a> {
&connection.client_identifier,
proof_height,
proof_ack,
&identifier,
&connection.counterparty_connection_identifier,
&expected,
)?;

Expand Down Expand Up @@ -233,8 +233,8 @@ impl<'a> Manager<'a> {
connection_identifier: Identifier,
) -> Result<(), String> {
let kv_store = self.ctx.get_kv_store_mut();
if kv_store.contains_key(&connection_path(&connection_identifier)) {
return Err("Connection exist".to_owned())
if !kv_store.contains_key(&connection_path(&connection_identifier)) {
return Err("Connection does not exist".to_owned())
}

let path = client_connections_path(&client_identifier);
Expand Down
6 changes: 4 additions & 2 deletions ibc.ts/.env.default
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
CHAIN_A_RPC_URL="http://localhost:18080"
CHAIN_A_NETWORK_ID="ac"
CHAIN_A_FAUCET_ADDRESS="accqym7qmn5yj29cdl405xlmx6awd3f3yz07g7vq2c9"
CHAIN_A_RELAYER_ADDRESS="accqym7qmn5yj29cdl405xlmx6awd3f3yz07g7vq2c9"
CHAIN_A_SCENARIO_ADDRESS="accq97692hdn2t0nhfdzzjz8znf0wlav8tq5clzzfts"
CHAIN_A_COUNTERPARTY_CLIENT_ID="BClient"
CHAIN_A_COUNTERPARTY_CONNECTION_ID="BConnection"
CHAIN_A_COUNTERPARTY_CHANNEL_ID="BChannel"
CHAIN_B_RPC_URL="http://localhost:18081"
CHAIN_B_NETWORK_ID="bc"
CHAIN_B_FAUCET_ADDRESS="bccqygjwzj8wupc9m7du9ccef4j6k2u3erjuv2w8pt0"
CHAIN_B_RELAYER_ADDRESS="bccqygjwzj8wupc9m7du9ccef4j6k2u3erjuv2w8pt0"
CHAIN_B_SCENARIO_ADDRESS="bccq8rd3qky8xqvzjrwwkz3ytgr34fvq40gfysdpk6d"
CHAIN_B_COUNTERPARTY_CLIENT_ID="AClient"
CHAIN_B_COUNTERPARTY_CONNECTION_ID="AConnection"
CHAIN_B_COUNTERPARTY_CHANNEL_ID="AChannel"
1 change: 1 addition & 0 deletions ibc.ts/chainA/chainA.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
quiet = false
base_path = "."
password_path = "./password.json"
instance_id = 1

[mining]
engine_signer = "accqym7qmn5yj29cdl405xlmx6awd3f3yz07g7vq2c9"
Expand Down
4 changes: 4 additions & 0 deletions ibc.ts/chainA/chainA.schem.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
"accqym7qmn5yj29cdl405xlmx6awd3f3yz07g7vq2c9": {
"balance": "10000000000000000000",
"seq": "0"
},
"accq97692hdn2t0nhfdzzjz8znf0wlav8tq5clzzfts": {
"balance": "10000000000000000000",
"seq": "0"
}
},
"shards": {
Expand Down
21 changes: 21 additions & 0 deletions ibc.ts/chainA/keystore.db
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@
"version": 3,
"address": "37e06e7424945c37f57d0dfd9b5d736298904ff2",
"meta": "{}"
},
{
"crypto": {
"ciphertext": "49cd2f6d5c6a61d1b554efe959e1b34b54fce2f3d228487fca7f9c7a86464840",
"cipherparams": {
"iv": "f8a7b8e199f110b6cbcf51c0d6beaa64"
},
"cipher": "aes-128-ctr",
"kdf": "pbkdf2",
"kdfparams": {
"dklen": 32,
"salt": "a3e115ac72241325719152fb3ecd6e0b3155d9ea26f532d45631c42ca293ea63",
"c": 262144,
"prf": "hmac-sha256"
},
"mac": "20bfd9d4bfb3fe34a94d1b48c7c3126f5ba7b982ad36fe1c45e2397534d906cf"
},
"id": "a3eca2fc-2cbe-4f08-a13e-b6732c01855c",
"version": 3,
"address": "7da2aaed9a96f9dd2d10a4238a697bbfd61d60a6",
"meta": "{}"
}
],
"asset": [],
Expand Down
1 change: 1 addition & 0 deletions ibc.ts/chainB/chainB.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
quiet = false
base_path = "."
password_path = "./password.json"
instance_id = 2

[mining]
engine_signer = "bccqygjwzj8wupc9m7du9ccef4j6k2u3erjuv2w8pt0"
Expand Down
4 changes: 4 additions & 0 deletions ibc.ts/chainB/chainB.schem.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
"bccqygjwzj8wupc9m7du9ccef4j6k2u3erjuv2w8pt0": {
"balance": "10000000000000000000",
"seq": "0"
},
"bccq8rd3qky8xqvzjrwwkz3ytgr34fvq40gfysdpk6d": {
"balance": "10000000000000000000",
"seq": "0"
}
},
"shards": {
Expand Down
21 changes: 21 additions & 0 deletions ibc.ts/chainB/keystore.db
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,27 @@
"version": 3,
"address": "11270a47770382efcde1718ca6b2d595c8e472e3",
"meta": "{}"
},
{
"crypto": {
"ciphertext": "985c9bf8e7162cb63af2f57619b136026e94298eda856e62f3118be453eebb3b",
"cipherparams": {
"iv": "4e01dc90d10b76d7a78992e6943fc2b0"
},
"cipher": "aes-128-ctr",
"kdf": "pbkdf2",
"kdfparams": {
"dklen": 32,
"salt": "d8df814d95379734f387a11fb0630ef5e462828c2f637d7059e10dba426e8b24",
"c": 262144,
"prf": "hmac-sha256"
},
"mac": "2c5cab0c0712c0cfde538083d2863e1c17cb04c61a1c973bf7c7f2632735afa7"
},
"id": "5d9fa12c-3307-4e59-bfa1-44dd007fd75d",
"version": 3,
"address": "c6d882c43980c1486e7585122d038d52c055e849",
"meta": "{}"
}
],
"asset": [],
Expand Down
1 change: 1 addition & 0 deletions ibc.ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"codechain-sdk": "^2.0.1",
"debug": "^4.1.1",
"dotenv": "^8.2.0",
"enquirer": "^2.3.4",
"rlp": "^2.0.0"
}
}
20 changes: 19 additions & 1 deletion ibc.ts/src/common/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IBC } from "./foundry/transaction";
import { delay } from "./util";
import Debug from "debug";
import { ClientState } from "./foundry/types";
import { IBCHeader, IBCQueryResult } from "./types";
import { IBCHeader, IBCQueryResult, ConnectionEnd } from "./types";

const debug = Debug("common:tx");

Expand Down Expand Up @@ -108,6 +108,24 @@ export class Chain {
blockNumber
]);
}

public async queryConnection(
blockNumber?: number
): Promise<IBCQueryResult<ConnectionEnd> | null> {
return this.sdk.rpc.sendRpcRequest("ibc_query_connection", [
this.counterpartyIdentifiers.connection,
blockNumber
]);
}

public async queryClientConnections(
blockNumber?: number
): Promise<IBCQueryResult<string[]> | null> {
return this.sdk.rpc.sendRpcRequest("ibc_query_client_connections", [
this.counterpartyIdentifiers.client,
blockNumber
]);
}
}

async function waitForTx(sdk: SDK, txHash: H256) {
Expand Down
9 changes: 6 additions & 3 deletions ibc.ts/src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface FoundryChainConfig {
*/
rpcURL: string;
networkId: string;
faucetAddress: string;
relayerAddress: string;
scenarioAddress: string;
counterpartyClientId: string;
counterpartyConnectionId: string;
counterpartyChannelId: string;
Expand All @@ -22,7 +23,8 @@ export function getConfig(): Config {
chainA: {
rpcURL: getEnv("CHAIN_A_RPC_URL"),
networkId: getEnv("CHAIN_A_NETWORK_ID"),
faucetAddress: getEnv("CHAIN_A_FAUCET_ADDRESS"),
relayerAddress: getEnv("CHAIN_A_RELAYER_ADDRESS"),
scenarioAddress: getEnv("CHAIN_A_SCENARIO_ADDRESS"),
counterpartyClientId: getEnv("CHAIN_A_COUNTERPARTY_CLIENT_ID"),
counterpartyConnectionId: getEnv(
"CHAIN_A_COUNTERPARTY_CONNECTION_ID"
Expand All @@ -33,7 +35,8 @@ export function getConfig(): Config {
chainB: {
rpcURL: getEnv("CHAIN_B_RPC_URL"),
networkId: getEnv("CHAIN_B_NETWORK_ID"),
faucetAddress: getEnv("CHAIN_B_FAUCET_ADDRESS"),
relayerAddress: getEnv("CHAIN_B_RELAYER_ADDRESS"),
scenarioAddress: getEnv("CHAIN_B_SCENARIO_ADDRESS"),
counterpartyClientId: getEnv("CHAIN_B_COUNTERPARTY_CLIENT_ID"),
counterpartyConnectionId: getEnv(
"CHAIN_B_COUNTERPARTY_CONNECTION_ID"
Expand Down
44 changes: 44 additions & 0 deletions ibc.ts/src/common/datagram/connOpenAck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const RLP = require("rlp");

export class ConnOpenAckDatagram {
private identifier: string;
private proofTry: Buffer;
private proofConsensus: Buffer;
private proofHeight: number;
private consensusHeight: number;

public constructor({
identifier,
proofTry,
proofConsensus,
proofHeight,
consensusHeight
}: {
identifier: string;
proofTry: Buffer;
proofConsensus: Buffer;
proofHeight: number;
consensusHeight: number;
}) {
this.identifier = identifier;
this.proofTry = proofTry;
this.proofConsensus = proofConsensus;
this.proofHeight = proofHeight;
this.consensusHeight = consensusHeight;
}

public rlpBytes(): Buffer {
return RLP.encode(this.toEncodeObject());
}

public toEncodeObject(): any[] {
return [
5,
this.identifier,
this.proofTry,
this.proofConsensus,
this.proofHeight,
this.consensusHeight
];
}
}
29 changes: 29 additions & 0 deletions ibc.ts/src/common/datagram/connOpenConfirm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const RLP = require("rlp");

export class ConnOpenConfirmDatagram {
private identifier: string;
private proofAck: Buffer;
private proofHeight: number;

public constructor({
identifier,
proofAck,
proofHeight
}: {
identifier: string;
proofAck: Buffer;
proofHeight: number;
}) {
this.identifier = identifier;
this.proofAck = proofAck;
this.proofHeight = proofHeight;
}

public rlpBytes(): Buffer {
return RLP.encode(this.toEncodeObject());
}

public toEncodeObject(): any[] {
return [6, this.identifier, this.proofAck, this.proofHeight];
}
}
Loading