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

Another set of minor improvements #598

Merged
merged 5 commits into from
Feb 10, 2023
Merged
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
20 changes: 15 additions & 5 deletions contracts/0.8.9/WithdrawalQueue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ abstract contract WithdrawalQueue is AccessControlEnumerable, PausableUntil, Wit

/// @notice Emitted when the contract initialized
event InitializedV1(address _admin, address _pauser, address _resumer, address _finalizer, address _bunkerReporter);
event BunkerModeEnabled(uint256 _sinceTimestamp);
event BunkerModeDisabled();

error AdminZeroAddress();
error AlreadyInitialized();
Expand Down Expand Up @@ -281,20 +283,27 @@ abstract contract WithdrawalQueue is AccessControlEnumerable, PausableUntil, Wit
/// @dev should be called by oracle
///
/// @param _isBunkerModeNow oracle report
/// @param _bunkerModeSinceTimestamp timestamp of start of the bunker mode
function updateBunkerMode(bool _isBunkerModeNow, uint256 _bunkerModeSinceTimestamp)
/// @param _sinceTimestamp timestamp of start of the bunker mode
function updateBunkerMode(bool _isBunkerModeNow, uint256 _sinceTimestamp)
external
onlyRole(BUNKER_MODE_REPORT_ROLE)
{
if (_bunkerModeSinceTimestamp >= block.timestamp) revert InvalidReportTimestamp();
if (_sinceTimestamp >= block.timestamp) revert InvalidReportTimestamp();

bool isBunkerModeWasSetBefore = isBunkerModeActive();

// on bunker mode state change
if (_isBunkerModeNow != isBunkerModeWasSetBefore) {
// write previous timestamp to enable bunker or max uint to disable
uint256 newTimestamp = _isBunkerModeNow ? _bunkerModeSinceTimestamp : BUNKER_MODE_DISABLED_TIMESTAMP;
BUNKER_MODE_SINCE_TIMESTAMP_POSITION.setStorageUint256(newTimestamp);
if (_isBunkerModeNow) {
BUNKER_MODE_SINCE_TIMESTAMP_POSITION.setStorageUint256(_sinceTimestamp);

emit BunkerModeEnabled(_sinceTimestamp);
} else {
BUNKER_MODE_SINCE_TIMESTAMP_POSITION.setStorageUint256(BUNKER_MODE_DISABLED_TIMESTAMP);

emit BunkerModeDisabled();
}
}
}

Expand All @@ -317,6 +326,7 @@ abstract contract WithdrawalQueue is AccessControlEnumerable, PausableUntil, Wit
internal
{
_initializeQueue();
_initializePausable();

_initializeContractVersionTo(1);

Expand Down
5 changes: 3 additions & 2 deletions contracts/0.8.9/WithdrawalQueueBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ abstract contract WithdrawalQueueBase {
/// @notice structure to store discount factors for requests in the queue
struct DiscountCheckpoint {
/// @notice first `_requestId` the discount is valid for
uint256 fromRequestId;
/// @dev storing in uint160 to pack into one slot. Overflowing here is unlikely
uint160 fromRequestId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

/// @notice discount factor with 1e27 precision (0 - 100% discount, 1e27 - means no discount)
uint96 discountFactor;
}
Expand Down Expand Up @@ -383,7 +384,7 @@ abstract contract WithdrawalQueueBase {
if (discountFactor != lastCheckpoint.discountFactor) {
// add a new discount if it differs from the previous
_getCheckpoints()[lastCheckpointIndex + 1] =
DiscountCheckpoint(firstUnfinalizedRequestId, uint96(discountFactor));
DiscountCheckpoint(uint160(firstUnfinalizedRequestId), uint96(discountFactor));
_setLastCheckpointIndex(lastCheckpointIndex + 1);
}

Expand Down
1 change: 1 addition & 0 deletions contracts/0.8.9/oracle/ValidatorsExitBusOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ contract ValidatorsExitBusOracle is BaseOracle, PausableUntil {
) external {
if (admin == address(0)) revert AdminCannotBeZero();
_setupRole(DEFAULT_ADMIN_ROLE, admin);
_initializePausable();
_initialize(consensusContract, consensusVersion, lastProcessingRefSlot);
RESUME_SINCE_TIMESTAMP_POSITION.setStorageUint256(PAUSE_INFINITELY); // pause it explicitly
}
Expand Down
4 changes: 4 additions & 0 deletions contracts/0.8.9/utils/PausableUntil.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ contract PausableUntil {
return block.timestamp < RESUME_SINCE_TIMESTAMP_POSITION.getStorageUint256();
}

function _initializePausable() internal {
emit Paused(PAUSE_INFINITELY);
}

function _resume() internal {
RESUME_SINCE_TIMESTAMP_POSITION.setStorageUint256(block.timestamp);

Expand Down
Loading