Skip to content

Commit

Permalink
Adjust the parameter input of enclave endpoint (#3048)
Browse files Browse the repository at this point in the history
* fix vccorrectness

* rename
  • Loading branch information
0xverin authored Sep 6, 2024
1 parent 0ecfdb7 commit 82fe52a
Show file tree
Hide file tree
Showing 28 changed files with 52 additions and 48 deletions.
8 changes: 4 additions & 4 deletions bitacross-worker/scripts/launch_local_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NODE_URL=${node_url:-"ws://127.0.0.1"} # "ws://host.docker.internal"
NODE_PORT=${node_port:-"9944"} # "9946"

# Fixed values:
WORKER_ENDPOINT="localhost"
ENCLAVE_ENDPOINT="localhost"
MU_RA_PORT="3443"
UNTRUSTED_HTTP_PORT="4545"
TRUSTED_WORKER_PORT="2000"
Expand Down Expand Up @@ -114,13 +114,13 @@ for ((i = 0; i < ${WORKER_NUM}; i++)); do
"

launch_command="RUST_LOG=${RUST_LOG} ./litentry-worker ${F_CLEAN} --ws-external \
--mu-ra-external-address ${WORKER_ENDPOINT} \
--mu-ra-external-address ${ENCLAVE_ENDPOINT} \
--mu-ra-port ${mu_ra_port} \
--node-port ${NODE_PORT} \
--node-url ${NODE_URL} \
--trusted-external-address wss://${WORKER_ENDPOINT} \
--trusted-external-address wss://${ENCLAVE_ENDPOINT} \
--trusted-worker-port ${trusted_worker_port} \
--untrusted-external-address ws://${WORKER_ENDPOINT} \
--untrusted-external-address ws://${ENCLAVE_ENDPOINT} \
--untrusted-http-port ${untrusted_http_port} \
--untrusted-worker-port ${untrusted_worker_port} \
run --skip-ra ${FSUBCMD_DEV} ${FSUBCMD_REQ_STATE}"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NODE_ENV = local
WORKER_ENDPOINT = ws://localhost:2000
NODE_ENDPOINT = ws://localhost:9944
ENCLAVE_ENDPOINT = ws://localhost:2000
PARACHAIN_ENDPOINT = ws://localhost:9944
BINARY_DIR=../../bin
LITENTRY_CLI_DIR=../../bin/bitacross-cli
4 changes: 2 additions & 2 deletions bitacross-worker/ts-tests/integration-tests/.env.staging
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NODE_ENV = staging
WORKER_ENDPOINT = ws://bitacross-worker-1:2011
NODE_ENDPOINT = "ws://litentry-node:9912"
ENCLAVE_ENDPOINT = ws://bitacross-worker-1:2011
PARACHAIN_ENDPOINT = "ws://litentry-node:9912"
BINARY_DIR=/usr/local/bin
LITENTRY_CLI_DIR=/usr/local/bin/bitacross-cli
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import dotenv from 'dotenv';

function getWorkerUrls(env: String): String[] {
if (env == 'local') {
let workerEndpoint = process.env.WORKER_ENDPOINT!;
const workerEndpointParts = workerEndpoint.split(':');
let url = workerEndpointParts[0] + ':' + workerEndpointParts[1];
let port = parseInt(workerEndpointParts[2]);
let enclaveEndpoint = process.env.ENCLAVE_ENDPOINT!;
const enclaveEndpointParts = enclaveEndpoint.split(':');
let url = enclaveEndpointParts[0] + ':' + enclaveEndpointParts[1];
let port = parseInt(enclaveEndpointParts[2]);
return [url + ':' + port, url + ':' + (port + 10), url + ':' + (port + 20)];
} else {
return ['wss://bitacross-worker-1:2011', 'wss://bitacross-worker-2:2011', 'wss://bitacross-worker-3:2011'];
Expand Down
4 changes: 2 additions & 2 deletions tee-worker/cli/lit_ts_worker_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ TEST=$1


BINARY_DIR="/usr/local/bin"
NODE_ENDPOINT="ws://localhost:9944"
PARACHAIN_ENDPOINT="ws://localhost:9944"

echo "Using binary dir: $BINARY_DIR"
echo "Using node endpoint: $NODE_ENDPOINT"
echo "Using node endpoint: $PARACHAIN_ENDPOINT"

cd /ts-tests
pnpm install
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/ts-tests/integration-tests/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NODE_ENV = local
NODE_ENDPOINT = ws://localhost:9944
PARACHAIN_ENDPOINT = ws://localhost:9944
BINARY_DIR=../../bin
LITENTRY_CLI_DIR=../../bin/litentry-cli
2 changes: 1 addition & 1 deletion tee-worker/ts-tests/integration-tests/.env.staging
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NODE_ENV = staging
NODE_ENDPOINT = "ws://litentry-node:9944"
PARACHAIN_ENDPOINT = "ws://litentry-node:9944"
BINARY_DIR=/usr/local/bin
LITENTRY_CLI_DIR=/usr/local/bin/litentry-cli
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Test Vc (direct request)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);
aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context);
Expand Down
12 changes: 8 additions & 4 deletions tee-worker/ts-tests/integration-tests/common/utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export async function initWorkerConnection(endpoint: string): Promise<WebSocketA
return wsp;
}

