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

chore(SubgraphService): add current epoch to IndexingRewardsCollected… #1036

Merged
merged 2 commits into from
Sep 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
* @param tokensIndexerRewards The amount of tokens collected for the indexer
* @param tokensDelegationRewards The amount of tokens collected for delegators
* @param poi The POI presented
* @param currentEpoch The current epoch
*/
event IndexingRewardsCollected(
address indexed indexer,
Expand All @@ -65,7 +66,8 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
uint256 tokensRewards,
uint256 tokensIndexerRewards,
uint256 tokensDelegationRewards,
bytes32 poi
bytes32 poi,
uint256 currentEpoch
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can we add the param explanation to the comments?

);

/**
Expand Down Expand Up @@ -321,7 +323,8 @@ abstract contract AllocationManager is EIP712Upgradeable, GraphDirectory, Alloca
tokensRewards,
tokensIndexerRewards,
tokensDelegationRewards,
_poi
_poi,
_graphEpochManager().currentEpoch()
);

// Check if the indexer is over-allocated and close the allocation if necessary
Expand Down
6 changes: 5 additions & 1 deletion packages/subgraph-service/test/SubgraphBaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Utils } from "./utils/Utils.sol";
import { MockCuration } from "./mocks/MockCuration.sol";
import { MockGRTToken } from "./mocks/MockGRTToken.sol";
import { MockRewardsManager } from "./mocks/MockRewardsManager.sol";
import { MockEpochManager } from "./mocks/MockEpochManager.sol";

abstract contract SubgraphBaseTest is Utils, Constants {

Expand All @@ -50,6 +51,7 @@ abstract contract SubgraphBaseTest is Utils, Constants {
MockCuration curation;
MockGRTToken token;
MockRewardsManager rewardsManager;
MockEpochManager epochManager;

/* Users */

Expand Down Expand Up @@ -91,6 +93,7 @@ abstract contract SubgraphBaseTest is Utils, Constants {
GraphProxy stakingProxy = new GraphProxy(address(0), address(proxyAdmin));
rewardsManager = new MockRewardsManager(token, rewardsPerSignal, rewardsPerSubgraphAllocationUpdate);
curation = new MockCuration();
epochManager = new MockEpochManager();

// GraphPayments predict address
bytes32 saltGraphPayments = keccak256("GraphPaymentsSalt");
Expand Down Expand Up @@ -126,7 +129,7 @@ abstract contract SubgraphBaseTest is Utils, Constants {
controller.setContractProxy(keccak256("RewardsManager"), address(rewardsManager));
controller.setContractProxy(keccak256("GraphPayments"), predictedGraphPaymentsAddress);
controller.setContractProxy(keccak256("PaymentsEscrow"), predictedEscrowAddress);
controller.setContractProxy(keccak256("EpochManager"), makeAddr("EpochManager"));
controller.setContractProxy(keccak256("EpochManager"), address(epochManager));
controller.setContractProxy(keccak256("GraphTokenGateway"), makeAddr("GraphTokenGateway"));
controller.setContractProxy(keccak256("GraphProxyAdmin"), makeAddr("GraphProxyAdmin"));
controller.setContractProxy(keccak256("Curation"), address(curation));
Expand Down Expand Up @@ -187,6 +190,7 @@ abstract contract SubgraphBaseTest is Utils, Constants {
subgraphService.transferOwnership(users.governor);
resetPrank(users.governor);
staking.setMaxThawingPeriod(MAX_THAWING_PERIOD);
epochManager.setEpochLength(EPOCH_LENGTH);
subgraphService.setMaxPOIStaleness(maxPOIStaleness);
subgraphService.setCurationCut(curationCut);
}
Expand Down
63 changes: 63 additions & 0 deletions packages/subgraph-service/test/mocks/MockEpochManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: GPL-2.0-or-later

pragma solidity 0.8.27;

import { IEpochManager } from "@graphprotocol/contracts/contracts/epochs/IEpochManager.sol";

contract MockEpochManager is IEpochManager {
// -- Variables --

uint256 public epochLength;
uint256 public lastRunEpoch;
uint256 public lastLengthUpdateEpoch;
uint256 public lastLengthUpdateBlock;

// -- Configuration --

function setEpochLength(uint256 _epochLength) public {
lastLengthUpdateEpoch = 1;
lastLengthUpdateBlock = blockNum();
epochLength = _epochLength;
}

// -- Epochs

function runEpoch() public {
lastRunEpoch = currentEpoch();
}

// -- Getters --

function isCurrentEpochRun() public view returns (bool) {
return lastRunEpoch == currentEpoch();
}

function blockNum() public view returns (uint256) {
return block.number;
}

function blockHash(uint256 _block) public view returns (bytes32) {
return blockhash(_block);
}

function currentEpoch() public view returns (uint256) {
return lastLengthUpdateEpoch + epochsSinceUpdate();
}

function currentEpochBlock() public view returns (uint256) {
return lastLengthUpdateBlock + (epochsSinceUpdate() * epochLength);
}

function currentEpochBlockSinceStart() public view returns (uint256) {
return blockNum() - currentEpochBlock();
}

function epochsSince(uint256 _epoch) public view returns (uint256) {
uint256 epoch = currentEpoch();
return _epoch < epoch ? (epoch - _epoch) : 0;
}

function epochsSinceUpdate() public view returns (uint256) {
return (blockNum() - lastLengthUpdateBlock) / epochLength;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@ contract SubgraphServiceTest is SubgraphServiceSharedTest {
paymentCollected,
indexingRewardsData.tokensIndexerRewards,
indexingRewardsData.tokensDelegationRewards,
indexingRewardsData.poi
indexingRewardsData.poi,
epochManager.currentEpoch()
);
}

Expand Down
3 changes: 2 additions & 1 deletion packages/subgraph-service/test/utils/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.27;
abstract contract Constants {
uint256 internal constant MAX_TOKENS = 10_000_000_000 ether;
uint256 internal constant MAX_PPM = 1_000_000;
uint256 internal constant EPOCH_LENGTH = 1;
// Dispute Manager
uint64 internal constant disputePeriod = 300; // 5 minutes
uint256 internal constant disputeDeposit = 100 ether; // 100 GRT
Expand All @@ -26,4 +27,4 @@ abstract contract Constants {
// RewardsMananger parameters
uint256 public constant rewardsPerSignal = 10000;
uint256 public constant rewardsPerSubgraphAllocationUpdate = 1000;
}
}