Skip to content

Commit 1cfef4d

Browse files
committed
add flag and auto create benchmark environment
1 parent a34a4f3 commit 1cfef4d

5 files changed

Lines changed: 57 additions & 3 deletions

File tree

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"claimDurationTimeout": 3600,
9494
"validateUnsignedDDO": true,
9595
"jwtSecret": "ocean-node-secret",
96+
"enableBenchmark": true,
9697
"dockerComputeEnvironments": [
9798
{
9899
"socketPath": "/var/run/docker.sock",

src/@types/OceanNode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export interface OceanNodeConfig {
139139
jwtSecret?: string
140140
httpCertPath?: string
141141
httpKeyPath?: string
142+
enableBenchmark?: boolean
142143
}
143144

144145
export interface P2PStatusResponse {

src/components/c2d/compute_engine_docker.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import type {
2222
ComputeResourceRequest,
2323
ComputeEnvFees,
2424
ComputeResource,
25-
C2DEnvironmentConfig
25+
C2DEnvironmentConfig,
26+
ComputeResourcesPricingInfo
2627
} from '../../@types/C2D/C2D.js'
27-
import { getConfiguration } from '../../utils/config.js'
28+
import { BENCHMARK_MONITORING_ADDRESS, getConfiguration } from '../../utils/config.js'
2829
import { C2DEngine } from './compute_engine_base.js'
2930
import { C2DDatabase } from '../database/C2DDatabase.js'
3031
import { Escrow } from '../core/utils/escrow.js'
@@ -215,6 +216,54 @@ export class C2DEngineDocker extends C2DEngine {
215216
}
216217
const consumerAddress = this.getKeyManager().getEthAddress()
217218

219+
if (config.enableBenchmark) {
220+
const ramGB = this.physicalLimits.get('ram') || 0
221+
const physicalDiskGB = this.physicalLimits.get('disk') || 0
222+
223+
const gpuResources: ComputeResource[] = []
224+
for (const env of envConfig.environments) {
225+
if (env.resources) {
226+
for (const res of env.resources) {
227+
if (res.id !== 'cpu' && res.id !== 'ram' && res.id !== 'disk') {
228+
gpuResources.push(res)
229+
}
230+
}
231+
}
232+
}
233+
234+
const benchmarkPrices: ComputeResourcesPricingInfo[] = gpuResources.map((gpu) => ({
235+
id: gpu.id,
236+
price: 1
237+
}))
238+
239+
const sepoliaChainId = '11155111' // TODO: add Sepolia chain ID
240+
const usdcToken = '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238' // TODO: add USDC token address on Sepolia
241+
242+
const benchmarkFees: ComputeEnvFeesStructure = {
243+
[sepoliaChainId]: [{ feeToken: usdcToken, prices: benchmarkPrices }]
244+
}
245+
246+
const benchmarkEnv: C2DEnvironmentConfig = {
247+
description: 'Auto-generated benchmark environment',
248+
storageExpiry: 604800,
249+
maxJobDuration: 180,
250+
minJobDuration: 60,
251+
resources: [
252+
{ id: 'cpu', total: sysinfo.NCPU, min: 1, max: sysinfo.NCPU },
253+
{ id: 'ram', total: ramGB, min: 1, max: ramGB },
254+
{ id: 'disk', total: physicalDiskGB, min: 0, max: physicalDiskGB },
255+
...gpuResources
256+
],
257+
access: {
258+
addresses: [BENCHMARK_MONITORING_ADDRESS],
259+
accessLists: null
260+
},
261+
fees: benchmarkFees
262+
}
263+
264+
envConfig.environments.push(benchmarkEnv)
265+
}
266+
218267
for (let envIdx = 0; envIdx < envConfig.environments.length; envIdx++) {
219268
const envDef: C2DEnvironmentConfig = envConfig.environments[envIdx]
220269

src/utils/config/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ export const ENV_TO_CONFIG_MAPPING = {
6868
P2P_AUTODIALINTERVAL: 'p2pConfig.autoDialInterval',
6969
P2P_ENABLE_NETWORK_STATS: 'p2pConfig.enableNetworkStats',
7070
HTTP_CERT_PATH: 'httpCertPath',
71-
HTTP_KEY_PATH: 'httpKeyPath'
71+
HTTP_KEY_PATH: 'httpKeyPath',
72+
ENABLE_BENCHMARK: 'enableBenchmark'
7273
} as const
7374

7475
// Configuration defaults
7576
export const DEFAULT_RATE_LIMIT_PER_MINUTE = 30
7677
export const DEFAULT_MAX_CONNECTIONS_PER_MINUTE = 60 * 2 // 120 requests per minute
78+
export const BENCHMARK_MONITORING_ADDRESS = '0xC5ea7916f95D5a087A644f1Dc0f7d19955eC446F'
7779

7880
export const DEFAULT_BOOTSTRAP_ADDRESSES = [
7981
// OPF nodes

src/utils/config/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ export const OceanNodeConfigSchema = z
319319
INTERFACES: z.string().optional(),
320320
hasP2P: booleanFromString.optional().default(true),
321321
hasHttp: booleanFromString.optional().default(true),
322+
enableBenchmark: booleanFromString.optional().default(false),
322323

323324
p2pConfig: OceanNodeP2PConfigSchema.nullable().optional(),
324325
hasIndexer: booleanFromString.default(true),

0 commit comments

Comments
 (0)