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

Feat/lit 1815 pull dynamic node urls #272

Merged
merged 260 commits into from
Nov 29, 2023

Conversation

joshLong145
Copy link

@joshLong145 joshLong145 commented Nov 28, 2023

Usage

  • yarn gen:internal-dev

note: the above command is added to the yarn build pipeline

To review

Scripts

Output

Integrations

Additionally

Test

  1. Run yarn build
  2. Run yarn test:e2e:node --filter=test-connection-internal-dev
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://199.115.117.113:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://199.115.117.113:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://199.115.117.114:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://199.115.117.114:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://108.62.0.105:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://108.62.0.105:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://64.131.85.106:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://64.131.85.106:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://64.131.85.108:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://64.131.85.108:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://167.114.17.201:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://167.114.17.201:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://167.114.17.202:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://167.114.17.202:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://167.114.17.203:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://167.114.17.203:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://167.114.17.204:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://167.114.17.204:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] handshakeWithSgx http://167.114.17.205:443/web/handshake
[Lit-JS-SDK v3.0.16] sendCommandToNode with url http://167.114.17.205:443/web/handshake and data { clientPublicKey: 'test' }
[Lit-JS-SDK v3.0.16] ✅ [BLS SDK] wasmExports loaded. 12 functions available. Run 'wasmExports' in the console to see them.
[Lit-JS-SDK v3.0.16] ✅ [ECDSA SDK NodeJS] wasmECDSA loaded. 6 functions available. Run 'wasmECDSA' in the console to see them.
Something went wrong, internal id for request: lit_c043c891323d1. Please provide this identifier with any support requests. Error is request to http://199.115.117.113:443/web/handshake failed, reason: socket hang up - undefined
[Lit-JS-SDK v3.0.16] Error connecting to node  http://199.115.117.113:443 FetchError: request to http://199.115.117.113:443/web/handshake failed, reason: socket hang up

Implementations

Implementation for calculating the validator set which takes the current active set and removes kicked validators

public static getValidators = async (network: "cayenne" | "internalDev"): Promise<string[]> => {

    const contract = await LitContracts.getStakingContract(network);

    // Fetch contract data
    const [activeValidators, currentValidatorsCount, kickedValidators] =
      await Promise.all([
        contract['getValidatorsStructsInCurrentEpoch'](),
        contract['currentValidatorCountForConsensus'](),
        contract['getKickedValidators'](),
      ]);

    const validators = [];

    // Check if active validator set meets the threshold
    if (
      activeValidators.length - kickedValidators.length >=
      currentValidatorsCount
    ) {
      // Process each validator
      for (const validator of activeValidators) {
        validators.push(validator);
      }
    } else {
      console.log('❌ Active validator set does not meet the threshold');
    }

    // remove kicked validators in active validators
    const cleanedActiveValidators = activeValidators.filter(
      (av: any) => !kickedValidators.some((kv: any) => kv.nodeAddress === av.nodeAddress)
    );

    const networks = cleanedActiveValidators.map((item: any) => {
      let proto = "https://";
      if (item.port !== 443) {
        proto = "http://";
      }
      return `${proto}${intToIP(item.ip)}:${item.port}`;
    });

    return networks;
  };

We calc the threshold or minNodeCount with the implementation below:


  public static getMinNodeCount = async (network: "cayenne" | "internalDev") => {

    const contract = await LitContracts.getStakingContract(network);

    const configs = await contract['config']();
    const minNodeCount = configs.minimumValidatorCount.toString();

    if (!minNodeCount) {
      throw new Error('❌ Minimum validator count is not set');
    }
    return minNodeCount;
  }

After connection we listen to StateChanged events on the Staking contract to reload network urls / threshold

Josh Long and others added 13 commits November 25, 2023 15:22
* it all works, yay

* gen contracts

* fix up tests

* remove unused thing

* add checkNodeAttestation boolean config option

* better attestation

* remove custom code to test on internaldev

* check ip and port against report

* check ip and port against attestation report

* remove unused params

* moving to get certs in js

* i built stuff

* it works

* fully working in nodejs and also browser

* fix valid cert test

* sync package version

* push readme changes

* add back attestation checking from bad merge

* add default for cayenne for attestation check

* add explicit attestation check disable in e2e tests

* fmt

---------

Co-authored-by: Josh Long <josh@litprotocol.com>
@CLAassistant
Copy link

CLAassistant commented Nov 28, 2023

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
5 out of 7 committers have signed the CLA.

✅ joshLong145
✅ Ansonhkg
✅ glitch003
✅ ericlewis
✅ vmc-crossmint
❌ VoR0220
❌ Adarsh-Kumar28
You have signed the CLA already but the status is still pending? Let us recheck it.

@joshLong145 joshLong145 marked this pull request as draft November 28, 2023 23:37
glitch003
glitch003 previously approved these changes Nov 29, 2023
Copy link
Collaborator

@glitch003 glitch003 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good to me! will try to get manzano up to test with, too

@joshLong145 joshLong145 merged commit 071873b into master Nov 29, 2023
1 of 2 checks passed
@joshLong145 joshLong145 deleted the feat/lit-1815-pull-dynamic-node-urls branch November 29, 2023 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.