Skip to content

Commit 1e5dd97

Browse files
feat: upload bulk files to thegraph ipfs node
1 parent ed73653 commit 1e5dd97

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

src/common/execution/order-helper.js

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Debug from 'debug';
2+
import { array } from 'yup';
13
import {
24
checkWeb2SecretExists,
35
checkWeb3SecretExists,
@@ -11,6 +13,7 @@ import {
1113
STORAGE_PROVIDERS,
1214
TEE_FRAMEWORKS,
1315
} from '../utils/constant.js';
16+
import { THEGRAPH_IPFS_NODE, THEGRAPH_IPFS_GATEWAY } from '../utils/config.js';
1417
import {
1518
getStorageTokenKeyName,
1619
reservedSecretKeyName,
@@ -27,7 +30,8 @@ import {
2730
} from '../utils/validator.js';
2831
import { resolveTeeFrameworkFromApp, showApp } from '../protocol/registries.js';
2932
import { add } from '../utils/ipfs.js';
30-
import { array } from 'yup';
33+
34+
const debug = Debug('iexec:execution:order-helper');
3135

3236
export const resolveTeeFrameworkFromTag = async (tag) => {
3337
const vTag = await tagSchema().validate(tag);
@@ -205,11 +209,34 @@ export const checkAppRequirements = async (
205209

206210
const MAX_DATASET_PER_TASK = 100; // TODO confirm value
207211

212+
const ipfsUpload = async ({
213+
content,
214+
ipfsNode,
215+
ipfsGateway,
216+
thegraphUpload,
217+
}) => {
218+
const [cid] = await Promise.all([
219+
add({ content, ipfsNode, ipfsGateway }),
220+
// best effort upload to thegraph ipfs
221+
thegraphUpload
222+
? add({
223+
content,
224+
ipfsNode: THEGRAPH_IPFS_NODE,
225+
ipfsGateway: THEGRAPH_IPFS_GATEWAY,
226+
}).catch((e) => {
227+
debug(`thegraph ipfs add failure: ${e.message}`);
228+
})
229+
: undefined,
230+
]);
231+
return cid;
232+
};
233+
208234
export const prepareDatasetBulk = async ({
209235
ipfsNode = throwIfMissing(),
210236
ipfsGateway = throwIfMissing(),
211237
datasetorders,
212238
maxDatasetPerTask = MAX_DATASET_PER_TASK,
239+
thegraphUpload = false,
213240
}) => {
214241
const vmMaxDatasetPerTask = await positiveStrictIntSchema()
215242
.max(MAX_DATASET_PER_TASK)
@@ -222,24 +249,24 @@ export const prepareDatasetBulk = async ({
222249
.label('datasetorders')
223250
.validate(datasetorders);
224251

225-
// TODO check orders eligibility?
226-
227252
const bulkRoot = [];
228253
while (vDatasetOrders.length > 0) {
229254
const slice = vDatasetOrders.slice(0, vmMaxDatasetPerTask);
230-
const sliceCid = await add({
255+
const sliceCid = await ipfsUpload({
231256
content: JSON.stringify(slice),
232257
ipfsNode,
233258
ipfsGateway,
259+
thegraphUpload,
234260
});
235261
bulkRoot.push(sliceCid);
236262
vDatasetOrders = vDatasetOrders.slice(vmMaxDatasetPerTask);
237263
}
238264

239-
const bulkCid = await add({
265+
const bulkCid = await ipfsUpload({
240266
content: JSON.stringify(bulkRoot),
241267
ipfsNode,
242268
ipfsGateway,
269+
thegraphUpload,
243270
});
244271
return { cid: bulkCid, volume: bulkRoot.length };
245272
};

src/common/utils/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const networkConfigs = [
7575
bridge: {}, // no bridge
7676
shouldRegisterNetwork: false,
7777
isExperimental: true,
78+
uploadBulkForThegraph: true,
7879
},
7980
{
8081
id: 42161,
@@ -97,6 +98,7 @@ const networkConfigs = [
9798
voucherSubgraph: undefined, // no voucher
9899
bridge: {}, // no bridge
99100
shouldRegisterNetwork: false,
101+
uploadBulkForThegraph: true,
100102
},
101103
];
102104

@@ -168,3 +170,9 @@ networkConfigs.forEach((networkConfig) => {
168170
Network.register(network.name, () => network);
169171
}
170172
});
173+
174+
export const shouldUploadBulkForThegraph = (id) =>
175+
networkConfigs[id]?.uploadBulkForThegraph || false;
176+
177+
export const THEGRAPH_IPFS_NODE = 'https://ipfs.thegraph.com';
178+
export const THEGRAPH_IPFS_GATEWAY = THEGRAPH_IPFS_NODE;

src/lib/IExecOrderModule.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import {
5151
datasetorderSchema,
5252
} from '../common/utils/validator.js';
5353
import { sumTags } from '../common/utils/utils.js';
54+
import { shouldUploadBulkForThegraph } from '../common/utils/config.js';
5455

5556
export default class IExecOrderModule extends IExecModule {
5657
constructor(...args) {
@@ -394,13 +395,17 @@ export default class IExecOrderModule extends IExecModule {
394395
};
395396
this.prepareDatasetBulk = async (
396397
datasetorders,
397-
{ maxDatasetPerTask } = {},
398+
{ maxDatasetPerTask, thegraphUpload } = {},
398399
) => {
399400
return prepareDatasetBulk({
400401
ipfsNode: await this.config.resolveIpfsNodeURL(),
401402
ipfsGateway: await this.config.resolveIpfsGatewayURL(),
402403
datasetorders,
403404
maxDatasetPerTask,
405+
thegraphUpload:
406+
thegraphUpload !== undefined
407+
? thegraphUpload
408+
: shouldUploadBulkForThegraph(await this.config.resolveChainId()),
404409
});
405410
};
406411
}

test/lib/e2e/IExecOrderModule.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('order', () => {
6969
test('prepares a bulk from datasetorders returns cid and volume', async () => {
7070
const res = await iexecRequester.order.prepareDatasetBulk(datasetorders, {
7171
maxDatasetPerTask: 3,
72+
thegraphUpload: false,
7273
});
7374
expect(res).toEqual({
7475
cid: expect.any(String),

0 commit comments

Comments
 (0)