Skip to content

Commit c591d09

Browse files
authored
Merge pull request #282 from hyperledger-labs/query-can-transition-to-flush-complete
Add `getCanTransitionToFlushComplete` to IBCQuerier Signed-off-by: Jun Kimura <[email protected]>
2 parents 732f269 + 0750feb commit c591d09

File tree

6 files changed

+217
-126
lines changed

6 files changed

+217
-126
lines changed

.gas-snapshot

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
1-
IBCMockAppTest:testHandshake() (gas: 4420400)
2-
IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3334308)
3-
IBCMockAppTest:testPacketRelay() (gas: 13931868)
4-
IBCMockAppTest:testPacketTimeout() (gas: 4279269)
1+
IBCMockAppTest:testHandshake() (gas: 4420488)
2+
IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3334373)
3+
IBCMockAppTest:testPacketRelay() (gas: 13931365)
4+
IBCMockAppTest:testPacketTimeout() (gas: 4279263)
55
IBCTest:testBenchmarkCreateMockClient() (gas: 233366)
66
IBCTest:testBenchmarkLCUpdateMockClient() (gas: 62005)
7-
IBCTest:testBenchmarkRecvPacket() (gas: 158921)
8-
IBCTest:testBenchmarkSendPacket() (gas: 128424)
7+
IBCTest:testBenchmarkRecvPacket() (gas: 158899)
8+
IBCTest:testBenchmarkSendPacket() (gas: 128432)
99
IBCTest:testBenchmarkUpdateMockClient() (gas: 160229)
1010
IBCTest:testToUint128((uint64,uint64)) (runs: 256, μ: 947, ~: 947)
11-
TestICS02:testCreateClient() (gas: 36328221)
12-
TestICS02:testInvalidCreateClient() (gas: 36225735)
13-
TestICS02:testInvalidUpdateClient() (gas: 36224438)
14-
TestICS02:testRegisterClient() (gas: 35880037)
15-
TestICS02:testRegisterClientDuplicatedClientType() (gas: 35865346)
16-
TestICS02:testRegisterClientInvalidClientType() (gas: 35894673)
17-
TestICS02:testUpdateClient() (gas: 36392638)
18-
TestICS03Handshake:testConnOpenAck() (gas: 1858318)
19-
TestICS03Handshake:testConnOpenConfirm() (gas: 2054253)
20-
TestICS03Handshake:testConnOpenInit() (gas: 1429882)
21-
TestICS03Handshake:testConnOpenTry() (gas: 2398932)
22-
TestICS03Handshake:testInvalidConnOpenAck() (gas: 2422020)
23-
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2535722)
11+
TestICS02:testCreateClient() (gas: 36551707)
12+
TestICS02:testInvalidCreateClient() (gas: 36448926)
13+
TestICS02:testInvalidUpdateClient() (gas: 36447834)
14+
TestICS02:testRegisterClient() (gas: 36103500)
15+
TestICS02:testRegisterClientDuplicatedClientType() (gas: 36088809)
16+
TestICS02:testRegisterClientInvalidClientType() (gas: 36118270)
17+
TestICS02:testUpdateClient() (gas: 36616034)
18+
TestICS03Handshake:testConnOpenAck() (gas: 1858230)
19+
TestICS03Handshake:testConnOpenConfirm() (gas: 2054143)
20+
TestICS03Handshake:testConnOpenInit() (gas: 1429838)
21+
TestICS03Handshake:testConnOpenTry() (gas: 2398844)
22+
TestICS03Handshake:testInvalidConnOpenAck() (gas: 2421822)
23+
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2535568)
2424
TestICS03Handshake:testInvalidConnOpenInit() (gas: 783147)
25-
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2342609)
25+
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2342543)
2626
TestICS03Version:testCopyVersions() (gas: 558658)
2727
TestICS03Version:testFindSupportedVersion() (gas: 19400)
2828
TestICS03Version:testIsSupportedVersion() (gas: 7864)
2929
TestICS03Version:testPickVersion() (gas: 25327)
3030
TestICS03Version:testVerifyProposedVersion() (gas: 11777)
3131
TestICS03Version:testVerifySupportedFeature() (gas: 4153)
3232
TestICS04Handshake:testBindPort() (gas: 124350)
33-
TestICS04Handshake:testChanClose() (gas: 12938668)
34-
TestICS04Handshake:testChanOpenAck() (gas: 3459596)
35-
TestICS04Handshake:testChanOpenConfirm() (gas: 3770909)
36-
TestICS04Handshake:testChanOpenInit() (gas: 2543717)
37-
TestICS04Handshake:testChanOpenTry() (gas: 3100002)
38-
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2439814)
39-
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2517403)
40-
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1758661)
41-
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1773244)
42-
TestICS04Packet:testAcknowledgementPacket() (gas: 3351538)
43-
TestICS04Packet:testInvalidSendPacket() (gas: 3551759)
44-
TestICS04Packet:testRecvPacket() (gas: 10996525)
45-
TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3260141)
46-
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3279291)
47-
TestICS04Packet:testSendPacket() (gas: 6413300)
48-
TestICS04Packet:testTimeoutOnClose() (gas: 3553791)
49-
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46694868)
50-
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3455607)
51-
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5244036)
52-
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5213202)
53-
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4405965)
54-
TestICS04Upgrade:testUpgradeFull() (gas: 57590258)
55-
TestICS04Upgrade:testUpgradeInit() (gas: 3068755)
56-
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2471908)
57-
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3902216)
58-
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5215801)
59-
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5589764)
60-
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4070972)
61-
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17679417)
62-
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21317049)
63-
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 44126259)
64-
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56352929)
65-
TestICS04Upgrade:testUpgradeToUnordered() (gas: 44985196)
66-
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 61712)
33+
TestICS04Handshake:testChanClose() (gas: 12938854)
34+
TestICS04Handshake:testChanOpenAck() (gas: 3459404)
35+
TestICS04Handshake:testChanOpenConfirm() (gas: 3770673)
36+
TestICS04Handshake:testChanOpenInit() (gas: 2543524)
37+
TestICS04Handshake:testChanOpenTry() (gas: 3099898)
38+
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2439749)
39+
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2517338)
40+
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1758704)
41+
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1773674)
42+
TestICS04Packet:testAcknowledgementPacket() (gas: 3351152)
43+
TestICS04Packet:testInvalidSendPacket() (gas: 3551583)
44+
TestICS04Packet:testRecvPacket() (gas: 10995054)
45+
TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3259727)
46+
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3278877)
47+
TestICS04Packet:testSendPacket() (gas: 6412442)
48+
TestICS04Packet:testTimeoutOnClose() (gas: 3553289)
49+
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46737910)
50+
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3455585)
51+
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5266374)
52+
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5235544)
53+
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4405811)
54+
TestICS04Upgrade:testUpgradeFull() (gas: 57775990)
55+
TestICS04Upgrade:testUpgradeInit() (gas: 3068711)
56+
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2471930)
57+
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3902151)
58+
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5238138)
59+
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5612071)
60+
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4070658)
61+
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17677097)
62+
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21313205)
63+
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 44260340)
64+
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56489888)
65+
TestICS04Upgrade:testUpgradeToUnordered() (gas: 45099675)
66+
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 61690)
6767
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2565532)
68-
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2473970)
68+
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2473992)
6969
TestICS20:testAddressToHex(address) (runs: 256, μ: 22726, ~: 22867)
7070
TestICS20:testHexToAddress(string) (runs: 256, μ: 4776, ~: 4734)
7171
TestICS20:testIsEscapedString() (gas: 48979)

