Skip to content

Commit 29ea956

Browse files
feat: added new formatting
1 parent e12d98c commit 29ea956

File tree

4 files changed

+68
-44
lines changed

4 files changed

+68
-44
lines changed

contracts/disputes/DisputeManager.sol

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -479,12 +479,10 @@ contract DisputeManager is DisputeManagerV1Storage, GraphUpgradeable, IDisputeMa
479479
_fisherman,
480480
_deposit,
481481
0, // no related dispute,
482-
DisputeType.QueryDispute
482+
DisputeType.QueryDispute,
483+
IDisputeManager.DisputeStatus.Pending
483484
);
484485

485-
// store the dispute status
486-
disputeStatus[disputeID] = IDisputeManager.DisputeStatus.Pending;
487-
488486
emit QueryDisputeCreated(
489487
disputeID,
490488
indexer,
@@ -549,17 +547,24 @@ contract DisputeManager is DisputeManagerV1Storage, GraphUpgradeable, IDisputeMa
549547
_fisherman,
550548
_deposit,
551549
0,
552-
DisputeType.IndexingDispute
550+
DisputeType.IndexingDispute,
551+
IDisputeManager.DisputeStatus.Pending
553552
);
554553

555-
// store dispute status
556-
disputeStatus[disputeID] = IDisputeManager.DisputeStatus.Pending;
557-
558554
emit IndexingDisputeCreated(disputeID, alloc.indexer, _fisherman, _deposit, _allocationID);
559555

560556
return disputeID;
561557
}
562558

