Skip to content

Commit f64aaac

Browse files
committed
more fixes
1 parent e39025f commit f64aaac

18 files changed

Lines changed: 75 additions & 83 deletions

src/OceanNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export class OceanNode {
163163
return this.indexer
164164
}
165165

166-
public getC2DEngines(): C2DEngines {
166+
public getC2DEngines(): C2DEngines | undefined {
167167
return this.c2dEngines
168168
}
169169

src/components/Indexer/ChainIndexer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ export class ChainIndexer {
4242
blockchain: Blockchain,
4343
rpcDetails: SupportedNetwork,
4444
eventEmitter: EventEmitter,
45-
database: Database
45+
database: Database,
46+
_config: OceanNodeConfig
4647
) {
4748
this.blockchain = blockchain
4849
this.eventEmitter = eventEmitter
4950
this.rpcDetails = rpcDetails
5051
this.db = database
52+
this.config = _config
5153
}
5254

5355
/**

src/components/Indexer/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { sleep } from '../../utils/util.js'
4040
import { isReindexingNeeded } from './version.js'
4141
import { getPackageVersion } from '../../utils/version.js'
4242
import { DB_EVENTS, ES_CONNECTION_EVENTS } from '../database/ElasticsearchConfigHelper.js'
43+
import { OceanNodeConfig } from '../../@types/OceanNode.js'
4344

4445
/**
4546
* Event emitter for DDO (Data Descriptor Object) events
@@ -79,6 +80,7 @@ let numCrawlAttempts = 0
7980
*/
8081
export class OceanIndexer {
8182
private db: Database
83+
private config: OceanNodeConfig
8284
private networks: RPCS
8385
private blockchainRegistry?: BlockchainRegistry
8486
private supportedChains: string[]
@@ -88,14 +90,15 @@ export class OceanIndexer {
8890
private reconnectTimer: NodeJS.Timeout | null = null
8991

9092
constructor(
91-
db: Database,
92-
supportedNetworks: RPCS,
93-
blockchainRegistry: BlockchainRegistry
93+
_db: Database,
94+
_config: OceanNodeConfig,
95+
_blockchainRegistry: BlockchainRegistry
9496
) {
95-
this.db = db
96-
this.networks = supportedNetworks
97-
this.blockchainRegistry = blockchainRegistry
98-
this.supportedChains = Object.keys(supportedNetworks)
97+
this.db = _db
98+
this.config = _config
99+
this.networks = this.config.indexingNetworks
100+
this.blockchainRegistry = _blockchainRegistry
101+
this.supportedChains = Object.keys(this.networks)
99102
INDEXING_QUEUE = []
100103
this.setupDbConnectionListeners()
101104
this.startAllChainIndexers()
@@ -293,7 +296,8 @@ export class OceanIndexer {
293296
blockchain,
294297
rpcDetails,
295298
INDEXER_CRAWLING_EVENT_EMITTER,
296-
this.db
299+
this.db,
300+
this.config
297301
)
298302

299303
INDEXER_LOGGER.log(

src/components/core/compute/environments.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ export class ComputeGetEnvironmentsHandler extends CommandHandler {
2626
}
2727
try {
2828
const computeEngines = this.getOceanNode().getC2DEngines()
29+
if (!computeEngines) {
30+
return {
31+
stream: null,
32+
status: {
33+
httpStatus: 503,
34+
error: 'Compute engines are not configured on this node'
35+
}
36+
}
37+
}
2938
const result = await computeEngines.fetchEnvironments(task.chainId)
3039

3140
CORE_LOGGER.logMessage(

src/components/core/handler/downloadHandler.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,20 @@ export class DownloadHandler extends CommandHandler {
380380
// get all compute envs
381381
const computeAddrs: string[] = []
382382

383-
const environments = await oceanNode.getC2DEngines().fetchEnvironments(ddo.chainId)
383+
const c2dEngines = oceanNode.getC2DEngines()
384+
if (!c2dEngines) {
385+
const msg =
386+
'Compute engines are not configured on this node; cannot validate compute download'
387+
CORE_LOGGER.logMessage(msg, true)
388+
return {
389+
stream: null,
390+
status: {
391+
httpStatus: 503,
392+
error: msg
393+
}
394+
}
395+
}
396+
const environments = await c2dEngines.fetchEnvironments(ddo.chainId)
384397
for (const env of environments)
385398
computeAddrs.push(env.consumerAddress?.toLowerCase())
386399

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ if (config.hasP2P) {
106106
await node.start()
107107
}
108108
if (config.hasIndexer && dbconn) {
109-
indexer = new OceanIndexer(dbconn, config.indexingNetworks, blockchainRegistry)
109+
indexer = new OceanIndexer(dbconn, config, blockchainRegistry)
110110
}
111111
if (dbconn) {
112112
provider = new OceanProvider(dbconn)
@@ -123,7 +123,7 @@ const oceanNode = OceanNode.getInstance(
123123
keyManager,
124124
blockchainRegistry
125125
)
126-
oceanNode.addC2DEngines()
126+
await oceanNode.addC2DEngines()
127127

128128
function removeExtraSlashes(req: any, res: any, next: any) {
129129
req.url = req.url.replace(/\/{2,}/g, '/')

src/test/integration/algorithmsAccess.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,7 @@ describe('Trusted algorithms Flow', () => {
108108
config = await getConfiguration(true)
109109
dbconn = await Database.init(config.dbConfig)
110110
oceanNode = await OceanNode.getInstance(config, dbconn, null, null, null)
111-
indexer = new OceanIndexer(
112-
dbconn,
113-
config.indexingNetworks,
114-
oceanNode.blockchainRegistry
115-
)
111+
indexer = new OceanIndexer(dbconn, config, oceanNode.blockchainRegistry)
116112
oceanNode.addIndexer(indexer)
117113
oceanNode.addC2DEngines()
118114

src/test/integration/compute.test.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,7 @@ describe('Compute', () => {
208208
}
209209

210210
oceanNode = OceanNode.getInstance(config, dbconn, null, null, null, null, null, true)
211-
indexer = new OceanIndexer(
212-
dbconn,
213-
config.indexingNetworks,
214-
oceanNode.blockchainRegistry
215-
)
211+
indexer = new OceanIndexer(dbconn, config, oceanNode.blockchainRegistry)
216212
oceanNode.addIndexer(indexer)
217213
await oceanNode.addC2DEngines()
218214

@@ -2754,11 +2750,7 @@ describe('Compute Access Restrictions', () => {
27542750
null,
27552751
true
27562752
)
2757-
const indexer = new OceanIndexer(
2758-
dbconn,
2759-
config.indexingNetworks,
2760-
oceanNode.blockchainRegistry
2761-
)
2753+
const indexer = new OceanIndexer(dbconn, config, oceanNode.blockchainRegistry)
27622754
oceanNode.addIndexer(indexer)
27632755
await oceanNode.addC2DEngines()
27642756

@@ -2951,11 +2943,7 @@ describe('Compute Access Restrictions', () => {
29512943
null,
29522944
true
29532945
)
2954-
const indexer = new OceanIndexer(
2955-
dbconn,
2956-
config.indexingNetworks,
2957-
oceanNode.blockchainRegistry
2958-
)
2946+
const indexer = new OceanIndexer(dbconn, config, oceanNode.blockchainRegistry)
29592947
oceanNode.addIndexer(indexer)
29602948
await oceanNode.addC2DEngines()
29612949

@@ -3083,11 +3071,7 @@ describe('Compute Access Restrictions', () => {
30833071
null,
30843072
true
30853073
)
3086-
const indexer = new OceanIndexer(
3087-
dbconn,
3088-
config.indexingNetworks,
3089-
oceanNode.blockchainRegistry
3090-
)
3074+
const indexer = new OceanIndexer(dbconn, config, oceanNode.blockchainRegistry)
30913075
oceanNode.addIndexer(indexer)
30923076
await oceanNode.addC2DEngines()
30933077

src/test/integration/configDatabase.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@ describe('Config Database', () => {
6161
initialVersionNull = await oceanIndexer.getDatabase().sqliteConfig.retrieveValue()
6262
assert(initialVersionNull.value === null, 'Initial version should be null')
6363
})
64-
65-
const oceanNode = await OceanNode.getInstance(await getConfiguration(true), database)
66-
oceanIndexer = new OceanIndexer(
67-
database,
68-
getMockSupportedNetworks(),
69-
oceanNode.blockchainRegistry
70-
)
64+
const config = await getConfiguration(true)
65+
const oceanNode = await OceanNode.getInstance(config, database)
66+
oceanIndexer = new OceanIndexer(database, config, oceanNode.blockchainRegistry)
7167
oceanNode.addIndexer(oceanIndexer)
7268
})
7369

src/test/integration/credentials.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ describe('[Credentials Flow] - Should run a complete node flow.', () => {
138138
config = await getConfiguration(true) // Force reload the configuration
139139
const database = await Database.init(config.dbConfig)
140140
oceanNode = OceanNode.getInstance(config, database)
141-
const indexer = new OceanIndexer(
142-
database,
143-
config.indexingNetworks,
144-
oceanNode.blockchainRegistry
145-
)
141+
const indexer = new OceanIndexer(database, config, oceanNode.blockchainRegistry)
146142
oceanNode.addIndexer(indexer)
147143
await oceanNode.addC2DEngines()
148144

0 commit comments

Comments
 (0)