Skip to content

Commit

Permalink
feat: add handling ordered channel for timeout packet
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhbx-smartosc committed May 7, 2024
1 parent 9ed88b9 commit 833836e
Show file tree
Hide file tree
Showing 3 changed files with 305 additions and 17 deletions.
41 changes: 33 additions & 8 deletions cardano/lib/ibc/core/ics-003-connection-semantics/verify.ak
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use ibc/core/ics_024_host_requirements/client_keys
use ibc/core/ics_024_host_requirements/connection_keys
use ibc/core/ics_024_host_requirements/packet_keys
use ibc/utils/math
use ibc/utils/bits

pub fn verify_connection_state(
client_datum_state: ClientDatumState,
Expand Down Expand Up @@ -229,13 +230,37 @@ pub fn get_block_delay(connection: ConnectionEnd) -> Int {
}

pub fn verify_next_sequence_recv(
_client_datum_state: ClientDatumState,
_connection: ConnectionEnd,
_proof_height: Height,
_proof: MerkleProof,
_port_id: ByteArray,
_channel_id: ByteArray,
_next_sequence_recv: Int,
client_datum_state: ClientDatumState,
connection: ConnectionEnd,
proof_height: Height,
proof: MerkleProof,
port_id: ByteArray,
channel_id: ByteArray,
next_sequence_recv: Int,
) -> Bool {
True
let time_delay = connection.delay_period
let block_delay = get_block_delay(connection)

let merkle_path =
merkle.apply_prefix(
connection.counterparty.prefix,
merkle.new_merkle_path(
[packet_keys.next_sequence_recv_path(port_id, channel_id)],
),
)

expect Some(consensus_state) =
dict.from_list(client_datum_state.consensus_states, height.compare)
|> dict.get(proof_height)

client_state.verify_membership(
client_datum_state.client_state,
consensus_state,
proof_height,
time_delay,
block_delay,
proof,
merkle_path,
bits.put_uint64_big_endian(next_sequence_recv),
)
}
17 changes: 16 additions & 1 deletion cardano/lib/ibc/core/ics-024-host-requirements/packet_keys.ak
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub const key_packet_receipt_prefix = "receipts"

pub const key_sequence_prefix = "sequences"

pub const key_next_seq_recv_prefix = "nextSequenceRecv"

pub fn packet_commitment_path(
port_id: ByteArray,
channel_id: ByteArray,
Expand Down Expand Up @@ -64,7 +66,16 @@ pub fn packet_receipt_path(
|> bytearray.concat(sequence_path(sequence))
}

pub fn sequence_path(sequence: Int) -> ByteArray {
pub fn next_sequence_recv_path(
port_id: ByteArray,
channel_id: ByteArray,
) -> ByteArray {
key_next_seq_recv_prefix
|> bytearray.concat("/")
|> bytearray.concat(channel_keys.channel_path_for_packet(port_id, channel_id))
}

fn sequence_path(sequence: Int) -> ByteArray {
key_sequence_prefix
|> bytearray.concat("/")
|> bytearray.concat(int.to_string(sequence))
Expand All @@ -81,3 +92,7 @@ test test_packet_acknowledgement_path() {
test test_packet_receipt_path() {
packet_receipt_path("transfer", "channel-00", 1112) == "receipts/ports/transfer/channels/channel-00/sequences/1112"
}

test test_next_sequence_recv_path() {
next_sequence_recv_path("transfer", "channel-00") == "nextSequenceRecv/ports/transfer/channels/channel-00"
}

0 comments on commit 833836e

Please sign in to comment.