export async function initIntegrationTestContext(substrateEndpoint: string): Promise<IntegrationTestContext> {
const provider = new WsProvider(substrateEndpoint);
export async function initIntegrationTestContext(
parachainEndpoint: string,
enclaveEndpoint?: string
): Promise<IntegrationTestContext> {
const provider = new WsProvider(parachainEndpoint);
await cryptoWaitReady();

const web3Wallets = createWeb3Wallets();
Expand All @@ -42,7 +45,8 @@ export async function initIntegrationTestContext(substrateEndpoint: string): Pro

const chainIdentifier = api.registry.chainSS58 as number;

const workerEndpoint = await getWorkerEndpoint(api);
const workerEndpoint = enclaveEndpoint ? enclaveEndpoint : await getenclaveEndpoint(api);

const wsp = await initWorkerConnection(workerEndpoint);
const requestId = 1;

Expand All @@ -61,7 +65,7 @@ export async function initIntegrationTestContext(substrateEndpoint: string): Pro
};
}

async function getWorkerEndpoint(api: ApiPromise): Promise<string> {
async function getenclaveEndpoint(api: ApiPromise): Promise<string> {
const registry = await api.query.teebag.enclaveRegistry.entries();
const identityEnclaves = registry.reduce((enclaves, [, enclave]) => {
if (enclave.isEmpty || !enclave.unwrap().workerType.isIdentity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function describeLitentry(title: string, cb: (context: IntegrationTestCon
before('Starting Litentry(parachain&tee)', async function () {
//env url

const tmp = await initIntegrationTestContext(process.env.NODE_ENDPOINT!);
const tmp = await initIntegrationTestContext(process.env.PARACHAIN_ENDPOINT!);
context.mrEnclave = tmp.mrEnclave;
context.api = tmp.api;
context.tee = tmp.tee;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('Test Identity (bitcoin direct invocation)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);
aliceBitcoinIdentity = await context.web3Wallets.bitcoin.Alice.getIdentity(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('Test Identity (evm direct invocation)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Test Identity (solana direct invocation)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('Test Identity (direct invocation)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);
aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context);
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/ts-tests/integration-tests/di_vc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Test Vc (direct invocation)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);
aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Test Discord Identity (direct invocation)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);

Expand Down
2 changes: 1 addition & 1 deletion tee-worker/ts-tests/integration-tests/dr_vc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('Test Vc (direct request)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);
aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('Test Twitter Identity (direct invocation)', function () {

before(async () => {
context = await initIntegrationTestContext(
process.env.NODE_ENDPOINT! // @fixme evil assertion; centralize env access
process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access
);
teeShieldingKey = await getTeeShieldingKey(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Test Vc (direct invocation)', function () {
const errorArray: { id: string; index: number; assertion: any; error: any }[] = [];
this.timeout(6000000);
before(async () => {
context = await initIntegrationTestContext(nodeEndpoint);
context = await initIntegrationTestContext(nodeEndpoint, enclaveEndpoint);
teeShieldingKey = await getTeeShieldingKey(context);
});

Expand Down
4 changes: 2 additions & 2 deletions tee-worker/ts-tests/stress/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NODE_ENV = local
WORKER_ENDPOINT = wss://localhost:2000
NODE_ENDPOINT = "ws://localhost:9944"
ENCLAVE_ENDPOINT = wss://localhost:2000
PARACHAIN_ENDPOINT = "ws://localhost:9944"
2 changes: 1 addition & 1 deletion tee-worker/ts-tests/stress/.env.staging
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NODE_ENV=staging
WORKER_ENDPOINT=wss://litentry-worker-1:2011
NODE_ENDPOINT="ws://litentry-node:9944"
PARACHAIN_ENDPOINT="ws://litentry-node:9944"
NODE_TLS_REJECT_UNAUTHORIZED=0
4 changes: 2 additions & 2 deletions tee-worker/ts-tests/stress/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"connections": 20,
"iterations": 10,
"substrateEndpoint": "ws://tee-staging.litentry.io:9944",
"workerEndpoint": "wss://tee-staging.litentry.io:2000"
"parachainEndpoint": "ws://tee-staging.litentry.io:9944",
"enclaveEndpoint": "wss://tee-staging.litentry.io:2000"
}
8 changes: 4 additions & 4 deletions tee-worker/ts-tests/stress/src/api-context-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { withRetry } from './util/with-retry';

export const apiContextManager = (
config: {
substrateEndpoint: string;
workerEndpoint: string;
parachainEndpoint: string;
enclaveEndpoint: string;
},
log: WritableStream<string>
): ContextManager<Api> => {
return ContextManager.blank()
.extend(
async () => ({
provider: new ParachainWsProvider(config.substrateEndpoint),
provider: new ParachainWsProvider(config.parachainEndpoint),
}),
async ({ provider }) => {
await provider.disconnect();
Expand All @@ -36,7 +36,7 @@ export const apiContextManager = (
)
.extend(
async () => ({
teeWorker: await withRetry(5, () => initWorkerConnection(config.workerEndpoint, log)),
teeWorker: await withRetry(5, () => initWorkerConnection(config.enclaveEndpoint, log)),
}),
async ({ teeWorker }) => {
await teeWorker.close();
Expand Down
4 changes: 2 additions & 2 deletions tee-worker/ts-tests/stress/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { readFileSync } from 'fs';
export const Config = z.object({
connections: z.number().int().positive(),
iterations: z.number(),
substrateEndpoint: z.string().url(),
workerEndpoint: z.string().url(),
parachainEndpoint: z.string().url(),
enclaveEndpoint: z.string().url(),
});

export type Config = z.infer<typeof Config>;
Expand Down
4 changes: 2 additions & 2 deletions tee-worker/ts-tests/stress/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function getConfig(): Config {
return {
connections: 3,
iterations: 2,
workerEndpoint: process.env.WORKER_ENDPOINT!, // @fixme evil assertion; centralize env access
substrateEndpoint: process.env.NODE_ENDPOINT!, // @fixme evil assertion; centralize env access
enclaveEndpoint: process.env.ENCLAVE_ENDPOINT!, // @fixme evil assertion; centralize env access
parachainEndpoint: process.env.PARACHAIN_ENDPOINT!, // @fixme evil assertion; centralize env access
};
}

Expand Down
2 changes: 1 addition & 1 deletion tee-worker/ts-tests/worker/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
NODE_ENV = local
NODE_ENDPOINT = "ws://localhost:9944"
PARACHAIN_ENDPOINT = "ws://localhost:9944"
BINARY_DIR=/usr/local/bin
2 changes: 1 addition & 1 deletion tee-worker/ts-tests/worker/.env.staging
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NODE_ENV=staging
NODE_ENDPOINT="ws://litentry-node:9944"
PARACHAIN_ENDPOINT="ws://litentry-node:9944"
NODE_TLS_REJECT_UNAUTHORIZED=0
BINARY_DIR=/usr/local/bin
4 changes: 2 additions & 2 deletions tee-worker/ts-tests/worker/resuming_worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ function getConfiguration(): { binaryDir: string; nodeUrl: string; nodePort: num
throw new Error('Environment variable BINARY_DIR not defined');
}

const [, nodeHost, nodePortRaw] = process.env.NODE_ENDPOINT!.split(':');
const [, nodeHost, nodePortRaw] = process.env.PARACHAIN_ENDPOINT!.split(':');
const nodePort = Number.parseInt(nodePortRaw);
if (nodeHost === undefined || Number.isNaN(nodePort)) {
throw new Error('Environment variable NODE_ENDPOINT undefined or malformed');
throw new Error('Environment variable PARACHAIN_ENDPOINT undefined or malformed');
}

return { binaryDir, nodeUrl: `ws:${nodeHost}`, nodePort };
Expand Down

0 comments on commit 82fe52a

Please sign in to comment.