Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set minNodeCount to all active nodes #289

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -659,7 +659,7 @@ export class LitContracts {
// Fetch contract data
const [activeValidators, currentValidatorsCount, kickedValidators] =
await Promise.all([
contract['getValidatorsStructsInCurrentEpoch'](),
contract['getValidatorsInCurrentEpoch'](),
contract['currentValidatorCountForConsensus'](),
contract['getKickedValidators'](),
]);
Expand All @@ -684,10 +684,12 @@ export class LitContracts {
// remove kicked validators in active validators
const cleanedActiveValidators = activeValidators.filter(
(av: any) =>
!kickedValidators.some((kv: any) => kv.nodeAddress === av.nodeAddress)
!kickedValidators.some((kv: any) => kv === av)
);

const networks = cleanedActiveValidators.map((item: any) => {
const activeValidatorStructs = await contract['getValidatorsStructs'](cleanedActiveValidators);

const networks = activeValidatorStructs.map((item: any) => {
let proto = 'https://';
if (item.port !== 443) {
proto = 'http://';
Expand Down
30 changes: 11 additions & 19 deletions packages/core/src/lib/lit-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,11 @@ 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({
Expand All @@ -178,15 +177,12 @@ export class LitCore {
});
}

this.config.minNodeCount = parseInt(minNodeCount, 10);
this.config.minNodeCount = minNodeCount;
} 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 == 2
? 2
: (LIT_NETWORKS.cayenne.length * 2) / 3;
this.config.minNodeCount = LIT_NETWORKS.cayenne.length;
}
};

Expand Down Expand Up @@ -407,13 +403,10 @@ 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);
}
Expand Down Expand Up @@ -532,10 +525,9 @@ 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);
Expand Down
Loading