Skip to content
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
35 changes: 14 additions & 21 deletions contracts/WorkerHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ ReentrancyGuardUpgradeable {
}
}

// todo
// kelvin
// minter submit result for specific infer
function submitSolution(uint256 _assigmentId, bytes calldata _data) public virtual whenNotPaused {
_updateEpoch();
Expand All @@ -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 (inference.assignments.length == 1) {
TransferHelper.safeTransferNative(_msgSender, clonedInference.value);
}

emit SolutionSubmission(_msgSender, _assigmentId);
}
Expand Down
1 change: 0 additions & 1 deletion contracts/interfaces/IWorkerHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ interface IWorkerHub is IInferable {
address disputingAddress;
address modelAddress;
uint40 expiredAt;
uint8 firstSubmitterIndex;
InferenceStatus status;
address creator;
}
Expand Down