@@ -260,7 +260,7 @@ module ibc::ibc {
260
260
}
261
261
262
262
public struct TimeoutPacket has drop , store , copy {
263
- packet: Packet
263
+ packet_hash: vector < u8 >
264
264
}
265
265
266
266
public struct WriteAck has drop , store , copy {
@@ -1423,7 +1423,7 @@ module ibc::ibc {
1423
1423
commitment::batch_packets_commitment_key (
1424
1424
packet_hash
1425
1425
);
1426
- set_packet_acknowledged (ibc_store, commitment_key);
1426
+ ibc_store. set_packet_acknowledged (commitment_key);
1427
1427
1428
1428
event::emit (
1429
1429
PacketAck {
@@ -1491,32 +1491,37 @@ module ibc::ibc {
1491
1491
*commitment = commitment::commit_ack (acknowledgement);
1492
1492
}
1493
1493
1494
- public fun timeout_packet (
1494
+ public fun timeout_packet < T : drop > (
1495
1495
ibc_store: &mut IBCStore ,
1496
1496
packet: Packet ,
1497
1497
proof: vector <u8 >,
1498
1498
proof_height: u64 ,
1499
+ witness: T ,
1499
1500
) {
1500
- let source_channel = packet::source_channel_id (&packet);
1501
- let destination_channel = packet::destination_channel_id (&packet);
1501
+ let source_channel = packet.source_channel_id ();
1502
+
1503
+ let port_id = *ibc_store.channel_to_port.borrow (source_channel);
1504
+ validate_port (port_id, witness);
1505
+
1506
+ let destination_channel = packet.destination_channel_id ();
1502
1507
1503
1508
if (!ibc_store.channels.contains (source_channel)) {
1504
1509
abort E_CHANNEL_NOT_FOUND
1505
1510
};
1506
1511
let channel = ibc_store.channels.borrow (source_channel);
1507
- assert !(channel:: state (channel ) == CHAN_STATE_OPEN , E_INVALID_CHANNEL_STATE );
1512
+ assert !(channel. state () == CHAN_STATE_OPEN , E_INVALID_CHANNEL_STATE );
1508
1513
1509
- let connection_id = channel:: connection_id (channel );
1514
+ let connection_id = channel. connection_id ();
1510
1515
1511
1516
if (!ibc_store.connections.contains (connection_id)) {
1512
1517
abort E_CONNECTION_NOT_FOUND
1513
1518
};
1514
1519
let connection = ibc_store.connections.borrow (connection_id);
1515
1520
assert !(
1516
- connection_end:: state (connection ) == CONN_STATE_OPEN ,
1521
+ connection. state () == CONN_STATE_OPEN ,
1517
1522
E_INVALID_CONNECTION_STATE
1518
1523
);
1519
- let client_id = connection_end:: client_id (connection );
1524
+ let client_id = connection. client_id ();
1520
1525
1521
1526
if (!ibc_store.client_mgr.exists (client_id)) {
1522
1527
abort E_CLIENT_NOT_FOUND
@@ -1525,36 +1530,30 @@ module ibc::ibc {
1525
1530
ibc_store.client_mgr.get_timestamp_at_height (client_id, proof_height);
1526
1531
assert !(proof_timestamp != 0 , E_LATEST_TIMESTAMP_NOT_FOUND );
1527
1532
1533
+ let packet_hash = commitment::commit_packet (&packet);
1534
+ let commitment_key = commitment::batch_receipts_commitment_key (packet_hash);
1535
+
1536
+ let err = ibc_store.client_mgr.verify_non_membership (
1537
+ client_id, proof_height, proof, commitment_key);
1528
1538
1529
- let commitment_key =
1530
- commitment::batch_receipts_commitment_key (
1531
- commitment::commit_packet (&packet)
1532
- );
1533
- let err = ibc_store.client_mgr.verify_non_membership (client_id, proof_height, proof, commitment_key);
1534
1539
assert !(err == 0 , err);
1535
1540
1536
- if (packet::timeout_timestamp (&packet) != 0 ) {
1541
+ if (packet.timeout_timestamp () == 0 ) {
1542
+ abort E_TIMEOUT_MUST_BE_SET
1543
+ } else {
1537
1544
assert !(
1538
- packet:: timeout_timestamp (&packet ) < proof_timestamp,
1545
+ packet. timeout_timestamp () < proof_timestamp,
1539
1546
E_TIMESTAMP_TIMEOUT_NOT_REACHED
1540
1547
);
1541
1548
};
1542
- let height = packet::timeout_height (&packet);
1543
- if (height != 0 ) {
1544
- assert !(
1545
- height < proof_height,
1546
- E_TIMEOUT_HEIGHT_NOT_REACHED
1547
- );
1548
- };
1549
1549
1550
- let commitment_key =
1550
+ ibc_store. set_packet_acknowledged (
1551
1551
commitment::batch_packets_commitment_key (
1552
- commitment::commit_packet (&packet)
1553
- );
1554
-
1555
- ibc_store.commitments.remove (commitment_key);
1552
+ packet_hash
1553
+ )
1554
+ );
1556
1555
1557
- event::emit (TimeoutPacket { packet });
1556
+ event::emit (TimeoutPacket { packet_hash });
1558
1557
}
1559
1558
1560
1559
// #[test]
0 commit comments