Skip to content

Commit 34c2004

Browse files
fix: update storage layout
1 parent 6ded616 commit 34c2004

File tree

7 files changed

+48
-91
lines changed

7 files changed

+48
-91
lines changed

contracts/src/arbitration/KlerosCoreBase.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
103103
bool public paused; // Whether asset withdrawals are paused.
104104
address public wNative; // The wrapped native token for safeSend().
105105

106+
uint256[50] private __gap; // Reserved slots for future upgrades.
107+
106108
// ************************************* //
107109
// * Events * //
108110
// ************************************* //

contracts/src/arbitration/SortitionModuleBase.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
2525
address account; // The address of the juror.
2626
uint96 courtID; // The ID of the court.
2727
uint256 stake; // The new stake.
28-
bool alreadyTransferred; // DEPRECATED. True if tokens were already transferred before delayed stake's execution.
2928
}
3029

3130
struct Juror {
@@ -44,17 +43,16 @@ abstract contract SortitionModuleBase is ISortitionModule, Initializable, UUPSPr
4443
uint256 public minStakingTime; // The time after which the phase can be switched to Drawing if there are open disputes.
4544
uint256 public maxDrawingTime; // The time after which the phase can be switched back to Staking.
4645
uint256 public lastPhaseChange; // The last time the phase was changed.
47-
uint256 public randomNumberRequestBlock; // DEPRECATED: to be removed in the next redeploy
4846
uint256 public disputesWithoutJurors; // The number of disputes that have not finished drawing jurors.
4947
IRNG public rng; // The random number generator.
5048
uint256 public randomNumber; // Random number returned by RNG.
51-
uint256 public rngLookahead; // DEPRECATED: to be removed in the next redeploy
5249
uint256 public delayedStakeWriteIndex; // The index of the last `delayedStake` item that was written to the array. 0 index is skipped.
5350
uint256 public delayedStakeReadIndex; // The index of the next `delayedStake` item that should be processed. Starts at 1 because 0 index is skipped.
5451
mapping(TreeKey key => SortitionTrees.Tree) sortitionSumTrees; // The mapping of sortition trees by keys.
5552
mapping(address account => Juror) public jurors; // The jurors.
5653
mapping(uint256 => DelayedStake) public delayedStakes; // Stores the stakes that were changed during Drawing phase, to update them when the phase is switched to Staking.
57-
mapping(address jurorAccount => mapping(uint96 courtId => uint256)) public latestDelayedStakeIndex; // DEPRECATED. Maps the juror to its latest delayed stake. If there is already a delayed stake for this juror then it'll be replaced. latestDelayedStakeIndex[juror][courtID].
54+
55+
uint256[50] private __gap; // Reserved slots for future upgrades.
5856

5957
// ************************************* //
6058
// * Events * //

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
4141
mapping(address account => mapping(uint256 choiceId => uint256)) contributions; // Maps contributors to their contributions for each choice.
4242
uint256 feeRewards; // Sum of reimbursable appeal fees available to the parties that made contributions to the ruling that ultimately wins a dispute.
4343
uint256[] fundedChoices; // Stores the choices that are fully funded.
44-
uint256 nbVotes; // Maximal number of votes this dispute can get.
44+
mapping(address drawnAddress => bool) alreadyDrawn; // True if the address has already been drawn, false by default.
4545
}
4646

