@audius/sdk 3.0.3-beta.83 → 3.0.3-beta.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/ServiceProvider.d.ts +1 -31
- package/dist/index.cjs.js +69 -872
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +74 -876
- package/dist/index.esm.js.map +1 -1
- package/dist/legacy.js +69 -872
- package/dist/legacy.js.map +1 -1
- package/dist/native-libs.js +1955 -2757
- package/dist/native-libs.js.map +1 -1
- package/dist/services/creatorNode/index.d.ts +0 -1
- package/dist/web-libs.js +69 -872
- package/dist/web-libs.js.map +1 -1
- package/package.json +2 -2
- package/src/api/ServiceProvider.ts +1 -108
- package/src/services/creatorNode/index.ts +0 -1
- package/dist/services/creatorNode/CreatorNodeSelection.d.ts +0 -96
- package/dist/services/creatorNode/CreatorNodeSelection.test.d.ts +0 -1
- package/src/services/creatorNode/CreatorNodeSelection.test.ts +0 -1022
- package/src/services/creatorNode/CreatorNodeSelection.ts +0 -428
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@audius/sdk",
|
|
3
|
-
"version": "3.0.3-beta.
|
|
3
|
+
"version": "3.0.3-beta.84",
|
|
4
4
|
"audius": {
|
|
5
|
-
"releaseSHA": "
|
|
5
|
+
"releaseSHA": "a742c13c166e5def2fca6faf9d40de19f6559e3f"
|
|
6
6
|
},
|
|
7
7
|
"description": "Audius SDK",
|
|
8
8
|
"main": "dist/index.cjs.js",
|
|
@@ -1,41 +1,13 @@
|
|
|
1
1
|
import { sampleSize } from 'lodash'
|
|
2
2
|
|
|
3
3
|
import { Base, BaseConstructorArgs } from './base'
|
|
4
|
-
import { timeRequests } from '../utils/network'
|
|
5
4
|
import { getNStorageNodes } from '../utils/getNStorageNodes'
|
|
6
|
-
import { CreatorNodeSelection } from '../services/creatorNode'
|
|
7
5
|
|
|
8
|
-
import type {
|
|
6
|
+
import type { ServiceWithEndpoint } from '../utils'
|
|
9
7
|
|
|
10
8
|
const CONTENT_NODE_SERVICE_NAME = 'content-node'
|
|
11
9
|
const DISCOVERY_NODE_SERVICE_NAME = 'discovery-node'
|
|
12
10
|
|
|
13
|
-
// Default timeout for each content node's sync and health check
|
|
14
|
-
const CONTENT_NODE_DEFAULT_SELECTION_TIMEOUT = 7500
|
|
15
|
-
// Default time at which responses are considered equal weighting.
|
|
16
|
-
// Content nodes that reply within 200ms of eachother are given equal footing
|
|
17
|
-
// in selection
|
|
18
|
-
const CONTENT_NODE_SELECTION_EQUIVALENCY_DELTA = 200
|
|
19
|
-
|
|
20
|
-
type AutoSelectCreatorNodesConfig = {
|
|
21
|
-
// total number of nodes to fetch (2 secondaries means 3 total)
|
|
22
|
-
numberOfNodes?: number
|
|
23
|
-
// whether or not to include only specified nodes (default no whitelist)
|
|
24
|
-
whitelist?: Nullable<Set<string>>
|
|
25
|
-
// whether or not to exclude any nodes (default no blacklist)
|
|
26
|
-
blacklist?: Nullable<Set<string>>
|
|
27
|
-
// whether or not to perform sync check
|
|
28
|
-
performSyncCheck?: boolean
|
|
29
|
-
// ms applied to each request made to a content node
|
|
30
|
-
timeout?: number
|
|
31
|
-
equivalencyDelta?: number
|
|
32
|
-
preferHigherPatchForPrimary?: boolean
|
|
33
|
-
preferHigherPatchForSecondaries?: boolean
|
|
34
|
-
log?: boolean
|
|
35
|
-
// override going to chain to generate a list of all service endpoints
|
|
36
|
-
getServices?: () => Promise<string[]>
|
|
37
|
-
}
|
|
38
|
-
|
|
39
11
|
/**
|
|
40
12
|
* API methods to interact with Audius service providers.
|
|
41
13
|
* Types of services include:
|
|
@@ -66,85 +38,6 @@ export class ServiceProvider extends Base {
|
|
|
66
38
|
)
|
|
67
39
|
}
|
|
68
40
|
|
|
69
|
-
/**
|
|
70
|
-
* Fetches healthy Content Nodes filtered down to a given whitelist and blacklist
|
|
71
|
-
*/
|
|
72
|
-
async getSelectableCreatorNodes(
|
|
73
|
-
whitelist: Nullable<Set<string>> = null, // whether or not to include only specified nodes (default no whiltelist)
|
|
74
|
-
blacklist: Nullable<Set<string>> = null, // whether or not to exclude any nodes (default no blacklist)
|
|
75
|
-
timeout = CONTENT_NODE_DEFAULT_SELECTION_TIMEOUT
|
|
76
|
-
) {
|
|
77
|
-
let creatorNodes = await this.listCreatorNodes()
|
|
78
|
-
|
|
79
|
-
// Filter whitelist
|
|
80
|
-
if (whitelist) {
|
|
81
|
-
creatorNodes = creatorNodes.filter((node) => whitelist.has(node.endpoint))
|
|
82
|
-
}
|
|
83
|
-
// Filter blacklist
|
|
84
|
-
if (blacklist) {
|
|
85
|
-
creatorNodes = creatorNodes.filter(
|
|
86
|
-
(node) => !blacklist.has(node.endpoint)
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Time requests and get version info
|
|
91
|
-
const timings = await timeRequests({
|
|
92
|
-
requests: creatorNodes.map((node) => ({
|
|
93
|
-
id: node.endpoint,
|
|
94
|
-
url: `${node.endpoint}/health_check/verbose`
|
|
95
|
-
})),
|
|
96
|
-
sortByVersion: true,
|
|
97
|
-
timeout,
|
|
98
|
-
headers: {
|
|
99
|
-
'User-Agent':
|
|
100
|
-
'Axios - @audius/sdk - ServiceProvider.ts#getSelectableCreatorNodes'
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
const services: { [id: string]: any } = {}
|
|
105
|
-
timings.forEach((timing) => {
|
|
106
|
-
if (timing.response && timing.request.id)
|
|
107
|
-
services[timing.request.id] = timing.response.data.data
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
return services
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Fetches healthy Content Nodes and autoselects a primary
|
|
115
|
-
* and two secondaries.
|
|
116
|
-
*/
|
|
117
|
-
async autoSelectCreatorNodes({
|
|
118
|
-
numberOfNodes = 3,
|
|
119
|
-
whitelist = null,
|
|
120
|
-
blacklist = null,
|
|
121
|
-
performSyncCheck = true,
|
|
122
|
-
timeout = CONTENT_NODE_DEFAULT_SELECTION_TIMEOUT,
|
|
123
|
-
equivalencyDelta = CONTENT_NODE_SELECTION_EQUIVALENCY_DELTA,
|
|
124
|
-
preferHigherPatchForPrimary = true,
|
|
125
|
-
preferHigherPatchForSecondaries = true,
|
|
126
|
-
log = true,
|
|
127
|
-
getServices
|
|
128
|
-
}: AutoSelectCreatorNodesConfig) {
|
|
129
|
-
const creatorNodeSelection = new CreatorNodeSelection({
|
|
130
|
-
creatorNode: this.creatorNode,
|
|
131
|
-
ethContracts: this.ethContracts,
|
|
132
|
-
logger: this.logger,
|
|
133
|
-
numberOfNodes,
|
|
134
|
-
whitelist,
|
|
135
|
-
blacklist,
|
|
136
|
-
timeout,
|
|
137
|
-
equivalencyDelta,
|
|
138
|
-
preferHigherPatchForPrimary,
|
|
139
|
-
preferHigherPatchForSecondaries,
|
|
140
|
-
getServices
|
|
141
|
-
})
|
|
142
|
-
|
|
143
|
-
const { primary, secondaries, services } =
|
|
144
|
-
await creatorNodeSelection.select(performSyncCheck, log)
|
|
145
|
-
return { primary, secondaries, services }
|
|
146
|
-
}
|
|
147
|
-
|
|
148
41
|
/**
|
|
149
42
|
* Selects numNodes storage nodes from the list of registered storage nodes on chain, optionally ordering them (descending) by rendezvous score.
|
|
150
43
|
* TODO: This might want to handle blocklist/allowlist, latency checks, health checks, etc... but for now it just uses all nodes.
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { EthContracts } from '../ethContracts';
|
|
2
|
-
import { ServiceSelection, ServiceSelectionConfig } from '../../service-selection';
|
|
3
|
-
import { ServiceName, Timing, Logger } from '../../utils';
|
|
4
|
-
import { DECISION_TREE_STATE } from './constants';
|
|
5
|
-
import type { MonitoringCallbacks } from '../types';
|
|
6
|
-
declare type Timeout = number | null;
|
|
7
|
-
export declare function getSpIDForEndpoint(endpoint: string): number | undefined;
|
|
8
|
-
export declare function setSpIDForEndpoint(endpoint: string, spID?: number): void;
|
|
9
|
-
declare type CreatorNode = {
|
|
10
|
-
passList: Set<string> | null;
|
|
11
|
-
blockList: Set<string> | null;
|
|
12
|
-
monitoringCallbacks: MonitoringCallbacks;
|
|
13
|
-
};
|
|
14
|
-
declare type CreatorNodeSelectionConfig = Omit<ServiceSelectionConfig, 'getServices'> & {
|
|
15
|
-
creatorNode: CreatorNode;
|
|
16
|
-
numberOfNodes: number;
|
|
17
|
-
ethContracts: EthContracts;
|
|
18
|
-
maxStorageUsedPercent?: number;
|
|
19
|
-
timeout?: Timeout;
|
|
20
|
-
equivalencyDelta?: number | null;
|
|
21
|
-
preferHigherPatchForPrimary?: boolean;
|
|
22
|
-
preferHigherPatchForSecondaries?: boolean;
|
|
23
|
-
logger?: Logger;
|
|
24
|
-
getServices?: () => Promise<string[]>;
|
|
25
|
-
};
|
|
26
|
-
interface Decision {
|
|
27
|
-
stage: DECISION_TREE_STATE;
|
|
28
|
-
val?: unknown;
|
|
29
|
-
}
|
|
30
|
-
export declare class CreatorNodeSelection extends ServiceSelection {
|
|
31
|
-
decisionTree: Decision[];
|
|
32
|
-
currentVersion: string | null;
|
|
33
|
-
ethContracts: EthContracts;
|
|
34
|
-
creatorNode: CreatorNode;
|
|
35
|
-
numberOfNodes: number;
|
|
36
|
-
timeout: Timeout;
|
|
37
|
-
equivalencyDelta: number | null;
|
|
38
|
-
preferHigherPatchForPrimary: boolean;
|
|
39
|
-
preferHigherPatchForSecondaries: boolean;
|
|
40
|
-
healthCheckPath: string;
|
|
41
|
-
backupsList: string[];
|
|
42
|
-
backupTimings: Timing[];
|
|
43
|
-
maxStorageUsedPercent: number;
|
|
44
|
-
logger: Logger;
|
|
45
|
-
constructor({ creatorNode, numberOfNodes, ethContracts, whitelist, blacklist, logger, maxStorageUsedPercent, timeout, equivalencyDelta, preferHigherPatchForPrimary, preferHigherPatchForSecondaries, getServices }: CreatorNodeSelectionConfig);
|
|
46
|
-
/**
|
|
47
|
-
* Selects a primary and secondary Content Nodes. Order of preference is highest version, then response time.
|
|
48
|
-
*
|
|
49
|
-
* 1. Retrieve all the Content Node services
|
|
50
|
-
* 2. Filter from/out Content Nodes based off of the whitelist and blacklist
|
|
51
|
-
* 3. Filter out unhealthy, outdated, and still syncing nodes via health and sync check
|
|
52
|
-
* 4. Sort by healthiest (highest version -> lowest version); secondary check if equal version based off of responseTime
|
|
53
|
-
* 5. Select a primary and numberOfNodes-1 number of secondaries (most likely 2) from backups
|
|
54
|
-
* @param @deprecated performSyncCheck (deprecated / unused) whether or not to check whether the nodes need syncs before selection
|
|
55
|
-
*/
|
|
56
|
-
select(_performSyncCheck?: boolean, log?: boolean): Promise<{
|
|
57
|
-
primary: string;
|
|
58
|
-
secondaries: string[];
|
|
59
|
-
services: Record<string, any>;
|
|
60
|
-
}>;
|
|
61
|
-
/**
|
|
62
|
-
* Sets backupsList to input
|
|
63
|
-
* @param backupsList string array of Content Node endpoints
|
|
64
|
-
*/
|
|
65
|
-
setBackupsList(backupsList: ServiceName[], backupTimings: Timing[]): void;
|
|
66
|
-
/**
|
|
67
|
-
* Get backups in the form of an array
|
|
68
|
-
*/
|
|
69
|
-
getBackupsList(): string[];
|
|
70
|
-
/**
|
|
71
|
-
* Get backup timings in the form of an array
|
|
72
|
-
*/
|
|
73
|
-
getBackupTimings(): Timing[];
|
|
74
|
-
/**
|
|
75
|
-
* Select a primary Content Node
|
|
76
|
-
* @param {string[]} services all healthy Content Node endpoints
|
|
77
|
-
*/
|
|
78
|
-
getPrimary(services: string[]): string;
|
|
79
|
-
/**
|
|
80
|
-
* Selects secondary Content Nodes
|
|
81
|
-
* Returns first nodes from `services`, optionally sorted by version
|
|
82
|
-
*/
|
|
83
|
-
getSecondaries(): string[];
|
|
84
|
-
/**
|
|
85
|
-
* Performs a health check for every endpoint in services. Returns an array of successful health checked endpoints and
|
|
86
|
-
* adds the err'd health checked endpoints to this.unhealthy, and a mapping of successful endpoint to its health check response.
|
|
87
|
-
* @param services content node endpoints
|
|
88
|
-
*/
|
|
89
|
-
_performHealthChecks(services: string[]): Promise<{
|
|
90
|
-
healthyServicesList: string[];
|
|
91
|
-
healthyServicesMap: Record<string, any>;
|
|
92
|
-
healthyServiceTimings: Timing[];
|
|
93
|
-
}>;
|
|
94
|
-
_hasEnoughStorageSpace(storagePathSize?: number | null, storagePathUsed?: number | null): boolean;
|
|
95
|
-
}
|
|
96
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|