559+
modifier onlyPendingDispute(bytes32 _disputeID) {
560+
require(isDisputeCreated(_disputeID), "Dispute does not exist");
561+
require(
562+
disputes[_disputeID].status == IDisputeManager.DisputeStatus.Pending,
563+
"Dispute must be pending"
564+
);
565+
_;
566+
}
567+
563568
/**
564569
* @dev The arbitrator accepts a dispute as being valid.
565570
* This function will revert if the indexer is not slashable, whether because it does not have
@@ -568,11 +573,16 @@ contract DisputeManager is DisputeManagerV1Storage, GraphUpgradeable, IDisputeMa
568573
* @notice Accept a dispute with ID `_disputeID`
569574
* @param _disputeID ID of the dispute to be accepted
570575
*/
571-
function acceptDispute(bytes32 _disputeID) external override onlyArbitrator {
572-
Dispute memory dispute = _resolveDispute(_disputeID);
576+
function acceptDispute(bytes32 _disputeID)
577+
external
578+
override
579+
onlyArbitrator
580+
onlyPendingDispute(_disputeID)
581+
{
582+
Dispute storage dispute = disputes[_disputeID];
573583

574-
// store dispute status
575-
disputeStatus[_disputeID] = IDisputeManager.DisputeStatus.Accepted;
584+
// store the dispute status
585+
dispute.status = IDisputeManager.DisputeStatus.Accepted;
576586

577587
// Slash
578588
(, uint256 tokensToReward) = _slashIndexer(
@@ -584,8 +594,9 @@ contract DisputeManager is DisputeManagerV1Storage, GraphUpgradeable, IDisputeMa
584594
// Give the fisherman their deposit back
585595
TokenUtils.pushTokens(graphToken(), dispute.fisherman, dispute.deposit);
586596

587-
// Resolve the conflicting dispute if any
588-
_resolveDisputeInConflict(dispute);
597+
if (_isDisputeInConflict(dispute)) {
598+
rejectDispute(dispute.relatedDisputeID);
599+
}
589600

590601
emit DisputeAccepted(
591602
_disputeID,
@@ -600,11 +611,16 @@ contract DisputeManager is DisputeManagerV1Storage, GraphUpgradeable, IDisputeMa
600611
* @notice Reject a dispute with ID `_disputeID`
601612
* @param _disputeID ID of the dispute to be rejected
602613
*/
603-
function rejectDispute(bytes32 _disputeID) external override onlyArbitrator {
604-
Dispute memory dispute = _resolveDispute(_disputeID);
614+
function rejectDispute(bytes32 _disputeID)
615+
public
616+
override
617+
onlyArbitrator
618+
onlyPendingDispute(_disputeID)
619+
{
620+
Dispute storage dispute = disputes[_disputeID];
605621

606622
// store dispute status
607-
disputeStatus[_disputeID] = IDisputeManager.DisputeStatus.Rejected;
623+
dispute.status = IDisputeManager.DisputeStatus.Rejected;
608624

609625
// Handle conflicting dispute if any
610626
require(
@@ -623,17 +639,24 @@ contract DisputeManager is DisputeManagerV1Storage, GraphUpgradeable, IDisputeMa
623639
* @notice Ignore a dispute with ID `_disputeID`
624640
* @param _disputeID ID of the dispute to be disregarded
625641
*/
626-
function drawDispute(bytes32 _disputeID) external override onlyArbitrator {
627-
Dispute memory dispute = _resolveDispute(_disputeID);
642+
function drawDispute(bytes32 _disputeID)
643+
public
644+
override
645+
onlyArbitrator
646+
onlyPendingDispute(_disputeID)
647+
{
648+
Dispute storage dispute = disputes[_disputeID];
628649

629650
// store dispute status
630-
disputeStatus[_disputeID] = IDisputeManager.DisputeStatus.Drawn;
651+
dispute.status = IDisputeManager.DisputeStatus.Drawn;
631652

632653
// Return deposit to the fisherman
633654
TokenUtils.pushTokens(graphToken(), dispute.fisherman, dispute.deposit);
634655

635656
// Resolve the conflicting dispute if any
636-
_resolveDisputeInConflict(dispute);
657+
if (_isDisputeInConflict(dispute)) {
658+
drawDispute(dispute.relatedDisputeID);
659+
}
637660

638661
emit DisputeDrawn(_disputeID, dispute.indexer, dispute.fisherman, dispute.deposit);
639662
}
@@ -643,39 +666,42 @@ contract DisputeManager is DisputeManagerV1Storage, GraphUpgradeable, IDisputeMa
643666
* @param _disputeID ID of the dispute to resolve
644667
* @return Dispute
645668
*/
646-
function _resolveDispute(bytes32 _disputeID) private returns (Dispute memory) {
647-
require(isDisputeCreated(_disputeID), "Dispute does not exist");
669+
// function _resolveDispute(bytes32 _disputeID) private returns (Dispute memory) {
670+
// require(isDisputeCreated(_disputeID), "Dispute does not exist");
648671

649-
Dispute memory dispute = disputes[_disputeID];
672+
// Dispute memory dispute = disputes[_disputeID];
650673

651-
// Resolve dispute
652-
delete disputes[_disputeID]; // Re-entrancy
674+
// // Resolve dispute
675+
// delete disputes[_disputeID]; // Re-entrancy
653676

654-
return dispute;
655-
}
677+
// return dispute;
678+
// }
656679

657680
/**
658681
* @dev Returns whether the dispute is for a conflicting attestation or not.
659682
* @param _dispute Dispute
660683
* @return True conflicting attestation dispute
661684
*/
662-
function _isDisputeInConflict(Dispute memory _dispute) private pure returns (bool) {
663-
return _dispute.relatedDisputeID != 0;
685+
function _isDisputeInConflict(Dispute memory _dispute) private view returns (bool) {
686+
bytes32 relatedID = _dispute.relatedDisputeID;
687+
return
688+
relatedID != 0 && disputes[relatedID].status == IDisputeManager.DisputeStatus.Pending;
664689
}
665690

666691
/**
667692
* @dev Resolve the conflicting dispute if there is any for the one passed to this function.
668693
* @param _dispute Dispute
669694
* @return True if resolved
670695
*/
671-
function _resolveDisputeInConflict(Dispute memory _dispute) private returns (bool) {
672-
if (_isDisputeInConflict(_dispute)) {
673-
bytes32 relatedDisputeID = _dispute.relatedDisputeID;
674-
delete disputes[relatedDisputeID];
675-
return true;
676-
}
677-
return false;
678-
}
696+
// function _resolveDisputeInConflict(Dispute memory _dispute) private returns (bool) {
697+
// if (_isDisputeInConflict(_dispute)) {
698+
// bytes32 relatedDisputeID = _dispute.relatedDisputeID;
699+
// Dispute storage relatedDispute = disputes[relatedDisputeID];
700+
// delete disputes[relatedDisputeID];
701+
// return true;
702+
// }
703+
// return false;
704+
// }
679705

680706
/**
681707
* @dev Pull deposit from submitter account.

contracts/disputes/DisputeManagerStorage.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,4 @@ contract DisputeManagerV1Storage is Managed {
3131
// Disputes created : disputeID => Dispute
3232
// disputeID - check creation functions to see how disputeID is built
3333
mapping(bytes32 => IDisputeManager.Dispute) public disputes;
34-
35-
// Dispute status : disputeID => DisputeStatus
36-
// disputeID - check creation functions to see how disputeID is built
37-
mapping(bytes32 => IDisputeManager.DisputeStatus) public disputeStatus;
3834
}

contracts/disputes/IDisputeManager.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface IDisputeManager {
2626
uint256 deposit;
2727
bytes32 relatedDisputeID;
2828
DisputeType disputeType;
29+
DisputeStatus status;
2930
}
3031

3132
// -- Attestation --

test/disputes/query.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
} from '../lib/testHelpers'
2222

2323
import { Dispute, createQueryDisputeID, encodeAttestation, MAX_PPM } from './common'
24+
import { isExportDeclaration } from 'typescript'
2425

2526
const { AddressZero, HashZero } = constants
2627

@@ -516,7 +517,7 @@ describe('DisputeManager:Query', async () => {
516517
await disputeManager.connect(arbitrator.signer).acceptDispute(dID1)
517518
// Check
518519
const relatedDispute = await disputeManager.disputes(dID2)
519-
expect(relatedDispute.indexer).eq(AddressZero)
520+
expect(relatedDispute.status).not.eq(3) // 3 = DisputeStatus.Pending
520521
})
521522

522523
it('should not allow to reject, user need to accept the related dispute ID to reject it', async function () {
@@ -536,7 +537,7 @@ describe('DisputeManager:Query', async () => {
536537
await disputeManager.connect(arbitrator.signer).drawDispute(dID1)
537538
// Check
538539
const relatedDispute = await disputeManager.disputes(dID2)
539-
expect(relatedDispute.indexer).eq(AddressZero)
540+
expect(relatedDispute.status).not.eq(3) // 3 = DisputeStatus.Pending
540541
})
541542
})
542543
})

0 commit comments

Comments
 (0)