Skip to content

Commit 31d4a28

Browse files
feat: add compass service for offchain config resolution (#454)
1 parent 9c747d0 commit 31d4a28

File tree

17 files changed

+264
-30
lines changed

17 files changed

+264
-30
lines changed

docs/classes/IExecConfig.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const wallet = IExecWalletModule.fromConfig(config);
2929
- [resolveBridgeBackAddress](IExecConfig.md#resolvebridgebackaddress)
3030
- [resolveBridgedContractsClient](IExecConfig.md#resolvebridgedcontractsclient)
3131
- [resolveChainId](IExecConfig.md#resolvechainid)
32+
- [resolveCompassURL](IExecConfig.md#resolvecompassurl)
3233
- [resolveContractsClient](IExecConfig.md#resolvecontractsclient)
3334
- [resolveEnsPublicResolverAddress](IExecConfig.md#resolveenspublicresolveraddress)
3435
- [resolveIexecGatewayURL](IExecConfig.md#resolveiexecgatewayurl)
@@ -123,6 +124,18 @@ resolve the current chainId
123124

124125
___
125126

127+
### resolveCompassURL
128+
129+
**resolveCompassURL**(): `Promise`<`undefined` \| `string`\>
130+
131+
resolve the current Compass URL
132+
133+
#### Returns
134+
135+
`Promise`<`undefined` \| `string`\>
136+
137+
___
138+
126139
### resolveContractsClient
127140

128141
**resolveContractsClient**(): `Promise`<[`IExecContractsClient`](internal_.IExecContractsClient.md)\>

docs/classes/errors.ApiCallError.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ ApiCallError encapsulates an error occurring during a call to an API such as a n
2020

2121
↳↳ [`IpfsGatewayCallError`](errors.IpfsGatewayCallError.md)
2222

23+
↳↳ [`CompassCallError`](errors.CompassCallError.md)
24+
2325
↳↳ [`WorkerpoolCallError`](errors.WorkerpoolCallError.md)
2426

2527
## Table of contents
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[iexec](../README.md) / [Exports](../modules.md) / [errors](../modules/errors.md) / CompassCallError
2+
3+
# Class: CompassCallError
4+
5+
[errors](../modules/errors.md).CompassCallError
6+
7+
CompassCallError encapsulates an error occurring during a call to the Compass API such as a network error or a server-side internal error.
8+
9+
## Hierarchy
10+
11+
- [`ApiCallError`](errors.ApiCallError.md)
12+
13+
**`CompassCallError`**
14+
15+
## Table of contents
16+
17+
### Constructors
18+
19+
- [constructor](errors.CompassCallError.md#constructor)
20+
21+
### Properties
22+
23+
- [cause](errors.CompassCallError.md#cause)
24+
- [originalError](errors.CompassCallError.md#originalerror)
25+
26+
## Constructors
27+
28+
### constructor
29+
30+
**new CompassCallError**(`message`, `originalError`): [`CompassCallError`](errors.CompassCallError.md)
31+
32+
#### Parameters
33+
34+
| Name | Type | Description |
35+
| :------ | :------ | :------ |
36+
| `message` | `string` | A descriptive error message detailing the nature of the error. |
37+
| `originalError` | `Error` | The original Error object that caused this API call error. |
38+
39+
#### Returns
40+
41+
[`CompassCallError`](errors.CompassCallError.md)
42+
43+
#### Inherited from
44+
45+
[ApiCallError](errors.ApiCallError.md).[constructor](errors.ApiCallError.md#constructor)
46+
47+
## Properties
48+
49+
### cause
50+
51+
**cause**: `Error`
52+
53+
The original Error object that caused this API call error.
54+
55+
#### Inherited from
56+
57+
[ApiCallError](errors.ApiCallError.md).[cause](errors.ApiCallError.md#cause)
58+
59+
___
60+
61+
### originalError
62+
63+
**originalError**: `Error`
64+
65+
**`Deprecated`**
66+
67+
use Error cause instead.
68+
69+
#### Inherited from
70+
71+
[ApiCallError](errors.ApiCallError.md).[originalError](errors.ApiCallError.md#originalerror)

docs/interfaces/IExecConfigOptions.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [allowExperimentalNetworks](IExecConfigOptions.md#allowexperimentalnetworks)
1010
- [bridgeAddress](IExecConfigOptions.md#bridgeaddress)
1111
- [bridgedNetworkConf](IExecConfigOptions.md#bridgednetworkconf)
12+
- [compassURL](IExecConfigOptions.md#compassurl)
1213
- [confirms](IExecConfigOptions.md#confirms)
1314
- [defaultTeeFramework](IExecConfigOptions.md#defaultteeframework)
1415
- [ensPublicResolverAddress](IExecConfigOptions.md#enspublicresolveraddress)
@@ -61,6 +62,14 @@ override the bridged network configuration
6162

6263
___
6364

65+
### compassURL
66+
67+
`Optional` **compassURL**: `string`
68+
69+
override the compass URL to target a custom instance
70+
71+
___
72+
6473
### confirms
6574

6675
`Optional` **confirms**: `number`

docs/modules/errors.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- [ApiCallError](../classes/errors.ApiCallError.md)
1010
- [BridgeError](../classes/errors.BridgeError.md)
11+
- [CompassCallError](../classes/errors.CompassCallError.md)
1112
- [ConfigurationError](../classes/errors.ConfigurationError.md)
1213
- [IpfsGatewayCallError](../classes/errors.IpfsGatewayCallError.md)
1314
- [MarketCallError](../classes/errors.MarketCallError.md)

src/cli/cmd/iexec-task.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,18 @@ debugTask
206206
const onchainData = await show(chain.contracts, taskid);
207207
const offchainData = await fetchTaskOffchainInfo(
208208
chain.contracts,
209+
chain.compass,
209210
taskid,
210211
).catch((e) => {
211212
spinner.warn(`Failed to fetch off-chain data: ${e.message}`);
212213
});
213214

214215
const appLogs = opts.logs
215-
? await fetchAllReplicatesLogs(chain.contracts, taskid).catch((e) => {
216+
? await fetchAllReplicatesLogs(
217+
chain.contracts,
218+
chain.compass,
219+
taskid,
220+
).catch((e) => {
216221
spinner.warn(`Failed to fetch app logs: ${e.message}`);
217222
})
218223
: undefined;

src/cli/cmd/iexec-workerpool.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ show
212212
throw e;
213213
}
214214
}),
215-
getWorkerpoolApiUrl(chain.contracts, addressOrIndex),
215+
getWorkerpoolApiUrl(chain.contracts, chain.compass, addressOrIndex),
216216
]);
217217
} else {
218218
showInfo = await showUserWorkerpool(
@@ -228,7 +228,11 @@ show
228228
throw e;
229229
}
230230
}),
231-
getWorkerpoolApiUrl(chain.contracts, showInfo.objAddress),
231+
getWorkerpoolApiUrl(
232+
chain.contracts,
233+
chain.compass,
234+
showInfo.objAddress,
235+
),
232236
]);
233237
}
234238
const { workerpool, objAddress } = showInfo;

src/cli/utils/fs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const chainConfSchema = () =>
3333
resultProxy: string(),
3434
ipfsGateway: string(),
3535
iexecGateway: string(),
36+
compass: string(),
3637
pocoSubgraph: string(),
3738
voucherSubgraph: string(),
3839
native: boolean(),

src/common/execution/debug.js

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import { WORKERPOOL_URL_TEXT_RECORD_KEY } from '../utils/constant.js';
1313
import { jsonApi, getAuthorization } from '../utils/api-utils.js';
1414
import { checkSigner } from '../utils/utils.js';
1515
import { getAddress } from '../wallet/address.js';
16-
import { WorkerpoolCallError } from '../utils/errors.js';
16+
import { CompassCallError, WorkerpoolCallError } from '../utils/errors.js';
1717

1818
const debug = Debug('iexec:execution:debug');
1919

2020
export const getWorkerpoolApiUrl = async (
2121
contracts = throwIfMissing(),
22+
compassUrl,
2223
workerpoolAddress,
2324
) => {
2425
try {
@@ -28,6 +29,21 @@ export const getWorkerpoolApiUrl = async (
2829
.required()
2930
.label('workerpool address')
3031
.validate(workerpoolAddress);
32+
33+
// Compass base workerpool API URL resolution
34+
if (compassUrl) {
35+
const json = await jsonApi.get({
36+
api: compassUrl,
37+
endpoint: `/${contracts.chainId}/workerpools/${vAddress}`,
38+
ApiCallErrorClass: CompassCallError,
39+
});
40+
if (!json?.apiUrl) {
41+
throw new Error(`No apiUrl found in compass response`);
42+
}
43+
return json.apiUrl;
44+
}
45+
46+
// ENS based workerpool API URL resolution
3147
const name = await lookupAddress(contracts, vAddress).catch(() => {
3248
/** return undefined */
3349
});
@@ -53,6 +69,7 @@ export const getWorkerpoolApiUrl = async (
5369

5470
const getTaskOffchainApiUrl = async (
5571
contracts = throwIfMissing(),
72+
compassUrl,
5673
taskid = throwIfMissing(),
5774
) => {
5875
try {
@@ -63,7 +80,11 @@ const getTaskOffchainApiUrl = async (
6380
if (!workerpool) {
6481
throw Error(`Cannot find task's workerpool`);
6582
}
66-
const workerpoolApiUrl = await getWorkerpoolApiUrl(contracts, workerpool);
83+
const workerpoolApiUrl = await getWorkerpoolApiUrl(
84+
contracts,
85+
compassUrl,
86+
workerpool,
87+
);
6788
if (!workerpoolApiUrl) {
6889
throw Error(`Impossible to resolve API url for workerpool ${workerpool}`);
6990
}
@@ -76,11 +97,16 @@ const getTaskOffchainApiUrl = async (
7697

7798
export const fetchTaskOffchainInfo = async (
7899
contracts = throwIfMissing(),
100+
compassURL,
79101
taskid = throwIfMissing(),
80102
) => {
81103
try {
82104
const vTaskid = await bytes32Schema().validate(taskid);
83-
const workerpoolApiUrl = await getTaskOffchainApiUrl(contracts, vTaskid);
105+
const workerpoolApiUrl = await getTaskOffchainApiUrl(
106+
contracts,
107+
compassURL,
108+
vTaskid,
109+
);
84110
const data = await jsonApi.get({
85111
api: workerpoolApiUrl,
86112
endpoint: `/tasks/${vTaskid}`,
@@ -106,12 +132,17 @@ export const fetchTaskOffchainInfo = async (
106132

107133
export const fetchAllReplicatesLogs = async (
108134
contracts = throwIfMissing(),
135+
compassURL,
109136
taskid = throwIfMissing(),
110137
) => {
111138
try {
112139
checkSigner(contracts);
113140
const vTaskid = await bytes32Schema().validate(taskid);
114-
const workerpoolApiUrl = await getTaskOffchainApiUrl(contracts, vTaskid);
141+
const workerpoolApiUrl = await getTaskOffchainApiUrl(
142+
contracts,
143+
compassURL,
144+
vTaskid,
145+
);
115146
const { dealid } = await taskShow(contracts, vTaskid);
116147
const { requester } = await dealShow(contracts, dealid);
117148
const userAddress = await getAddress(contracts);

src/common/utils/config.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const networkConfigs = [
1818
resultProxy: 'https://result.v8-bellecour.iex.ec',
1919
ipfsGateway: 'https://ipfs-gateway.v8-bellecour.iex.ec',
2020
iexecGateway: 'https://api.market.v8-bellecour.iex.ec',
21+
compass: undefined, // no compass using ENS
2122
pocoSubgraph: 'https://thegraph.iex.ec/subgraphs/name/bellecour/poco-v5',
2223
voucherHub: voucherHubBellecourAddress,
2324
voucherSubgraph:
@@ -40,6 +41,7 @@ const networkConfigs = [
4041
resultProxy: undefined, // no protocol running
4142
ipfsGateway: undefined, // no protocol running
4243
iexecGateway: undefined, // no protocol running
44+
compass: undefined, // no protocol running
4345
pocoSubgraph: undefined, // no protocol running
4446
voucherHub: undefined, // no voucher
4547
voucherSubgraph: undefined, // no voucher
@@ -55,14 +57,15 @@ const networkConfigs = [
5557
name: 'arbitrum-sepolia-testnet',
5658
hub: '0x14B465079537655E1662F012e99EBa3863c8B9E0',
5759
host: 'https://sepolia-rollup.arbitrum.io/rpc',
58-
ensRegistry: undefined, // TODO: not supported
59-
ensPublicResolver: undefined, // TODO: not supported
60+
ensRegistry: undefined, // not supported
61+
ensPublicResolver: undefined, // not supported
6062
sms: {
6163
[TEE_FRAMEWORKS.SCONE]: 'https://sms.arbitrum-sepolia-testnet.iex.ec',
6264
},
6365
resultProxy: undefined, // not exposed
6466
ipfsGateway: 'https://ipfs-gateway.arbitrum-sepolia-testnet.iex.ec',
6567
iexecGateway: 'https://api-market.arbitrum-sepolia-testnet.iex.ec',
68+
compass: 'https://compass.arbitrum-sepolia-testnet.iex.ec',
6669
pocoSubgraph:
6770
'https://thegraph.arbitrum-sepolia-testnet.iex.ec/api/subgraphs/id/2GCj8gzLCihsiEDq8cYvC5nUgK6VfwZ6hm3Wj8A3kcxz',
6871
voucherHub: undefined, // no voucher
@@ -94,6 +97,7 @@ export const getChainDefaults = (
9497
resultProxy,
9598
iexecGateway,
9699
ipfsGateway,
100+
compass,
97101
pocoSubgraph,
98102
voucherHub,
99103
voucherSubgraph,
@@ -115,6 +119,7 @@ export const getChainDefaults = (
115119
resultProxy,
116120
iexecGateway,
117121
ipfsGateway,
122+
compass,
118123
pocoSubgraph,
119124
voucherHub,
120125
voucherSubgraph,

0 commit comments

Comments
 (0)