Skip to content

fix: avoid unnecessary calls draw() when no juror is available #2002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/deploy/upgrade-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", []);
};
Expand Down
15 changes: 14 additions & 1 deletion contracts/scripts/keeperBot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Cores, getContracts as getContractsForCoreType } from "./utils/contract

let request: <T>(url: string, query: string) => Promise<T>; // 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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/arbitration/KlerosCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 * //
Expand Down Expand Up @@ -56,7 +56,7 @@ contract KlerosCore is KlerosCoreBase {
);
}

function initialize4() external reinitializer(4) {
function initialize5() external reinitializer(5) {
// NOP
}

Expand Down
4 changes: 3 additions & 1 deletion contracts/src/arbitration/KlerosCoreBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/arbitration/KlerosCoreNeo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 * //
Expand Down Expand Up @@ -67,7 +67,7 @@ contract KlerosCoreNeo is KlerosCoreBase {
jurorNft = _jurorNft;
}

function initialize4() external reinitializer(4) {
function initialize5() external reinitializer(5) {
// NOP
}

Expand Down
Loading