Skip to content

Commit 96882e5

Browse files
authored
Add policyServer object in compute routes. (#1964)
* Add policyServer object in compute routes. * Fix datasets samples. Fix node logs file location from ci. * Added print for payment assert. * Fix assert. * Update ddo.js * Update lock file. * Tweak dataset. * Test. * Put back the updated structure. * Updating ComputeExamples.md --------- Co-authored-by: GitHub Actions Bot <>
1 parent ad9e5de commit 96882e5

9 files changed

Lines changed: 279 additions & 253 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ jobs:
173173
if: ${{ failure() }}
174174
run: |
175175
echo "========== Ocean Node Logs =========="
176-
tac ${{ github.workspace }}/ocean-node/start-node.log || echo "Log file not found"
176+
tac ${{ github.workspace }}/barge/start-node.log || echo "Log file not found"
177177
- name: Upload coverage
178178
uses: actions/upload-artifact@v4
179179
with:

ComputeExamples.md

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+
] as any,
218224
allowRawAlgorithm: false,
219225
allowNetworkAccess: true
220226
}

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"dependencies": {
5959
"@oasisprotocol/sapphire-paratime": "^1.3.2",
6060
"@oceanprotocol/contracts": "^2.3.0",
61-
"@oceanprotocol/ddo-js": "^0.1.0",
61+
"@oceanprotocol/ddo-js": "^0.1.2",
6262
"@rdfjs/dataset": "^2.0.2",
6363
"@rdfjs/formats-common": "^3.1.0",
6464
"@zazuko/env-node": "^2.1.4",

src/@types/PolicyServer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export interface PolicyServer {
2+
sessionId?: string
3+
successRedirectUri?: string
4+
errorRedirectUri?: string
5+
responseRedirectUri?: string
6+
presentationDefinitionUri?: string
7+
}

src/services/Provider.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ComputeJobMetadata
2121
} from '../@types'
2222
import { decodeJwt } from '../utils/Jwt.js'
23+
import { PolicyServer } from '../@types/PolicyServer.js'
2324

