Skip to content

Commit

Permalink
bring back timeout params in WriteTimeoutPacket event
Browse files Browse the repository at this point in the history
  • Loading branch information
WenweiX committed Aug 18, 2023
1 parent a7c334d commit 27998c8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
24 changes: 21 additions & 3 deletions contracts/Dispatcher.sol
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ contract Dispatcher is IbcDispatcher, Ownable {
AckPacket ackPacket
);

event WriteTimeoutPacket(address indexed writerPortAddress, bytes32 indexed writerChannelId, uint64 sequence);
event WriteTimeoutPacket(
address indexed writerPortAddress,
bytes32 indexed writerChannelId,
uint64 sequence,
Height timeoutHeight,
uint64 timeoutTimestamp
);

//
// fields
Expand Down Expand Up @@ -659,7 +665,13 @@ contract Dispatcher is IbcDispatcher, Ownable {
// If pkt is already timed out, then return early so dApps won't receive it.
if (isPacketTimeout(packet)) {
address writerPortAddress = address(receiver);
emit WriteTimeoutPacket(writerPortAddress, packet.dest.channelId, packet.sequence);
emit WriteTimeoutPacket(
writerPortAddress,
packet.dest.channelId,
packet.sequence,
packet.timeoutHeight,
packet.timeoutTimestamp
);
return;
}

Expand Down Expand Up @@ -707,7 +719,13 @@ contract Dispatcher is IbcDispatcher, Ownable {
// verify packet has timed out; zero-value in packet.timeout means no timeout set
require(!isPacketTimeout(packet), 'Packet not timed out yet');

emit WriteTimeoutPacket(receiver, packet.dest.channelId, packet.sequence);
emit WriteTimeoutPacket(
receiver,
packet.dest.channelId,
packet.sequence,
packet.timeoutHeight,
packet.timeoutTimestamp
);
}

/**
Expand Down
19 changes: 14 additions & 5 deletions test/Dispatcher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ contract Base is Test {
AckPacket ackPacket
);

event WriteTimeoutPacket(address indexed writerPortAddress, bytes32 indexed writerChannelId, uint64 sequence);
event WriteTimeoutPacket(
address indexed writerPortAddress,
bytes32 indexed writerChannelId,
uint64 sequence,
Height timeoutHeight,
uint64 timeoutTimestamp
);

ConsensusState untrustedState =
ConsensusState(
80990,
Expand Down Expand Up @@ -589,21 +596,23 @@ contract DispatcherRecvPacketTest is ChannelOpenTestBase {
// recvPacket emits a WriteTimeoutPacket if timestamp passes chain B's block time
function test_timeout_timestamp() public {
uint64 packetSeq = 1;
IbcPacket memory pkt = IbcPacket(src, dest, packetSeq, payload, ZERO_HEIGHT, 1);
vm.expectEmit(true, true, true, true, address(dispatcher));
emit RecvPacket(address(mars), channelId, packetSeq);
vm.expectEmit(true, true, false, true, address(dispatcher));
emit WriteTimeoutPacket(address(mars), channelId, packetSeq);
dispatcher.recvPacket(IbcReceiver(mars), IbcPacket(src, dest, packetSeq, payload, ZERO_HEIGHT, 1), validProof);
emit WriteTimeoutPacket(address(mars), channelId, packetSeq, pkt.timeoutHeight, pkt.timeoutTimestamp);
dispatcher.recvPacket(IbcReceiver(mars), pkt, validProof);
}

// recvPacket emits a WriteTimeoutPacket if block height passes chain B's block height
function test_timeout_blockHeight() public {
uint64 packetSeq = 1;
IbcPacket memory pkt = IbcPacket(src, dest, packetSeq, payload, Height(0, 1), 0);
vm.expectEmit(true, true, true, true, address(dispatcher));
emit RecvPacket(address(mars), channelId, packetSeq);
vm.expectEmit(true, true, false, true, address(dispatcher));
emit WriteTimeoutPacket(address(mars), channelId, packetSeq);
dispatcher.recvPacket(IbcReceiver(mars), IbcPacket(src, dest, packetSeq, payload, Height(0, 1), 0), validProof);
emit WriteTimeoutPacket(address(mars), channelId, packetSeq, pkt.timeoutHeight, pkt.timeoutTimestamp);
dispatcher.recvPacket(IbcReceiver(mars), pkt, validProof);
}

// cannot receive packets out of order for ordered channel
Expand Down

0 comments on commit 27998c8

Please sign in to comment.