|
1 |
| -mod chan_close_confirm; |
2 |
| -mod chan_close_init; |
3 |
| -mod chan_open_ack; |
4 |
| -mod chan_open_confirm; |
5 |
| -mod chan_open_init; |
6 |
| -mod chan_open_try; |
7 |
| - |
8 |
| -mod acknowledgement; |
9 |
| -mod recv_packet; |
10 |
| -mod timeout; |
| 1 | +use core::time::Duration; |
| 2 | +use displaydoc::Display; |
| 3 | +use ibc_proto::google::protobuf::Any; |
11 | 4 |
|
12 | 5 | use crate::prelude::*;
|
13 | 6 | use crate::signer::Signer;
|
14 | 7 |
|
15 |
| -use self::chan_close_confirm::{chan_close_confirm_execute, chan_close_confirm_validate}; |
16 |
| -use self::chan_close_init::{chan_close_init_execute, chan_close_init_validate}; |
17 |
| -use self::chan_open_ack::{chan_open_ack_execute, chan_open_ack_validate}; |
18 |
| -use self::chan_open_confirm::{chan_open_confirm_execute, chan_open_confirm_validate}; |
19 |
| -use self::chan_open_init::{chan_open_init_execute, chan_open_init_validate}; |
20 |
| -use self::chan_open_try::{chan_open_try_execute, chan_open_try_validate}; |
21 |
| - |
22 |
| -use self::acknowledgement::{acknowledgement_packet_execute, acknowledgement_packet_validate}; |
23 |
| -use self::recv_packet::{recv_packet_execute, recv_packet_validate}; |
24 |
| -use self::timeout::{timeout_packet_execute, timeout_packet_validate, TimeoutMsgType}; |
25 |
| - |
26 |
| -use super::ics02_client::msgs::MsgUpdateOrMisbehaviour; |
27 |
| -use super::router::Router; |
28 |
| -use super::{ |
29 |
| - ics02_client::error::ClientError, |
30 |
| - ics03_connection::error::ConnectionError, |
31 |
| - ics04_channel::error::{ChannelError, PacketError}, |
32 |
| -}; |
33 |
| -use core::time::Duration; |
34 |
| - |
35 |
| -use ibc_proto::google::protobuf::Any; |
36 |
| - |
37 | 8 | use crate::core::events::IbcEvent;
|
38 | 9 | use crate::core::ics02_client::client_state::ClientState;
|
39 | 10 | use crate::core::ics02_client::consensus_state::ConsensusState;
|
| 11 | +use crate::core::ics02_client::error::ClientError; |
40 | 12 | use crate::core::ics03_connection::connection::ConnectionEnd;
|
| 13 | +use crate::core::ics03_connection::error::ConnectionError; |
41 | 14 | use crate::core::ics03_connection::version::{
|
42 | 15 | get_compatible_versions, pick_version, Version as ConnectionVersion,
|
43 | 16 | };
|
44 | 17 | use crate::core::ics04_channel::channel::ChannelEnd;
|
45 | 18 | use crate::core::ics04_channel::commitment::{AcknowledgementCommitment, PacketCommitment};
|
46 | 19 | use crate::core::ics04_channel::context::calculate_block_delay;
|
47 |
| -use crate::core::ics04_channel::msgs::{ChannelMsg, PacketMsg}; |
| 20 | +use crate::core::ics04_channel::error::{ChannelError, PacketError}; |
48 | 21 | use crate::core::ics04_channel::packet::{Receipt, Sequence};
|
49 | 22 | use crate::core::ics23_commitment::commitment::CommitmentPrefix;
|
| 23 | +use crate::core::ics24_host::identifier::ClientId; |
50 | 24 | use crate::core::ics24_host::identifier::ConnectionId;
|
51 | 25 | use crate::core::ics24_host::path::{
|
52 | 26 | AckPath, ChannelEndPath, ClientConnectionPath, ClientConsensusStatePath, ClientStatePath,
|
53 | 27 | CommitmentPath, ConnectionPath, ReceiptPath, SeqAckPath, SeqRecvPath, SeqSendPath,
|
54 | 28 | };
|
| 29 | +use crate::core::router::Router; |
55 | 30 | use crate::core::timestamp::Timestamp;
|
56 |
| -use crate::core::{ |
57 |
| - ics02_client::{ |
58 |
| - handler::{create_client, update_client, upgrade_client}, |
59 |
| - msgs::ClientMsg, |
60 |
| - }, |
61 |
| - ics03_connection::{ |
62 |
| - handler::{conn_open_ack, conn_open_confirm, conn_open_init, conn_open_try}, |
63 |
| - msgs::ConnectionMsg, |
64 |
| - }, |
65 |
| - ics24_host::identifier::ClientId, |
66 |
| - msgs::MsgEnvelope, |
67 |
| -}; |
68 | 31 | use crate::Height;
|
69 | 32 |
|
70 |
| -use displaydoc::Display; |
71 |
| - |
72 | 33 | /// Top-level error
|
73 | 34 | #[derive(Debug, Display)]
|
74 | 35 | pub enum ContextError {
|
@@ -151,81 +112,6 @@ impl std::error::Error for RouterError {
|
151 | 112 | ///
|
152 | 113 | /// Trait used for the top-level [`validate`](crate::core::validate)
|
153 | 114 | pub trait ValidationContext: Router {
|
154 |
| - /// Validation entrypoint. |
155 |
| - fn validate(&self, msg: MsgEnvelope) -> Result<(), RouterError> |
156 |
| - where |
157 |
| - Self: Sized, |
158 |
| - { |
159 |
| - match msg { |
160 |
| - MsgEnvelope::Client(msg) => match msg { |
161 |
| - ClientMsg::CreateClient(msg) => create_client::validate(self, msg), |
162 |
| - ClientMsg::UpdateClient(msg) => { |
163 |
| - update_client::validate(self, MsgUpdateOrMisbehaviour::UpdateClient(msg)) |
164 |
| - } |
165 |
| - ClientMsg::Misbehaviour(msg) => { |
166 |
| - update_client::validate(self, MsgUpdateOrMisbehaviour::Misbehaviour(msg)) |
167 |
| - } |
168 |
| - ClientMsg::UpgradeClient(msg) => upgrade_client::validate(self, msg), |
169 |
| - } |
170 |
| - .map_err(RouterError::ContextError), |
171 |
| - MsgEnvelope::Connection(msg) => match msg { |
172 |
| - ConnectionMsg::OpenInit(msg) => conn_open_init::validate(self, msg), |
173 |
| - ConnectionMsg::OpenTry(msg) => conn_open_try::validate(self, msg), |
174 |
| - ConnectionMsg::OpenAck(msg) => conn_open_ack::validate(self, msg), |
175 |
| - ConnectionMsg::OpenConfirm(ref msg) => conn_open_confirm::validate(self, msg), |
176 |
| - } |
177 |
| - .map_err(RouterError::ContextError), |
178 |
| - MsgEnvelope::Channel(msg) => { |
179 |
| - let module_id = self |
180 |
| - .lookup_module_channel(&msg) |
181 |
| - .map_err(ContextError::from)?; |
182 |
| - if !self.has_route(&module_id) { |
183 |
| - return Err(ChannelError::RouteNotFound) |
184 |
| - .map_err(ContextError::ChannelError) |
185 |
| - .map_err(RouterError::ContextError); |
186 |
| - } |
187 |
| - |
188 |
| - match msg { |
189 |
| - ChannelMsg::OpenInit(msg) => chan_open_init_validate(self, module_id, msg), |
190 |
| - ChannelMsg::OpenTry(msg) => chan_open_try_validate(self, module_id, msg), |
191 |
| - ChannelMsg::OpenAck(msg) => chan_open_ack_validate(self, module_id, msg), |
192 |
| - ChannelMsg::OpenConfirm(msg) => { |
193 |
| - chan_open_confirm_validate(self, module_id, msg) |
194 |
| - } |
195 |
| - ChannelMsg::CloseInit(msg) => chan_close_init_validate(self, module_id, msg), |
196 |
| - ChannelMsg::CloseConfirm(msg) => { |
197 |
| - chan_close_confirm_validate(self, module_id, msg) |
198 |
| - } |
199 |
| - } |
200 |
| - .map_err(RouterError::ContextError) |
201 |
| - } |
202 |
| - MsgEnvelope::Packet(msg) => { |
203 |
| - let module_id = self |
204 |
| - .lookup_module_packet(&msg) |
205 |
| - .map_err(ContextError::from)?; |
206 |
| - if !self.has_route(&module_id) { |
207 |
| - return Err(ChannelError::RouteNotFound) |
208 |
| - .map_err(ContextError::ChannelError) |
209 |
| - .map_err(RouterError::ContextError); |
210 |
| - } |
211 |
| - |
212 |
| - match msg { |
213 |
| - PacketMsg::Recv(msg) => recv_packet_validate(self, msg), |
214 |
| - PacketMsg::Ack(msg) => acknowledgement_packet_validate(self, module_id, msg), |
215 |
| - PacketMsg::Timeout(msg) => { |
216 |
| - timeout_packet_validate(self, module_id, TimeoutMsgType::Timeout(msg)) |
217 |
| - } |
218 |
| - PacketMsg::TimeoutOnClose(msg) => timeout_packet_validate( |
219 |
| - self, |
220 |
| - module_id, |
221 |
| - TimeoutMsgType::TimeoutOnClose(msg), |
222 |
| - ), |
223 |
| - } |
224 |
| - .map_err(RouterError::ContextError) |
225 |
| - } |
226 |
| - } |
227 |
| - } |
228 |
| - |
229 | 115 | /// Returns the ClientState for the given identifier `client_id`.
|
230 | 116 | fn client_state(&self, client_id: &ClientId) -> Result<Box<dyn ClientState>, ContextError>;
|
231 | 117 |
|
@@ -379,77 +265,6 @@ pub trait ValidationContext: Router {
|
379 | 265 | ///
|
380 | 266 | /// Trait used for the top-level [`execute`](crate::core::execute) and [`dispatch`](crate::core::dispatch)
|
381 | 267 | pub trait ExecutionContext: ValidationContext {
|
382 |
| - /// Execution entrypoint |
383 |
| - fn execute(&mut self, msg: MsgEnvelope) -> Result<(), RouterError> |
384 |
| - where |
385 |
| - Self: Sized, |
386 |
| - { |
387 |
| - match msg { |
388 |
| - MsgEnvelope::Client(msg) => match msg { |
389 |
| - ClientMsg::CreateClient(msg) => create_client::execute(self, msg), |
390 |
| - ClientMsg::UpdateClient(msg) => { |
391 |
| - update_client::execute(self, MsgUpdateOrMisbehaviour::UpdateClient(msg)) |
392 |
| - } |
393 |
| - ClientMsg::Misbehaviour(msg) => { |
394 |
| - update_client::execute(self, MsgUpdateOrMisbehaviour::Misbehaviour(msg)) |
395 |
| - } |
396 |
| - ClientMsg::UpgradeClient(msg) => upgrade_client::execute(self, msg), |
397 |
| - } |
398 |
| - .map_err(RouterError::ContextError), |
399 |
| - MsgEnvelope::Connection(msg) => match msg { |
400 |
| - ConnectionMsg::OpenInit(msg) => conn_open_init::execute(self, msg), |
401 |
| - ConnectionMsg::OpenTry(msg) => conn_open_try::execute(self, msg), |
402 |
| - ConnectionMsg::OpenAck(msg) => conn_open_ack::execute(self, msg), |
403 |
| - ConnectionMsg::OpenConfirm(ref msg) => conn_open_confirm::execute(self, msg), |
404 |
| - } |
405 |
| - .map_err(RouterError::ContextError), |
406 |
| - MsgEnvelope::Channel(msg) => { |
407 |
| - let module_id = self |
408 |
| - .lookup_module_channel(&msg) |
409 |
| - .map_err(ContextError::from)?; |
410 |
| - if !self.has_route(&module_id) { |
411 |
| - return Err(ChannelError::RouteNotFound) |
412 |
| - .map_err(ContextError::ChannelError) |
413 |
| - .map_err(RouterError::ContextError); |
414 |
| - } |
415 |
| - |
416 |
| - match msg { |
417 |
| - ChannelMsg::OpenInit(msg) => chan_open_init_execute(self, module_id, msg), |
418 |
| - ChannelMsg::OpenTry(msg) => chan_open_try_execute(self, module_id, msg), |
419 |
| - ChannelMsg::OpenAck(msg) => chan_open_ack_execute(self, module_id, msg), |
420 |
| - ChannelMsg::OpenConfirm(msg) => chan_open_confirm_execute(self, module_id, msg), |
421 |
| - ChannelMsg::CloseInit(msg) => chan_close_init_execute(self, module_id, msg), |
422 |
| - ChannelMsg::CloseConfirm(msg) => { |
423 |
| - chan_close_confirm_execute(self, module_id, msg) |
424 |
| - } |
425 |
| - } |
426 |
| - .map_err(RouterError::ContextError) |
427 |
| - } |
428 |
| - MsgEnvelope::Packet(msg) => { |
429 |
| - let module_id = self |
430 |
| - .lookup_module_packet(&msg) |
431 |
| - .map_err(ContextError::from)?; |
432 |
| - if !self.has_route(&module_id) { |
433 |
| - return Err(ChannelError::RouteNotFound) |
434 |
| - .map_err(ContextError::ChannelError) |
435 |
| - .map_err(RouterError::ContextError); |
436 |
| - } |
437 |
| - |
438 |
| - match msg { |
439 |
| - PacketMsg::Recv(msg) => recv_packet_execute(self, module_id, msg), |
440 |
| - PacketMsg::Ack(msg) => acknowledgement_packet_execute(self, module_id, msg), |
441 |
| - PacketMsg::Timeout(msg) => { |
442 |
| - timeout_packet_execute(self, module_id, TimeoutMsgType::Timeout(msg)) |
443 |
| - } |
444 |
| - PacketMsg::TimeoutOnClose(msg) => { |
445 |
| - timeout_packet_execute(self, module_id, TimeoutMsgType::TimeoutOnClose(msg)) |
446 |
| - } |
447 |
| - } |
448 |
| - .map_err(RouterError::ContextError) |
449 |
| - } |
450 |
| - } |
451 |
| - } |
452 |
| - |
453 | 268 | /// Called upon successful client creation and update
|
454 | 269 | fn store_client_state(
|
455 | 270 | &mut self,
|
|
0 commit comments