-
Notifications
You must be signed in to change notification settings - Fork 435
feat: release manager #1469
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
Open
0xClandestine
wants to merge
13
commits into
release-dev/multichain
Choose a base branch
from
0xclandestine/rms
base: release-dev/multichain
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: release manager #1469
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a68cf90
draft
0xClandestine 0517cdf
refactor: explicit `using` statements
0xClandestine 2188c01
feat: add `getReleaseRegistryUrl`
0xClandestine db0f478
docs: improvements
0xClandestine cd53f2d
fix: decoding
0xClandestine 532d85e
fix: gap
0xClandestine f165133
wip: cleanup
0xClandestine 42beb45
chore: make fmt
0xClandestine e75fb26
wip
0xClandestine 2e77814
wip
0xClandestine c022fbe
wip
0xClandestine 8cf7e53
wip
0xClandestine 9079dcd
wip
0xClandestine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.27; | ||
|
||
import "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol"; | ||
import "@openzeppelin/contracts/utils/Strings.sol"; | ||
import "../mixins/PermissionControllerMixin.sol"; | ||
import "../mixins/SemVerMixin.sol"; | ||
import "./ReleaseManagerStorage.sol"; | ||
|
||
contract ReleaseManager is Initializable, ReleaseManagerStorage, PermissionControllerMixin, SemVerMixin { | ||
using EnumerableSet for EnumerableSet.Bytes32Set; | ||
using OperatorSetLib for OperatorSet; | ||
using Strings for uint16; | ||
|
||
/** | ||
* | ||
* INITIALIZING FUNCTIONS | ||
* | ||
*/ | ||
constructor( | ||
IAllocationManager _allocationManager, | ||
IPermissionController _permissionController, | ||
string memory _version | ||
) | ||
ReleaseManagerStorage(_allocationManager) | ||
PermissionControllerMixin(_permissionController) | ||
SemVerMixin(_version) | ||
{ | ||
_disableInitializers(); | ||
} | ||
|
||
/** | ||
* | ||
* EXTERNAL FUNCTIONS | ||
* | ||
*/ | ||
|
||
/// @inheritdoc IReleaseManager | ||
function publishRelease( | ||
OperatorSet calldata operatorSet, | ||
Artifact[] calldata artifacts, | ||
uint32 upgradeWindow, | ||
ReleaseType releaseType | ||
) external checkCanCall(operatorSet.avs) returns (Version memory) { | ||
Version memory version = getLatestVersion(operatorSet); | ||
|
||
uint32 upgradeByTime = uint32(block.timestamp + upgradeWindow); | ||
|
||
if (releaseType == ReleaseType.MAJOR) { | ||
++version.major; | ||
version.minor = 0; | ||
version.patch = 0; | ||
_upgradeByTimes[operatorSet.key()][version.major] = upgradeByTime; | ||
} else if (releaseType == ReleaseType.MINOR) { | ||
++version.minor; | ||
version.patch = 0; | ||
} else if (releaseType == ReleaseType.PATCH) { | ||
++version.patch; | ||
} | ||
|
||
bytes32 versionKey = _encodeVersion(version); | ||
|
||
// Append the version to the operator set's version history. | ||
_versions[operatorSet.key()].add(versionKey); | ||
// Map the version to the release artifacts and deprecation time. | ||
Release storage release = _releases[operatorSet.key()][versionKey]; | ||
for (uint256 i = 0; i < artifacts.length; i++) { | ||
release.artifacts.push(artifacts[i]); | ||
} | ||
|
||
emit ReleasePublished(operatorSet.key(), version, releaseType, upgradeByTime, artifacts); | ||
|
||
return version; | ||
} | ||
|
||
/// @inheritdoc IReleaseManager | ||
function deprecateRelease( | ||
OperatorSet calldata operatorSet, | ||
Version calldata version, | ||
uint32 deprecationDelay | ||
) public checkCanCall(operatorSet.avs) { | ||
bytes32 versionKey = _encodeVersion(version); | ||
|
||
// Check that the release is not already deprecated and modify state. | ||
Release storage release = _releases[operatorSet.key()][versionKey]; | ||
require(release.deprecateAtTime == 0, ReleaseAlreadyDeprecated()); | ||
uint32 deprecateAtTime = uint32(block.timestamp + deprecationDelay); | ||
release.deprecateAtTime = deprecateAtTime; | ||
|
||
// Checked that there is at least one stable version after deprecating this release. | ||
Version memory lastStableVersion = getLatestStableVersion(operatorSet); | ||
require(lastStableVersion.major != type(uint16).max, MustHaveAtLeastOneStableVersion()); | ||
|
||
emit ReleaseDeprecated(operatorSet.key(), version, deprecateAtTime); | ||
} | ||
|
||
/// @inheritdoc IReleaseManager | ||
function extendUpgradeWindow( | ||
OperatorSet calldata operatorSet, | ||
Version calldata version, | ||
uint32 upgradeWindow | ||
) public checkCanCall(operatorSet.avs) { | ||
_upgradeByTimes[operatorSet.key()][version.major] = uint32(block.timestamp + upgradeWindow); | ||
|
||
emit UpgradeWindowExtended(operatorSet.key(), version, upgradeWindow); | ||
} | ||
|
||
/** | ||
* | ||
* INTERNAL FUNCTIONS | ||
* | ||
*/ | ||
/// @notice Encodes a Version struct into a bytes32 value for storage. | ||
/// @dev Needed to store versions in an EnumerableSet. | ||
/// @dev Packs the major, minor, and patch versions into a single bytes32 value. | ||
/// The encoding format is: [major(16 bits)][minor(16 bits)][patch(16 bits)][padding(224 bits)] | ||
function _encodeVersion( | ||
Version memory version | ||
) internal pure returns (bytes32) { | ||
return bytes32(abi.encodePacked(version.major, version.minor, version.patch)); | ||
} | ||
|
||
/// @notice Decodes a bytes32 value back into a Version struct. | ||
/// @dev Unpacks the major, minor, and patch versions from the encoded bytes32 value. | ||
/// The decoding format is: [major(16 bits)][minor(16 bits)][patch(16 bits)][padding(224 bits)] | ||
function _decodeVersion( | ||
bytes32 encoded | ||
) internal pure returns (Version memory) { | ||
return Version({ | ||
major: uint16((uint256(encoded) >> 208) & type(uint16).max), | ||
minor: uint16((uint256(encoded) >> 192) & type(uint16).max), | ||
patch: uint16((uint256(encoded) >> 176) & type(uint16).max) | ||
}); | ||
} | ||
|
||
/** | ||
* | ||
* VIEW FUNCTIONS | ||
* | ||
*/ | ||
|
||
/// @inheritdoc IReleaseManager | ||
function getTotalVersions( | ||
OperatorSet memory operatorSet | ||
) external view returns (uint256) { | ||
return _versions[operatorSet.key()].length(); | ||
} | ||
|
||
/// @inheritdoc IReleaseManager | ||
function getVersion(OperatorSet memory operatorSet, uint256 index) external view returns (Version memory) { | ||
return _decodeVersion(_versions[operatorSet.key()].at(index)); | ||
} | ||
|
||
/// @inheritdoc IReleaseManager | ||
function getRelease( | ||
OperatorSet memory operatorSet, | ||
Version memory version | ||
) external view returns (Release memory) { | ||
return _releases[operatorSet.key()][_encodeVersion(version)]; | ||
} | ||
|
||
/// @inheritdoc IReleaseManager | ||
function getReleaseStatus( | ||
OperatorSet memory operatorSet, | ||
Version memory version | ||
) external view returns (ReleaseStatus) { | ||
// First, check whether the version exists. | ||
bytes32 versionKey = _encodeVersion(version); | ||
bool exists = _versions[operatorSet.key()].contains(versionKey); | ||
|
||
// If the version does not exist, it is not valid. | ||
if (!exists) return ReleaseStatus.NONEXISTENT; | ||
|
||
// Second, check whether the version is deprecated by a force deprecation. | ||
uint32 deprecateAtTime = _releases[operatorSet.key()][versionKey].deprecateAtTime; | ||
if (deprecateAtTime != 0 && block.timestamp >= deprecateAtTime) return (ReleaseStatus.DEPRECATED); | ||
|
||
// Third, check whether the version is deprecated by a major version upgrade. | ||
uint32 lastUpgradeByTime = _upgradeByTimes[operatorSet.key()][getLatestStableVersion(operatorSet).major]; | ||
if (lastUpgradeByTime != 0 && block.timestamp >= lastUpgradeByTime) return (ReleaseStatus.OUTDATED); | ||
|
||
// Otherwise, the version is live. | ||
return (ReleaseStatus.LIVE); | ||
} | ||
|
||
/// @inheritdoc IReleaseManager | ||
function getLatestVersion( | ||
OperatorSet memory operatorSet | ||
) public view returns (Version memory) { | ||
EnumerableSet.Bytes32Set storage versions = _versions[operatorSet.key()]; | ||
return _decodeVersion(versions.at(versions.length() - 1)); | ||
} | ||
|
||
/// @inheritdoc IReleaseManager | ||
function getLatestStableVersion( | ||
OperatorSet memory operatorSet | ||
) public view returns (Version memory) { | ||
EnumerableSet.Bytes32Set storage versions = _versions[operatorSet.key()]; | ||
uint256 versionCount = versions.length(); | ||
|
||
// Linear search backwards for the latest stable version. | ||
for (uint256 i = versionCount - 1; i >= 0; i--) { | ||
bytes32 versionKey = versions.at(i); | ||
uint32 deprecateAtTime = _releases[operatorSet.key()][versionKey].deprecateAtTime; | ||
|
||
// If the release is deprecated, skip it. | ||
if (block.timestamp >= deprecateAtTime) { | ||
continue; | ||
} | ||
|
||
// Othersise, return the release version. | ||
return _decodeVersion(versionKey); | ||
} | ||
|
||
// No version has been published. | ||
return Version({major: type(uint16).max, minor: type(uint16).max, patch: type(uint16).max}); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.27; | ||
|
||
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol"; | ||
import "../interfaces/IReleaseManager.sol"; | ||
import "../interfaces/IAllocationManager.sol"; | ||
|
||
abstract contract ReleaseManagerStorage is IReleaseManager { | ||
// Immutables | ||
|
||
/// @notice The EigenLayer AllocationManager contract. | ||
IAllocationManager public immutable allocationManager; | ||
|
||
// Mutables | ||
|
||
/// @notice Maps operator set keys to their version history. | ||
/// @param operatorSetKey The key identifying the operator set. | ||
/// @return versions The set of version keys for this operator set. | ||
mapping(bytes32 operatorSetKey => EnumerableSet.Bytes32Set versions) internal _versions; | ||
|
||
/// @notice Maps operator set and version keys to their release details. | ||
/// @param operatorSetKey The key identifying the operator set. | ||
/// @param versionKey The key identifying the version. | ||
/// @return release The release details including artifacts and deprecation time. | ||
mapping(bytes32 operatorSetKey => mapping(bytes32 versionKey => Release release)) internal _releases; | ||
|
||
/// @notice Maps operator set keys and major versions to their upgrade deadlines. | ||
/// @param operatorSetKey The key identifying the operator set. | ||
/// @param major The major version number. | ||
/// @return upgradeByTime The timestamp by which operators must upgrade to this major version. | ||
mapping(bytes32 operatorSetKey => mapping(uint16 major => uint32 upgradeByTime)) internal _upgradeByTimes; | ||
|
||
constructor( | ||
IAllocationManager _allocationManager | ||
) { | ||
allocationManager = _allocationManager; | ||
} | ||
|
||
uint256[47] private __gap; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be upgradeable.