Skip to content

Commit

Permalink
imp: rename to flatten + revert to Path::*(*)
Browse files Browse the repository at this point in the history
  • Loading branch information
Farhad-Shabani committed Jul 12, 2024
1 parent 6e42616 commit e5dfbfb
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 42 deletions.
4 changes: 2 additions & 2 deletions ibc-clients/cw-context/src/types/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl TryFrom<VerifyMembershipMsgRaw> for VerifyMembershipMsg {
fn try_from(mut raw: VerifyMembershipMsgRaw) -> Result<Self, Self::Error> {
let proof = CommitmentProofBytes::try_from(raw.proof.to_vec())?;
let prefix = CommitmentPrefix::from(raw.path.key_path.remove(0).into_vec());
let path = PathBytes::concat(raw.path.key_path);
let path = PathBytes::flatten(raw.path.key_path);
let height = Height::try_from(raw.height)?;

Ok(Self {
Expand Down Expand Up @@ -180,7 +180,7 @@ impl TryFrom<VerifyNonMembershipMsgRaw> for VerifyNonMembershipMsg {
fn try_from(mut raw: VerifyNonMembershipMsgRaw) -> Result<Self, Self::Error> {
let proof = CommitmentProofBytes::try_from(raw.proof.to_vec())?;
let prefix = CommitmentPrefix::from(raw.path.key_path.remove(0).into_vec());
let path = PathBytes::concat(raw.path.key_path);
let path = PathBytes::flatten(raw.path.key_path);
let height = raw.height.try_into()?;

Ok(Self {
Expand Down
14 changes: 8 additions & 6 deletions ibc-clients/ics07-tendermint/src/client_state/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ impl ClientStateCommon for ClientState {
) -> Result<(), ClientError> {
let last_height = self.latest_height().revision_height();

let upgrade_client_path_bytes =
self.serialize_path(UpgradeClientPath::UpgradedClientState(last_height))?;
let upgrade_client_path_bytes = self.serialize_path(Path::UpgradeClient(
UpgradeClientPath::UpgradedClientState(last_height),
))?;

let upgrade_consensus_path_bytes =
self.serialize_path(UpgradeClientPath::UpgradedClientConsensusState(last_height))?;
let upgrade_consensus_path_bytes = self.serialize_path(Path::UpgradeClient(
UpgradeClientPath::UpgradedClientConsensusState(last_height),
))?;

verify_upgrade_client::<HostFunctionsManager>(
self.inner(),
Expand All @@ -64,8 +66,8 @@ impl ClientStateCommon for ClientState {
)
}

fn serialize_path(&self, path: impl Into<Path>) -> Result<PathBytes, ClientError> {
Ok(path.into().to_string().into_bytes().into())
fn serialize_path(&self, path: Path) -> Result<PathBytes, ClientError> {
Ok(path.to_string().into_bytes().into())
}

fn verify_membership_raw(
Expand Down
6 changes: 3 additions & 3 deletions ibc-core/ics02-client/context/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub trait ClientStateCommon: Convertible<Any> {
/// them to understand how path serialization is performed on the chain this
/// light client represents it before passing the path bytes to either
/// `verify_membership_raw()` or `verify_non_membership_raw()`.
fn serialize_path(&self, path: impl Into<Path>) -> Result<PathBytes, ClientError>;
fn serialize_path(&self, path: Path) -> Result<PathBytes, ClientError>;

/// Verifies a proof of the existence of a value at a given raw path bytes.
fn verify_membership_raw(
Expand All @@ -76,7 +76,7 @@ pub trait ClientStateCommon: Convertible<Any> {
prefix: &CommitmentPrefix,
proof: &CommitmentProofBytes,
root: &CommitmentRoot,
path: impl Into<Path>,
path: Path,
value: Vec<u8>,
) -> Result<(), ClientError> {
let path_bytes = self.serialize_path(path)?;
Expand All @@ -98,7 +98,7 @@ pub trait ClientStateCommon: Convertible<Any> {
prefix: &CommitmentPrefix,
proof: &CommitmentProofBytes,
root: &CommitmentRoot,
path: impl Into<Path>,
path: Path,
) -> Result<(), ClientError> {
let path_bytes = self.serialize_path(path)?;
self.verify_non_membership_raw(prefix, proof, root, path_bytes)
Expand Down
8 changes: 4 additions & 4 deletions ibc-core/ics03-connection/src/handler/conn_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ibc_core_connection_types::{ConnectionEnd, Counterparty, State};
use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::identifiers::ClientId;
use ibc_core_host::types::path::{ClientConsensusStatePath, ClientStatePath, ConnectionPath};
use ibc_core_host::types::path::{ClientConsensusStatePath, ClientStatePath, ConnectionPath, Path};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_primitives::prelude::*;
use ibc_primitives::proto::{Any, Protobuf};
Expand Down Expand Up @@ -101,7 +101,7 @@ where
prefix_on_b,
&msg.proof_conn_end_on_b,
consensus_state_of_b_on_a.root(),
ConnectionPath::new(&msg.conn_id_on_b),
Path::Connection(ConnectionPath::new(&msg.conn_id_on_b)),
expected_conn_end_on_b.encode_vec(),
)
.map_err(ConnectionError::VerifyConnectionState)?;
Expand All @@ -112,7 +112,7 @@ where
prefix_on_b,
&msg.proof_client_state_of_a_on_b,
consensus_state_of_b_on_a.root(),
ClientStatePath::new(vars.client_id_on_b().clone()),
Path::ClientState(ClientStatePath::new(vars.client_id_on_b().clone())),
msg.client_state_of_a_on_b.to_vec(),
)
.map_err(|e| ConnectionError::ClientStateVerificationFailure {
Expand All @@ -137,7 +137,7 @@ where
prefix_on_b,
&msg.proof_consensus_state_of_a_on_b,
consensus_state_of_b_on_a.root(),
client_cons_state_path_on_b,
Path::ClientConsensusState(client_cons_state_path_on_b),
stored_consensus_state_of_a_on_b.to_vec(),
)
.map_err(|e| ConnectionError::ConsensusStateVerificationFailure {
Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics03-connection/src/handler/conn_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ibc_core_connection_types::{ConnectionEnd, Counterparty, State};
use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::identifiers::{ClientId, ConnectionId};
use ibc_core_host::types::path::{ClientConsensusStatePath, ConnectionPath};
use ibc_core_host::types::path::{ClientConsensusStatePath, ConnectionPath, Path};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_primitives::prelude::*;
use ibc_primitives::proto::Protobuf;
Expand Down Expand Up @@ -78,7 +78,7 @@ where
prefix_on_a,
&msg.proof_conn_end_on_a,
consensus_state_of_a_on_b.root(),
ConnectionPath::new(conn_id_on_a),
Path::Connection(ConnectionPath::new(conn_id_on_a)),
expected_conn_end_on_a.encode_vec(),
)
.map_err(ConnectionError::VerifyConnectionState)?;
Expand Down
8 changes: 4 additions & 4 deletions ibc-core/ics03-connection/src/handler/conn_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::identifiers::{ClientId, ConnectionId};
use ibc_core_host::types::path::{
ClientConnectionPath, ClientConsensusStatePath, ClientStatePath, ConnectionPath,
ClientConnectionPath, ClientConsensusStatePath, ClientStatePath, ConnectionPath, Path,
};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_primitives::prelude::*;
Expand Down Expand Up @@ -97,7 +97,7 @@ where
prefix_on_a,
&msg.proof_conn_end_on_a,
consensus_state_of_a_on_b.root(),
ConnectionPath::new(&vars.conn_id_on_a),
Path::Connection(ConnectionPath::new(&vars.conn_id_on_a)),
expected_conn_end_on_a.encode_vec(),
)
.map_err(ConnectionError::VerifyConnectionState)?;
Expand All @@ -108,7 +108,7 @@ where
prefix_on_a,
&msg.proof_client_state_of_b_on_a,
consensus_state_of_a_on_b.root(),
ClientStatePath::new(client_id_on_a.clone()),
Path::ClientState(ClientStatePath::new(client_id_on_a.clone())),
msg.client_state_of_b_on_a.to_vec(),
)
.map_err(|e| ConnectionError::ClientStateVerificationFailure {
Expand All @@ -133,7 +133,7 @@ where
prefix_on_a,
&msg.proof_consensus_state_of_b_on_a,
consensus_state_of_a_on_b.root(),
client_cons_state_path_on_a,
Path::ClientConsensusState(client_cons_state_path_on_a),
stored_consensus_state_of_b_on_a.to_vec(),
)
.map_err(|e| ConnectionError::ConsensusStateVerificationFailure {
Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics04-channel/src/handler/acknowledgement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ibc_core_connection::types::State as ConnectionState;
use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::path::{
AckPath, ChannelEndPath, ClientConsensusStatePath, CommitmentPath, SeqAckPath,
AckPath, ChannelEndPath, ClientConsensusStatePath, CommitmentPath, Path, SeqAckPath,
};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_core_router::module::Module;
Expand Down Expand Up @@ -196,7 +196,7 @@ where
conn_end_on_a.counterparty().prefix(),
&msg.proof_acked_on_b,
consensus_state_of_b_on_a.root(),
ack_path_on_b,
Path::Ack(ack_path_on_b),
ack_commitment.into_vec(),
)
.map_err(|e| ChannelError::PacketVerificationFailed {
Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics04-channel/src/handler/chan_close_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ibc_core_client::context::prelude::*;
use ibc_core_connection::types::State as ConnectionState;
use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::path::{ChannelEndPath, ClientConsensusStatePath};
use ibc_core_host::types::path::{ChannelEndPath, ClientConsensusStatePath, Path};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_core_router::module::Module;
use ibc_primitives::prelude::*;
Expand Down Expand Up @@ -156,7 +156,7 @@ where
prefix_on_a,
&msg.proof_chan_end_on_a,
consensus_state_of_a_on_b.root(),
chan_end_path_on_a,
Path::ChannelEnd(chan_end_path_on_a),
expected_chan_end_on_a.encode_vec(),
)
.map_err(ChannelError::VerifyChannelFailed)?;
Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics04-channel/src/handler/chan_open_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use ibc_core_client::context::prelude::*;
use ibc_core_connection::types::State as ConnectionState;
use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::path::{ChannelEndPath, ClientConsensusStatePath};
use ibc_core_host::types::path::{ChannelEndPath, ClientConsensusStatePath, Path};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_core_router::module::Module;
use ibc_primitives::prelude::*;
Expand Down Expand Up @@ -149,7 +149,7 @@ where
prefix_on_b,
&msg.proof_chan_end_on_b,
consensus_state_of_b_on_a.root(),
chan_end_path_on_b,
Path::ChannelEnd(chan_end_path_on_b),
expected_chan_end_on_b.encode_vec(),
)
.map_err(ChannelError::VerifyChannelFailed)?;
Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics04-channel/src/handler/chan_open_confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ibc_core_client::context::prelude::*;
use ibc_core_connection::types::State as ConnectionState;
use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::path::{ChannelEndPath, ClientConsensusStatePath};
use ibc_core_host::types::path::{ChannelEndPath, ClientConsensusStatePath, Path};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_core_router::module::Module;
use ibc_primitives::prelude::*;
Expand Down Expand Up @@ -156,7 +156,7 @@ where
prefix_on_a,
&msg.proof_chan_end_on_a,
consensus_state_of_a_on_b.root(),
chan_end_path_on_a,
Path::ChannelEnd(chan_end_path_on_a),
expected_chan_end_on_a.encode_vec(),
)
.map_err(ChannelError::VerifyChannelFailed)?;
Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics04-channel/src/handler/chan_open_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::identifiers::ChannelId;
use ibc_core_host::types::path::{
ChannelEndPath, ClientConsensusStatePath, SeqAckPath, SeqRecvPath, SeqSendPath,
ChannelEndPath, ClientConsensusStatePath, Path, SeqAckPath, SeqRecvPath, SeqSendPath,
};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_core_router::module::Module;
Expand Down Expand Up @@ -175,7 +175,7 @@ where
prefix_on_a,
&msg.proof_chan_end_on_a,
consensus_state_of_a_on_b.root(),
chan_end_path_on_a,
Path::ChannelEnd(chan_end_path_on_a),
expected_chan_end_on_a.encode_vec(),
)
.map_err(ChannelError::VerifyChannelFailed)?;
Expand Down
5 changes: 3 additions & 2 deletions ibc-core/ics04-channel/src/handler/recv_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use ibc_core_connection::types::State as ConnectionState;
use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::path::{
AckPath, ChannelEndPath, ClientConsensusStatePath, CommitmentPath, ReceiptPath, SeqRecvPath,
AckPath, ChannelEndPath, ClientConsensusStatePath, CommitmentPath, Path, ReceiptPath,
SeqRecvPath,
};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_core_router::module::Module;
Expand Down Expand Up @@ -214,7 +215,7 @@ where
conn_end_on_b.counterparty().prefix(),
&msg.proof_commitment_on_a,
consensus_state_of_a_on_b.root(),
commitment_path_on_a,
Path::Commitment(commitment_path_on_a),
expected_commitment_on_a.into_vec(),
)
.map_err(|e| ChannelError::PacketVerificationFailed {
Expand Down
6 changes: 3 additions & 3 deletions ibc-core/ics04-channel/src/handler/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ibc_core_connection::delay::verify_conn_delay_passed;
use ibc_core_handler_types::error::ContextError;
use ibc_core_handler_types::events::{IbcEvent, MessageEvent};
use ibc_core_host::types::path::{
ChannelEndPath, ClientConsensusStatePath, CommitmentPath, ReceiptPath, SeqRecvPath,
ChannelEndPath, ClientConsensusStatePath, CommitmentPath, Path, ReceiptPath, SeqRecvPath,
};
use ibc_core_host::{ExecutionContext, ValidationContext};
use ibc_core_router::module::Module;
Expand Down Expand Up @@ -225,7 +225,7 @@ where
conn_end_on_a.counterparty().prefix(),
&msg.proof_unreceived_on_b,
consensus_state_of_b_on_a.root(),
seq_recv_path_on_b,
Path::SeqRecv(seq_recv_path_on_b),
msg.packet.seq_on_a.to_vec(),
)
}
Expand All @@ -240,7 +240,7 @@ where
conn_end_on_a.counterparty().prefix(),
&msg.proof_unreceived_on_b,
consensus_state_of_b_on_a.root(),
receipt_path_on_b,
Path::Receipt(receipt_path_on_b),
)
}
Order::None => {
Expand Down
8 changes: 4 additions & 4 deletions ibc-core/ics04-channel/src/handler/timeout_on_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ibc_core_client::context::prelude::*;
use ibc_core_connection::delay::verify_conn_delay_passed;
use ibc_core_handler_types::error::ContextError;
use ibc_core_host::types::path::{
ChannelEndPath, ClientConsensusStatePath, CommitmentPath, ReceiptPath, SeqRecvPath,
ChannelEndPath, ClientConsensusStatePath, CommitmentPath, Path, ReceiptPath, SeqRecvPath,
};
use ibc_core_host::ValidationContext;
use ibc_primitives::prelude::*;
Expand Down Expand Up @@ -111,7 +111,7 @@ where
prefix_on_b,
&msg.proof_close_on_b,
consensus_state_of_b_on_a.root(),
chan_end_path_on_b,
Path::ChannelEnd(chan_end_path_on_b),
expected_chan_end_on_b.encode_vec(),
)
.map_err(ChannelError::VerifyChannelFailed)
Expand All @@ -135,7 +135,7 @@ where
conn_end_on_a.counterparty().prefix(),
&msg.proof_unreceived_on_b,
consensus_state_of_b_on_a.root(),
seq_recv_path_on_b,
Path::SeqRecv(seq_recv_path_on_b),
packet.seq_on_a.to_vec(),
)
}
Expand All @@ -150,7 +150,7 @@ where
conn_end_on_a.counterparty().prefix(),
&msg.proof_unreceived_on_b,
consensus_state_of_b_on_a.root(),
receipt_path_on_b,
Path::Receipt(receipt_path_on_b),
)
}
Order::None => {
Expand Down
4 changes: 2 additions & 2 deletions ibc-core/ics24-host/types/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ impl PathBytes {
self.0
}

/// Concatenates a list of path bytes into a single path.
pub fn concat(paths: Vec<PathBytes>) -> Self {
/// Flattens a list of path bytes into a single path.
pub fn flatten(paths: Vec<PathBytes>) -> Self {
let mut bytes = Vec::new();
paths.iter().for_each(|path| {
bytes.extend_from_slice(&path.0);
Expand Down

0 comments on commit e5dfbfb

Please sign in to comment.