diff --git a/contracts/deploy/upgrade-all.ts b/contracts/deploy/upgrade-all.ts index e545cac8d..ddb6d440b 100644 --- a/contracts/deploy/upgrade-all.ts +++ b/contracts/deploy/upgrade-all.ts @@ -81,7 +81,7 @@ const deployUpgradeAll: DeployFunction = async (hre: HardhatRuntimeEnvironment) await upgrade(disputeKitClassic, "initialize6", []); await upgrade(disputeTemplateRegistry, "initialize2", []); await upgrade(evidence, "initialize2", []); - await upgrade(core, "initialize4", []); + await upgrade(core, "initialize5", []); await upgrade(policyRegistry, "initialize2", []); await upgrade(sortition, "initialize3", []); }; diff --git a/contracts/scripts/keeperBot.ts b/contracts/scripts/keeperBot.ts index bd4ebcf35..c211f171b 100644 --- a/contracts/scripts/keeperBot.ts +++ b/contracts/scripts/keeperBot.ts @@ -7,6 +7,7 @@ import { Cores, getContracts as getContractsForCoreType } from "./utils/contract let request: (url: string, query: string) => Promise; // Workaround graphql-request ESM import const { ethers } = hre; +const MAX_DRAW_CALLS_WITHOUT_JURORS = 10; const MAX_DRAW_ITERATIONS = 30; const MAX_EXECUTE_ITERATIONS = 20; const MAX_DELAYED_STAKES_ITERATIONS = 50; @@ -248,7 +249,19 @@ const drawJurors = async (dispute: { id: string; currentRoundIndex: string }, it const { core } = await getContracts(); let success = false; try { - await core.draw.staticCall(dispute.id, iterations, HIGH_GAS_LIMIT); + const simulatedIterations = iterations * MAX_DRAW_CALLS_WITHOUT_JURORS; // Drawing will be skipped as long as no juror is available in the next MAX_DRAW_CALLS_WITHOUT_JURORS calls to draw() given this nb of iterations. + const { drawnJurors: drawnJurorsBefore } = await core.getRoundInfo(dispute.id, dispute.currentRoundIndex); + const nbDrawnJurors = (await core.draw.staticCall(dispute.id, simulatedIterations, HIGH_GAS_LIMIT)) as bigint; + const extraJurors = nbDrawnJurors - BigInt(drawnJurorsBefore.length); + logger.debug( + `Draw: ${extraJurors} jurors available in the next ${simulatedIterations} iterations for dispute ${dispute.id}` + ); + if (extraJurors <= 0n) { + logger.warn( + `Draw: skipping, no jurors available in the next ${simulatedIterations} iterations for dispute ${dispute.id}` + ); + return success; + } } catch (e) { logger.error(`Draw: will fail for ${dispute.id}, skipping`); return success; diff --git a/contracts/src/arbitration/KlerosCore.sol b/contracts/src/arbitration/KlerosCore.sol index 88272f22b..287e4f685 100644 --- a/contracts/src/arbitration/KlerosCore.sol +++ b/contracts/src/arbitration/KlerosCore.sol @@ -8,7 +8,7 @@ import {KlerosCoreBase, IDisputeKit, ISortitionModule, IERC20} from "./KlerosCor /// Core arbitrator contract for Kleros v2. /// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts. contract KlerosCore is KlerosCoreBase { - string public constant override version = "0.9.3"; + string public constant override version = "0.9.4"; // ************************************* // // * Constructor * // @@ -56,7 +56,7 @@ contract KlerosCore is KlerosCoreBase { ); } - function initialize4() external reinitializer(4) { + function initialize5() external reinitializer(5) { // NOP } diff --git a/contracts/src/arbitration/KlerosCoreBase.sol b/contracts/src/arbitration/KlerosCoreBase.sol index 6d45381e7..6a435489b 100644 --- a/contracts/src/arbitration/KlerosCoreBase.sol +++ b/contracts/src/arbitration/KlerosCoreBase.sol @@ -593,7 +593,8 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable /// @dev Draws jurors for the dispute. Can be called in parts. /// @param _disputeID The ID of the dispute. /// @param _iterations The number of iterations to run. - function draw(uint256 _disputeID, uint256 _iterations) external { + /// @return nbDrawnJurors The total number of jurors drawn in the round. + function draw(uint256 _disputeID, uint256 _iterations) external returns (uint256 nbDrawnJurors) { Dispute storage dispute = disputes[_disputeID]; uint256 currentRound = dispute.rounds.length - 1; Round storage round = dispute.rounds[currentRound]; @@ -616,6 +617,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable } } round.drawIterations += i; + return round.drawnJurors.length; } /// @dev Appeals the ruling of a specified dispute. diff --git a/contracts/src/arbitration/KlerosCoreNeo.sol b/contracts/src/arbitration/KlerosCoreNeo.sol index 6edbede01..988e42a53 100644 --- a/contracts/src/arbitration/KlerosCoreNeo.sol +++ b/contracts/src/arbitration/KlerosCoreNeo.sol @@ -9,7 +9,7 @@ import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; /// Core arbitrator contract for Kleros v2. /// Note that this contract trusts the PNK token, the dispute kit and the sortition module contracts. contract KlerosCoreNeo is KlerosCoreBase { - string public constant override version = "0.8.0"; + string public constant override version = "0.9.4"; // ************************************* // // * Storage * // @@ -67,7 +67,7 @@ contract KlerosCoreNeo is KlerosCoreBase { jurorNft = _jurorNft; } - function initialize4() external reinitializer(4) { + function initialize5() external reinitializer(5) { // NOP }