2425
export class Provider {
2526
private async getConsumerAddress(signerOrAuthToken: Signer | string): Promise<string> {
@@ -512,6 +513,7 @@ export class Provider {
512513
* @param {SignerOrAuthToken} signerOrAuthToken Signer or auth token
513514
* @param {ComputeResourceRequest[]} resources The resources to start compute job with.
514515
* @param {number} chainId The chain used to do payments
516+
* @param {PolicyServer} policyServer The policy server object.
515517
* @param {AbortSignal} signal abort signal
516518
* @return {Promise<ProviderComputeInitialize>} ProviderComputeInitialize data
517519
*/
@@ -525,6 +527,7 @@ export class Provider {
525527
signerOrAuthToken: Signer | string,
526528
resources: ComputeResourceRequest[],
527529
chainId: number,
530+
policyServer?: PolicyServer,
528531
signal?: AbortSignal
529532
): Promise<ProviderComputeInitializeResults> {
530533
const providerEndpoints = await this.getEndpoints(providerUri)
@@ -556,7 +559,7 @@ export class Provider {
556559
signatureMessage += nonce
557560
const signature = await this.getSignature(signerOrAuthToken, signatureMessage)
558561

559-
const providerData: Object = {
562+
const providerData: Record<string, any> = {
560563
datasets: assets,
561564
algorithm,
562565
environment: computeEnv,
@@ -570,6 +573,8 @@ export class Provider {
570573
signature
571574
}
572575

576+
if (policyServer) providerData.policyServer = policyServer
577+
573578
let response
574579
try {
575580
console.log('Initialize compute url:', initializeUrl)
@@ -615,7 +620,7 @@ export class Provider {
615620
* @param {string} transferTxId - The transfer transaction ID.
616621
* @param {string} providerUri - The provider URI.
617622
* @param {SignerOrAuthToken} signerOrAuthToken - The signer or auth token.
618-
* @param {any} policyServer - The policy server (if any is to be used).
623+
* @param {PolicyServer} policyServer - The policy server (if any is to be used).
619624
* @param {UserCustomParameters} userCustomParameters - The user custom parameters.
620625
* @returns {Promise<any>} The download URL.
621626
*/
@@ -626,7 +631,7 @@ export class Provider {
626631
transferTxId: string,
627632
providerUri: string,
628633
signerOrAuthToken: Signer | string,
629-
policyServer?: any,
634+
policyServer?: PolicyServer,
630635
userCustomParameters?: UserCustomParameters
631636
): Promise<any> {
632637
const providerEndpoints = await this.getEndpoints(providerUri)
@@ -763,6 +768,7 @@ export class Provider {
763768
* @param {chainId} chainId The chain used to do payments
764769
* @param {ComputeJobMetadata} metadata The compute job metadata. Additional metadata to be stored in the database.
765770
* @param {ComputeOutput} output The compute job output settings.
771+
* @param {PolicyServer} policyServer The policy server object.
766772
* @param {AbortSignal} signal abort signal
767773
* @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
768774
*/
@@ -778,6 +784,7 @@ export class Provider {
778784
chainId: number, // network used by payment (only for payed compute jobs)
779785
metadata?: ComputeJobMetadata,
780786
output?: ComputeOutput,
787+
policyServer?: PolicyServer,
781788
signal?: AbortSignal
782789
): Promise<ComputeJob | ComputeJob[]> {
783790
console.log('called new compute start method...')
@@ -837,6 +844,7 @@ export class Provider {
837844
if (metadata) payload.metadata = metadata
838845
// if (additionalDatasets) payload.additionalDatasets = additionalDatasets
839846
if (output) payload.output = output
847+
if (policyServer) payload.policyServer = policyServer
840848
let response
841849
try {
842850
response = await fetch(computeStartUrl, {
@@ -877,6 +885,7 @@ export class Provider {
877885
* @param {ComputeResourceRequest} resources The resources to start compute job with.
878886
* @param {ComputeJobMetadata} metadata The compute job metadata. Additional metadata to be stored in the database.
879887
* @param {ComputeOutput} output The compute job output settings.
888+
* @param {PolicyServer} policyServer The policy server object.
880889
* @param {AbortSignal} signal abort signal
881890
* @return {Promise<ComputeJob | ComputeJob[]>} The compute job or jobs.
882891
*/
@@ -889,6 +898,7 @@ export class Provider {
889898
resources?: ComputeResourceRequest[],
890899
metadata?: ComputeJobMetadata,
891900
output?: ComputeOutput,
901+
policyServer?: PolicyServer,
892902
signal?: AbortSignal
893903
): Promise<ComputeJob | ComputeJob[]> {
894904
console.log('called new free compute start method...')
@@ -939,6 +949,7 @@ export class Provider {
939949
if (metadata) payload.metadata = metadata
940950
// if (additionalDatasets) payload.additionalDatasets = additionalDatasets
941951
payload.output = output
952+
if (policyServer) payload.policyServer = policyServer
942953
let response
943954
try {
944955
response = await fetch(computeStartUrl, {

test/integration/ComputeExamples.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ const DATASET_DDO: DDO = {
220220
filesChecksum: '*',
221221
containerSectionChecksum: '*'
222222
}
223-
],
223+
] as any,
224224
allowRawAlgorithm: false,
225225
allowNetworkAccess: true
226226
}

test/integration/ComputeFlow.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ let escrow: EscrowContract
5555
let freeComputeRouteSupport = null
5656

5757
const computeJobDuration = 60 * 15 // 15 minutes
58+
let computeMinutes: number
5859

5960
const assetUrl: Files = {
6061
datatokenAddress: '0x0',
@@ -495,7 +496,7 @@ describe('Compute flow tests', async () => {
495496

496497
it('Should fast forward time and set a new computeValidUntil', async () => {
497498
const mytime = new Date()
498-
const computeMinutes = 2
499+
computeMinutes = 2
499500
mytime.setMinutes(mytime.getMinutes() + computeMinutes)
500501
computeValidUntil = Math.floor(mytime.getTime() / 1000)
501502
})
@@ -613,8 +614,8 @@ describe('Compute flow tests', async () => {
613614
assert(
614615
Number(
615616
ethers.utils.formatUnits(providerInitializeComputeResults.payment.amount, 18)
616-
) >=
617-
(computeEnv.maxJobDuration / 60) * price,
617+
) ===
618+
(computeEnv.maxJobDuration / 60) * price * computeMinutes,
618619
'Incorrect payment token amount'
619620
) // 60 minutes per price 1 -> amount = 60
620621
assert(

0 commit comments

Comments
 (0)