Skip to content

Commit

Permalink
give channel proof
Browse files Browse the repository at this point in the history
  • Loading branch information
yito88 committed Aug 20, 2022
1 parent b739e9a commit 198089d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
24 changes: 23 additions & 1 deletion shared/src/ledger/ibc/vp/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub enum Error {
IbcStorage(IbcStorageError),
#[error("IBC event error: {0}")]
IbcEvent(String),
#[error("IBC proof error: {0}")]
Proof(String),
}

/// IBC packet functions result
Expand Down Expand Up @@ -601,13 +603,14 @@ where
channel.version().clone(),
);

let proofs_closed = make_proofs_for_channel(&proofs)?;
verify_channel_proofs(
self,
height,
&channel,
&connection,
&expected_channel,
&proofs,
&proofs_closed,
)
.map_err(Error::ProofVerificationFailure)?;
}
Expand Down Expand Up @@ -693,6 +696,25 @@ where
}
}

/// The proof for the counterpart channel should be in proofs.other_proof
/// `verify_channel_proofs()` requires the proof is in proofs.object_proof
fn make_proofs_for_channel(proofs: &Proofs) -> Result<Proofs> {
let proof_closed = match proofs.other_proof() {
Some(p) => p.clone(),
None => {
return Err(Error::Proof(
"No proof for the counterpart channel".to_string(),
));
}
};
Proofs::new(proof_closed, None, None, None, proofs.height()).map_err(|e| {
Error::Proof(format!(
"Creating Proofs for the counterpart channel failed: error {}",
e
))
})
}

impl From<IbcStorageError> for Error {
fn from(err: IbcStorageError) -> Self {
Self::IbcStorage(err)
Expand Down
19 changes: 16 additions & 3 deletions tests/src/vm_host_env/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,9 @@ pub fn msg_transfer(
}
}

pub fn set_timeout_height(msg: &mut MsgTransfer) {
msg.timeout_height = Height::new(1, 1);
pub fn set_timeout_timestamp(msg: &mut MsgTransfer) {
msg.timeout_timestamp =
(msg.timeout_timestamp - Duration::from_secs(101)).unwrap();
}

pub fn msg_packet_recv(packet: Packet) -> MsgRecvPacket {
Expand Down Expand Up @@ -657,10 +658,22 @@ pub fn msg_timeout_on_close(
packet: Packet,
next_sequence_recv: Sequence,
) -> MsgTimeoutOnClose {
// add the channel proof
let height = Height::new(0, 1);
let consensus_proof =
ConsensusProof::new(vec![0].try_into().unwrap(), height).unwrap();
let proofs = Proofs::new(
vec![0].try_into().unwrap(),
Some(vec![0].try_into().unwrap()),
Some(consensus_proof),
Some(vec![0].try_into().unwrap()),
height,
)
.unwrap();
MsgTimeoutOnClose {
packet,
next_sequence_recv,
proofs: dummy_proofs(),
proofs,
signer: Signer::new("test"),
}
}
2 changes: 1 addition & 1 deletion tests/src/vm_host_env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ mod tests {
// Start a transaction to send a packet
let mut msg =
ibc::msg_transfer(port_id, channel_id, token.to_string(), &sender);
ibc::set_timeout_height(&mut msg);
ibc::set_timeout_timestamp(&mut msg);
let mut tx_data = vec![];
msg.clone()
.to_any()
Expand Down

0 comments on commit 198089d

Please sign in to comment.