Skip to content

Commit

Permalink
Merge pull request #1047 from graphprotocol/fix_oz_n-13
Browse files Browse the repository at this point in the history
fix: standardize naming conventions throughout the codebase (OZ N-13)
  • Loading branch information
MoonBoi9001 authored Oct 2, 2024
2 parents 2b79a69 + e33bf12 commit 31d57b2
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 96 deletions.
6 changes: 3 additions & 3 deletions packages/contracts/contracts/governance/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ contract Controller is Governed, Pausable, IController {
/**
* @notice Change the partial paused state of the contract
* Partial pause is intended as a partial pause of the protocol
* @param _toPause True if the contracts should be (partially) paused, false otherwise
* @param _toPartialPause True if the contracts should be (partially) paused, false otherwise
*/
function setPartialPaused(bool _toPause) external override onlyGovernorOrGuardian {
_setPartialPaused(_toPause);
function setPartialPaused(bool _toPartialPause) external override onlyGovernorOrGuardian {
_setPartialPaused(_toPartialPause);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/contracts/governance/Pausable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ abstract contract Pausable {
bool internal _paused;

/// Timestamp for the last time the partial pause was set
uint256 public lastPausePartialTime;
uint256 public lastPartialPauseTime;
/// Timestamp for the last time the full pause was set
uint256 public lastPauseTime;

Expand All @@ -31,15 +31,15 @@ abstract contract Pausable {

/**
* @dev Change the partial paused state of the contract
* @param _toPause New value for the partial pause state (true means the contracts will be partially paused)
* @param _toPartialPause New value for the partial pause state (true means the contracts will be partially paused)
*/
function _setPartialPaused(bool _toPause) internal {
if (_toPause == _partialPaused) {
function _setPartialPaused(bool _toPartialPause) internal {
if (_toPartialPause == _partialPaused) {
return;
}
_partialPaused = _toPause;
_partialPaused = _toPartialPause;
if (_partialPaused) {
lastPausePartialTime = block.timestamp;
lastPartialPauseTime = block.timestamp;
}
emit PartialPauseChanged(_partialPaused);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/test/unit/disputes/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface Dispute {
export function createQueryDisputeID(
attestation: Attestation,
indexerAddress: string,
submitterAddress: string,
fishermanAddress: string,
): string {
return solidityKeccak256(
['bytes32', 'bytes32', 'bytes32', 'address', 'address'],
Expand All @@ -25,7 +25,7 @@ export function createQueryDisputeID(
attestation.responseCID,
attestation.subgraphDeploymentID,
indexerAddress,
submitterAddress,
fishermanAddress,
],
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
/**
* @notice See {IDataServiceFees-releaseStake}
*/
function releaseStake(uint256 n) external virtual override {
_releaseStake(msg.sender, n);
function releaseStake(uint256 numClaimsToRelease) external virtual override {
_releaseStake(msg.sender, numClaimsToRelease);
}

/**
Expand All @@ -49,7 +49,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
claims[claimId] = StakeClaim({
tokens: _tokens,
createdAt: block.timestamp,
releaseAt: _unlockTimestamp,
releasableAt: _unlockTimestamp,
nextClaim: bytes32(0)
});
if (claimsList.count != 0) claims[claimsList.tail].nextClaim = claimId;
Expand All @@ -61,14 +61,14 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
/**
* @notice See {IDataServiceFees-releaseStake}
*/
function _releaseStake(address _serviceProvider, uint256 _n) internal {
function _releaseStake(address _serviceProvider, uint256 _numClaimsToRelease) internal {
LinkedList.List storage claimsList = claimsLists[_serviceProvider];
(uint256 claimsReleased, bytes memory data) = claimsList.traverse(
_getNextStakeClaim,
_processStakeClaim,
_deleteStakeClaim,
abi.encode(0, _serviceProvider),
_n
_numClaimsToRelease
);

emit StakeClaimsReleased(_serviceProvider, claimsReleased, abi.decode(data, (uint256)));
Expand All @@ -86,7 +86,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat
StakeClaim memory claim = _getStakeClaim(_claimId);

// early exit
if (claim.releaseAt > block.timestamp) {
if (claim.releasableAt > block.timestamp) {
return (true, LinkedList.NULL_BYTES);
}

Expand All @@ -95,7 +95,7 @@ abstract contract DataServiceFees is DataService, DataServiceFeesV1Storage, IDat

// process
feesProvisionTracker.release(serviceProvider, claim.tokens);
emit StakeClaimReleased(serviceProvider, _claimId, claim.tokens, claim.releaseAt);
emit StakeClaimReleased(serviceProvider, _claimId, claim.tokens, claim.releasableAt);

// encode
_acc = abi.encode(tokensClaimed + claim.tokens, serviceProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface IDataService {
* @notice Emitted when a service provider accepts a provision in {Graph Horizon staking contract}.
* @param serviceProvider The address of the service provider.
*/
event ProvisionAccepted(address indexed serviceProvider);
event ProvisionPendingParametersAccepted(address indexed serviceProvider);

/**
* @notice Emitted when a service provider starts providing the service.
Expand Down Expand Up @@ -79,16 +79,16 @@ interface IDataService {
function register(address serviceProvider, bytes calldata data) external;

/**
* @notice Accepts staged parameters in the provision of a service provider in the {Graph Horizon staking
* @notice Accepts pending parameters in the provision of a service provider in the {Graph Horizon staking
* contract}.
* @dev Provides a way for the data service to validate and accept provision parameter changes. Call {_acceptProvision}.
*
* Emits a {ProvisionAccepted} event.
* Emits a {ProvisionPendingParametersAccepted} event.
*
* @param serviceProvider The address of the service provider.
* @param data Custom data, usage defined by the data service.
*/
function acceptProvision(address serviceProvider, bytes calldata data) external;
function acceptProvisionPendingParameters(address serviceProvider, bytes calldata data) external;

/**
* @notice Service provider starts providing the service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface IDataServiceFees is IDataService {
// Timestamp when the claim was created
uint256 createdAt;
// Timestamp when the claim will expire and tokens can be released
uint256 releaseAt;
uint256 releasableAt;
// Next claim in the linked list
bytes32 nextClaim;
}
Expand All @@ -56,13 +56,13 @@ interface IDataServiceFees is IDataService {
* @param serviceProvider The address of the service provider
* @param claimId The id of the stake claim
* @param tokens The amount of tokens released
* @param releaseAt The timestamp when the tokens were released
* @param releasableAt The timestamp when the tokens were released
*/
event StakeClaimReleased(
address indexed serviceProvider,
bytes32 indexed claimId,
uint256 tokens,
uint256 releaseAt
uint256 releasableAt
);

/**
Expand All @@ -89,7 +89,7 @@ interface IDataServiceFees is IDataService {
* stake claims that releasing them all at once would exceed the block gas limit.
* @dev This function can be overriden and/or disabled.
* @dev Emits a {StakeClaimsReleased} event, and a {StakeClaimReleased} event for each claim released.
* @param n Amount of stake claims to process. If 0, all stake claims are processed.
* @param numClaimsToRelease Amount of stake claims to process. If 0, all stake claims are processed.
*/
function releaseStake(uint256 n) external;
function releaseStake(uint256 numClaimsToRelease) external;
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
/**
* @notice Checks if the caller is authorized to manage the provision of a service provider.
*/
modifier onlyProvisionAuthorized(address serviceProvider) {
modifier onlyAuthorizedForProvision(address serviceProvider) {
require(
_graphStaking().isAuthorized(msg.sender, serviceProvider, address(this)),
ProvisionManagerNotAuthorized(msg.sender, serviceProvider)
Expand Down Expand Up @@ -133,7 +133,7 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
* the {HorizonStaking} contract.
* @dev Checks the pending provision parameters, not the current ones.
*
* Emits a {ProvisionAccepted} event.
* Emits a {ProvisionPendingParametersAccepted} event.
*
* @param _serviceProvider The address of the service provider.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/horizon/contracts/interfaces/IPaymentsEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ interface IPaymentsEscrow {
/**
* @notice Thrown when setting the thawing period to a value greater than the maximum
* @param thawingPeriod The thawing period
* @param maxThawingPeriod The maximum thawing period
* @param maxWaitPeriod The maximum wait period
*/
error PaymentsEscrowThawingPeriodTooLong(uint256 thawingPeriod, uint256 maxThawingPeriod);
error PaymentsEscrowThawingPeriodTooLong(uint256 thawingPeriod, uint256 maxWaitPeriod);

/**
* @notice Thrown when a collector has insufficient allowance to collect funds
Expand Down
10 changes: 5 additions & 5 deletions packages/horizon/contracts/payments/PaymentsEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract PaymentsEscrow is Initializable, MulticallUpgradeable, GraphDirectory,

/// @notice The maximum thawing period (in seconds) for both escrow withdrawal and signer revocation
/// @dev This is a precautionary measure to avoid inadvertedly locking funds for too long
uint256 public constant MAX_THAWING_PERIOD = 90 days;
uint256 public constant MAX_WAIT_PERIOD = 90 days;

/// @notice Thawing period in seconds for authorized collectors
uint256 public immutable REVOKE_COLLECTOR_THAWING_PERIOD;
Expand All @@ -58,12 +58,12 @@ contract PaymentsEscrow is Initializable, MulticallUpgradeable, GraphDirectory,
uint256 withdrawEscrowThawingPeriod
) GraphDirectory(controller) {
require(
revokeCollectorThawingPeriod <= MAX_THAWING_PERIOD,
PaymentsEscrowThawingPeriodTooLong(revokeCollectorThawingPeriod, MAX_THAWING_PERIOD)
revokeCollectorThawingPeriod <= MAX_WAIT_PERIOD,
PaymentsEscrowThawingPeriodTooLong(revokeCollectorThawingPeriod, MAX_WAIT_PERIOD)
);
require(
withdrawEscrowThawingPeriod <= MAX_THAWING_PERIOD,
PaymentsEscrowThawingPeriodTooLong(withdrawEscrowThawingPeriod, MAX_THAWING_PERIOD)
withdrawEscrowThawingPeriod <= MAX_WAIT_PERIOD,
PaymentsEscrowThawingPeriodTooLong(withdrawEscrowThawingPeriod, MAX_WAIT_PERIOD)
);

REVOKE_COLLECTOR_THAWING_PERIOD = revokeCollectorThawingPeriod;
Expand Down
12 changes: 6 additions & 6 deletions packages/horizon/contracts/staking/HorizonStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,16 @@ contract HorizonStaking is HorizonStakingBase, IHorizonStakingMain {
function setProvisionParameters(
address serviceProvider,
address verifier,
uint32 maxVerifierCut,
uint64 thawingPeriod
uint32 newMaxVerifierCut,
uint64 newThawingPeriod
) external override notPaused onlyAuthorized(serviceProvider, verifier) {
Provision storage prov = _provisions[serviceProvider][verifier];
require(prov.createdAt != 0, HorizonStakingInvalidProvision(serviceProvider, verifier));

if ((prov.maxVerifierCutPending != maxVerifierCut) || (prov.thawingPeriodPending != thawingPeriod)) {
prov.maxVerifierCutPending = maxVerifierCut;
prov.thawingPeriodPending = thawingPeriod;
emit ProvisionParametersStaged(serviceProvider, verifier, maxVerifierCut, thawingPeriod);
if ((prov.maxVerifierCutPending != newMaxVerifierCut) || (prov.thawingPeriodPending != newThawingPeriod)) {
prov.maxVerifierCutPending = newMaxVerifierCut;
prov.thawingPeriodPending = newThawingPeriod;
emit ProvisionParametersStaged(serviceProvider, verifier, newMaxVerifierCut, newThawingPeriod);
}
}

Expand Down
22 changes: 11 additions & 11 deletions packages/horizon/test/data-service/extensions/DataServiceFees.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ contract DataServiceFeesTest is HorizonStakingSharedTest {
function test_Release_WhenNIsValid(
uint256 tokens,
uint256 steps,
uint256 n
uint256 numClaimsToRelease
) external useIndexer useProvisionDataService(address(dataService), PROVISION_TOKENS, 0, 0) {
// lock all provisioned stake in steps
// limit tokens to at least 1 per step
// limit steps to at least 15 so we stagger locks every 5 seconds to have some expired
tokens = bound(tokens, 50, PROVISION_TOKENS / dataService.STAKE_TO_FEES_RATIO());
steps = bound(steps, 15, 50);
n = bound(n, 0, steps);
numClaimsToRelease = bound(numClaimsToRelease, 0, steps);

uint256 stepAmount = tokens / steps;

Expand All @@ -99,7 +99,7 @@ contract DataServiceFeesTest is HorizonStakingSharedTest {
}

// it should release all expired claims
_assert_releaseStake(users.indexer, n);
_assert_releaseStake(users.indexer, numClaimsToRelease);
}

function test_Release_WhenNIsNotValid(
Expand Down Expand Up @@ -159,12 +159,12 @@ contract DataServiceFeesTest is HorizonStakingSharedTest {
assertEq(beforeLockedStake + calcValues.stakeToLock, afterLockedStake);

// it should create a stake claim
(uint256 claimTokens, uint256 createdAt, uint256 releaseAt, bytes32 nextClaim) = dataService.claims(
(uint256 claimTokens, uint256 createdAt, uint256 releasableAt, bytes32 nextClaim) = dataService.claims(
calcValues.predictedClaimId
);
assertEq(claimTokens, calcValues.stakeToLock);
assertEq(createdAt, block.timestamp);
assertEq(releaseAt, calcValues.unlockTimestamp);
assertEq(releasableAt, calcValues.unlockTimestamp);
assertEq(nextClaim, bytes32(0));

// it should update the list
Expand All @@ -180,7 +180,7 @@ contract DataServiceFeesTest is HorizonStakingSharedTest {
uint256 tokensReleased;
bytes32 head;
}
function _assert_releaseStake(address serviceProvider, uint256 n) private {
function _assert_releaseStake(address serviceProvider, uint256 numClaimsToRelease) private {
// before state
(bytes32 beforeHead, bytes32 beforeTail, uint256 beforeNonce, uint256 beforeCount) = dataService.claimsLists(
serviceProvider
Expand All @@ -195,21 +195,21 @@ contract DataServiceFeesTest is HorizonStakingSharedTest {
tokensReleased: 0,
head: beforeHead
});
while (calcValues.head != bytes32(0) && (calcValues.claimsCount < n || n == 0)) {
(uint256 claimTokens, , uint256 releaseAt, bytes32 nextClaim) = dataService.claims(calcValues.head);
if (releaseAt > block.timestamp) {
while (calcValues.head != bytes32(0) && (calcValues.claimsCount < numClaimsToRelease || numClaimsToRelease == 0)) {
(uint256 claimTokens, , uint256 releasableAt, bytes32 nextClaim) = dataService.claims(calcValues.head);
if (releasableAt > block.timestamp) {
break;
}

emit IDataServiceFees.StakeClaimReleased(serviceProvider, calcValues.head, claimTokens, releaseAt);
emit IDataServiceFees.StakeClaimReleased(serviceProvider, calcValues.head, claimTokens, releasableAt);
calcValues.head = nextClaim;
calcValues.tokensReleased += claimTokens;
calcValues.claimsCount++;
}

// it should emit a an event
emit IDataServiceFees.StakeClaimsReleased(serviceProvider, calcValues.claimsCount, calcValues.tokensReleased);
dataService.releaseStake(n);
dataService.releaseStake(numClaimsToRelease);

// after state
(bytes32 afterHead, bytes32 afterTail, uint256 afterNonce, uint256 afterCount) = dataService.claimsLists(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ contract DataServiceBase is DataService {

function register(address serviceProvider, bytes calldata data) external {}

function acceptProvision(address serviceProvider, bytes calldata data) external {}
function acceptProvisionPendingParameters(address serviceProvider, bytes calldata data) external {}

function startService(address serviceProvider, bytes calldata data) external {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract DataServiceBaseUpgradeable is DataService {

function register(address serviceProvider, bytes calldata data) external {}

function acceptProvision(address serviceProvider, bytes calldata data) external {}
function acceptProvisionPendingParameters(address serviceProvider, bytes calldata data) external {}

function startService(address serviceProvider, bytes calldata data) external {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract DataServiceImpFees is DataServiceFees {

function register(address serviceProvider, bytes calldata data) external {}

function acceptProvision(address serviceProvider, bytes calldata data) external {}
function acceptProvisionPendingParameters(address serviceProvider, bytes calldata data) external {}

function startService(address serviceProvider, bytes calldata data) external {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract DataServiceImpPausable is DataServicePausable {

function register(address serviceProvider, bytes calldata data) external {}

function acceptProvision(address serviceProvider, bytes calldata data) external {}
function acceptProvisionPendingParameters(address serviceProvider, bytes calldata data) external {}

function startService(address serviceProvider, bytes calldata data) external {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract DataServiceImpPausableUpgradeable is DataServicePausableUpgradeable {

function register(address serviceProvider, bytes calldata data) external {}

function acceptProvision(address serviceProvider, bytes calldata data) external {}
function acceptProvisionPendingParameters(address serviceProvider, bytes calldata data) external {}

function startService(address serviceProvider, bytes calldata data) external {}

Expand Down
Loading

0 comments on commit 31d57b2

Please sign in to comment.