Skip to content

Commit ca0dd96

Browse files
committed
Add support for old and new extension management schemes simultaneously
1 parent fc144be commit ca0dd96

File tree

7 files changed

+152
-86
lines changed

7 files changed

+152
-86
lines changed

contracts/colony/IColony.sol

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,35 +266,16 @@ interface IColony is ColonyDataTypes, IRecovery {
266266
/// @return extension The address of the extension installation
267267
function installExtension(bytes32 extensionId, uint256 version) external returns (address extension);
268268

269-
/// @dev DEPRECATED
270-
/// @notice Upgrade an extension in a colony. Secured function to authorised members.
271-
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
272-
/// @param newVersion The version to upgrade to (must be one larger than the current version)
273-
function upgradeExtension(bytes32 extensionId, uint256 newVersion) external;
274-
275269
/// @notice Upgrade an extension in a colony. Secured function to authorised members.
276270
/// @param extension The address of the extension installation
277271
/// @param newVersion The version to upgrade to (must be one larger than the current version)
278272
function upgradeExtension(address extension, uint256 newVersion) external;
279273

280-
/// @dev DEPRECATED
281-
/// @notice Set the deprecation of an extension in a colony. Secured function to authorised members.
282-
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
283-
/// @param deprecated Whether to deprecate the extension or not
284-
function deprecateExtension(bytes32 extensionId, bool deprecated) external;
285-
286274
/// @notice Set the deprecation of an extension in a colony. Secured function to authorised members.
287275
/// @param extension The address of the extension installation
288276
/// @param deprecated Whether to deprecate the extension or not
289277
function deprecateExtension(address extension, bool deprecated) external;
290278

291-
/// @dev DEPRECATED
292-
/// @notice Uninstall an extension from a colony. Secured function to authorised members.
293-
/// @dev This is a permanent action -- re-installing the extension will deploy a new contract
294-
/// @dev It is recommended to deprecate an extension before uninstalling to allow active objects to be resolved
295-
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
296-
function uninstallExtension(bytes32 extensionId) external;
297-
298279
/// @notice Uninstall an extension from a colony. Secured function to authorised members.
299280
/// @dev This is a permanent action -- re-installing the extension will deploy a new contract
300281
/// @dev It is recommended to deprecate an extension before uninstalling to allow active objects to be resolved

contracts/colonyNetwork/ColonyNetworkExtensions.sol

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
5555
require(resolvers[_extensionId][_version] != address(0x0), "colony-network-extension-bad-version");
5656

5757
EtherRouter extension = new EtherRouter();
58-
multiInstallations[address(extension)] = msg.sender;
58+
59+
// Install in old installations mapping if version 7 or below
60+
if (IColony(msg.sender).version() <= 7) {
61+
require(installations[_extensionId][msg.sender] == address(0x0), "colony-network-extension-already-installed");
62+
installations[_extensionId][msg.sender] = address(extension);
63+
} else {
64+
multiInstallations[address(extension)] = msg.sender;
65+
}
5966

6067
extension.setResolver(resolvers[_extensionId][_version]);
6168
ColonyExtension(address(extension)).install(msg.sender);
@@ -69,9 +76,17 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
6976
function upgradeExtension(bytes32 _extensionId, uint256 _newVersion)
7077
public
7178
stoppable
79+
calledByColony
7280
{
73-
address extension = migrateToMultiExtension(_extensionId, msg.sender);
74-
upgradeExtension(extension, _newVersion);
81+
require(installations[_extensionId][msg.sender] != address(0x0), "colony-network-extension-not-installed");
82+
83+
address payable extension = installations[_extensionId][msg.sender];
84+
require(_newVersion == ColonyExtension(extension).version() + 1, "colony-network-extension-bad-increment");
85+
require(resolvers[_extensionId][_newVersion] != address(0x0), "colony-network-extension-bad-version");
86+
87+
EtherRouter(extension).setResolver(resolvers[_extensionId][_newVersion]);
88+
ColonyExtension(extension).finishUpgrade();
89+
assert(ColonyExtension(extension).version() == _newVersion);
7590

7691
emit ExtensionUpgraded(_extensionId, msg.sender, _newVersion);
7792
}
@@ -100,9 +115,9 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
100115
function deprecateExtension(bytes32 _extensionId, bool _deprecated)
101116
public
102117
stoppable
118+
calledByColony
103119
{
104-
address extension = migrateToMultiExtension(_extensionId, msg.sender);
105-
deprecateExtension(extension, _deprecated);
120+
ColonyExtension(installations[_extensionId][msg.sender]).deprecate(_deprecated);
106121

107122
emit ExtensionDeprecated(_extensionId, msg.sender, _deprecated);
108123
}
@@ -121,9 +136,13 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
121136
function uninstallExtension(bytes32 _extensionId)
122137
public
123138
stoppable
139+
calledByColony
124140
{
125-
address extension = migrateToMultiExtension(_extensionId, msg.sender);
126-
uninstallExtension(extension);
141+
require(installations[_extensionId][msg.sender] != address(0x0), "colony-network-extension-not-installed");
142+
143+
ColonyExtension extension = ColonyExtension(installations[_extensionId][msg.sender]);
144+
delete installations[_extensionId][msg.sender];
145+
extension.uninstall();
127146

128147
emit ExtensionUninstalled(_extensionId, msg.sender);
129148
}
@@ -136,7 +155,6 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
136155
require(multiInstallations[_extension] == msg.sender, "colony-network-extension-not-installed");
137156

138157
delete multiInstallations[_extension];
139-
140158
ColonyExtension(_extension).uninstall();
141159

142160
emit ExtensionUninstalled(_extension, msg.sender);
@@ -145,13 +163,12 @@ contract ColonyNetworkExtensions is ColonyNetworkStorage {
145163
function migrateToMultiExtension(bytes32 _extensionId, address _colony)
146164
public
147165
stoppable
148-
returns (address)
149166
{
150-
address extension = installations[_extensionId][_colony];
151-
require(extension != address(0x0), "colony-network-extension-not-installed");
167+
require(installations[_extensionId][_colony] != address(0x0), "colony-network-extension-not-installed");
168+
169+
multiInstallations[installations[_extensionId][_colony]] = payable(_colony);
152170

153-
multiInstallations[extension] = payable(_colony);
154-
return extension;
171+
delete installations[_extensionId][_colony];
155172
}
156173

157174
// Public view functions

contracts/colonyNetwork/IColonyNetwork.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ interface IColonyNetwork is ColonyNetworkDataTypes, IRecovery {
353353
/// @notice Migrate extension bookkeeping to multiExtension
354354
/// @param extensionId keccak256 hash of the extension name, used as an indentifier
355355
/// @param colony Address of the colony the extension is installed in
356-
/// @return extension The address of the extension
357-
function migrateToMultiExtension(bytes32 extensionId, address colony) external returns (address extension);
356+
function migrateToMultiExtension(bytes32 extensionId, address colony) external;
358357

359358
/// @notice Get an extension's resolver.
360359
/// @param extensionId keccak256 hash of the extension name, used as an indentifier

contracts/testHelpers/PreviousVersion.sol

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
pragma solidity 0.7.3;
22

3+
import "./../colonyNetwork/IColonyNetwork.sol";
4+
35
contract Version3 {
46
function version() pure external returns (uint256) {
57
return 3;
@@ -10,4 +12,32 @@ contract Version4 {
1012
function version() pure external returns (uint256) {
1113
return 4;
1214
}
13-
}
15+
}
16+
17+
contract Version7 {
18+
function version() public pure returns (uint256) {
19+
return 7;
20+
}
21+
22+
address colonyNetworkAddress;
23+
24+
constructor(address _colonyNetworkAddress) public {
25+
colonyNetworkAddress = _colonyNetworkAddress;
26+
}
27+
28+
function installExtension(bytes32 _extensionId, uint256 _version) public {
29+
IColonyNetwork(colonyNetworkAddress).installExtension(_extensionId, _version);
30+
}
31+
32+
function upgradeExtension(bytes32 _extensionId, uint256 _newVersion) public {
33+
IColonyNetwork(colonyNetworkAddress).upgradeExtension(_extensionId, _newVersion);
34+
}
35+
36+
function deprecateExtension(bytes32 _extensionId, bool _deprecated) public {
37+
IColonyNetwork(colonyNetworkAddress).deprecateExtension(_extensionId, _deprecated);
38+
}
39+
40+
function uninstallExtension(bytes32 _extensionId) public {
41+
IColonyNetwork(colonyNetworkAddress).uninstallExtension(_extensionId);
42+
}
43+
}

docs/_Interface_IColony.md

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,6 @@ Set the deprecation of an extension in a colony. Secured function to authorised
261261
|deprecated|bool|Whether to deprecate the extension or not
262262

263263

264-
### `deprecateExtension`
265-
266-
Set the deprecation of an extension in a colony. Secured function to authorised members.
267-
268-
269-
**Parameters**
270-
271-
|Name|Type|Description|
272-
|---|---|---|
273-
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
274-
|deprecated|bool|Whether to deprecate the extension or not
275-
276-
277264
### `editColony`
278265

279266
Called to change the metadata associated with a colony. Expected to be a IPFS hash of a JSON blob, but not enforced to any degree by the contracts
@@ -1915,19 +1902,6 @@ Uninstall an extension from a colony. Secured function to authorised members.
19151902
|extension|address|The address of the extension installation
19161903

19171904

1918-
### `uninstallExtension`
1919-
1920-
Uninstall an extension from a colony. Secured function to authorised members.
1921-
1922-
*Note: This is a permanent action -- re-installing the extension will deploy a new contract*
1923-
1924-
**Parameters**
1925-
1926-
|Name|Type|Description|
1927-
|---|---|---|
1928-
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
1929-
1930-
19311905
### `unlockToken`
19321906

19331907
unlock the native colony token, if possible
@@ -1999,19 +1973,6 @@ Upgrade an extension in a colony. Secured function to authorised members.
19991973
|newVersion|uint256|The version to upgrade to (must be one larger than the current version)
20001974

20011975

2002-
### `upgradeExtension`
2003-
2004-
Upgrade an extension in a colony. Secured function to authorised members.
2005-
2006-
2007-
**Parameters**
2008-
2009-
|Name|Type|Description|
2010-
|---|---|---|
2011-
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
2012-
|newVersion|uint256|The version to upgrade to (must be one larger than the current version)
2013-
2014-
20151976
### `userCanSetRoles`
20161977

20171978
Check whether a given user can modify roles in the target domain `_childDomainId`. Mostly a convenience function to provide a uniform interface for extension contracts validating permissions

docs/_Interface_IColonyNetwork.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -745,11 +745,6 @@ Migrate extension bookkeeping to multiExtension
745745
|extensionId|bytes32|keccak256 hash of the extension name, used as an indentifier
746746
|colony|address|Address of the colony the extension is installed in
747747

748-
**Return Parameters**
749-
750-
|Name|Type|Description|
751-
|---|---|---|
752-
|extension|address|The address of the extension
753748

754749
### `punishStakers`
755750

0 commit comments

Comments
 (0)