Skip to content

Commit

Permalink
fix: add a new mapping instead of splitting thaw requests (TRST-H02)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maikol committed Dec 6, 2024
1 parent c59c186 commit d1c5cc7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 51 deletions.
6 changes: 3 additions & 3 deletions packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1181,23 +1181,23 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
* @param _thawRequestId The ID of the thaw request to delete.
*/
function _deleteProvisionThawRequest(bytes32 _thawRequestId) private {
delete _provisionThawRequests[_thawRequestId];
delete _thawRequests[ThawRequestType.Provision][_thawRequestId];
}

/**
* @notice Deletes a thaw request for a delegation.
* @param _thawRequestId The ID of the thaw request to delete.
*/
function _deleteDelegationThawRequest(bytes32 _thawRequestId) private {
delete _delegationThawRequests[_thawRequestId];
delete _thawRequests[ThawRequestType.Delegation][_thawRequestId];
}

/**
* @notice Deletes a thaw request for a delegation with a beneficiary.
* @param _thawRequestId The ID of the thaw request to delete.
*/
function _deleteDelegationWithBeneficiaryThawRequest(bytes32 _thawRequestId) private {
delete _delegationWithBeneficiaryThawRequests[_thawRequestId];
delete _thawRequests[ThawRequestType.DelegationWithBeneficiary][_thawRequestId];
}

/**
Expand Down
26 changes: 5 additions & 21 deletions packages/horizon/contracts/staking/HorizonStakingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ abstract contract HorizonStakingBase is
* @return The ID of the next thaw request in the list.
*/
function _getNextProvisionThawRequest(bytes32 _thawRequestId) internal view returns (bytes32) {
return _provisionThawRequests[_thawRequestId].next;
return _thawRequests[ThawRequestType.Provision][_thawRequestId].next;
}

/**
Expand All @@ -332,7 +332,7 @@ abstract contract HorizonStakingBase is
* @return The ID of the next thaw request in the list.
*/
function _getNextDelegationThawRequest(bytes32 _thawRequestId) internal view returns (bytes32) {
return _delegationThawRequests[_thawRequestId].next;
return _thawRequests[ThawRequestType.Delegation][_thawRequestId].next;
}

/**
Expand All @@ -341,7 +341,7 @@ abstract contract HorizonStakingBase is
* @return The ID of the next thaw request in the list.
*/
function _getNextDelegationWithBeneficiaryThawRequest(bytes32 _thawRequestId) internal view returns (bytes32) {
return _delegationWithBeneficiaryThawRequests[_thawRequestId].next;
return _thawRequests[ThawRequestType.DelegationWithBeneficiary][_thawRequestId].next;
}

/**
Expand All @@ -360,15 +360,7 @@ abstract contract HorizonStakingBase is
address _verifier,
address _owner
) internal view returns (LinkedList.List storage) {
if (_requestType == ThawRequestType.Provision) {
return _provisionThawRequestLists[_serviceProvider][_verifier][_owner];
} else if (_requestType == ThawRequestType.Delegation) {
return _delegationThawRequestLists[_serviceProvider][_verifier][_owner];
} else if (_requestType == ThawRequestType.DelegationWithBeneficiary) {
return _delegationWithBeneficiaryThawRequestLists[_serviceProvider][_verifier][_owner];
} else {
revert HorizonStakingInvalidThawRequestType();
}
return _thawRequestLists[_requestType][_serviceProvider][_verifier][_owner];
}

/**
Expand All @@ -383,15 +375,7 @@ abstract contract HorizonStakingBase is
ThawRequestType _requestType,
bytes32 _thawRequestId
) internal view returns (IHorizonStakingTypes.ThawRequest storage) {
if (_requestType == ThawRequestType.Provision) {
return _provisionThawRequests[_thawRequestId];
} else if (_requestType == ThawRequestType.Delegation) {
return _delegationThawRequests[_thawRequestId];
} else if (_requestType == ThawRequestType.DelegationWithBeneficiary) {
return _delegationWithBeneficiaryThawRequests[_thawRequestId];
} else {
revert("Unknown ThawRequestType");
}
return _thawRequests[_requestType][_thawRequestId];
}

/**
Expand Down
30 changes: 6 additions & 24 deletions packages/horizon/contracts/staking/HorizonStakingStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,32 +148,14 @@ abstract contract HorizonStakingV1Storage {
internal _delegationFeeCut;

/// @dev Thaw requests
/// Details for each thawing operation in the staking contract for both service providers.
mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest) internal _provisionThawRequests;
/// Details for each thawing operation in the staking contract (for both service providers and delegators).
mapping(IHorizonStakingTypes.ThawRequestType thawRequestType => mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest))
internal _thawRequests;

/// @dev Thaw request lists
/// Metadata defining linked lists of thaw requests for each service provider (owner).
mapping(address serviceProvider => mapping(address verifier => mapping(address owner => LinkedList.List list)))
internal _provisionThawRequestLists;

/// @dev Thaw requests
/// Details for each thawing operation in the staking contract for delegators.
mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest) internal _delegationThawRequests;

/// @dev Thaw request lists
/// Metadata defining linked lists of thaw requests for each delegator (owner).
mapping(address serviceProvider => mapping(address verifier => mapping(address owner => LinkedList.List list)))
internal _delegationThawRequestLists;

/// @dev Thaw requests
/// Details for each thawing operation in the staking contract for both delegators undelegating to a beneficiary.
mapping(bytes32 thawRequestId => IHorizonStakingTypes.ThawRequest thawRequest)
internal _delegationWithBeneficiaryThawRequests;

/// @dev Thaw request lists
/// Metadata defining linked lists of thaw requests for each delegator (owner) undelegating to a beneficiary.
mapping(address serviceProvider => mapping(address verifier => mapping(address owner => LinkedList.List list)))
internal _delegationWithBeneficiaryThawRequestLists;
/// Metadata defining linked lists of thaw requests for each service provider or delegator (owner)
mapping(IHorizonStakingTypes.ThawRequestType thawRequestType => mapping(address serviceProvider => mapping(address verifier => mapping(address owner => LinkedList.List list))))
internal _thawRequestLists;

/// @dev Operator allow list
/// Used for all verifiers except the subgraph data service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
address operator,
bool legacy
) internal view returns (bool) {
uint256 slotNumber = legacy ? 21 : 35;
uint256 slotNumber = legacy ? 21 : 31;
uint256 slot;

if (legacy) {
Expand Down Expand Up @@ -1934,7 +1934,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
address verifier,
bool legacy
) internal view returns (DelegationPoolInternalTest memory) {
uint256 slotNumber = legacy ? 20 : 37;
uint256 slotNumber = legacy ? 20 : 33;
uint256 baseSlot;
if (legacy) {
baseSlot = uint256(keccak256(abi.encode(serviceProvider, slotNumber)));
Expand Down Expand Up @@ -1966,7 +1966,7 @@ abstract contract HorizonStakingSharedTest is GraphBaseTest {
address delegator,
bool legacy
) internal view returns (DelegationInternal memory) {
uint256 slotNumber = legacy ? 20 : 37;
uint256 slotNumber = legacy ? 20 : 33;
uint256 baseSlot;

// DelegationPool
Expand Down

0 comments on commit d1c5cc7

Please sign in to comment.