diff --git a/packages/contracts-sdk/src/lib/contracts-sdk.ts b/packages/contracts-sdk/src/lib/contracts-sdk.ts index d758c2aba6..b37c24f4f6 100644 --- a/packages/contracts-sdk/src/lib/contracts-sdk.ts +++ b/packages/contracts-sdk/src/lib/contracts-sdk.ts @@ -7,7 +7,7 @@ import { AuthMethod } from '@lit-protocol/types'; let CID: any; try { CID = require('multiformats/cid'); -} catch (e) { } +} catch (e) {} // ----- autogen:import-data:start ----- // Generated at 2023-11-07T01:50:52.460Z @@ -659,7 +659,7 @@ export class LitContracts { // Fetch contract data const [activeValidators, currentValidatorsCount, kickedValidators] = await Promise.all([ - contract['getValidatorsInCurrentEpoch'](), + contract['getValidatorsStructsInCurrentEpoch'](), contract['currentValidatorCountForConsensus'](), contract['getKickedValidators'](), ]); @@ -684,12 +684,10 @@ export class LitContracts { // remove kicked validators in active validators const cleanedActiveValidators = activeValidators.filter( (av: any) => - !kickedValidators.some((kv: any) => kv === av) + !kickedValidators.some((kv: any) => kv.nodeAddress === av.nodeAddress) ); - const activeValidatorStructs = await contract['getValidatorsStructs'](cleanedActiveValidators); - - const networks = activeValidatorStructs.map((item: any) => { + const networks = cleanedActiveValidators.map((item: any) => { let proto = 'https://'; if (item.port !== 443) { proto = 'http://'; diff --git a/packages/core/src/lib/lit-core.ts b/packages/core/src/lib/lit-core.ts index fb35b487f6..0f889ab14e 100644 --- a/packages/core/src/lib/lit-core.ts +++ b/packages/core/src/lib/lit-core.ts @@ -155,11 +155,12 @@ export class LitCore { this.config.litNetwork !== LitNetwork.Cayenne && this.config.litNetwork !== LitNetwork.Custom ) { - + const minNodeCount = await LitContracts.getMinNodeCount( + this.config.litNetwork as LitNetwork + ); const bootstrapUrls = await LitContracts.getValidators( this.config.litNetwork as LitNetwork ); - const minNodeCount = bootstrapUrls.length; log('Bootstrap urls: ', bootstrapUrls); if (minNodeCount <= 0) { throwError({ @@ -177,12 +178,15 @@ export class LitCore { }); } - this.config.minNodeCount = minNodeCount; + this.config.minNodeCount = parseInt(minNodeCount, 10); } else if (this.config.litNetwork === LitNetwork.Cayenne) { // If the network is cayenne it is a centralized testnet so we use a static config // This is due to staking contracts holding local ip / port contexts which are innacurate to the ip / port exposed to the world this.config.bootstrapUrls = LIT_NETWORKS.cayenne; - this.config.minNodeCount = LIT_NETWORKS.cayenne.length; + this.config.minNodeCount = + LIT_NETWORKS.cayenne.length == 2 + ? 2 + : (LIT_NETWORKS.cayenne.length * 2) / 3; } }; @@ -403,10 +407,13 @@ export class LitCore { const now = Date.now(); if (now - startTime > this.config.connectTimeout) { clearInterval(interval); - const msg = `Error: Could not connect to enough nodes after timeout of ${this.config.connectTimeout - }ms. Could only connect to ${Object.keys(this.serverKeys).length - } of ${this.config.minNodeCount - } required nodes. Please check your network connection and try again. Note that you can control this timeout with the connectTimeout config option which takes milliseconds.`; + const msg = `Error: Could not connect to enough nodes after timeout of ${ + this.config.connectTimeout + }ms. Could only connect to ${ + Object.keys(this.serverKeys).length + } of ${ + this.config.minNodeCount + } required nodes. Please check your network connection and try again. Note that you can control this timeout with the connectTimeout config option which takes milliseconds.`; logErrorWithRequestId(requestId, msg); reject(msg); } @@ -525,9 +532,10 @@ export class LitCore { .catch((error: NodeErrorV3) => { logErrorWithRequestId( requestId, - `Something went wrong, internal id for request: lit_${requestId}. Please provide this identifier with any support requests. ${error?.message || error?.details - ? `Error is ${error.message} - ${error.details}` - : '' + `Something went wrong, internal id for request: lit_${requestId}. Please provide this identifier with any support requests. ${ + error?.message || error?.details + ? `Error is ${error.message} - ${error.details}` + : '' }` ); return Promise.reject(error);