-
Notifications
You must be signed in to change notification settings - Fork 16
feat: announcePlannedUpgrade #260
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
57e744f
feat: announcePlannedUpgrade
wjmelements 090e985
make update-abi
wjmelements 351cc6e
Update service_contracts/src/FilecoinWarmStorageService.sol
wjmelements 467039a
Update service_contracts/test/FilecoinWarmStorageService.t.sol
wjmelements ebfd0f6
Merge remote-tracking branch 'origin/main' into announce-planned-upgrade
wjmelements f0be07e
move serviceCommissionBps to view contract
wjmelements 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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 |
---|---|---|
|
@@ -151,6 +151,14 @@ contract FilecoinWarmStorageService is | |
uint256 epochsPerMonth; // Number of epochs in a month | ||
} | ||
|
||
// Used for announcing upgrades, packed into one slot | ||
struct PlannedUpgrade { | ||
// Address of the new implementation contract | ||
address nextImplementation; | ||
// Upgrade will not occur until at least this epoch | ||
uint96 afterEpoch; | ||
} | ||
|
||
// ========================================================================= | ||
// Constants | ||
|
||
|
@@ -229,7 +237,7 @@ contract FilecoinWarmStorageService is | |
uint256 private challengeWindowSize; | ||
|
||
// Commission rate | ||
uint256 public serviceCommissionBps; | ||
uint256 private serviceCommissionBps; | ||
|
||
// Track which proving periods have valid proofs with bitmap | ||
mapping(uint256 dataSetId => mapping(uint256 periodId => uint256)) private provenPeriods; | ||
|
@@ -266,6 +274,10 @@ contract FilecoinWarmStorageService is | |
// The address allowed to terminate CDN services | ||
address private filBeamControllerAddress; | ||
|
||
PlannedUpgrade private nextUpgrade; | ||
|
||
event UpgradeAnnounced(PlannedUpgrade plannedUpgrade); | ||
|
||
// ========================================================================= | ||
|
||
// Modifier to ensure only the PDP verifier contract can call certain functions | ||
|
@@ -374,7 +386,19 @@ contract FilecoinWarmStorageService is | |
serviceCommissionBps = 0; // 0% | ||
} | ||
|
||
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {} | ||
function announcePlannedUpgrade(PlannedUpgrade calldata plannedUpgrade) external onlyOwner { | ||
require(plannedUpgrade.nextImplementation.code.length > 3000); | ||
require(plannedUpgrade.afterEpoch > block.number); | ||
nextUpgrade = plannedUpgrade; | ||
emit UpgradeAnnounced(plannedUpgrade); | ||
} | ||
|
||
function _authorizeUpgrade(address newImplementation) internal override onlyOwner { | ||
// zero address already checked by ERC1967Utils._setImplementation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also test for this case in
|
||
require(newImplementation == nextUpgrade.nextImplementation); | ||
require(block.number >= nextUpgrade.afterEpoch); | ||
delete nextUpgrade; | ||
} | ||
|
||
/** | ||
* @notice Sets new proving period parameters | ||
|
@@ -398,9 +422,7 @@ contract FilecoinWarmStorageService is | |
* Only callable during proxy upgrade process | ||
* @param _viewContract Address of the view contract (optional, can be address(0)) | ||
*/ | ||
function migrate(address _viewContract) public onlyProxy reinitializer(4) { | ||
require(msg.sender == address(this), Errors.OnlySelf(address(this), msg.sender)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the fix for #259 |
||
|
||
function migrate(address _viewContract) public onlyProxy onlyOwner reinitializer(4) { | ||
// Set view contract if provided | ||
if (_viewContract != address(0)) { | ||
viewContractAddress = _viewContract; | ||
|
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
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
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
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
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.
We could also require a minimum delay, but in the event of an emergency we might want a shorter delay. I can add it if someone else wants it. Mainly if we discovered a problem right after a deployment a mandatory delay would become mandatory downtime.
Such a minimum delay would help facilitate security by allowing time to check, for example, that the bytecode matches the source code. It would enforce transparency by mandating a notice period for service providers, who can watch for the
UpgradeAnnounced
event log.However such a delay could also just be enforced off-chain by best-practices. This is why I don't enforce it in the code.
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.
sgtm