Skip to content

Commit

Permalink
add counterpartyUpgradeTimeout to the storage
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Nov 26, 2024
1 parent 43f77d2 commit deac22d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions contracts/core/04-channel/IBCChannelUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ abstract contract IBCChannelUpgradeBase is IBCModuleManager, IIBCChannelUpgradeB
channel.state = Channel.State.STATE_OPEN;

delete channelStorage.upgrade;
deleteUpgradeCommitment(portId, channelId);
revertCounterpartyUpgrade(channelStorage.recvStartSequence);
revertCounterpartyUpgrade(channelStorage);
delete channelStorage.counterpartyUpgradeTimeout;

deleteUpgradeCommitment(portId, channelId);
updateChannelCommitment(portId, channelId, channel);
writeErrorReceipt(portId, channelId, channel.upgrade_sequence, err);
}
Expand Down Expand Up @@ -81,13 +82,15 @@ abstract contract IBCChannelUpgradeBase is IBCModuleManager, IIBCChannelUpgradeB
getCommitments()[IBCCommitment.channelUpgradeCommitmentKey(portId, channelId)] = commitment;
}

function revertCounterpartyUpgrade(RecvStartSequence storage recvStartSequence) internal {
function revertCounterpartyUpgrade(ChannelStorage storage channelStorage) internal {
RecvStartSequence storage recvStartSequence = channelStorage.recvStartSequence;
uint64 prevRecvStartSequence = recvStartSequence.prevSequence;
if (prevRecvStartSequence == 0) {
return;
}
recvStartSequence.prevSequence = 0;
recvStartSequence.sequence = prevRecvStartSequence;
delete channelStorage.counterpartyUpgradeTimeout;
}

function toString(UpgradeHandshakeError err) internal pure returns (string memory) {
Expand Down Expand Up @@ -135,10 +138,11 @@ abstract contract IBCChannelUpgradeCommon is IBCChannelUpgradeBase {
function setCounterpartyUpgrade(ChannelStorage storage channelStorage, Upgrade.Data calldata upgrade) internal {
RecvStartSequence storage recvStartSequence = channelStorage.recvStartSequence;
if (recvStartSequence.prevSequence != 0) {
revertCounterpartyUpgrade(recvStartSequence);
revertCounterpartyUpgrade(channelStorage);
}
recvStartSequence.prevSequence = recvStartSequence.sequence;
recvStartSequence.sequence = upgrade.next_sequence_send;
channelStorage.counterpartyUpgradeTimeout = upgrade.timeout;
}

function verifyMembership(
Expand Down Expand Up @@ -230,7 +234,7 @@ contract IBCChannelUpgradeInitTryAck is
Upgrade.Data storage upgrade = channelStorage.upgrade;
if (upgrade.fields.ordering != Channel.Order.ORDER_NONE_UNSPECIFIED) {
delete channelStorage.upgrade;
revertCounterpartyUpgrade(channelStorage.recvStartSequence);
revertCounterpartyUpgrade(channelStorage);
// NOTE: we do not delete the upgrade commitment here since the new upgrade will overwrite the old one
writeErrorReceipt(msg_.portId, msg_.channelId, channel.upgrade_sequence, UpgradeHandshakeError.Overwritten);
}
Expand Down
3 changes: 2 additions & 1 deletion contracts/core/24-host/IBCStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import {ConnectionEnd} from "../../proto/Connection.sol";
import {Channel, Upgrade} from "../../proto/Channel.sol";
import {Channel, Upgrade, Timeout} from "../../proto/Channel.sol";

abstract contract IBCStore {
// keccak256(abi.encode(uint256(keccak256("ibc.commitment")) - 1)) & ~bytes32(uint256(0xff))
Expand Down Expand Up @@ -63,6 +63,7 @@ abstract contract IBCStore {
uint64 nextSequenceRecv;
uint64 nextSequenceAck;
Upgrade.Data upgrade;
Timeout.Data counterpartyUpgradeTimeout;
uint64 latestErrorReceiptSequence;
RecvStartSequence recvStartSequence;
uint64 ackStartSequence;
Expand Down

0 comments on commit deac22d

Please sign in to comment.