-
Notifications
You must be signed in to change notification settings - Fork 326
/
client_def.rs
170 lines (155 loc) · 5.14 KB
/
client_def.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
use ibc_proto::ibc::core::commitment::v1::MerkleProof;
use crate::core::ics02_client::client_consensus::AnyConsensusState;
use crate::core::ics02_client::client_def::ClientDef;
use crate::core::ics02_client::client_state::AnyClientState;
use crate::core::ics02_client::context::ClientReader;
use crate::core::ics02_client::error::Error;
use crate::core::ics03_connection::connection::ConnectionEnd;
use crate::core::ics04_channel::channel::ChannelEnd;
use crate::core::ics04_channel::packet::Sequence;
use crate::core::ics23_commitment::commitment::{
CommitmentPrefix, CommitmentProofBytes, CommitmentRoot,
};
use crate::core::ics23_commitment::merkle::apply_prefix;
use crate::core::ics24_host::identifier::{ChannelId, ClientId, ConnectionId, PortId};
use crate::core::ics24_host::Path;
use crate::mock::client_state::{MockClientState, MockConsensusState};
use crate::mock::header::MockHeader;
use crate::prelude::*;
use crate::Height;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MockClient;
impl ClientDef for MockClient {
type Header = MockHeader;
type ClientState = MockClientState;
type ConsensusState = MockConsensusState;
fn check_header_and_update_state(
&self,
_ctx: &dyn ClientReader,
_client_id: ClientId,
client_state: Self::ClientState,
header: Self::Header,
) -> Result<(Self::ClientState, Self::ConsensusState), Error> {
if client_state.latest_height() >= header.height() {
return Err(Error::low_header_height(
header.height(),
client_state.latest_height(),
));
}
Ok((MockClientState(header), MockConsensusState::new(header)))
}
fn verify_client_consensus_state(
&self,
_client_state: &Self::ClientState,
height: Height,
prefix: &CommitmentPrefix,
_proof: &CommitmentProofBytes,
client_id: &ClientId,
_consensus_height: Height,
_expected_consensus_state: &AnyConsensusState,
) -> Result<(), Error> {
let client_prefixed_path = Path::ClientConsensusState {
client_id: client_id.clone(),
epoch: height.revision_number,
height: height.revision_height,
}
.to_string();
let _path =
apply_prefix(prefix, vec![client_prefixed_path]).map_err(Error::empty_prefix)?;
// TODO - add ctx to all client verification functions
// let cs = ctx.fetch_self_consensus_state(height);
// TODO - implement this
// proof.verify_membership(cs.root(), path, expected_consensus_state)
Ok(())
}
fn verify_connection_state(
&self,
_client_state: &Self::ClientState,
_height: Height,
_prefix: &CommitmentPrefix,
_proof: &CommitmentProofBytes,
_connection_id: Option<&ConnectionId>,
_expected_connection_end: &ConnectionEnd,
) -> Result<(), Error> {
Ok(())
}
fn verify_channel_state(
&self,
_client_state: &Self::ClientState,
_height: Height,
_prefix: &CommitmentPrefix,
_proof: &CommitmentProofBytes,
_port_id: &PortId,
_channel_id: &ChannelId,
_expected_channel_end: &ChannelEnd,
) -> Result<(), Error> {
Ok(())
}
fn verify_client_full_state(
&self,
_client_state: &Self::ClientState,
_height: Height,
_root: &CommitmentRoot,
_prefix: &CommitmentPrefix,
_client_id: &ClientId,
_proof: &CommitmentProofBytes,
_expected_client_state: &AnyClientState,
) -> Result<(), Error> {
Ok(())
}
fn verify_packet_data(
&self,
_client_state: &Self::ClientState,
_height: Height,
_proof: &CommitmentProofBytes,
_port_id: &PortId,
_channel_id: &ChannelId,
_seq: &Sequence,
_data: String,
) -> Result<(), Error> {
Ok(())
}
fn verify_packet_acknowledgement(
&self,
_client_state: &Self::ClientState,
_height: Height,
_proof: &CommitmentProofBytes,
_port_id: &PortId,
_channel_id: &ChannelId,
_seq: &Sequence,
_data: Vec<u8>,
) -> Result<(), Error> {
Ok(())
}
fn verify_next_sequence_recv(
&self,
_client_state: &Self::ClientState,
_height: Height,
_proof: &CommitmentProofBytes,
_port_id: &PortId,
_channel_id: &ChannelId,
_seq: &Sequence,
) -> Result<(), Error> {
Ok(())
}
fn verify_packet_receipt_absence(
&self,
_client_state: &Self::ClientState,
_height: Height,
_proof: &CommitmentProofBytes,
_port_id: &PortId,
_channel_id: &ChannelId,
_seq: &Sequence,
) -> Result<(), Error> {
Ok(())
}
fn verify_upgrade_and_update_state(
&self,
client_state: &Self::ClientState,
consensus_state: &Self::ConsensusState,
_proof_upgrade_client: MerkleProof,
_proof_upgrade_consensus_state: MerkleProof,
) -> Result<(Self::ClientState, Self::ConsensusState), Error> {
Ok((*client_state, consensus_state.clone()))
}
}