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

Add getCanTransitionToFlushComplete to IIBCChannelUpgradeBase #281

Closed
Closed
Show file tree
Hide file tree
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
116 changes: 58 additions & 58 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
IBCMockAppTest:testHandshake() (gas: 4420400)
IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3334308)
IBCMockAppTest:testPacketRelay() (gas: 13931868)
IBCMockAppTest:testPacketTimeout() (gas: 4279269)
IBCMockAppTest:testHandshake() (gas: 4420444)
IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3334329)
IBCMockAppTest:testPacketRelay() (gas: 13932110)
IBCMockAppTest:testPacketTimeout() (gas: 4284202)
IBCTest:testBenchmarkCreateMockClient() (gas: 233366)
IBCTest:testBenchmarkLCUpdateMockClient() (gas: 62005)
IBCTest:testBenchmarkRecvPacket() (gas: 158921)
IBCTest:testBenchmarkRecvPacket() (gas: 158899)
IBCTest:testBenchmarkSendPacket() (gas: 128424)
IBCTest:testBenchmarkUpdateMockClient() (gas: 160229)
IBCTest:testToUint128((uint64,uint64)) (runs: 256, μ: 947, ~: 947)
TestICS02:testCreateClient() (gas: 36328221)
TestICS02:testInvalidCreateClient() (gas: 36225735)
TestICS02:testInvalidUpdateClient() (gas: 36224438)
TestICS02:testRegisterClient() (gas: 35880037)
TestICS02:testRegisterClientDuplicatedClientType() (gas: 35865346)
TestICS02:testRegisterClientInvalidClientType() (gas: 35894673)
TestICS02:testUpdateClient() (gas: 36392638)
TestICS03Handshake:testConnOpenAck() (gas: 1858318)
TestICS03Handshake:testConnOpenConfirm() (gas: 2054253)
TestICS03Handshake:testConnOpenInit() (gas: 1429882)
TestICS03Handshake:testConnOpenTry() (gas: 2398932)
TestICS03Handshake:testInvalidConnOpenAck() (gas: 2422020)
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2535722)
TestICS02:testCreateClient() (gas: 39608978)
TestICS02:testInvalidCreateClient() (gas: 39506240)
TestICS02:testInvalidUpdateClient() (gas: 39505105)
TestICS02:testRegisterClient() (gas: 39160771)
TestICS02:testRegisterClientDuplicatedClientType() (gas: 39146080)
TestICS02:testRegisterClientInvalidClientType() (gas: 39175541)
TestICS02:testUpdateClient() (gas: 39673305)
TestICS03Handshake:testConnOpenAck() (gas: 1858230)
TestICS03Handshake:testConnOpenConfirm() (gas: 2054143)
TestICS03Handshake:testConnOpenInit() (gas: 1429838)
TestICS03Handshake:testConnOpenTry() (gas: 2398844)
TestICS03Handshake:testInvalidConnOpenAck() (gas: 2421822)
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2535568)
TestICS03Handshake:testInvalidConnOpenInit() (gas: 783147)
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2342609)
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2342543)
TestICS03Version:testCopyVersions() (gas: 558658)
TestICS03Version:testFindSupportedVersion() (gas: 19400)
TestICS03Version:testIsSupportedVersion() (gas: 7864)
TestICS03Version:testPickVersion() (gas: 25327)
TestICS03Version:testVerifyProposedVersion() (gas: 11777)
TestICS03Version:testVerifySupportedFeature() (gas: 4153)
TestICS04Handshake:testBindPort() (gas: 124350)
TestICS04Handshake:testChanClose() (gas: 12938668)
TestICS04Handshake:testChanOpenAck() (gas: 3459596)
TestICS04Handshake:testChanOpenConfirm() (gas: 3770909)
TestICS04Handshake:testChanOpenInit() (gas: 2543717)
TestICS04Handshake:testChanOpenTry() (gas: 3100002)
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2439814)
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2517403)
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1758661)
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1773244)
TestICS04Packet:testAcknowledgementPacket() (gas: 3351538)
TestICS04Packet:testInvalidSendPacket() (gas: 3551759)
TestICS04Packet:testRecvPacket() (gas: 10996525)
TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3260141)
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3279291)
TestICS04Packet:testSendPacket() (gas: 6413300)
TestICS04Packet:testTimeoutOnClose() (gas: 3553791)
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46694868)
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3455607)
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5244036)
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5213202)
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4405965)
TestICS04Upgrade:testUpgradeFull() (gas: 57590258)
TestICS04Upgrade:testUpgradeInit() (gas: 3068755)
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2471908)
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3902216)
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5215801)
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5589764)
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4070972)
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17679417)
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21317049)
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 44126259)
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56352929)
TestICS04Upgrade:testUpgradeToUnordered() (gas: 44985196)
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 61712)
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2565532)
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2473970)
TestICS20:testAddressToHex(address) (runs: 256, μ: 22726, ~: 22867)
TestICS04Handshake:testBindPort() (gas: 124338)
TestICS04Handshake:testChanClose() (gas: 12973840)
TestICS04Handshake:testChanOpenAck() (gas: 3459464)
TestICS04Handshake:testChanOpenConfirm() (gas: 3770689)
TestICS04Handshake:testChanOpenInit() (gas: 2543587)
TestICS04Handshake:testChanOpenTry() (gas: 3099958)
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2439815)
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2517382)
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1758864)
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1773770)
TestICS04Packet:testAcknowledgementPacket() (gas: 3351624)
TestICS04Packet:testInvalidSendPacket() (gas: 3578905)
TestICS04Packet:testRecvPacket() (gas: 11004848)
TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3259655)
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3283805)
TestICS04Packet:testSendPacket() (gas: 6412242)
TestICS04Packet:testTimeoutOnClose() (gas: 3553217)
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46767387)
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3455431)
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5281166)
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5250234)
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4405249)
TestICS04Upgrade:testUpgradeFull() (gas: 57901350)
TestICS04Upgrade:testUpgradeInit() (gas: 3071123)
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2471864)
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3901850)
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5252930)
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5626921)
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4070257)
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17674603)
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21309579)
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 44347565)
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56577617)
TestICS04Upgrade:testUpgradeToUnordered() (gas: 45172851)
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 61690)
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2565510)
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2475970)
TestICS20:testAddressToHex(address) (runs: 256, μ: 22668, ~: 22804)
TestICS20:testHexToAddress(string) (runs: 256, μ: 4776, ~: 4734)
TestICS20:testIsEscapedString() (gas: 48979)
TestICS20:testMarshaling() (gas: 148517)
TestICS20:testParseAmount(uint256) (runs: 256, μ: 26449, ~: 24175)
TestICS20:testParseAmount(uint256) (runs: 256, μ: 26349, ~: 23311)
27 changes: 21 additions & 6 deletions contracts/core/04-channel/IBCChannelUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import {IBCConnectionLib} from "../03-connection/IBCConnectionLib.sol";
import {IIBCConnectionErrors} from "../03-connection/IIBCConnectionErrors.sol";
import {
IIBCChannelUpgradeBase,
IIBCChannelUpgradeInitTryAck,
IIBCChannelUpgradeConfirmOpenTimeoutCancel
IIBCChannelUpgradeInitTry,
IIBCChannelUpgradeAckConfirm,
IIBCChannelUpgradeOpenTimeoutCancel
} from "../04-channel/IIBCChannelUpgrade.sol";
import {IBCCommitment} from "../24-host/IBCCommitment.sol";
import {IBCModuleManager} from "../26-router/IBCModuleManager.sol";
Expand Down Expand Up @@ -226,7 +227,7 @@ abstract contract IBCChannelUpgradeBase is
string calldata portId,
string calldata channelId,
uint64 upgradeSequence
) internal view virtual returns (bool) {
) internal view returns (bool) {
if (ordering == Channel.Order.ORDER_ORDERED) {
if (nextSequenceSends[portId][channelId] == nextSequenceAcks[portId][channelId]) {
return true;
Expand Down Expand Up @@ -370,9 +371,21 @@ abstract contract IBCChannelUpgradeBase is
}
return string(result);
}

// --------------------- External Functions --------------------- //

function getCanTransitionToFlushComplete(string calldata portId, string calldata channelId)
external
view
override
returns (bool)
{
Channel.Data storage channel = channels[portId][channelId];
return canTransitionToFlushComplete(channel.ordering, portId, channelId, channel.upgrade_sequence);
}
}

