Skip to content

Commit ad9e5de

Browse files
authored
C2D Metadata (#1963)
* metadata wip * fix publisherTrusted * fix test * lint fix
1 parent 5ccfb8f commit ad9e5de

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

src/@types/Compute.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ export interface ComputeResult {
107107
index?: number
108108
}
109109

110+
export type ComputeJobMetadata = {
111+
[key: string]: string | number | boolean
112+
}
113+
110114
export interface ComputeJob {
111115
owner: string
112116
did?: string
@@ -120,6 +124,7 @@ export interface ComputeJob {
120124
algoDID?: string
121125
agreementId?: string
122126
expireTimestamp: number
127+
metadata?: ComputeJobMetadata
123128
}
124129

125130
export interface ComputeOutput {

src/services/Provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
UserCustomParameters,
1717
Ipfs,
1818
ComputeResourceRequest,
19-
ComputePayment
19+
ComputePayment,
20+
ComputeJobMetadata
2021
} from '../@types'
2122
import { decodeJwt } from '../utils/Jwt.js'
2223

@@ -760,6 +761,7 @@ export class Provider {
760761
* @param {string} token The token address for compute payment.
761762
* @param {ComputeResourceRequest} resources The resources to start compute job with.
762763
* @param {chainId} chainId The chain used to do payments
764+
* @param {ComputeJobMetadata} metadata The compute job metadata. Additional metadata to be stored in the database.
763765
* @param {ComputeOutput} output The compute job output settings.
764766
* @param {AbortSignal} signal abort signal
765767
* @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
@@ -774,6 +776,7 @@ export class Provider {
774776
token: string,
775777
resources: ComputeResourceRequest[],
776778
chainId: number, // network used by payment (only for payed compute jobs)
779+
metadata?: ComputeJobMetadata,
777780
output?: ComputeOutput,
778781
signal?: AbortSignal
779782
): Promise<ComputeJob | ComputeJob[]> {
@@ -831,6 +834,7 @@ export class Provider {
831834
maxJobDuration
832835
}
833836
if (resources) payload.payment.resources = resources
837+
if (metadata) payload.metadata = metadata
834838
// if (additionalDatasets) payload.additionalDatasets = additionalDatasets
835839
if (output) payload.output = output
836840
let response
@@ -871,6 +875,7 @@ export class Provider {
871875
* @param {ComputeAsset} datasets The dataset to start compute on + additionalDatasets (the additional datasets if that is the case)
872876
* @param {ComputeAlgorithm} algorithm The algorithm to start compute with.
873877
* @param {ComputeResourceRequest} resources The resources to start compute job with.
878+
* @param {ComputeJobMetadata} metadata The compute job metadata. Additional metadata to be stored in the database.
874879
* @param {ComputeOutput} output The compute job output settings.
875880
* @param {AbortSignal} signal abort signal
876881
* @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
@@ -882,6 +887,7 @@ export class Provider {
882887
datasets: ComputeAsset[],
883888
algorithm: ComputeAlgorithm,
884889
resources?: ComputeResourceRequest[],
890+
metadata?: ComputeJobMetadata,
885891
output?: ComputeOutput,
886892
signal?: AbortSignal
887893
): Promise<ComputeJob | ComputeJob[]> {
@@ -930,6 +936,7 @@ export class Provider {
930936
// new field for C2D v2
931937
payload.datasets = datasets
932938
payload.algorithm = algorithm
939+
if (metadata) payload.metadata = metadata
933940
// if (additionalDatasets) payload.additionalDatasets = additionalDatasets
934941
payload.output = output
935942
let response

test/integration/ComputeExamples.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,13 @@ const DATASET_DDO: DDO = {
214214
timeout: 300,
215215
compute: {
216216
publisherTrustedAlgorithmPublishers: ['*'] as any,
217-
publisherTrustedAlgorithms: ['*'] as any,
217+
publisherTrustedAlgorithms: [
218+
{
219+
did: '*',
220+
filesChecksum: '*',
221+
containerSectionChecksum: '*'
222+
}
223+
],
218224
allowRawAlgorithm: false,
219225
allowNetworkAccess: true
220226
}

test/integration/ComputeFlow.test.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ const ddoWithNoTimeout: DDO = {
9696
timeout: 0,
9797
compute: {
9898
publisherTrustedAlgorithmPublishers: ['*'] as any,
99-
publisherTrustedAlgorithms: ['*'] as any,
99+
publisherTrustedAlgorithms: [
100+
{
101+
did: '*',
102+
filesChecksum: '*',
103+
containerSectionChecksum: '*'
104+
}
105+
],
100106
allowRawAlgorithm: false,
101107
allowNetworkAccess: true
102108
}
@@ -133,7 +139,13 @@ const ddoWith2mTimeout: DDO = {
133139
timeout: 120,
134140
compute: {
135141
publisherTrustedAlgorithmPublishers: ['*'] as any,
136-
publisherTrustedAlgorithms: ['*'] as any,
142+
publisherTrustedAlgorithms: [
143+
{
144+
did: '*',
145+
filesChecksum: '*',
146+
containerSectionChecksum: '*'
147+
}
148+
],
137149
allowRawAlgorithm: false,
138150
allowNetworkAccess: true
139151
}
@@ -601,7 +613,7 @@ describe('Compute flow tests', async () => {
601613
assert(
602614
Number(
603615
ethers.utils.formatUnits(providerInitializeComputeResults.payment.amount, 18)
604-
) ===
616+
) >=
605617
(computeEnv.maxJobDuration / 60) * price,
606618
'Incorrect payment token amount'
607619
) // 60 minutes per price 1 -> amount = 60

0 commit comments

Comments
 (0)