From ab0261973c8eb0818a7ebcf9b1e3a6900e1328d4 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 23 Jul 2024 16:11:19 +0100 Subject: [PATCH 1/5] feat: add custom `nodeProtocol` and enable `https` for port `443` --- .../constants/src/lib/constants/constants.ts | 9 +++---- .../contracts-sdk/src/lib/contracts-sdk.ts | 24 +++++++++++++++---- packages/core/src/lib/lit-core.ts | 8 +++++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/packages/constants/src/lib/constants/constants.ts b/packages/constants/src/lib/constants/constants.ts index f5ab3ff489..759307a0b9 100644 --- a/packages/constants/src/lib/constants/constants.ts +++ b/packages/constants/src/lib/constants/constants.ts @@ -789,8 +789,8 @@ export const METAMASK_CHAIN_INFO_BY_NETWORK: Record< localhost: metamaskChainInfo.yellowstone, }; -const HTTP = 'http://'; -const HTTPS = 'https://'; +export const HTTP = 'http://'; +export const HTTPS = 'https://'; /** * Mapping of network values to corresponding http protocol. @@ -804,8 +804,9 @@ export const HTTP_BY_NETWORK: Record< habanero: HTTPS, 'datil-dev': HTTPS, 'datil-test': HTTPS, - custom: HTTP, - localhost: HTTP, + internalDev: HTTPS, + custom: HTTP, // default, can be changed by config + localhost: HTTP, // default, can be changed by config }; /** diff --git a/packages/contracts-sdk/src/lib/contracts-sdk.ts b/packages/contracts-sdk/src/lib/contracts-sdk.ts index 254a107436..67b2aef81c 100644 --- a/packages/contracts-sdk/src/lib/contracts-sdk.ts +++ b/packages/contracts-sdk/src/lib/contracts-sdk.ts @@ -56,6 +56,8 @@ import { HTTP_BY_NETWORK, CENTRALISATION_BY_NETWORK, LIT_NETWORK, + HTTP, + HTTPS, } from '@lit-protocol/constants'; import { LogManager, Logger } from '@lit-protocol/logger'; import { computeAddress } from 'ethers/lib/utils'; @@ -888,7 +890,8 @@ export class LitContracts { public static getValidators = async ( network: LIT_NETWORKS_KEYS, context?: LitContractContext | LitContractResolverContext, - rpcUrl?: string + rpcUrl?: string, + nodeProtocol?: typeof HTTP | typeof HTTPS | null ): Promise => { const contract = await LitContracts.getStakingContract( network, @@ -941,13 +944,24 @@ export class LitContracts { }); const networks = activeValidatorStructs.map((item: ValidatorStruct) => { - const protocol = HTTP_BY_NETWORK[network]; const centralisation = CENTRALISATION_BY_NETWORK[network]; - const ip = intToIP(item.ip); - const port = item.port; + // Convert the integer IP to a string format + const ip = intToIP(item.ip); + let port = item.port; + + // Determine the protocol to use based on various conditions + const protocol = + // If nodeProtocol is defined, use it + nodeProtocol || + // If port is 443, use HTTPS, otherwise use network-specific HTTP + (port === 443 ? HTTPS : HTTP_BY_NETWORK[network]) || + // Fallback to HTTP if no other conditions are met + HTTP; + + // Check for specific conditions in centralised networks if (centralisation === 'centralised') { - // -- validate if it's cayenne AND port range is 8470 - 8479, if not, throw error + // Validate if it's cayenne AND port range is 8470 - 8479, if not, throw error if ( network === LIT_NETWORK.Cayenne && !port.toString().startsWith('8') diff --git a/packages/core/src/lib/lit-core.ts b/packages/core/src/lib/lit-core.ts index b37f221e71..cfa73bbaad 100644 --- a/packages/core/src/lib/lit-core.ts +++ b/packages/core/src/lib/lit-core.ts @@ -99,7 +99,9 @@ export type LitNodeClientConfigWithDefaults = Required< Pick > & { bootstrapUrls: string[]; - }; + } & { + nodeProtocol?: `http://` | `https://` | null; + } // On epoch change, we wait this many seconds for the nodes to update to the new epoch before using the new epoch # const EPOCH_PROPAGATION_DELAY = 30_000; @@ -131,6 +133,7 @@ export class LitCore { litNetwork: 'cayenne', // Default to cayenne network. will be replaced by custom config. minNodeCount: 2, // Default value, should be replaced bootstrapUrls: [], // Default value, should be replaced + nodeProtocol: null, }; connectedNodes = new Set(); serverKeys: Record = {}; @@ -234,7 +237,8 @@ export class LitCore { LitContracts.getValidators( this.config.litNetwork, this.config.contractContext, - this.config.rpcUrl + this.config.rpcUrl, + this.config.nodeProtocol ), ]); From 1302cd4b654ceb3e9aaa81d584f5a2e4f0fc2d34 Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 23 Jul 2024 16:17:03 +0100 Subject: [PATCH 2/5] fix: lint --- packages/constants/src/lib/constants/constants.ts | 2 +- packages/core/src/lib/lit-core.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/constants/src/lib/constants/constants.ts b/packages/constants/src/lib/constants/constants.ts index 759307a0b9..22f74f7859 100644 --- a/packages/constants/src/lib/constants/constants.ts +++ b/packages/constants/src/lib/constants/constants.ts @@ -804,7 +804,7 @@ export const HTTP_BY_NETWORK: Record< habanero: HTTPS, 'datil-dev': HTTPS, 'datil-test': HTTPS, - internalDev: HTTPS, + internalDev: HTTPS, custom: HTTP, // default, can be changed by config localhost: HTTP, // default, can be changed by config }; diff --git a/packages/core/src/lib/lit-core.ts b/packages/core/src/lib/lit-core.ts index cfa73bbaad..0893ecae1e 100644 --- a/packages/core/src/lib/lit-core.ts +++ b/packages/core/src/lib/lit-core.ts @@ -101,7 +101,7 @@ export type LitNodeClientConfigWithDefaults = Required< bootstrapUrls: string[]; } & { nodeProtocol?: `http://` | `https://` | null; - } + }; // On epoch change, we wait this many seconds for the nodes to update to the new epoch before using the new epoch # const EPOCH_PROPAGATION_DELAY = 30_000; From f97727d505de5a6ae92a7850a78d24016d3ec5ad Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 23 Jul 2024 16:59:31 +0100 Subject: [PATCH 3/5] fix(ci): make CI run whole test suite --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9d05d8cee2..0bf6ab2b94 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,4 +55,4 @@ jobs: run: yarn build:dev - name: Run End to End Tests if: steps.build.outputs.exit_code == 0 - run: yarn test:local --filter=testUseEoaSessionSigsToExecuteJsSigning,testUseEoaSessionSigsToPkpSign,testUsePkpSessionSigsToExecuteJsSigning,testUsePkpSessionSigsToPkpSign,testUseValidLitActionCodeGeneratedSessionSigsToPkpSign,testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning,testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs,testEthAuthSigToEncryptDecryptString,testExecuteJsSignAndCombineEcdsa,testExecutJsDecryptAndCombine,testExecuteJsBroadcastAndCollect --exclude=Parallel + run: yarn test:local From 956efbb7eb1e62f20bae3d91dd0f2cb6216603ef Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 23 Jul 2024 17:11:16 +0100 Subject: [PATCH 4/5] fix(ci): add limited tests back and increase chunk size --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bf6ab2b94..b36cafd8aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,7 @@ jobs: NETWORK: datil-dev DEBUG: true MAX_ATTEMPTS: 3 + CHUNK_SIZE: 9 steps: - name: Checkout repo uses: actions/checkout@v2 @@ -55,4 +56,4 @@ jobs: run: yarn build:dev - name: Run End to End Tests if: steps.build.outputs.exit_code == 0 - run: yarn test:local + run: yarn test:local --filter=testUseEoaSessionSigsToExecuteJsSigning,testUseEoaSessionSigsToPkpSign,testUsePkpSessionSigsToExecuteJsSigning,testUsePkpSessionSigsToPkpSign,testUseValidLitActionCodeGeneratedSessionSigsToPkpSign,testUseValidLitActionCodeGeneratedSessionSigsToExecuteJsSigning,testDelegatingCapacityCreditsNFTToAnotherWalletToExecuteJs,testEthAuthSigToEncryptDecryptString,testExecuteJsSignAndCombineEcdsa,testExecutJsDecryptAndCombine,testExecuteJsBroadcastAndCollect --exclude=Parallel From 3d4f710044a3d985afb91eb65d35fed436a01b15 Mon Sep 17 00:00:00 2001 From: Anson Date: Wed, 24 Jul 2024 12:52:51 +0100 Subject: [PATCH 5/5] fix(comment): https://github.com/LIT-Protocol/js-sdk/pull/554#discussion_r1689609337 --- packages/core/src/lib/lit-core.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/src/lib/lit-core.ts b/packages/core/src/lib/lit-core.ts index 0893ecae1e..c1038f4953 100644 --- a/packages/core/src/lib/lit-core.ts +++ b/packages/core/src/lib/lit-core.ts @@ -24,6 +24,8 @@ import { LitNetwork, StakingStates, version, + HTTP, + HTTPS, } from '@lit-protocol/constants'; import { LitContracts } from '@lit-protocol/contracts-sdk'; import { @@ -100,7 +102,7 @@ export type LitNodeClientConfigWithDefaults = Required< > & { bootstrapUrls: string[]; } & { - nodeProtocol?: `http://` | `https://` | null; + nodeProtocol?: typeof HTTP | typeof HTTPS | null; }; // On epoch change, we wait this many seconds for the nodes to update to the new epoch before using the new epoch #