4747
struct Vote {
@@ -64,12 +64,11 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
6464
Dispute[] public disputes; // Array of the locally created disputes.
6565
mapping(uint256 => uint256) public coreDisputeIDToLocal; // Maps the dispute ID in Kleros Core to the local dispute ID.
6666
bool public singleDrawPerJuror; // Whether each juror can only draw once per dispute, false by default.
67-
mapping(uint256 localDisputeID => mapping(uint256 localRoundID => mapping(address drawnAddress => bool)))
68-
public alreadyDrawn; // True if the address has already been drawn, false by default. To be added to the Round struct when fully redeploying rather than upgrading.
6967
mapping(uint256 coreDisputeID => bool) public coreDisputeIDToActive; // True if this dispute kit is active for this core dispute ID.
7068
address public wNative; // The wrapped native token for safeSend().
7169
uint256 public jumpDisputeKitID; // The ID of the dispute kit in Kleros Core disputeKits array that the dispute should switch to after the court jump, in case the new court doesn't support this dispute kit.
7270

71+
uint256[50] private __gap; // Reserved slots for future upgrades.
7372
// ************************************* //
7473
// * Events * //
7574
// ************************************* //
@@ -201,12 +200,11 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
201200
/// @param _coreDisputeID The ID of the dispute in Kleros Core.
202201
/// @param _numberOfChoices Number of choices of the dispute
203202
/// @param _extraData Additional info about the dispute, for possible use in future dispute kits.
204-
/// @param _nbVotes Number of votes for this dispute.
205203
function createDispute(
206204
uint256 _coreDisputeID,
207205
uint256 _numberOfChoices,
208206
bytes calldata _extraData,
209-
uint256 _nbVotes
207+
uint256 /*_nbVotes*/
210208
) external override onlyByCore {
211209
uint256 localDisputeID = disputes.length;
212210
Dispute storage dispute = disputes.push();
@@ -218,7 +216,6 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
218216
dispute.coreRoundIDToLocal[core.getNumberOfRounds(_coreDisputeID) - 1] = dispute.rounds.length;
219217

220218
Round storage round = dispute.rounds.push();
221-
round.nbVotes = _nbVotes;
222219
round.tied = true;
223220

224221
coreDisputeIDToLocal[_coreDisputeID] = localDisputeID;
@@ -250,7 +247,7 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
250247

251248
if (_postDrawCheck(round, _coreDisputeID, drawnAddress)) {
252249
round.votes.push(Vote({account: drawnAddress, commit: bytes32(0), choice: 0, voted: false}));
253-
alreadyDrawn[localDisputeID][localRoundID][drawnAddress] = true;
250+
round.alreadyDrawn[drawnAddress] = true;
254251
} else {
255252
drawnAddress = address(0);
256253
}
@@ -422,7 +419,6 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
422419
dispute.coreRoundIDToLocal[coreRoundID + 1] = dispute.rounds.length;
423420

424421
Round storage newRound = dispute.rounds.push();
425-
newRound.nbVotes = core.getNumberOfVotes(_coreDisputeID);
426422
newRound.tied = true;
427423
}
428424
core.appeal{value: appealCost}(_coreDisputeID, dispute.numberOfChoices, dispute.extraData);
@@ -768,8 +764,8 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
768764
if (singleDrawPerJuror) {
769765
uint256 localDisputeID = coreDisputeIDToLocal[_coreDisputeID];
770766
Dispute storage dispute = disputes[localDisputeID];
771-
uint256 localRoundID = dispute.rounds.length - 1;
772-
result = !alreadyDrawn[localDisputeID][localRoundID][_juror];
767+
Round storage round = dispute.rounds[dispute.rounds.length - 1];
768+
result = !round.alreadyDrawn[_juror];
773769
} else {
774770
result = true;
775771
}

contracts/src/arbitration/interfaces/IDisputeKit.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ interface IDisputeKit {
3535
/// @param _coreDisputeID The ID of the dispute in Kleros Core, not in the Dispute Kit.
3636
/// @param _numberOfChoices Number of choices of the dispute
3737
/// @param _extraData Additional info about the dispute, for possible use in future dispute kits.
38-
/// @param _nbVotes Maximal number of votes this dispute can get. DEPRECATED as we don't need to pass it now. KC handles the count.
38+
/// @param _nbVotes Maximal number of votes this dispute can get. Added for future-proofing.
3939
function createDispute(
4040
uint256 _coreDisputeID,
4141
uint256 _numberOfChoices,

contracts/test/arbitration/staking-neo.ts

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ describe("Staking", async () => {
431431
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
432432
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
433433
await pnk.approve(core.target, PNK(1000));
434-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
435434
await expect(core.setStake(2, PNK(3000)))
436435
.to.emit(sortition, "StakeDelayed")
437436
.withArgs(deployer, 2, PNK(3000));
@@ -443,10 +442,9 @@ describe("Staking", async () => {
443442
});
444443

445444
it("Should store the delayed stake for later", async () => {
446-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
447445
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
448446
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
449-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000), false]);
447+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000)]);
450448
});
451449
});
452450

@@ -469,9 +467,8 @@ describe("Staking", async () => {
469467
]); // stake unchanged, delayed
470468
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
471469
expect(await sortition.delayedStakeReadIndex()).to.be.equal(2);
472-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
473-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
474-
expect(await sortition.latestDelayedStakeIndex(deployer, 1)).to.be.equal(0); // Deprecated. Always 0
470+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 1st delayed stake got deleted
471+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 2nd delayed stake got deleted
475472
});
476473

477474
it("Should transfer PNK after delayed stake execution", async () => {
@@ -497,7 +494,6 @@ describe("Staking", async () => {
497494
it("Should delay the stake decrease", async () => {
498495
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
499496
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
500-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
501497
await expect(core.setStake(2, PNK(1000)))
502498
.to.emit(sortition, "StakeDelayed")
503499
.withArgs(deployer, 2, PNK(1000));
@@ -509,10 +505,9 @@ describe("Staking", async () => {
509505
});
510506

511507
it("Should store the delayed stake for later", async () => {
512-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
513508
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
514509
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
515-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000), false]);
510+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000)]);
516511
});
517512
});
518513