contracts/core/04-channel/IBCChannelUpgrade.sol

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from "../04-channel/IIBCChannelUpgrade.sol";
1515
import {IBCCommitment} from "../24-host/IBCCommitment.sol";
1616
import {IBCModuleManager} from "../26-router/IBCModuleManager.sol";
17-
import {IIBCModuleUpgrade} from "../26-router/IIBCModuleUpgrade.sol";
1817
import {IBCChannelLib} from "./IBCChannelLib.sol";
1918
import {IIBCChannelUpgradeErrors} from "./IIBCChannelUpgradeErrors.sol";
2019

@@ -201,10 +200,6 @@ abstract contract IBCChannelUpgradeBase is
201200
== keccak256(bytes(proposedConnection.counterparty.connection_id));
202201
}
203202

204-
function lookupUpgradableModuleByPort(string calldata portId) internal view returns (IIBCModuleUpgrade) {
205-
return IIBCModuleUpgrade(address(lookupModuleByPort(portId)));
206-
}
207-
208203
function isAuthorizedUpgrader(string calldata portId, string calldata channelId, address msgSender)
209204
internal
210205
view
@@ -221,22 +216,6 @@ abstract contract IBCChannelUpgradeBase is
221216
return lookupUpgradableModuleByPort(portId).getUpgradeTimeout(portId, channelId);
222217
}
223218

