Skip to content

Commit 02a2fc3

Browse files
committed
feat: use poi to create dispute
Signed-off-by: Tomás Migone <[email protected]>
1 parent 6f376cd commit 02a2fc3

File tree

4 files changed

+38
-20
lines changed

4 files changed

+38
-20
lines changed

packages/subgraph-service/contracts/DisputeManager.sol

+14-6
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,24 @@ contract DisputeManager is
119119

120120
/**
121121
* @notice Create an indexing dispute for the arbitrator to resolve.
122-
* The disputes are created in reference to an allocationId
122+
* The disputes are created in reference to an allocationId and specifically
123+
* a POI for that allocation.
123124
* This function is called by a challenger that will need to `_deposit` at
124125
* least `minimumDeposit` GRT tokens.
125126
* @param allocationId The allocation to dispute
127+
* @param poi The Proof of Indexing (POI) being disputed
126128
* @param deposit Amount of tokens staked as deposit
127129
*/
128-
function createIndexingDispute(address allocationId, uint256 deposit) external override returns (bytes32) {
130+
function createIndexingDispute(
131+
address allocationId,
132+
bytes32 poi,
133+
uint256 deposit
134+
) external override returns (bytes32) {
129135
// Get funds from submitter
130136
_pullSubmitterDeposit(deposit);
131137

132138
// Create a dispute
133-
return _createIndexingDisputeWithAllocation(msg.sender, deposit, allocationId);
139+
return _createIndexingDisputeWithAllocation(msg.sender, deposit, allocationId, poi);
134140
}
135141

136142
/**
@@ -486,14 +492,16 @@ contract DisputeManager is
486492
* @param _fisherman The challenger creating the dispute
487493
* @param _deposit Amount of tokens staked as deposit
488494
* @param _allocationId Allocation disputed
495+
* @param _poi The POI being disputed
489496
*/
490497
function _createIndexingDisputeWithAllocation(
491498
address _fisherman,
492499
uint256 _deposit,
493-
address _allocationId
500+
address _allocationId,
501+
bytes32 _poi
494502
) private returns (bytes32) {
495503
// Create a disputeId
496-
bytes32 disputeId = keccak256(abi.encodePacked(_allocationId));
504+
bytes32 disputeId = keccak256(abi.encodePacked(_allocationId, _poi));
497505

498506
// Only one dispute for an allocationId at a time
499507
require(!isDisputeCreated(disputeId), DisputeManagerDisputeAlreadyCreated(disputeId));
@@ -518,7 +526,7 @@ contract DisputeManager is
518526
block.timestamp
519527
);
520528

521-
emit IndexingDisputeCreated(disputeId, alloc.indexer, _fisherman, _deposit, _allocationId);
529+
emit IndexingDisputeCreated(disputeId, alloc.indexer, _fisherman, _deposit, _allocationId, _poi);
522530

523531
return disputeId;
524532
}

packages/subgraph-service/contracts/interfaces/IDisputeManager.sol

+3-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ interface IDisputeManager {
100100
address indexed indexer,
101101
address indexed fisherman,
102102
uint256 tokens,
103-
address allocationId
103+
address allocationId,
104+
bytes32 poi
104105
);
105106

