From 0ad778f2db21c3f903ba8cf561728bb12b9f7c93 Mon Sep 17 00:00:00 2001 From: kelvin2608 <2608@newbitcoincity.com> Date: Thu, 9 May 2024 13:57:20 +0700 Subject: [PATCH 1/2] Modify: change logic related to expiration time and transferring value to minter --- contracts/WorkerHub.sol | 35 ++++++++++++----------------- contracts/interfaces/IWorkerHub.sol | 1 - 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/contracts/WorkerHub.sol b/contracts/WorkerHub.sol index c825546..3d5be1a 100644 --- a/contracts/WorkerHub.sol +++ b/contracts/WorkerHub.sol @@ -302,8 +302,6 @@ ReentrancyGuardUpgradeable { } } - // todo - // kelvin // minter submit result for specific infer function submitSolution(uint256 _assigmentId, bytes calldata _data) public virtual whenNotPaused { _updateEpoch(); @@ -314,35 +312,30 @@ ReentrancyGuardUpgradeable { if (_msgSender != clonedAssignments.worker) revert("Sender is invalid"); if (clonedAssignments.output.length != 0) revert("Assignment already submitted"); - assignments[_assigmentId].output = _data; //Record the solution - Inference memory clonedInference = inferences[clonedAssignments.inferenceId]; - Inference storage inference = inferences[clonedAssignments.inferenceId]; - // if inference.status is not Solving, the Tx will fail. - if (clonedInference.status != InferenceStatus.Solving) { - revert("Assignment already submitted"); - } - if (clonedInference.expiredAt > block.timestamp) { - _assignMinters(clonedAssignments.inferenceId); + if (clonedInference.expiredAt < block.timestamp) { + if (clonedInference.assignments.length == 0) { + _assignMinters(clonedAssignments.inferenceId); + return; + } else { + revert("Expire time"); + } } - inference.status = InferenceStatus.Solved; - uint256[] memory inferAssignments = clonedInference.assignments; - uint256 assignmentsLen = inferAssignments.length; + Inference storage inference = inferences[clonedAssignments.inferenceId]; - for (uint8 i = 0; i < assignmentsLen; i++) { - if (inferAssignments[i] == _assigmentId) { - inference.firstSubmitterIndex = i; - break; - } - } + assignments[_assigmentId].output = _data; //Record the solution + inference.status = InferenceStatus.Solved; + inference.assignments.push(_assigmentId); uint curEpoch = currentEpoch; minterTaskCompleted[_msgSender][curEpoch] += 1; rewardInEpoch[curEpoch].totalTaskCompleted += 1; - TransferHelper.safeTransferNative(_msgSender, clonedInference.value); + if (clonedInference.assignments.length == 1) { + TransferHelper.safeTransferNative(_msgSender, clonedInference.value); + } emit SolutionSubmission(_msgSender, _assigmentId); } diff --git a/contracts/interfaces/IWorkerHub.sol b/contracts/interfaces/IWorkerHub.sol index 28b860a..458adfb 100644 --- a/contracts/interfaces/IWorkerHub.sol +++ b/contracts/interfaces/IWorkerHub.sol @@ -47,7 +47,6 @@ interface IWorkerHub is IInferable { address disputingAddress; address modelAddress; uint40 expiredAt; - uint8 firstSubmitterIndex; InferenceStatus status; address creator; } From de1826e29c767d2cebd0e7601aff2d6f23672239 Mon Sep 17 00:00:00 2001 From: kelvin2608 <2608@newbitcoincity.com> Date: Thu, 9 May 2024 14:18:12 +0700 Subject: [PATCH 2/2] Modify: update code related to transferring value --- contracts/WorkerHub.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/WorkerHub.sol b/contracts/WorkerHub.sol index 3d5be1a..b4b8530 100644 --- a/contracts/WorkerHub.sol +++ b/contracts/WorkerHub.sol @@ -333,7 +333,7 @@ ReentrancyGuardUpgradeable { minterTaskCompleted[_msgSender][curEpoch] += 1; rewardInEpoch[curEpoch].totalTaskCompleted += 1; - if (clonedInference.assignments.length == 1) { + if (inference.assignments.length == 1) { TransferHelper.safeTransferNative(_msgSender, clonedInference.value); }