Skip to content

Commit 6b7e365

Browse files
committed
feat: removed an external call to Core in DK.createDispute()
1 parent a934ba5 commit 6b7e365

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

contracts/src/arbitration/KlerosCore.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
683683

684684
sortitionModule.createDisputeHook(disputeID, 0); // Default round ID.
685685

686-
disputeKit.createDispute(disputeID, _numberOfChoices, _extraData, round.nbVotes);
686+
disputeKit.createDispute(disputeID, 0, _numberOfChoices, _extraData, round.nbVotes);
687687
emit DisputeCreation(disputeID, IArbitrableV2(msg.sender));
688688
}
689689

@@ -782,6 +782,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
782782

783783
// Warning: the extra round must be created before calling disputeKit.createDispute()
784784
Round storage extraRound = dispute.rounds.push();
785+
uint256 extraRoundID = dispute.rounds.length - 1;
785786

786787
(uint96 newCourtID, uint256 newDisputeKitID, bool courtJump, ) = _getCourtAndDisputeKitJumps(
787788
dispute,
@@ -790,7 +791,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
790791
_disputeID
791792
);
792793
if (courtJump) {
793-
emit CourtJump(_disputeID, dispute.rounds.length - 1, dispute.courtID, newCourtID);
794+
emit CourtJump(_disputeID, extraRoundID, dispute.courtID, newCourtID);
794795
}
795796

796797
dispute.courtID = newCourtID;
@@ -803,13 +804,14 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
803804
extraRound.totalFeesForJurors = msg.value;
804805
extraRound.disputeKitID = newDisputeKitID;
805806

806-
sortitionModule.createDisputeHook(_disputeID, dispute.rounds.length - 1);
807+
sortitionModule.createDisputeHook(_disputeID, extraRoundID);
807808

808809
// Dispute kit was changed, so create a dispute in the new DK contract.
809810
if (extraRound.disputeKitID != round.disputeKitID) {
810811
emit DisputeKitJump(_disputeID, dispute.rounds.length - 1, round.disputeKitID, extraRound.disputeKitID);
811812
disputeKits[extraRound.disputeKitID].createDispute(
812813
_disputeID,
814+
extraRoundID,
813815
_numberOfChoices,
814816
_extraData,
815817
extraRound.nbVotes

contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
200200
/// @inheritdoc IDisputeKit
201201
function createDispute(
202202
uint256 _coreDisputeID,
203+
uint256 _coreRoundID,
203204
uint256 _numberOfChoices,
204205
bytes calldata _extraData,
205206
uint256 /*_nbVotes*/
@@ -224,7 +225,7 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
224225
dispute.extraData = _extraData;
225226

226227
// KlerosCore.Round must have been already created.
227-
dispute.coreRoundIDToLocal[core.getNumberOfRounds(_coreDisputeID) - 1] = dispute.rounds.length;
228+
dispute.coreRoundIDToLocal[_coreRoundID] = dispute.rounds.length;
228229
dispute.rounds.push().tied = true;
229230

230231
emit DisputeCreation(_coreDisputeID, _numberOfChoices, _extraData);

contracts/src/arbitration/interfaces/IDisputeKit.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ interface IDisputeKit {
3434
/// @dev Access restricted to Kleros Core only.
3535
/// @dev The new `KlerosCore.Round` must be created before calling this function.
3636
/// @param _coreDisputeID The ID of the dispute in Kleros Core, not in the Dispute Kit.
37+
/// @param _coreRoundID The ID of the round in Kleros Core, not in the Dispute Kit.
3738
/// @param _numberOfChoices Number of choices of the dispute
3839
/// @param _extraData Additional info about the dispute, for possible use in future dispute kits.
3940
/// @param _nbVotes Maximal number of votes this dispute can get. Added for future-proofing.
4041
function createDispute(
4142
uint256 _coreDisputeID,
43+
uint256 _coreRoundID,
4244
uint256 _numberOfChoices,
4345
bytes calldata _extraData,
4446
uint256 _nbVotes

contracts/src/arbitration/university/KlerosCoreUniversity.sol

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
531531

532532
sortitionModule.createDisputeHook(disputeID, 0); // Default round ID.
533533

534-
disputeKit.createDispute(disputeID, _numberOfChoices, _extraData, round.nbVotes);
534+
disputeKit.createDispute(disputeID, 0, _numberOfChoices, _extraData, round.nbVotes);
535535
emit DisputeCreation(disputeID, IArbitrableV2(msg.sender));
536536
}
537537

@@ -634,6 +634,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
634634

635635
// Warning: the extra round must be created before calling disputeKit.createDispute()
636636
Round storage extraRound = dispute.rounds.push();
637+
uint256 extraRoundID = dispute.rounds.length - 1;
637638

638639
if (round.nbVotes >= courts[newCourtID].jurorsForCourtJump) {
639640
// Jump to parent court.
@@ -645,7 +646,7 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
645646
}
646647

647648
if (newCourtID != dispute.courtID) {
648-
emit CourtJump(_disputeID, dispute.rounds.length - 1, dispute.courtID, newCourtID);
649+
emit CourtJump(_disputeID, extraRoundID, dispute.courtID, newCourtID);
649650
}
650651
}
651652

@@ -659,13 +660,14 @@ contract KlerosCoreUniversity is IArbitratorV2, UUPSProxiable, Initializable {
659660
extraRound.totalFeesForJurors = msg.value;
660661
extraRound.disputeKitID = newDisputeKitID;
661662

662-
sortitionModule.createDisputeHook(_disputeID, dispute.rounds.length - 1);
663+
sortitionModule.createDisputeHook(_disputeID, extraRoundID);
663664

664665
// Dispute kit was changed, so create a dispute in the new DK contract.
665666
if (extraRound.disputeKitID != round.disputeKitID) {
666667
emit DisputeKitJump(_disputeID, dispute.rounds.length - 1, round.disputeKitID, extraRound.disputeKitID);
667668
disputeKits[extraRound.disputeKitID].createDispute(
668669
_disputeID,
670+
extraRoundID,
669671
_numberOfChoices,
670672
_extraData,
671673
extraRound.nbVotes

contracts/test/arbitration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe("DisputeKitClassic", async () => {
7474

7575
it("Should create a dispute", async () => {
7676
await expect(
77-
disputeKit.connect(deployer).createDispute(0, 0, ethers.toBeHex(3), "0x00")
77+
disputeKit.connect(deployer).createDispute(0, 0, 0, ethers.toBeHex(3), "0x00")
7878
).to.be.revertedWithCustomError(disputeKit, "KlerosCoreOnly");
7979

8080
const tx = await core

0 commit comments

Comments
 (0)