Skip to content

Commit a4b6f70

Browse files
committed
Implementing ICS connection's open_try datagram
1 parent 95da20d commit a4b6f70

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

core/src/ibc/client_02/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ pub trait State {
4343
fn set_root(&self, ctx: &mut dyn ibc::Context, block_height: u64, root: &dyn commitment::Root);
4444
fn exists(&self, ctx: &mut dyn ibc::Context) -> bool;
4545
fn update(&self, ctx: &mut dyn ibc::Context, header: &[u8]) -> Result<(), String>;
46+
fn verify_membership()
4647
}

core/src/ibc/connection_03/manager.rs

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

1717
use super::path as connection_path;
18-
use super::types::{CommitmentPrefix, Identifier};
18+
use super::types::{CommitmentPrefix, CommitmentProof, Identifier};
1919
use crate::ibc;
2020
use crate::ibc::connection_03::client_connections_path;
2121
use crate::ibc::connection_03::types::{ConnectionEnd, ConnectionIdentifiersInClient, ConnectionState};
@@ -24,6 +24,11 @@ use rlp::{Encodable, Rlp};
2424
#[derive(Default)]
2525
pub struct Manager {}
2626

27+
// FIXME:
28+
fn get_commiment_prefix() -> String {
29+
"".to_owned()
30+
}
31+
2732
impl Manager {
2833
pub fn new() -> Self {
2934
Manager {}
@@ -55,6 +60,71 @@ impl Manager {
5560
Ok(())
5661
}
5762

63+
// We can't know the exact format of counterparty parameters
64+
pub fn handle_open_try(
65+
&self,
66+
ctx: &mut dyn ibc::Context,
67+
desired_identifier: Identifier,
68+
counterparty_connection_identifier: Identifier,
69+
counterparty_prefix: CommitmentPrefix,
70+
counterparty_client_identifier: Identifier,
71+
client_identifier: Identifier,
72+
counterparty_versions: Vec<String>,
73+
proof_init: CommitmentProof,
74+
proof_consensus: CommitmentProof,
75+
proof_height: u64,
76+
consensus_height: u64,
77+
) -> Result<(), String> {
78+
if consensus_height > ctx.get_current_height() {
79+
return Err(format!(
80+
"Consensus height {} is greater than current height {}",
81+
consensus_height,
82+
ctx.get_current_height()
83+
))
84+
}
85+
let expected = ConnectionEnd {
86+
state: ConnectionState::INIT,
87+
counterparty_connection_identifier: desired_identifier,
88+
counterparty_prefix: get_commiment_prefix(),
89+
client_identifier,
90+
counterparty_client_identifier,
91+
};
92+
93+
// let connection =
94+
95+
// consensus_height <
96+
Ok(())
97+
}
98+
99+
fn verify_connection_state(
100+
&self,
101+
ctx: &mut dyn ibc::Context,
102+
connection: ConnectionEnd,
103+
proof_height: u64,
104+
proof: CommitmentProof,
105+
connection_identifier: Identifier,
106+
connection_end: ConnectionEnd,
107+
) -> Result<(), String> {
108+
// let client_manager = ibc::client_02::Manager::new();
109+
// should we use connection.client_identifier?
110+
// let client = client_manager.query(ctx, &connection.client_identifier)?;
111+
// client.verify
112+
let path = format!("connections/{}", connection_identifier);
113+
114+
let
115+
self.client_verify_membership(proof_height, proof, path, connection_end.);
116+
}
117+
118+
fn client_verify_membership(
119+
&self,
120+
_height: u64,
121+
_commitment_proof: CommitmentProof,
122+
_path: String,
123+
_value: String,
124+
) {
125+
true
126+
}
127+
58128
fn add_connection_to_client(
59129
&self,
60130
ctx: &mut dyn ibc::Context,

core/src/ibc/connection_03/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ impl rlp::Decodable for ConnectionState {
4545

4646
// FIXME: current commitment_23::Prefix is too generic.
4747
pub type CommitmentPrefix = String;
48+
// FIXME: This type will be replaced after commitment code changed.
49+
pub type CommitmentProof = String;
4850
pub type Identifier = String;
4951

52+
5053
#[derive(RlpEncodable, RlpDecodable, PartialEq, Debug)]
5154
pub struct ConnectionEnd {
5255
pub state: ConnectionState,

0 commit comments

Comments
 (0)