Skip to content

Commit f2aab9d

Browse files
feat(lit-node-client): LIT-4207 - Remove node price tracking state from LitCore/LitNodeClient; use price-feed-info-manager instead
- Removed `nodePrices` array from `LitCore` config state; this would be redundant since we cache price feed info in the manager module now - Update `getMaxPricesForNodeProduct()` on `LitNodeClient` to be an async method, since it will sometimes fetch new prices - CHORE: Removed unused access control method imports from `lit-node-client-nodejs.ts` - CHORE: Removed duplicate `export * from...` in constants/index.ts - Added private `_getNodePrices()` method to LitNodeClient that calls the new `price-feed-info-manager` method w/ args from the current client config
1 parent d5ecfda commit f2aab9d

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

packages/constants/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export * from './lib/version';
55
export * from './lib/constants/constants';
66
export * from './lib/constants/mappers';
77
export * from './lib/constants/endpoints';
8-
export * from './lib/constants/mappers';
98
export * from './lib/constants/curves';
109

1110
// ----------- Interfaces -----------

packages/core/src/lib/lit-core.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ export type LitNodeClientConfigWithDefaults = Required<
115115
bootstrapUrls: string[];
116116
} & {
117117
nodeProtocol?: typeof HTTP | typeof HTTPS | null;
118-
} & {
119-
nodePrices: { url: string; prices: bigint[] }[]; // eg. <nodeAddress, price[]>
120118
};
121119

