From 32dc68331733b19a984023a6cb05b8237d67b0ef Mon Sep 17 00:00:00 2001 From: "Davide Gessa (dakk)" Date: Tue, 14 May 2024 09:01:25 +0200 Subject: [PATCH] fix contract workflow --- dqpu-contract/README.md | 14 +++++++++++--- dqpu-contract/sandbox-ts/workflow_executed.ava.ts | 2 +- .../sandbox-ts/workflow_invalid_result.ava.ts | 2 +- .../sandbox-ts/workflow_job_remove.ava.ts | 2 +- dqpu-contract/src/contract.ts | 11 +++++++---- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/dqpu-contract/README.md b/dqpu-contract/README.md index 8cdc597..ee62a0c 100644 --- a/dqpu-contract/README.md +++ b/dqpu-contract/README.md @@ -56,11 +56,19 @@ and then use the logged account to sign the transaction: `--accountId { t.is(await contract.view('get_job_status', { id: jid }), 'pending-validation'); await owner.call(contract, 'set_job_validity', { - id: jid, valid: true + id: jid, valid: true, trapped_file: 'ta12bff' }); // t.is((await alice.balance()).total, alice_initial_balance.total); diff --git a/dqpu-contract/sandbox-ts/workflow_invalid_result.ava.ts b/dqpu-contract/sandbox-ts/workflow_invalid_result.ava.ts index 56d6730..dc90bd9 100644 --- a/dqpu-contract/sandbox-ts/workflow_invalid_result.ava.ts +++ b/dqpu-contract/sandbox-ts/workflow_invalid_result.ava.ts @@ -43,7 +43,7 @@ test('add a job and submit an invalid result', async (t) => { t.is(await contract.view('get_job_status', { id: jid }), 'pending-validation'); await owner.call(contract, 'set_job_validity', { - id: jid, valid: true + id: jid, valid: true, trapped_file: 'ta12bff' }); // t.is((await alice.balance()).total, alice_initial_balance.total); diff --git a/dqpu-contract/sandbox-ts/workflow_job_remove.ava.ts b/dqpu-contract/sandbox-ts/workflow_job_remove.ava.ts index 51a39c8..7fbde45 100644 --- a/dqpu-contract/sandbox-ts/workflow_job_remove.ava.ts +++ b/dqpu-contract/sandbox-ts/workflow_job_remove.ava.ts @@ -43,7 +43,7 @@ test('add a job and submit an invalid result', async (t) => { t.is(await contract.view('get_job_status', { id: jid }), 'pending-validation'); await owner.call(contract, 'set_job_validity', { - id: jid, valid: true + id: jid, valid: true, trapped_file: 'ta12bff' }); // t.is((await alice.balance()).total, alice_initial_balance.total); diff --git a/dqpu-contract/src/contract.ts b/dqpu-contract/src/contract.ts index dec4d9c..82f999a 100644 --- a/dqpu-contract/src/contract.ts +++ b/dqpu-contract/src/contract.ts @@ -85,7 +85,7 @@ class DQPU { // Called by validators, set the validity of a pending-validation job @call({}) - set_job_validity({ id, valid }: { id: string, valid: boolean }) { + set_job_validity({ id, valid, trapped_file = null }: { id: string, valid: boolean, trapped_file: string }) { assert(this.verifiers.get(near.predecessorAccountId()) != null, 'Only a verifier can set job validity'); // Set job validity @@ -95,9 +95,10 @@ class DQPU { j.verifier_id = near.predecessorAccountId(); - if (valid) + if (valid) { + j.job_file = trapped_file; j.status = 'waiting'; - else { + } else { j.status = 'invalid'; // Send the reward back to the client @@ -115,8 +116,10 @@ class DQPU { let deposit: bigint = near.attachedDeposit() as bigint; - assert(deposit >= (j.reward_amount / BigInt(10)), `Deposit should be greater than ${j.reward_amount / BigInt(10)}`); assert(j.status == 'waiting', `Job ${id} is not in 'waiting' state`); + assert(deposit >= (j.reward_amount / BigInt(10)), `Deposit should be greater than ${j.reward_amount / BigInt(10)}`); + assert(j.owner_id != near.predecessorAccountId(), `Job owner and Verifier can't be the same account`); + assert(j.verifier_id != near.predecessorAccountId(), `Sampler and Verifier can't be the same account`); j.result_file = result_file; j.status = 'validating-result';