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

connect to all nodes, fix kicked nodes filtering #291

Merged
merged 2 commits 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
7 changes: 4 additions & 3 deletions e2e-nodejs/group-lit-actions/test-lit-action-2-sigs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export async function main() {
const res = await client.executeJs({
authSig: globalThis.LitCI.CONTROLLER_AUTHSIG,
code: `(async () => {
console.log('hello world')

async function signMultipleSigs(numSigs, toSign, publicKey) {
const sigShares = [];
for(let i = 0; i < numSigs; i++) {
const DATA_TO_SIGN = new Uint8Array(
await crypto.subtle.digest('SHA-256', new TextEncoder().encode('Hello world' + i))
);
const sigShare = await LitActions.signEcdsa({
toSign,
toSign: DATA_TO_SIGN,
publicKey,
sigName: "sig" + i,
});
Expand Down
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
20 changes: 8 additions & 12 deletions packages/core/src/lib/lit-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ export class LitCore {
const promise = new Promise((resolve: any, reject: any) => {
const startTime = Date.now();
const interval = setInterval(() => {
if (Object.keys(this.serverKeys).length >= this.config.minNodeCount) {
if (Object.keys(this.serverKeys).length == this.config.bootstrapUrls.length) {
clearInterval(interval);

// pick the most common public keys for the subnet and network from the bunch, in case some evil node returned a bad key
Expand Down Expand Up @@ -407,13 +407,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 +529,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