contract IBCChannelUpgradeInitTryAck is IBCChannelUpgradeBase, IIBCChannelUpgradeInitTryAck {
contract IBCChannelUpgradeInitTry is IBCChannelUpgradeBase, IIBCChannelUpgradeInitTry {
/**
* @dev See {IIBCChannelUpgrade-channelUpgradeInit}
*/
Expand Down Expand Up @@ -514,7 +527,9 @@ contract IBCChannelUpgradeInitTryAck is IBCChannelUpgradeBase, IIBCChannelUpgrad

return (true, channel.upgrade_sequence);
}
}

contract IBCChannelUpgradeAckConfirm is IBCChannelUpgradeBase, IIBCChannelUpgradeAckConfirm {
/**
* @dev See {IIBCChannelUpgrade-channelUpgradeAck}
*/
Expand Down Expand Up @@ -602,9 +617,7 @@ contract IBCChannelUpgradeInitTryAck is IBCChannelUpgradeBase, IIBCChannelUpgrad

return true;
}
}

contract IBCChannelUpgradeConfirmTimeoutCancel is IBCChannelUpgradeBase, IIBCChannelUpgradeConfirmOpenTimeoutCancel {
/**
* @dev See {IIBCChannelUpgrade-channelUpgradeConfirm}
*/
Expand Down Expand Up @@ -665,7 +678,9 @@ contract IBCChannelUpgradeConfirmTimeoutCancel is IBCChannelUpgradeBase, IIBCCha

return true;
}
}

