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/clonenet #724

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
fmt
  • Loading branch information
Ansonhkg committed Dec 10, 2024
commit 5d791be5b491963586917ed9d13e276ef90f1d90
8 changes: 4 additions & 4 deletions local-tests/setup/tinny-environment.ts
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ export class TinnyEnvironment {
DEBUG: process.env['DEBUG'] === 'true',
REQUEST_PER_KILOSECOND:
parseInt(process.env['REQUEST_PER_KILOSECOND']) ||
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
(process.env['NETWORK'] as LIT_NETWORK_VALUES) === 'datil-dev'
? 1
: 200,
LIT_RPC_URL: process.env['LIT_RPC_URL'],
@@ -247,7 +247,7 @@ export class TinnyEnvironment {
checkNodeAttestation: false, // disable node attestation check for local testing
contractContext: networkContext,
...(this.processEnvs.NETWORK_TYPE !== 'random' && {
networkType: this.processEnvs.NETWORK_TYPE || 'mainnet'
networkType: this.processEnvs.NETWORK_TYPE || 'mainnet',
}),
});
} else if (centralisation === 'decentralised') {
@@ -256,7 +256,7 @@ export class TinnyEnvironment {
checkNodeAttestation: true,
debug: this.processEnvs.DEBUG,
...(this.processEnvs.NETWORK_TYPE !== 'random' && {
networkType: this.processEnvs.NETWORK_TYPE || 'mainnet'
networkType: this.processEnvs.NETWORK_TYPE || 'mainnet',
}),
});
} else if (centralisation === 'centralised') {
@@ -265,7 +265,7 @@ export class TinnyEnvironment {
checkNodeAttestation: false,
debug: this.processEnvs.DEBUG,
...(this.processEnvs.NETWORK_TYPE !== 'random' && {
networkType: this.processEnvs.NETWORK_TYPE || 'mainnet'
networkType: this.processEnvs.NETWORK_TYPE || 'mainnet',
}),
});
} else {
4 changes: 1 addition & 3 deletions packages/access-control-conditions/package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,5 @@
"tags": [
"universal"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/auth-browser/package.json
Original file line number Diff line number Diff line change
@@ -30,7 +30,5 @@
"tags": [
"browser"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/auth-helpers/package.json
Original file line number Diff line number Diff line change
@@ -25,7 +25,5 @@
"crypto": false,
"stream": false
},
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/constants/package.json
Original file line number Diff line number Diff line change
@@ -20,7 +20,5 @@
"tags": [
"universal"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/contracts-sdk/package.json
Original file line number Diff line number Diff line change
@@ -25,7 +25,5 @@
"tags": [
"universal"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
26 changes: 18 additions & 8 deletions packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
@@ -622,7 +622,7 @@ export class LitContracts {

/**
* Retrieves a contract instance based on the provided network, contract name, context, and RPC URL.
*
*
* This method handles three scenarios:
* 1. No context provided - Resolves contract data from network context
* 2. Context without resolver - Uses contract data directly from context
@@ -1081,10 +1081,14 @@ export class LitContracts {
rpcUrl
);

const allThings = await cloneNetContract['getAllActiveUnkickedValidatorStructsAndCounts']();
const allThings = await cloneNetContract[
'getAllActiveUnkickedValidatorStructsAndCounts'
]();

// First get all the active staking contract addresses.
const activeStakingContractAddresses = allThings.map((item: any) => item[0]);
const activeStakingContractAddresses = allThings.map(
(item: any) => item[0]
);

if (activeStakingContractAddresses.length < 2) {
throw new Error('❌ Not enough active staking contracts');
@@ -1096,10 +1100,13 @@ export class LitContracts {
for (let i = 0; i < activeStakingContractAddresses.length; i++) {
const stakingContractAddress = activeStakingContractAddresses[i];

const contractInfo = allThings.find((item: any) => item.stakingContractAddress === stakingContractAddress);
const contractInfo = allThings.find(
(item: any) => item.stakingContractAddress === stakingContractAddress
);

const epochInfo = contractInfo.details.epoch;
const minNodeCount = contractInfo.details.currentValidatorCountForConsensus;
const minNodeCount =
contractInfo.details.currentValidatorCountForConsensus;

const typedEpochInfo: EpochInfo = {
epochLength: ethers.BigNumber.from(epochInfo.epochLength).toNumber(),
@@ -1115,7 +1122,9 @@ export class LitContracts {
throw new Error('❌ Minimum validator count is not set');
}

if (contractInfo.details.activeUnkickedValidators.length < minNodeCountInt) {
if (
contractInfo.details.activeUnkickedValidators.length < minNodeCountInt
) {
throw new Error(
`❌ Active validator set does not meet the threshold. Required: ${minNodeCountInt} but got: ${contractInfo.details.activeUnkickedValidators.length}`
);
@@ -1209,11 +1218,12 @@ export class LitContracts {

// Randomly select network type if not specified
if (!networkType) {
networkType = Math.floor(Math.random() * 100) % 2 === 0 ? 'mainnet' : 'cloneNet';
networkType =
Math.floor(Math.random() * 100) % 2 === 0 ? 'mainnet' : 'cloneNet';
log('Randomly selected network type:', networkType);
}

log("Selected network type:", networkType);
log('Selected network type:', networkType);

// Return info based on network type
if (networkType === 'mainnet') {
4 changes: 1 addition & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -24,7 +24,5 @@
},
"tags": [
"universal"
],
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
]
}
33 changes: 16 additions & 17 deletions packages/core/src/lib/lit-core.ts
Original file line number Diff line number Diff line change
@@ -256,7 +256,6 @@ export class LitCore {
minNodeCount: number;
bootstrapUrls: string[];
}> {

const stakingContract = await LitContracts.getContractInstance(
this.config.litNetwork,
'Staking',
@@ -305,21 +304,21 @@ export class LitCore {
}

private _getNetworkType = (): 'mainnet' | 'cloneNet' => {
const networkType = this.config.networkType
|| Math.floor(Math.random() * 100) % 2 === 0 ? 'mainnet' : 'cloneNet';
const networkType =
this.config.networkType || Math.floor(Math.random() * 100) % 2 === 0
? 'mainnet'
: 'cloneNet';

return networkType;
}
};

// ========== Scoped Class Helpers ==========
private async _handleStakingContractStateChange(
state: STAKING_STATES_VALUES
) {
log(`New state detected: "${state}"`);

const validatorData = await this._getValidatorData(
this._getNetworkType(),
);
const validatorData = await this._getValidatorData(this._getNetworkType());

if (state === STAKING_STATES.Active) {
// We always want to track the most recent epoch number on _all_ networks
@@ -541,9 +540,7 @@ export class LitCore {

// Re-use staking contract instance from previous connect() executions that succeeded to improve performance
// noinspection ES6MissingAwait - intentionally not `awaiting` so we can run this in parallel below
const validatorData = await this._getValidatorData(
this._getNetworkType(),
);
const validatorData = await this._getValidatorData(this._getNetworkType());

this._stakingContract = validatorData.stakingContract;
this.config.minNodeCount = validatorData.minNodeCount;
@@ -695,9 +692,11 @@ export class LitCore {
await Promise.race([
new Promise((_resolve, reject) => {
timeoutHandle = setTimeout(() => {
const msg = `Error: Could not handshake with nodes after timeout of ${this.config.connectTimeout
}ms. Could only connect to ${Object.keys(serverKeys).length} of ${this.config.bootstrapUrls.length
} 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 handshake with nodes after timeout of ${
this.config.connectTimeout
}ms. Could only connect to ${Object.keys(serverKeys).length} of ${
this.config.bootstrapUrls.length
} nodes. Please check your network connection and try again. Note that you can control this timeout with the connectTimeout config option which takes milliseconds.`;

try {
throw new InitError({}, msg);
@@ -975,7 +974,7 @@ export class LitCore {
);
try {
const validatorData = await this._getValidatorData(
this._getNetworkType(),
this._getNetworkType()
);
epochInfo = validatorData.epochInfo;
} catch (error) {
@@ -1005,8 +1004,8 @@ export class LitCore {
this._epochCache.currentNumber &&
this._epochCache.startTime &&
Math.floor(Date.now() / 1000) <
this._epochCache.startTime +
Math.floor(EPOCH_PROPAGATION_DELAY / 1000) &&
this._epochCache.startTime +
Math.floor(EPOCH_PROPAGATION_DELAY / 1000) &&
this._epochCache.currentNumber >= 3 // FIXME: Why this check?
) {
return this._epochCache.currentNumber - 1;
@@ -1037,7 +1036,7 @@ export class LitCore {
data,
requestId,
}: // eslint-disable-next-line @typescript-eslint/no-explicit-any
SendNodeCommand): Promise<any> => {
SendNodeCommand): Promise<any> => {
// FIXME: Replace <any> usage with explicit, strongly typed handlers
data = { ...data, epoch: this.currentEpochNumber };

4 changes: 1 addition & 3 deletions packages/crypto/package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,5 @@
"tags": [
"universal"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/encryption/package.json
Original file line number Diff line number Diff line change
@@ -25,7 +25,5 @@
"crypto": false,
"stream": false
},
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/lit-auth-client/package.json
Original file line number Diff line number Diff line change
@@ -28,7 +28,5 @@
"peerDependencies": {
"@simplewebauthn/browser": "^7.2.0",
"@simplewebauthn/typescript-types": "^7.0.0"
},
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
4 changes: 1 addition & 3 deletions packages/lit-node-client-nodejs/package.json
Original file line number Diff line number Diff line change
@@ -24,7 +24,5 @@
"tags": [
"nodejs"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/lit-node-client/package.json
Original file line number Diff line number Diff line change
@@ -28,7 +28,5 @@
"crypto": false,
"stream": false
},
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,5 @@
"publishConfig": {
"access": "public",
"directory": "../../dist/packages/logger"
},
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
}
}
4 changes: 1 addition & 3 deletions packages/misc-browser/package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,5 @@
"tags": [
"browser"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/misc/package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,5 @@
"tags": [
"universal"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/nacl/package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,5 @@
"access": "public",
"directory": "../../dist/packages/nacl"
},
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/pkp-base/package.json
Original file line number Diff line number Diff line change
@@ -24,7 +24,5 @@
},
"tags": [
"universal"
],
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
]
}
4 changes: 1 addition & 3 deletions packages/pkp-cosmos/package.json
Original file line number Diff line number Diff line change
@@ -24,7 +24,5 @@
},
"tags": [
"universal"
],
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
]
}
4 changes: 1 addition & 3 deletions packages/pkp-ethers/package.json
Original file line number Diff line number Diff line change
@@ -20,7 +20,5 @@
"tags": [
"universal"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/pkp-sui/package.json
Original file line number Diff line number Diff line change
@@ -24,7 +24,5 @@
},
"tags": [
"universal"
],
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
]
}
4 changes: 1 addition & 3 deletions packages/pkp-walletconnect/package.json
Original file line number Diff line number Diff line change
@@ -31,7 +31,5 @@
},
"tags": [
"universal"
],
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
]
}
4 changes: 1 addition & 3 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -23,7 +23,5 @@
"buildOptions": {
"genReact": false
},
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
4 changes: 1 addition & 3 deletions packages/uint8arrays/package.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,5 @@
"tags": [
"universal"
],
"version": "7.0.0",
"main": "./dist/src/index.js",
"typings": "./dist/src/index.d.ts"
"version": "7.0.0"
}
Loading