224-
function canTransitionToFlushComplete(
225-
Channel.Order ordering,
226-
string calldata portId,
227-
string calldata channelId,
228-
uint64 upgradeSequence
229-
) internal view virtual returns (bool) {
230-
if (ordering == Channel.Order.ORDER_ORDERED) {
231-
if (nextSequenceSends[portId][channelId] == nextSequenceAcks[portId][channelId]) {
232-
return true;
233-
}
234-
}
235-
return lookupUpgradableModuleByPort(portId).canTransitionToFlushComplete(
236-
portId, channelId, upgradeSequence, _msgSender()
237-
);
238-
}
239-
240219
// --------------------- Private Functions --------------------- //
241220

242221
function writeErrorReceipt(

contracts/core/25-handler/IBCQuerier.sol

Lines changed: 77 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,89 +5,140 @@ import {Height} from "../../proto/Client.sol";
55
import {ConnectionEnd} from "../../proto/Connection.sol";
66
import {Channel, Upgrade} from "../../proto/Channel.sol";
77
import {IBCChannelLib} from "../04-channel/IBCChannelLib.sol";
8-
import {IBCHost} from "../24-host/IBCHost.sol";
98
import {IBCCommitment} from "../24-host/IBCCommitment.sol";
9+
import {IIBCModule} from "../26-router/IIBCModule.sol";
10+
import {IBCModuleManager} from "../26-router/IBCModuleManager.sol";
1011
import {IIBCQuerier} from "./IIBCQuerier.sol";
1112

12-
contract IBCQuerier is IBCHost, IIBCQuerier {
13-
function getClientByType(string calldata clientType) external view returns (address) {
13+
contract IBCQuerier is IBCModuleManager, IIBCQuerier {
14+
function getCommitmentPrefix() public view override returns (bytes memory) {
15+
return _getCommitmentPrefix();
16+
}
17+
18+
function getCommitment(bytes32 hashedPath) public view override returns (bytes32) {
19+
return commitments[hashedPath];
20+
}
21+
22+
function getExpectedTimePerBlock() public view override returns (uint64) {
23+
return expectedTimePerBlock;
24+
}
25+
26+
function getIBCModuleByPort(string calldata portId) public view override returns (IIBCModule) {
27+
return lookupModuleByPort(portId);
28+
}
29+
30+
function getIBCModuleByChannel(string calldata portId, string calldata channelId)
31+
public
32+
view
33+
override
34+
returns (IIBCModule)
35+
{
36+
return lookupModuleByChannel(portId, channelId);
37+
}
38+
39+
function getClientByType(string calldata clientType) public view override returns (address) {
1440
return clientRegistry[clientType];
1541
}
1642

17-
function getClientType(string calldata clientId) external view returns (string memory) {
43+
function getClientType(string calldata clientId) public view override returns (string memory) {
1844
return clientTypes[clientId];
1945
}
2046

21-
function getClient(string calldata clientId) external view returns (address) {
47+
function getClient(string calldata clientId) public view override returns (address) {
2248
return clientImpls[clientId];
2349
}
2450

25-
function getClientState(string calldata clientId) external view returns (bytes memory, bool) {
51+
function getClientState(string calldata clientId) public view override returns (bytes memory, bool) {
2652
return checkAndGetClient(clientId).getClientState(clientId);
2753
}
2854

2955
function getConsensusState(string calldata clientId, Height.Data calldata height)
30-
external
56+
public
3157
view
58+
override
3259
returns (bytes memory consensusStateBytes, bool)
3360
{
3461
return checkAndGetClient(clientId).getConsensusState(clientId, height);
3562
}
3663

37-
function getConnection(string calldata connectionId) external view returns (ConnectionEnd.Data memory, bool) {
64+
function getConnection(string calldata connectionId)
65+
public
66+
view
67+
override
68+
returns (ConnectionEnd.Data memory, bool)
69+
{
3870
ConnectionEnd.Data storage connection = connections[connectionId];
3971
return (connection, connection.state != ConnectionEnd.State.STATE_UNINITIALIZED_UNSPECIFIED);
4072
}
4173

4274
function getChannel(string calldata portId, string calldata channelId)
43-
external
75+
public
4476
view
77+
override
4578
returns (Channel.Data memory, bool)
4679
{
4780
Channel.Data storage channel = channels[portId][channelId];
4881
return (channel, channel.state != Channel.State.STATE_UNINITIALIZED_UNSPECIFIED);
4982
}
5083

51-
function getNextSequenceSend(string calldata portId, string calldata channelId) external view returns (uint64) {
84+
function getNextSequenceSend(string calldata portId, string calldata channelId)
85+
public
86+
view
87+
override
88+
returns (uint64)
89+
{
5290
return nextSequenceSends[portId][channelId];
5391
}
5492

55-
function getNextSequenceRecv(string calldata portId, string calldata channelId) external view returns (uint64) {
93+
function getNextSequenceRecv(string calldata portId, string calldata channelId)
94+
public
95+
view
96+
override
97+
returns (uint64)
98+
{
5699
return nextSequenceRecvs[portId][channelId];
57100
}
58101

59-
function getNextSequenceAck(string calldata portId, string calldata channelId) external view returns (uint64) {
102+
function getNextSequenceAck(string calldata portId, string calldata channelId)
103+
public
104+
view
105+
override
106+
returns (uint64)
107+
{
60108
return nextSequenceAcks[portId][channelId];
61109
}
62110

63111
function getPacketReceipt(string calldata portId, string calldata channelId, uint64 sequence)
64-
external
112+
public
65113
view
114+
override
66115
returns (IBCChannelLib.PacketReceipt)
67116
{
68117
return IBCChannelLib.receiptCommitmentToReceipt(
69118
commitments[IBCCommitment.packetReceiptCommitmentKeyCalldata(portId, channelId, sequence)]
70119
);
71120
}
72121

73-
function getCommitmentPrefix() external view returns (bytes memory) {
74-
return _getCommitmentPrefix();
75-
}
76-
77-
function getCommitment(bytes32 hashedPath) public view returns (bytes32) {
78-
return commitments[hashedPath];
79-
}
80-
81-
function getExpectedTimePerBlock() external view returns (uint64) {
82-
return expectedTimePerBlock;
83-
}
84-
85122
function getChannelUpgrade(string calldata portId, string calldata channelId)
86-
external
123+
public
87124
view
125+
override
88126
returns (Upgrade.Data memory, bool)
89127
{
90128
Upgrade.Data storage upgrade = upgrades[portId][channelId];
91129
return (upgrade, upgrade.fields.connection_hops.length != 0);
92130
}
131+
132+
function getCanTransitionToFlushComplete(string calldata portId, string calldata channelId)
133+
public
134+
view
135+
override
136+
returns (bool)
137+
{
138+
Channel.Data storage channel = channels[portId][channelId];
139+
if (channel.state != Channel.State.STATE_FLUSHING) {
140+
return false;
141+
}
142+
return canTransitionToFlushComplete(channel.ordering, portId, channelId, channel.upgrade_sequence);
143+
}
93144
}

contracts/core/25-handler/IIBCQuerier.sol

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ import {Height} from "../../proto/Client.sol";
55
import {ConnectionEnd} from "../../proto/Connection.sol";
66
import {Channel, Upgrade} from "../../proto/Channel.sol";
77
import {IBCChannelLib} from "../04-channel/IBCChannelLib.sol";
8+
import {IIBCModule} from "../26-router/IIBCModule.sol";
89

910
interface IIBCQuerier {
11+
function getCommitmentPrefix() external view returns (bytes memory);
12+
13+
function getCommitment(bytes32 hashedPath) external view returns (bytes32);
14+
15+
function getExpectedTimePerBlock() external view returns (uint64);
16+
17+
function getIBCModuleByPort(string calldata portId) external view returns (IIBCModule);
18+
19+
function getIBCModuleByChannel(string calldata portId, string calldata channelId)
20+
external
21+
view
22+
returns (IIBCModule);
23+
1024
function getClientByType(string calldata clientType) external view returns (address);
1125

1226
function getClientType(string calldata clientId) external view returns (string memory);
@@ -38,14 +52,13 @@ interface IIBCQuerier {
3852
view
3953
returns (IBCChannelLib.PacketReceipt);
4054

41-
function getCommitmentPrefix() external view returns (bytes memory);
42-
43-
function getCommitment(bytes32 hashedPath) external view returns (bytes32);
44-
45-
function getExpectedTimePerBlock() external view returns (uint64);
46-
4755
function getChannelUpgrade(string calldata portId, string calldata channelId)
4856
external
4957
view
5058
returns (Upgrade.Data memory, bool);
59+
60+
function getCanTransitionToFlushComplete(string calldata portId, string calldata channelId)
61+
external
62+
view
63+
returns (bool);
5164
}

0 commit comments

Comments
 (0)