contract IBCChannelUpgradeOpenTimeoutCancel is IBCChannelUpgradeBase, IIBCChannelUpgradeOpenTimeoutCancel {
/**
* @dev See {IIBCChannelUpgrade-channelUpgradeOpen}
*/
Expand Down
69 changes: 43 additions & 26 deletions contracts/core/04-channel/IIBCChannelUpgrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ interface IIBCChannelUpgradeBase {
/// @param channelId channel identifier
/// @param upgradeSequence upgrade sequence
event WriteErrorReceipt(string portId, string channelId, uint64 upgradeSequence, string message);

// --------------------- External Functions --------------------- //

function getCanTransitionToFlushComplete(string calldata portId, string calldata channelId)
external
view
returns (bool);
}

interface IIBCChannelUpgradeInitTryAck is IIBCChannelUpgradeBase {
interface IIBCChannelUpgradeInitTry is IIBCChannelUpgradeBase {
// --------------------- Events --------------------- //

/// @notice emitted when channelUpgradeInit is successfully executed
Expand All @@ -101,18 +108,6 @@ interface IIBCChannelUpgradeInitTryAck is IIBCChannelUpgradeBase {
uint64 nextSequenceSend
);

/// @notice emitted when channelUpgradeAck is successfully executed
/// @param channelState post channel state (FLUSHING or FLUSHCOMPLETE)
event ChannelUpgradeAck(
string portId,
string channelId,
uint64 upgradeSequence,
Channel.State channelState,
UpgradeFields.Data upgradeFields,
Timeout.Data timeout,
uint64 nextSequenceSend
);

// --------------------- External Functions --------------------- //

/**
Expand All @@ -130,6 +125,28 @@ interface IIBCChannelUpgradeInitTryAck is IIBCChannelUpgradeBase {
* If the upgrade fails, the upgrade sequence will still be incremented but an error will be returned.
*/
function channelUpgradeTry(MsgChannelUpgradeTry calldata msg_) external returns (bool ok, uint64 upgradeSequence);
}

interface IIBCChannelUpgradeAckConfirm is IIBCChannelUpgradeBase {
// --------------------- Events --------------------- //

/// @notice emitted when channelUpgradeAck is successfully executed
/// @param channelState post channel state (FLUSHING or FLUSHCOMPLETE)
event ChannelUpgradeAck(
string portId,
string channelId,
uint64 upgradeSequence,
Channel.State channelState,
UpgradeFields.Data upgradeFields,
Timeout.Data timeout,
uint64 nextSequenceSend
);

/// @notice emitted when channelUpgradeConfirm is successfully executed
/// @param channelState post channel state (FLUSHING or FLUSHCOMPLETE or OPEN)
event ChannelUpgradeConfirm(string portId, string channelId, uint64 upgradeSequence, Channel.State channelState);

// --------------------- External Functions --------------------- //

/**
* @dev channelUpgradeAck is called by a module to accept the ACKUPGRADE handshake step of the channel upgrade protocol.
Expand All @@ -144,27 +161,23 @@ interface IIBCChannelUpgradeInitTryAck is IIBCChannelUpgradeBase {
* A -> Init (OPEN), B -> Init (OPEN) -> A -> Try (FLUSHING), B -> Try (FLUSHING), A -> Ack (begins in FLUSHING, ends in FLUSHING or FLUSHCOMPLETE)
*/
function channelUpgradeAck(MsgChannelUpgradeAck calldata msg_) external returns (bool);

/**
* @dev channelUpgradeConfirm is called on the chain which is on FLUSHING after channelUpgradeAck is called on the counterparty.
* This will inform the TRY chain of the timeout set on ACK by the counterparty. If the timeout has already exceeded,
* we will write an error receipt and restore the channel to OPEN state.
*/
function channelUpgradeConfirm(MsgChannelUpgradeConfirm calldata msg_) external returns (bool);
}

interface IIBCChannelUpgradeConfirmOpenTimeoutCancel is IIBCChannelUpgradeBase {
interface IIBCChannelUpgradeOpenTimeoutCancel is IIBCChannelUpgradeBase {
// --------------------- Events --------------------- //

/// @notice emitted when channelUpgradeConfirm is successfully executed
/// @param channelState post channel state (FLUSHING or FLUSHCOMPLETE or OPEN)
event ChannelUpgradeConfirm(string portId, string channelId, uint64 upgradeSequence, Channel.State channelState);

/// @notice emitted when channelUpgradeOpen is successfully executed
event ChannelUpgradeOpen(string portId, string channelId, uint64 upgradeSequence);

// --------------------- External Functions --------------------- //

/**
* @dev channelUpgradeConfirm is called on the chain which is on FLUSHING after channelUpgradeAck is called on the counterparty.
* This will inform the TRY chain of the timeout set on ACK by the counterparty. If the timeout has already exceeded,
* we will write an error receipt and restore the channel to OPEN state.
*/
function channelUpgradeConfirm(MsgChannelUpgradeConfirm calldata msg_) external returns (bool);

/**
* @dev channelUpgradeOpen is called by a module to complete the channel upgrade handshake and move the channel back to an OPEN state.
* This method should only be called after both channels have flushed any in-flight packets.
Expand All @@ -185,4 +198,8 @@ interface IIBCChannelUpgradeConfirmOpenTimeoutCancel is IIBCChannelUpgradeBase {
function timeoutChannelUpgrade(MsgTimeoutChannelUpgrade calldata msg_) external;
}

interface IIBCChannelUpgrade is IIBCChannelUpgradeInitTryAck, IIBCChannelUpgradeConfirmOpenTimeoutCancel {}
interface IIBCChannelUpgrade is
IIBCChannelUpgradeInitTry,
IIBCChannelUpgradeAckConfirm,
IIBCChannelUpgradeOpenTimeoutCancel
{}
Loading