Skip to content

Commit

Permalink
connect to all nodes, fix kicked nodes filtering (#291)
Browse files Browse the repository at this point in the history
* connect to all nodes, fix kicked nodes filtering

* fix 2-sigs test

---------

Co-authored-by: Josh Long <josh@litprotocol.com>
  • Loading branch information
glitch003 and Josh Long committed Dec 20, 2023
1 parent 4ffeecd commit 77e2431
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 0 additions & 2 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,8 +13,6 @@ 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++) {
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 @@ -357,7 +357,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 @@ -413,13 +413,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 @@ -538,10 +535,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

0 comments on commit 77e2431

Please sign in to comment.