106107
/**
@@ -193,7 +194,7 @@ interface IDisputeManager {
193194
bytes calldata attestationData2
194195
) external returns (bytes32, bytes32);
195196

196-
function createIndexingDispute(address allocationId, uint256 deposit) external returns (bytes32);
197+
function createIndexingDispute(address allocationId, bytes32 poi, uint256 deposit) external returns (bytes32);
197198

198199
function acceptDispute(bytes32 disputeId, uint256 tokensSlash) external;
199200

packages/subgraph-service/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "yarn lint:ts && yarn lint:sol",
1111
"clean": "rm -rf build cache typechain-types",
1212
"build": "forge build && hardhat compile",
13-
"test": "FOUNDRY_PROFILE=lite forge test -vvv && hardhat test"
13+
"test": "FOUNDRY_PROFILE=lite forge test -vvvv && hardhat test"
1414
},
1515
"devDependencies": {
1616
"@graphprotocol/contracts": "workspace:^7.0.0",

packages/subgraph-service/test/DisputeManager.t.sol

+20-11
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "forge-std/Test.sol";
66
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
77
import { TokenUtils } from "@graphprotocol/contracts/contracts/utils/TokenUtils.sol";
88
import { Controller } from "@graphprotocol/contracts/contracts/governance/Controller.sol";
9+
import { UnsafeUpgrades } from "openzeppelin-foundry-upgrades/Upgrades.sol";
910

1011
import { DisputeManager } from "../contracts/DisputeManager.sol";
1112
import { IDisputeManager } from "../contracts/interfaces/IDisputeManager.sol";
@@ -72,16 +73,24 @@ contract DisputeManagerTest is Test {
7273
controller.setContractProxy(keccak256("GraphToken"), address(graphToken));
7374
controller.setContractProxy(keccak256("Staking"), address(staking));
7475
controller.setContractProxy(keccak256("RewardsManager"), address(rewardsManager));
76+
controller.setContractProxy(keccak256("GraphPayments"), address(0x100));
77+
controller.setContractProxy(keccak256("PaymentsEscrow"), address(0x101));
78+
controller.setContractProxy(keccak256("EpochManager"), address(0x102));
79+
controller.setContractProxy(keccak256("GraphTokenGateway"), address(0x103));
80+
controller.setContractProxy(keccak256("GraphProxyAdmin"), address(0x104));
81+
controller.setContractProxy(keccak256("Curation"), address(0x105));
7582
vm.stopPrank();
7683

77-
disputeManager = new DisputeManager(address(controller));
78-
disputeManager.initialize(
79-
arbitrator,
80-
disputePeriod,
81-
minimumDeposit,
82-
fishermanRewardPercentage,
83-
maxSlashingPercentage
84+
address disputeManagerImplementation = address(new DisputeManager(address(controller)));
85+
address disputeManagerProxy = UnsafeUpgrades.deployTransparentProxy(
86+
disputeManagerImplementation,
87+
governor,
88+
abi.encodeCall(
89+
DisputeManager.initialize,
90+
(arbitrator, disputePeriod, minimumDeposit, fishermanRewardPercentage, maxSlashingPercentage)
91+
)
8492
);
93+
disputeManager = DisputeManager(disputeManagerProxy);
8594

8695
subgraphService = new SubgraphService(address(controller), address(disputeManager), tapVerifier, curation);
8796
subgraphService.initialize(1000 ether, 16);
@@ -110,7 +119,7 @@ contract DisputeManagerTest is Test {
110119
vm.startPrank(fisherman);
111120
graphToken.mint(fisherman, tokens);
112121
graphToken.approve(address(disputeManager), tokens);
113-
bytes32 _disputeID = disputeManager.createIndexingDispute(_allocationID, tokens);
122+
bytes32 _disputeID = disputeManager.createIndexingDispute(_allocationID, bytes32("POI1234"), tokens);
114123
vm.stopPrank();
115124
return _disputeID;
116125
}
@@ -218,7 +227,7 @@ contract DisputeManagerTest is Test {
218227
graphToken.approve(address(disputeManager), tokens);
219228
bytes memory expectedError = abi.encodeWithSignature("DisputeManagerDisputeAlreadyCreated(bytes32)", disputeID);
220229
vm.expectRevert(expectedError);
221-
disputeManager.createIndexingDispute(allocationID, tokens);
230+
disputeManager.createIndexingDispute(allocationID, bytes32("POI1234"), tokens);
222231
vm.stopPrank();
223232
}
224233

@@ -232,7 +241,7 @@ contract DisputeManagerTest is Test {
232241
100 ether
233242
);
234243
vm.expectRevert(expectedError);
235-
disputeManager.createIndexingDispute(allocationID, 50 ether);
244+
disputeManager.createIndexingDispute(allocationID, bytes32("POI1234"), 50 ether);
236245
vm.stopPrank();
237246
}
238247

@@ -244,7 +253,7 @@ contract DisputeManagerTest is Test {
244253
graphToken.approve(address(disputeManager), tokens);
245254
bytes memory expectedError = abi.encodeWithSignature("DisputeManagerIndexerNotFound(address)", allocationID);
246255
vm.expectRevert(expectedError);
247-
disputeManager.createIndexingDispute(allocationID, tokens);
256+
disputeManager.createIndexingDispute(allocationID, bytes32("POI1234"), tokens);
248257
vm.stopPrank();
249258
}
250259

0 commit comments

Comments
 (0)