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
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ jobs:
working-directory: ${{ github.workspace }}/barge
run: |
bash -x start_ocean.sh 2>&1 > start_ocean.log &

env:
NODE_VERSION: pr-1622
- name: Install deps & build
run: npm ci && npm run build:metadata
- name: Wait for node to be ready
Expand Down Expand Up @@ -141,6 +142,8 @@ jobs:
working-directory: ${{ github.workspace }}/barge
run: |
bash -x start_ocean.sh 2>&1 > start-node.log &
env:
NODE_VERSION: pr-1622
- name: Install deps & build
run: npm ci && npm run build:metadata

Expand Down
780 changes: 375 additions & 405 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"@libp2p/websockets": "^10.1.21",
"@multiformats/multiaddr": "^13.0.3",
"@oasisprotocol/sapphire-ethers-v6": "^6.0.1",
"@oceanprotocol/ddo-js": "^1.0.0",
"@oceanprotocol/ddo-js": "^1.1.0",
"bignumber.js": "^11.1.5",
"cross-fetch": "^4.1.0",
"crypto-js": "^4.2.0",
Expand Down
10 changes: 10 additions & 0 deletions src/@types/Provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export interface NodeStatus {
http: boolean
p2p: boolean
provider: NodeStatusProvider[]
/**
* Per-chain last-indexed-block info. Populated by DETAILED status only (the node reads it from
* its metadata DB per chain); basic status — what `getNodeStatus()` requests — returns `[]`.
*/
indexer: NodeStatusIndexer[]
escrowAddress: Record<string, string>
/** chainId -> subsidy-provider contract addresses the node applies. Absent on older nodes. */
Expand All @@ -91,6 +95,12 @@ export interface NodeStatus {
* only subsidizes a job whose image matches; `{}` / absent = unrestricted. Absent on older nodes.
*/
subsidyProviderAllowedImages?: Record<string, string[]>
/**
* Seconds reserved to claim an escrow payment (the node's `ESCROW_CLAIM_TIMEOUT`, default 3600).
* Added to a job's `maxJobDuration` when locking escrow funds, so the caller can tell how long
* funds stay locked beyond the job's runtime. Absent on older nodes.
*/
claimDurationTimeout?: number
/** Maintenance (drain) mode. Absent on nodes that predate the feature. */
maintenance?: NodeStatusMaintenance
supportedStorage: Record<string, boolean>
Expand Down
10 changes: 8 additions & 2 deletions src/services/providers/BaseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -951,11 +951,17 @@ export class BaseProvider {
)
}

/**
* @param detailed when true, requests the node's DETAILED status (adds `indexer`,
* `c2dClusters`, `supportedSchemas`). Basic status (the default) stays cheap and returns
* `indexer: []`. Mirrors ocean-node's `status` vs `detailedStatus` split.
*/
public async getNodeStatus(
nodeUri: OceanNode,
signal?: AbortSignal
signal?: AbortSignal,
detailed: boolean = false
): Promise<NodeStatus> {
return this.getImpl(nodeUri).getNodeStatus(nodeUri, signal)
return this.getImpl(nodeUri).getNodeStatus(nodeUri, signal, detailed)
}

public async getNodeJobs(
Expand Down
63 changes: 28 additions & 35 deletions src/services/providers/HttpProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,35 +94,29 @@ export class HttpProvider {
return { consumerAddress, nonce, signature }
}

/**
* Returns the node's root info document (nodeId, chainIds, providerAddress, nodePublicKey, ...).
* @param {string} nodeUri - the provider url
* @return {Promise<any>}
*/
private async getNodeInfo(nodeUri: string, authorization?: string): Promise<any> {
try {
const info = await this.getData(nodeUri, authorization)
return await info.json()
} catch (e) {
LoggerInstance.error('Finding the node info failed:', e)
throw new Error('HTTP request failed calling Provider')
}
}

public async getNodeStatus(nodeUri: string, signal?: AbortSignal): Promise<NodeStatus> {
const path = this.baseUrl(nodeUri) + '/directCommand'
public async getNodeStatus(
nodeUri: string,
signal?: AbortSignal,
detailed: boolean = false
): Promise<NodeStatus> {
// The root endpoint is the HTTP alias of the `status` command (ocean-node #1622):
// GET / returns the full node status object (id, publicKey, address, provider[], ...).
// `?detailed=true` opts into the extended status (indexer + c2dClusters + supportedSchemas);
// basic status (the default) returns `indexer: []` and never reads the node's metadata DB.
const path = this.baseUrl(nodeUri) + (detailed ? '/?detailed=true' : '/')
try {
const response = await fetch(path, {
method: 'POST',
method: 'GET',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ command: PROTOCOL_COMMANDS.STATUS }),
signal
})
if (response?.ok) return response.json()
return null
if (!response?.ok) {
throw new Error(`Node status request failed with HTTP ${response?.status}`)
}
return response.json()
} catch (e) {
LoggerInstance.error('getNodeStatus failed:', e)
return null
throw e
}
}

Expand Down Expand Up @@ -271,8 +265,11 @@ export class HttpProvider {
* @return {string} The node public key
*/
private async getNodePublicKey(nodeUri: string): Promise<string> {
const nodeInfo = await this.getNodeInfo(nodeUri)
return nodeInfo.nodePublicKey
const status = await this.getNodeStatus(nodeUri)
if (!status?.publicKey) {
throw new Error('Node status did not include a publicKey; cannot encrypt payload.')
}
return status.publicKey
}

/**
Expand Down Expand Up @@ -1299,7 +1296,13 @@ export class HttpProvider {
})
if (response?.ok) {
const params = await response.json()
if (params && (params.providerAddress || params.providerAddresses)) return true
// Post #1622 the root endpoint returns the status shape, whose node ETH address
// is `address`; older nodes used `providerAddress`/`providerAddresses`.
if (
params &&
(params.address || params.providerAddress || params.providerAddresses)
)
return true
}
return false
} catch (error) {
Expand Down Expand Up @@ -1667,16 +1670,6 @@ export class HttpProvider {
} as ValidateMetadata
}

private async getData(url: string, authorization?: string): Promise<Response> {
return fetch(url, {
method: 'GET',
headers: {
'Content-type': 'application/json',
Authorization: authorization
}
})
}

public async createPersistentStorageBucket(
nodeUri: string,
signerOrAuthToken: SignerOrAuthTokenOrSignature,
Expand Down
24 changes: 14 additions & 10 deletions src/services/providers/P2pProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,10 @@ export class P2pProvider {

private async getNodePublicKey(nodeUri: OceanNode): Promise<string> {
const status = await this.getNodeStatus(nodeUri)
return status?.publicKey
if (!status?.publicKey) {
throw new Error('Node status did not include a publicKey; cannot encrypt payload.')
}
return status.publicKey
}

protected getAuthorization(s: SignerOrAuthTokenOrSignature) {
Expand Down Expand Up @@ -2476,18 +2479,19 @@ export class P2pProvider {
*/
public async getNodeStatus(
nodeUri: OceanNode,
signal?: AbortSignal
signal?: AbortSignal,
detailed: boolean = false
): Promise<NodeStatus> {
// Over P2P the detailed variant is a distinct command: `detailedStatus` adds
// indexer + c2dClusters + supportedSchemas, while `status` returns `indexer: []` and skips
// the node's metadata-DB reads. Mirrors ocean-node's StatusHandler / DetailedStatusHandler.
const command = detailed
? PROTOCOL_COMMANDS.DETAILED_STATUS
: PROTOCOL_COMMANDS.STATUS
try {
return await this.sendP2pCommand(
nodeUri,
PROTOCOL_COMMANDS.STATUS,
{},
null,
signal
)
return await this.sendP2pCommand(nodeUri, command, {}, null, signal)
} catch (e) {
LoggerInstance.error('P2P getNodeStatus (STATUS) failed:', e)
LoggerInstance.error(`P2P getNodeStatus (${command}) failed:`, e)
throw e
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/utils/Assets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ethers, hexlify, Signer, toBeHex, toUtf8Bytes } from 'ethers'
import { ConfigHelper } from '../../src/config/index.js'
import SHA256 from 'crypto-js/sha256.js'
import { Aquarius } from '../services/Aquarius.js'
import { NftFactory } from '../contracts/NFTFactory.js'
import { Nft } from '../contracts/NFT.js'
Expand All @@ -15,7 +14,7 @@ import { ProviderInstance } from '../services/Provider.js'
import AccessListFactory from '@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessListFactory.sol/AccessListFactory.json'
import ERC20Template4 from '@oceanprotocol/contracts/artifacts/contracts/templates/ERC20Template4.sol/ERC20Template4.json'
import { calculateActiveTemplateIndex } from './Addresses.js'
import { DDOManager, type DDO } from '@oceanprotocol/ddo-js'
import { DDOManager, hashSerializedDdo, type DDO } from '@oceanprotocol/ddo-js'
import { StorageObject } from '../@types/File.js'

export const DEVELOPMENT_CHAIN_ID = 8996
Expand Down Expand Up @@ -241,7 +240,7 @@ export async function createAsset(
} else {
const stringDDO = JSON.stringify(ddo)
metadata = hexlify(toUtf8Bytes(stringDDO))
metadataHash = '0x' + SHA256(metadata).toString()
metadataHash = hashSerializedDdo(stringDDO, 'hex-json-text')
flags = 0
}

Expand Down
9 changes: 3 additions & 6 deletions src/utils/DdoHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sha256 from 'crypto-js/sha256.js'
import { getAddress } from 'ethers'
import { deriveDid, hashSerializedDdo } from '@oceanprotocol/ddo-js'

/**
* Generates a valid DID
Expand All @@ -8,9 +7,7 @@ import { getAddress } from 'ethers'
* @returns {string} - The DID
*/
export function generateDid(nftAddress: string, chainId: number): string {
nftAddress = getAddress(nftAddress)
const checksum = sha256(nftAddress + chainId.toString(10))
return `did:op:${checksum.toString()}`
return deriveDid(nftAddress, chainId, '4')
}

/**
Expand All @@ -19,5 +16,5 @@ export function generateDid(nftAddress: string, chainId: number): string {
* @returns {string} - The SHA256 hash of the input data
*/
export function getHash(data: any): string {
return sha256(data).toString()
return hashSerializedDdo(String(data), 'json-utf8').slice(2)
Comment thread
alexcos20 marked this conversation as resolved.
Resolved
}
Loading