Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp: relocate timeout checks and use get app function #49

Merged
merged 4 commits into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions src/ICS26Router.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ contract ICS26Router is IICS26Router, IBCStore, Ownable, IICS26RouterErrors, Ree
revert IBCInvalidPortIdentifier(newPortId);
}

emit IBCAppAdded(newPortId, app);

apps[newPortId] = IIBCApp(app);

emit IBCAppAdded(newPortId, app);
}

/// @notice Sends a packet
Expand Down Expand Up @@ -90,14 +90,9 @@ contract ICS26Router is IICS26Router, IBCStore, Ownable, IICS26RouterErrors, Ree
data: msg_.data
});

IIBCAppCallbacks.OnSendPacketCallback memory sendPacketCallback =
IIBCAppCallbacks.OnSendPacketCallback({ packet: packet, sender: msg.sender });

IIBCApp app = apps[msg_.sourcePort];
if (app == IIBCApp(address(0))) {
revert IBCAppNotFound(msg_.sourcePort);
}
app.onSendPacket(sendPacketCallback);
getIBCApp(msg_.sourcePort).onSendPacket(
IIBCAppCallbacks.OnSendPacketCallback({ packet: packet, sender: msg.sender })
);

IBCStore.commitPacket(packet);

Expand All @@ -114,6 +109,10 @@ contract ICS26Router is IICS26Router, IBCStore, Ownable, IICS26RouterErrors, Ree
revert IBCInvalidCounterparty(cInfo.clientId, msg_.packet.sourceChannel);
}

if (msg_.packet.timeoutTimestamp <= block.timestamp) {
revert IBCInvalidTimeoutTimestamp(msg_.packet.timeoutTimestamp, block.timestamp);
}

bytes memory commitmentPath = ICS24Host.packetCommitmentPathCalldata(
msg_.packet.sourcePort, msg_.packet.sourceChannel, msg_.packet.sequence
);
Expand All @@ -128,10 +127,6 @@ contract ICS26Router is IICS26Router, IBCStore, Ownable, IICS26RouterErrors, Ree

ics02Client.getClient(msg_.packet.destChannel).membership(membershipMsg);

if (msg_.packet.timeoutTimestamp <= block.timestamp) {
revert IBCInvalidTimeoutTimestamp(msg_.packet.timeoutTimestamp, block.timestamp);
}

bytes memory ack = getIBCApp(msg_.packet.destPort).onRecvPacket(
IIBCAppCallbacks.OnRecvPacketCallback({ packet: msg_.packet, relayer: msg.sender })
);
Expand Down Expand Up @@ -191,8 +186,6 @@ contract ICS26Router is IICS26Router, IBCStore, Ownable, IICS26RouterErrors, Ree
/// @param msg_ The message for timing out packets
/// @inheritdoc IICS26Router
function timeoutPacket(MsgTimeoutPacket calldata msg_) external nonReentrant {
IIBCApp app = getIBCApp(msg_.packet.sourcePort);

IICS02ClientMsgs.CounterpartyInfo memory cInfo = ics02Client.getCounterparty(msg_.packet.sourceChannel);
if (keccak256(bytes(cInfo.clientId)) != keccak256(bytes(msg_.packet.destChannel))) {
revert IBCInvalidCounterparty(cInfo.clientId, msg_.packet.destChannel);
Expand All @@ -219,7 +212,9 @@ contract ICS26Router is IICS26Router, IBCStore, Ownable, IICS26RouterErrors, Ree
revert IBCInvalidTimeoutTimestamp(msg_.packet.timeoutTimestamp, counterpartyTimestamp);
}

app.onTimeoutPacket(IIBCAppCallbacks.OnTimeoutPacketCallback({ packet: msg_.packet, relayer: msg.sender }));
getIBCApp(msg_.packet.sourcePort).onTimeoutPacket(
IIBCAppCallbacks.OnTimeoutPacketCallback({ packet: msg_.packet, relayer: msg.sender })
);

emit TimeoutPacket(msg_.packet);
}
Expand Down
Loading