@@ -534,9 +529,8 @@ describe("Staking", async () => {
534529
]); // stake unchanged, delayed
535530
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
536531
expect(await sortition.delayedStakeReadIndex()).to.be.equal(2);
537-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
538-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
539-
expect(await sortition.latestDelayedStakeIndex(deployer, 1)).to.be.equal(0); // Deprecated. Always 0
532+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 1st delayed stake got deleted
533+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 2nd delayed stake got deleted
540534
});
541535

542536
it("Should withdraw some PNK", async () => {
@@ -562,7 +556,6 @@ describe("Staking", async () => {
562556
it("Should delay the stake decrease", async () => {
563557
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
564558
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
565-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
566559
await expect(core.setStake(2, PNK(1000)))
567560
.to.emit(sortition, "StakeDelayed")
568561
.withArgs(deployer, 2, PNK(1000));
@@ -574,17 +567,15 @@ describe("Staking", async () => {
574567
});
575568

576569
it("Should store the delayed stake for later", async () => {
577-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
578570
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
579571
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
580-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000), false]);
572+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000)]);
581573
});
582574
});
583575

584576
describe("When stake is increased back to the previous amount", () => {
585577
it("Should delay the stake increase", async () => {
586578
balanceBefore = await pnk.balanceOf(deployer);
587-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
588579
await expect(core.setStake(2, PNK(2000)))
589580
.to.emit(sortition, "StakeDelayed")
590581
.withArgs(deployer, 2, PNK(2000));
@@ -596,11 +587,10 @@ describe("Staking", async () => {
596587
});
597588

598589
it("Should store the delayed stake for later", async () => {
599-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
600590
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
601591
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
602-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000), false]);
603-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000), false]);
592+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(1000)]);
593+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000)]);
604594
});
605595
});
606596

@@ -625,9 +615,8 @@ describe("Staking", async () => {
625615
]); // stake unchanged, delayed
626616
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
627617
expect(await sortition.delayedStakeReadIndex()).to.be.equal(3);
628-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
629-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
630-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
618+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 1st delayed stake got deleted
619+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 2nd delayed stake got deleted
631620
});
632621

633622
it("Should not transfer any PNK", async () => {
@@ -654,7 +643,6 @@ describe("Staking", async () => {
654643
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(0);
655644
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
656645
await pnk.approve(core.target, PNK(1000));
657-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
658646
await expect(core.setStake(2, PNK(3000)))
659647
.to.emit(sortition, "StakeDelayed")
660648
.withArgs(deployer, 2, PNK(3000));
@@ -666,17 +654,15 @@ describe("Staking", async () => {
666654
});
667655

668656
it("Should store the delayed stake for later", async () => {
669-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
670657
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(1);
671658
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
672-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000), false]);
659+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000)]);
673660
});
674661
});
675662

676663
describe("When stake is decreased back to the previous amount", () => {
677664
it("Should cancel out the stake decrease back", async () => {
678665
balanceBefore = await pnk.balanceOf(deployer);
679-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
680666
await expect(core.setStake(2, PNK(2000)))
681667
.to.emit(sortition, "StakeDelayed")
682668
.withArgs(deployer, 2, PNK(2000));
@@ -688,11 +674,10 @@ describe("Staking", async () => {
688674
});
689675

690676
it("Should store the delayed stake for later", async () => {
691-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
692677
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
693678
expect(await sortition.delayedStakeReadIndex()).to.be.equal(1);
694-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000), false]);
695-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000), false]);
679+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([deployer, 2, PNK(3000)]);
680+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([deployer, 2, PNK(2000)]);
696681
});
697682
});
698683

@@ -715,9 +700,8 @@ describe("Staking", async () => {
715700
]); // stake unchanged, delayed
716701
expect(await sortition.delayedStakeWriteIndex()).to.be.equal(2);
717702
expect(await sortition.delayedStakeReadIndex()).to.be.equal(3);
718-
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 1st delayed stake got deleted
719-
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0, false]); // the 2nd delayed stake got deleted
720-
expect(await sortition.latestDelayedStakeIndex(deployer, 2)).to.be.equal(0); // Deprecated. Always 0
703+
expect(await sortition.delayedStakes(1)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 1st delayed stake got deleted
704+
expect(await sortition.delayedStakes(2)).to.be.deep.equal([ethers.ZeroAddress, 0, 0]); // the 2nd delayed stake got deleted
721705
});
722706

723707
it("Should not transfer any PNK", async () => {

0 commit comments

Comments
 (0)