122120
export class LitCore {
@@ -129,7 +127,6 @@ export class LitCore {
129127
minNodeCount: 2, // Default value, should be replaced
130128
bootstrapUrls: [], // Default value, should be replaced
131129
nodeProtocol: null,
132-
nodePrices: [],
133130
};
134131
connectedNodes = new Set<string>();
135132
serverKeys: Record<string, JsonHandshakeResponse> = {};
@@ -504,7 +501,6 @@ export class LitCore {
504501
this._stakingContract = validatorData.stakingContract;
505502
this.config.minNodeCount = validatorData.minNodeCount;
506503
this.config.bootstrapUrls = validatorData.bootstrapUrls;
507-
this.config.nodePrices = validatorData.nodePrices;
508504

509505
this._epochState = await this._fetchCurrentEpochState(
510506
validatorData.epochInfo

packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { computeAddress } from '@ethersproject/transactions';
22
import { ethers } from 'ethers';
33
import { SiweMessage } from 'siwe';
44

5+
import {
6+
getFormattedAccessControlConditions,
7+
getHashedAccessControlConditions,
8+
validateAccessControlConditions,
9+
} from '@lit-protocol/access-control-conditions';
510
import {
611
createSiweMessage,
712
createSiweMessageWithCapacityDelegation,
@@ -34,6 +39,7 @@ import {
3439
UnsupportedMethodError,
3540
WalletSignatureNotFoundError,
3641
} from '@lit-protocol/constants';
42+
import { getNodePrices } from '@lit-protocol/contracts-sdk';
3743
import { composeLitUrl, LitCore } from '@lit-protocol/core';
3844
import {
3945
combineSignatureShares,
@@ -107,16 +113,17 @@ import {
107113
SigResponse,
108114
SuccessNodePromises,
109115
} from '@lit-protocol/types';
116+
import { AuthMethod } from '@lit-protocol/types';
110117
import {
111118
uint8arrayFromString,
112119
uint8arrayToString,
113120
} from '@lit-protocol/uint8arrays';
114121

115-
import { AuthMethod } from '@lit-protocol/types';
116122
import { encodeCode } from './helpers/encode-code';
117123
import { getBlsSignatures } from './helpers/get-bls-signatures';
118124
import { getClaims } from './helpers/get-claims';
119125
import { getClaimsList } from './helpers/get-claims-list';
126+
import { getExpiration } from './helpers/get-expiration';
120127
import { getMaxPricesForNodeProduct } from './helpers/get-max-prices-for-node-product';
121128
import { getSignatures } from './helpers/get-signatures';
122129
import { normalizeArray } from './helpers/normalize-array';
@@ -126,12 +133,6 @@ import { parsePkpSignResponse } from './helpers/parse-pkp-sign-response';
126133
import { processLitActionResponseStrategy } from './helpers/process-lit-action-response-strategy';
127134
import { removeDoubleQuotes } from './helpers/remove-double-quotes';
128135
import { blsSessionSigVerify } from './helpers/validate-bls-session-sig';
129-
import {
130-
getFormattedAccessControlConditions,
131-
getHashedAccessControlConditions,
132-
validateAccessControlConditions,
133-
} from '@lit-protocol/access-control-conditions';
134-
import { getExpiration } from './helpers/get-expiration';
135136

136137
export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
137138
/** Tracks the total max price a user is willing to pay for each supported product type
@@ -164,6 +165,15 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
164165
this.defaultMaxPriceByProduct[product] = price;
165166
}
166167

168+
private _getNodePrices() {
169+
return getNodePrices({
170+
realmId: 1,
171+
litNetwork: this.config.litNetwork,
172+
networkContext: this.config.contractContext,
173+
rpcUrl: this.config.rpcUrl,
174+
nodeProtocol: this.config.nodeProtocol,
175+
});
176+
}
167177
// ========== Rate Limit NFT ==========
168178

169179
// TODO: Add support for browser feature/lit-2321-js-sdk-add-browser-support-for-createCapacityDelegationAuthSig
@@ -673,7 +683,7 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
673683

674684
const requestId = this._getNewRequestId();
675685

676-
const userMaxPrices = this.getMaxPricesForNodeProduct({
686+
const userMaxPrices = await this.getMaxPricesForNodeProduct({
677687
product: 'LIT_ACTION',
678688
userMaxPrice: params.userMaxPrice,
679689
});
@@ -866,7 +876,7 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
866876

867877
const requestId = this._getNewRequestId();
868878

869-
const targetNodePrices = this.getMaxPricesForNodeProduct({
879+
const targetNodePrices = await this.getMaxPricesForNodeProduct({
870880
product: 'SIGN',
871881
userMaxPrice: params.userMaxPrice,
872882
});
@@ -1154,7 +1164,7 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
11541164
log('identityParam', identityParam);
11551165

11561166
let sessionSigs: SessionSigsMap = {};
1157-
const userMaxPrices = this.getMaxPricesForNodeProduct({
1167+
const userMaxPrices = await this.getMaxPricesForNodeProduct({
11581168
product: 'DECRYPTION',
11591169
userMaxPrice: params.userMaxPrice,
11601170
});
@@ -1343,7 +1353,7 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
13431353

13441354
// This may seem a bit weird because we usually only care about prices for sessionSigs...
13451355
// But this also ensures we use the cheapest nodes and takes care of getting the minNodeCount of node URLs for the operation
1346-
const targetNodePrices = this.getMaxPricesForNodeProduct({
1356+
const targetNodePrices = await this.getMaxPricesForNodeProduct({
13471357
product: 'LIT_ACTION',
13481358
});
13491359

@@ -1536,7 +1546,7 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
15361546
});
15371547
};
15381548

1539-
getMaxPricesForNodeProduct = ({
1549+
getMaxPricesForNodeProduct = async ({
15401550
userMaxPrice,
15411551
product,
15421552
}: {
@@ -1564,7 +1574,7 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
15641574

15651575
console.log('getMaxPricesForNodeProduct():', {});
15661576
return getMaxPricesForNodeProduct({
1567-
nodePrices: this.config.nodePrices,
1577+
nodePrices: await this._getNodePrices(),
15681578
userMaxPrice: getUserMaxPrice(),
15691579
productId: PRODUCT_IDS[product],
15701580
numRequiredNodes: this._getThreshold(),
@@ -1914,7 +1924,7 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
19141924

19151925
// This may seem a bit weird because we usually only care about prices for sessionSigs...
19161926
// But this also ensures we use the cheapest nodes and takes care of getting the minNodeCount of node URLs for the operation
1917-
const targetNodePrices = this.getMaxPricesForNodeProduct({
1927+
const targetNodePrices = await this.getMaxPricesForNodeProduct({
19181928
product: 'LIT_ACTION',
19191929
});
19201930

packages/types/src/lib/ILitNodeClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { PRODUCT_IDS } from '@lit-protocol/constants';
2+
13
import {
24
AuthenticationContext,
35
CapacityCreditsReq,
@@ -14,8 +16,6 @@ import {
1416
LitNodeClientConfig,
1517
SigResponse,
1618
} from './interfaces';
17-
18-
import { PRODUCT_IDS } from '@lit-protocol/constants';
1919
import { ClaimProcessor, ClaimRequest } from './types';
2020

2121
export interface ILitNodeClient {
@@ -58,7 +58,7 @@ export interface ILitNodeClient {
5858
getMaxPricesForNodeProduct(params: {
5959
userMaxPrice?: bigint;
6060
product: keyof typeof PRODUCT_IDS;
61-
}): { url: string; price: bigint }[];
61+
}): Promise<{ url: string; price: bigint }[]>;
6262

6363
/**
6464
* Create capacity delegation authentication signature

0 commit comments

Comments
 (0)