@streamr/node 100.0.0-rc.0
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/LICENSE +78 -0
- package/README.md +54 -0
- package/bin/broker.ts +36 -0
- package/bin/config-wizard.js +4 -0
- package/bin/config-wizard.ts +17 -0
- package/bin/delete-expired-data.ts +41 -0
- package/bin/entry-point.ts +27 -0
- package/configs/development-1.env.json +68 -0
- package/configs/development-2.env.json +53 -0
- package/configs/development-3.env.json +53 -0
- package/configs/development-prod-resend.env.json +21 -0
- package/configs/docker-1.env.json +72 -0
- package/configs/docker-2.env.json +58 -0
- package/configs/docker-3.env.json +58 -0
- package/configuration.md +38 -0
- package/dist/bin/broker.d.ts +2 -0
- package/dist/bin/broker.js +42 -0
- package/dist/bin/broker.js.map +1 -0
- package/dist/bin/config-wizard.d.ts +2 -0
- package/dist/bin/config-wizard.js +22 -0
- package/dist/bin/config-wizard.js.map +1 -0
- package/dist/bin/delete-expired-data.d.ts +2 -0
- package/dist/bin/delete-expired-data.js +44 -0
- package/dist/bin/delete-expired-data.js.map +1 -0
- package/dist/bin/entry-point.d.ts +2 -0
- package/dist/bin/entry-point.js +28 -0
- package/dist/bin/entry-point.js.map +1 -0
- package/dist/package.json +78 -0
- package/dist/src/Plugin.d.ts +33 -0
- package/dist/src/Plugin.js +43 -0
- package/dist/src/Plugin.js.map +1 -0
- package/dist/src/apiAuthentication.d.ts +4 -0
- package/dist/src/apiAuthentication.js +16 -0
- package/dist/src/apiAuthentication.js.map +1 -0
- package/dist/src/broker.d.ts +8 -0
- package/dist/src/broker.js +69 -0
- package/dist/src/broker.js.map +1 -0
- package/dist/src/config/ConfigWizard.d.ts +5 -0
- package/dist/src/config/ConfigWizard.js +466 -0
- package/dist/src/config/ConfigWizard.js.map +1 -0
- package/dist/src/config/config.d.ts +26 -0
- package/dist/src/config/config.js +92 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/config.schema.json +86 -0
- package/dist/src/config/definitions.schema.json +35 -0
- package/dist/src/config/migration.d.ts +6 -0
- package/dist/src/config/migration.js +210 -0
- package/dist/src/config/migration.js.map +1 -0
- package/dist/src/config/validateConfig.d.ts +4 -0
- package/dist/src/config/validateConfig.js +40 -0
- package/dist/src/config/validateConfig.js.map +1 -0
- package/dist/src/exports.d.ts +3 -0
- package/dist/src/exports.js +6 -0
- package/dist/src/exports.js.map +1 -0
- package/dist/src/helpers/PayloadFormat.d.ts +19 -0
- package/dist/src/helpers/PayloadFormat.js +85 -0
- package/dist/src/helpers/PayloadFormat.js.map +1 -0
- package/dist/src/helpers/applyPluginClientConfigs.d.ts +3 -0
- package/dist/src/helpers/applyPluginClientConfigs.js +29 -0
- package/dist/src/helpers/applyPluginClientConfigs.js.map +1 -0
- package/dist/src/helpers/fetchOrThrow.d.ts +2 -0
- package/dist/src/helpers/fetchOrThrow.js +20 -0
- package/dist/src/helpers/fetchOrThrow.js.map +1 -0
- package/dist/src/helpers/generateMnemonicFromAddress.d.ts +5 -0
- package/dist/src/helpers/generateMnemonicFromAddress.js +16 -0
- package/dist/src/helpers/generateMnemonicFromAddress.js.map +1 -0
- package/dist/src/helpers/multiply.d.ts +1 -0
- package/dist/src/helpers/multiply.js +10 -0
- package/dist/src/helpers/multiply.js.map +1 -0
- package/dist/src/helpers/parser.d.ts +9 -0
- package/dist/src/helpers/parser.js +62 -0
- package/dist/src/helpers/parser.js.map +1 -0
- package/dist/src/helpers/partitions.d.ts +8 -0
- package/dist/src/helpers/partitions.js +32 -0
- package/dist/src/helpers/partitions.js.map +1 -0
- package/dist/src/helpers/weightedSample.d.ts +16 -0
- package/dist/src/helpers/weightedSample.js +35 -0
- package/dist/src/helpers/weightedSample.js.map +1 -0
- package/dist/src/httpServer.d.ts +16 -0
- package/dist/src/httpServer.js +71 -0
- package/dist/src/httpServer.js.map +1 -0
- package/dist/src/pluginRegistry.d.ts +3 -0
- package/dist/src/pluginRegistry.js +35 -0
- package/dist/src/pluginRegistry.js.map +1 -0
- package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.d.ts +12 -0
- package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js +36 -0
- package/dist/src/plugins/consoleMetrics/ConsoleMetricsPlugin.js.map +1 -0
- package/dist/src/plugins/consoleMetrics/config.schema.json +18 -0
- package/dist/src/plugins/http/HttpPlugin.d.ts +8 -0
- package/dist/src/plugins/http/HttpPlugin.js +23 -0
- package/dist/src/plugins/http/HttpPlugin.js.map +1 -0
- package/dist/src/plugins/http/config.schema.json +12 -0
- package/dist/src/plugins/http/publishEndpoint.d.ts +3 -0
- package/dist/src/plugins/http/publishEndpoint.js +72 -0
- package/dist/src/plugins/http/publishEndpoint.js.map +1 -0
- package/dist/src/plugins/info/InfoPlugin.d.ts +9 -0
- package/dist/src/plugins/info/InfoPlugin.js +31 -0
- package/dist/src/plugins/info/InfoPlugin.js.map +1 -0
- package/dist/src/plugins/info/config.schema.json +12 -0
- package/dist/src/plugins/mqtt/Bridge.d.ts +40 -0
- package/dist/src/plugins/mqtt/Bridge.js +136 -0
- package/dist/src/plugins/mqtt/Bridge.js.map +1 -0
- package/dist/src/plugins/mqtt/MqttPlugin.d.ts +14 -0
- package/dist/src/plugins/mqtt/MqttPlugin.js +30 -0
- package/dist/src/plugins/mqtt/MqttPlugin.js.map +1 -0
- package/dist/src/plugins/mqtt/MqttServer.d.ts +22 -0
- package/dist/src/plugins/mqtt/MqttServer.js +109 -0
- package/dist/src/plugins/mqtt/MqttServer.js.map +1 -0
- package/dist/src/plugins/mqtt/config.schema.json +26 -0
- package/dist/src/plugins/operator/ConsistentHashRing.d.ts +20 -0
- package/dist/src/plugins/operator/ConsistentHashRing.js +64 -0
- package/dist/src/plugins/operator/ConsistentHashRing.js.map +1 -0
- package/dist/src/plugins/operator/ContractFacade.d.ts +80 -0
- package/dist/src/plugins/operator/ContractFacade.js +364 -0
- package/dist/src/plugins/operator/ContractFacade.js.map +1 -0
- package/dist/src/plugins/operator/MaintainTopologyHelper.d.ts +23 -0
- package/dist/src/plugins/operator/MaintainTopologyHelper.js +75 -0
- package/dist/src/plugins/operator/MaintainTopologyHelper.js.map +1 -0
- package/dist/src/plugins/operator/MaintainTopologyService.d.ts +11 -0
- package/dist/src/plugins/operator/MaintainTopologyService.js +57 -0
- package/dist/src/plugins/operator/MaintainTopologyService.js.map +1 -0
- package/dist/src/plugins/operator/OperatorFleetState.d.ts +33 -0
- package/dist/src/plugins/operator/OperatorFleetState.js +112 -0
- package/dist/src/plugins/operator/OperatorFleetState.js.map +1 -0
- package/dist/src/plugins/operator/OperatorPlugin.d.ts +50 -0
- package/dist/src/plugins/operator/OperatorPlugin.js +159 -0
- package/dist/src/plugins/operator/OperatorPlugin.js.map +1 -0
- package/dist/src/plugins/operator/StreamPartAssignments.d.ts +28 -0
- package/dist/src/plugins/operator/StreamPartAssignments.js +104 -0
- package/dist/src/plugins/operator/StreamPartAssignments.js.map +1 -0
- package/dist/src/plugins/operator/announceNodeToContract.d.ts +3 -0
- package/dist/src/plugins/operator/announceNodeToContract.js +39 -0
- package/dist/src/plugins/operator/announceNodeToContract.js.map +1 -0
- package/dist/src/plugins/operator/announceNodeToStream.d.ts +3 -0
- package/dist/src/plugins/operator/announceNodeToStream.js +25 -0
- package/dist/src/plugins/operator/announceNodeToStream.js.map +1 -0
- package/dist/src/plugins/operator/checkOperatorValueBreach.d.ts +2 -0
- package/dist/src/plugins/operator/checkOperatorValueBreach.js +21 -0
- package/dist/src/plugins/operator/checkOperatorValueBreach.js.map +1 -0
- package/dist/src/plugins/operator/closeExpiredFlags.d.ts +3 -0
- package/dist/src/plugins/operator/closeExpiredFlags.js +24 -0
- package/dist/src/plugins/operator/closeExpiredFlags.js.map +1 -0
- package/dist/src/plugins/operator/config.schema.json +152 -0
- package/dist/src/plugins/operator/createIsLeaderFn.d.ts +4 -0
- package/dist/src/plugins/operator/createIsLeaderFn.js +14 -0
- package/dist/src/plugins/operator/createIsLeaderFn.js.map +1 -0
- package/dist/src/plugins/operator/fetchRedundancyFactor.d.ts +2 -0
- package/dist/src/plugins/operator/fetchRedundancyFactor.js +43 -0
- package/dist/src/plugins/operator/fetchRedundancyFactor.js.map +1 -0
- package/dist/src/plugins/operator/formCoordinationStreamId.d.ts +3 -0
- package/dist/src/plugins/operator/formCoordinationStreamId.js +9 -0
- package/dist/src/plugins/operator/formCoordinationStreamId.js.map +1 -0
- package/dist/src/plugins/operator/heartbeatUtils.d.ts +67 -0
- package/dist/src/plugins/operator/heartbeatUtils.js +26 -0
- package/dist/src/plugins/operator/heartbeatUtils.js.map +1 -0
- package/dist/src/plugins/operator/inspectOverTime.d.ts +22 -0
- package/dist/src/plugins/operator/inspectOverTime.js +146 -0
- package/dist/src/plugins/operator/inspectOverTime.js.map +1 -0
- package/dist/src/plugins/operator/inspectRandomNode.d.ts +8 -0
- package/dist/src/plugins/operator/inspectRandomNode.js +44 -0
- package/dist/src/plugins/operator/inspectRandomNode.js.map +1 -0
- package/dist/src/plugins/operator/inspectionUtils.d.ts +23 -0
- package/dist/src/plugins/operator/inspectionUtils.js +120 -0
- package/dist/src/plugins/operator/inspectionUtils.js.map +1 -0
- package/dist/src/plugins/operator/maintainOperatorValue.d.ts +2 -0
- package/dist/src/plugins/operator/maintainOperatorValue.js +21 -0
- package/dist/src/plugins/operator/maintainOperatorValue.js.map +1 -0
- package/dist/src/plugins/operator/reviewSuspectNode.d.ts +24 -0
- package/dist/src/plugins/operator/reviewSuspectNode.js +56 -0
- package/dist/src/plugins/operator/reviewSuspectNode.js.map +1 -0
- package/dist/src/plugins/storage/Batch.d.ts +51 -0
- package/dist/src/plugins/storage/Batch.js +121 -0
- package/dist/src/plugins/storage/Batch.js.map +1 -0
- package/dist/src/plugins/storage/BatchManager.d.ts +27 -0
- package/dist/src/plugins/storage/BatchManager.js +117 -0
- package/dist/src/plugins/storage/BatchManager.js.map +1 -0
- package/dist/src/plugins/storage/Bucket.d.ts +23 -0
- package/dist/src/plugins/storage/Bucket.js +90 -0
- package/dist/src/plugins/storage/Bucket.js.map +1 -0
- package/dist/src/plugins/storage/BucketManager.d.ts +56 -0
- package/dist/src/plugins/storage/BucketManager.js +306 -0
- package/dist/src/plugins/storage/BucketManager.js.map +1 -0
- package/dist/src/plugins/storage/DataQueryFormat.d.ts +10 -0
- package/dist/src/plugins/storage/DataQueryFormat.js +51 -0
- package/dist/src/plugins/storage/DataQueryFormat.js.map +1 -0
- package/dist/src/plugins/storage/DeleteExpiredCmd.d.ts +28 -0
- package/dist/src/plugins/storage/DeleteExpiredCmd.js +155 -0
- package/dist/src/plugins/storage/DeleteExpiredCmd.js.map +1 -0
- package/dist/src/plugins/storage/SetMembershipSynchronizer.d.ts +33 -0
- package/dist/src/plugins/storage/SetMembershipSynchronizer.js +102 -0
- package/dist/src/plugins/storage/SetMembershipSynchronizer.js.map +1 -0
- package/dist/src/plugins/storage/Storage.d.ts +47 -0
- package/dist/src/plugins/storage/Storage.js +459 -0
- package/dist/src/plugins/storage/Storage.js.map +1 -0
- package/dist/src/plugins/storage/StorageConfig.d.ts +43 -0
- package/dist/src/plugins/storage/StorageConfig.js +83 -0
- package/dist/src/plugins/storage/StorageConfig.js.map +1 -0
- package/dist/src/plugins/storage/StorageEventListener.d.ts +17 -0
- package/dist/src/plugins/storage/StorageEventListener.js +46 -0
- package/dist/src/plugins/storage/StorageEventListener.js.map +1 -0
- package/dist/src/plugins/storage/StoragePlugin.d.ts +32 -0
- package/dist/src/plugins/storage/StoragePlugin.js +103 -0
- package/dist/src/plugins/storage/StoragePlugin.js.map +1 -0
- package/dist/src/plugins/storage/StoragePoller.d.ts +15 -0
- package/dist/src/plugins/storage/StoragePoller.js +47 -0
- package/dist/src/plugins/storage/StoragePoller.js.map +1 -0
- package/dist/src/plugins/storage/config.schema.json +88 -0
- package/dist/src/plugins/storage/dataMetadataEndpoint.d.ts +3 -0
- package/dist/src/plugins/storage/dataMetadataEndpoint.js +35 -0
- package/dist/src/plugins/storage/dataMetadataEndpoint.js.map +1 -0
- package/dist/src/plugins/storage/dataQueryEndpoint.d.ts +6 -0
- package/dist/src/plugins/storage/dataQueryEndpoint.js +181 -0
- package/dist/src/plugins/storage/dataQueryEndpoint.js.map +1 -0
- package/dist/src/plugins/storage/storageConfigEndpoint.d.ts +3 -0
- package/dist/src/plugins/storage/storageConfigEndpoint.js +31 -0
- package/dist/src/plugins/storage/storageConfigEndpoint.js.map +1 -0
- package/dist/src/plugins/subscriber/SubscriberPlugin.d.ts +16 -0
- package/dist/src/plugins/subscriber/SubscriberPlugin.js +22 -0
- package/dist/src/plugins/subscriber/SubscriberPlugin.js.map +1 -0
- package/dist/src/plugins/subscriber/config.schema.json +31 -0
- package/dist/src/plugins/websocket/Connection.d.ts +9 -0
- package/dist/src/plugins/websocket/Connection.js +45 -0
- package/dist/src/plugins/websocket/Connection.js.map +1 -0
- package/dist/src/plugins/websocket/PublishConnection.d.ts +12 -0
- package/dist/src/plugins/websocket/PublishConnection.js +46 -0
- package/dist/src/plugins/websocket/PublishConnection.js.map +1 -0
- package/dist/src/plugins/websocket/SubscribeConnection.d.ts +13 -0
- package/dist/src/plugins/websocket/SubscribeConnection.js +50 -0
- package/dist/src/plugins/websocket/SubscribeConnection.js.map +1 -0
- package/dist/src/plugins/websocket/WebsocketPlugin.d.ts +19 -0
- package/dist/src/plugins/websocket/WebsocketPlugin.js +26 -0
- package/dist/src/plugins/websocket/WebsocketPlugin.js.map +1 -0
- package/dist/src/plugins/websocket/WebsocketServer.d.ts +16 -0
- package/dist/src/plugins/websocket/WebsocketServer.js +132 -0
- package/dist/src/plugins/websocket/WebsocketServer.js.map +1 -0
- package/dist/src/plugins/websocket/config.schema.json +51 -0
- package/package.json +78 -0
- package/plugins.md +318 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "config.schema.json",
|
|
3
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"description": "Operator plugin configuration",
|
|
6
|
+
"additionalProperties": false,
|
|
7
|
+
"required": [
|
|
8
|
+
"operatorContractAddress"
|
|
9
|
+
],
|
|
10
|
+
"properties": {
|
|
11
|
+
"operatorContractAddress": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"description": "Operator contract Ethereum address",
|
|
14
|
+
"format": "ethereum-address"
|
|
15
|
+
},
|
|
16
|
+
"heartbeatUpdateIntervalInMs": {
|
|
17
|
+
"type": "integer",
|
|
18
|
+
"description": "The interval (in milliseconds) at which heartbeats get published to coordination stream",
|
|
19
|
+
"minimum": 0,
|
|
20
|
+
"default": 10000
|
|
21
|
+
},
|
|
22
|
+
"heartbeatTimeoutInMs": {
|
|
23
|
+
"type": "integer",
|
|
24
|
+
"description": "The maximum time (in milliseconds) to wait for the 1st heartbeat of a target operator's nodes",
|
|
25
|
+
"minimum": 0,
|
|
26
|
+
"default": 120000
|
|
27
|
+
},
|
|
28
|
+
"fleetState": {
|
|
29
|
+
"type": "object",
|
|
30
|
+
"description": "Operator fleet state settings (both for me and targets)",
|
|
31
|
+
"additionalProperties": false,
|
|
32
|
+
"default": {},
|
|
33
|
+
"properties": {
|
|
34
|
+
"pruneAgeInMs": {
|
|
35
|
+
"type": "integer",
|
|
36
|
+
"description": "The maximum time (in milliseconds) of a heartbeat to count towards a node being online",
|
|
37
|
+
"minimum": 0,
|
|
38
|
+
"default": 180000
|
|
39
|
+
},
|
|
40
|
+
"pruneIntervalInMs": {
|
|
41
|
+
"type": "integer",
|
|
42
|
+
"description": "The interval (in milliseconds) at which to prune old heartbeats",
|
|
43
|
+
"minimum": 0,
|
|
44
|
+
"default": 30000
|
|
45
|
+
},
|
|
46
|
+
"latencyExtraInMs": {
|
|
47
|
+
"type": "integer",
|
|
48
|
+
"description": "Account for extra latency (milliseconds) due to networking",
|
|
49
|
+
"minimum": 0,
|
|
50
|
+
"default": 2000
|
|
51
|
+
},
|
|
52
|
+
"warmupPeriodInMs": {
|
|
53
|
+
"type": "integer",
|
|
54
|
+
"description": "The time (in milliseconds) to wait before starting to count heartbeats",
|
|
55
|
+
"minimum": 0,
|
|
56
|
+
"default": 10000
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"checkOperatorValueBreachIntervalInMs": {
|
|
61
|
+
"type": "integer",
|
|
62
|
+
"description": "The interval (in milliseconds) at which to check for operator value breach",
|
|
63
|
+
"minimum": 0,
|
|
64
|
+
"default": 3600000
|
|
65
|
+
},
|
|
66
|
+
"announceNodeToContract": {
|
|
67
|
+
"type": "object",
|
|
68
|
+
"description": "Announce node to contract settings",
|
|
69
|
+
"additionalProperties": false,
|
|
70
|
+
"default": {},
|
|
71
|
+
"properties": {
|
|
72
|
+
"pollIntervalInMs": {
|
|
73
|
+
"type": "integer",
|
|
74
|
+
"description": "The interval (in milliseconds) at which to poll for need to write new value to contract",
|
|
75
|
+
"minimum": 0,
|
|
76
|
+
"default": 600000
|
|
77
|
+
},
|
|
78
|
+
"writeIntervalInMs": {
|
|
79
|
+
"type": "integer",
|
|
80
|
+
"description": "How often (in milliseconds) should a new value be written to contract",
|
|
81
|
+
"minimum": 0,
|
|
82
|
+
"default": 86400000
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
"maintainOperatorValue": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"description": "Maintain operator value settings",
|
|
89
|
+
"additionalProperties": false,
|
|
90
|
+
"default": {},
|
|
91
|
+
"properties": {
|
|
92
|
+
"intervalInMs": {
|
|
93
|
+
"type": "integer",
|
|
94
|
+
"description": "How often to run (in milliseconds)",
|
|
95
|
+
"minimum": 0,
|
|
96
|
+
"default": 3600000
|
|
97
|
+
},
|
|
98
|
+
"withdrawLimitSafetyFraction": {
|
|
99
|
+
"type": "number",
|
|
100
|
+
"description": "The fraction of the withdraw limit to use as a safety margin",
|
|
101
|
+
"minimum": 0,
|
|
102
|
+
"maximum": 1,
|
|
103
|
+
"default": 0.5
|
|
104
|
+
},
|
|
105
|
+
"minSponsorshipEarningsInWithdraw": {
|
|
106
|
+
"type": "integer",
|
|
107
|
+
"minimum": 0,
|
|
108
|
+
"default": 1
|
|
109
|
+
},
|
|
110
|
+
"maxSponsorshipsInWithdraw": {
|
|
111
|
+
"type": "integer",
|
|
112
|
+
"minimum": 0,
|
|
113
|
+
"default": 20
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"inspectRandomNode": {
|
|
118
|
+
"type": "object",
|
|
119
|
+
"description": "Inspect random node settings",
|
|
120
|
+
"additionalProperties": false,
|
|
121
|
+
"default": {},
|
|
122
|
+
"properties": {
|
|
123
|
+
"intervalInMs": {
|
|
124
|
+
"type": "integer",
|
|
125
|
+
"description": "How often to run (in milliseconds)",
|
|
126
|
+
"minimum": 0,
|
|
127
|
+
"default": 900000
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
"closeExpiredFlags": {
|
|
132
|
+
"type": "object",
|
|
133
|
+
"description": "Close expired flags settings",
|
|
134
|
+
"additionalProperties": false,
|
|
135
|
+
"default": {},
|
|
136
|
+
"properties": {
|
|
137
|
+
"intervalInMs": {
|
|
138
|
+
"type": "integer",
|
|
139
|
+
"description": "How often to run (in milliseconds)",
|
|
140
|
+
"minimum": 0,
|
|
141
|
+
"default": 600000
|
|
142
|
+
},
|
|
143
|
+
"maxAgeInMs": {
|
|
144
|
+
"type": "integer",
|
|
145
|
+
"description": "The maximum age (in milliseconds) of a flag before it is expired",
|
|
146
|
+
"minimum": 0,
|
|
147
|
+
"default": 86400000
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StreamrClient } from '@streamr/sdk';
|
|
2
|
+
import { OperatorFleetState } from './OperatorFleetState';
|
|
3
|
+
import { Logger } from '@streamr/utils';
|
|
4
|
+
export declare function createIsLeaderFn(streamrClient: StreamrClient, operatorFleetState: OperatorFleetState, logger?: Logger): Promise<() => boolean>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createIsLeaderFn = void 0;
|
|
4
|
+
async function createIsLeaderFn(streamrClient, operatorFleetState, logger) {
|
|
5
|
+
const myNodeId = await streamrClient.getNodeId();
|
|
6
|
+
return () => {
|
|
7
|
+
const leaderNodeId = operatorFleetState.getLeaderNodeId();
|
|
8
|
+
const isLeader = myNodeId === leaderNodeId;
|
|
9
|
+
logger?.debug('Check whether leader', { isLeader, leaderNodeId, myNodeId });
|
|
10
|
+
return isLeader;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.createIsLeaderFn = createIsLeaderFn;
|
|
14
|
+
//# sourceMappingURL=createIsLeaderFn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createIsLeaderFn.js","sourceRoot":"","sources":["../../../../src/plugins/operator/createIsLeaderFn.ts"],"names":[],"mappings":";;;AAIO,KAAK,UAAU,gBAAgB,CAClC,aAA4B,EAC5B,kBAAsC,EACtC,MAAe;IAEf,MAAM,QAAQ,GAAG,MAAM,aAAa,CAAC,SAAS,EAAE,CAAA;IAChD,OAAO,GAAG,EAAE;QACR,MAAM,YAAY,GAAG,kBAAkB,CAAC,eAAe,EAAE,CAAA;QACzD,MAAM,QAAQ,GAAG,QAAQ,KAAK,YAAY,CAAA;QAC1C,MAAM,EAAE,KAAK,CAAC,sBAAsB,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAA;QAC3E,OAAO,QAAQ,CAAA;IACnB,CAAC,CAAA;AACL,CAAC;AAZD,4CAYC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchRedundancyFactor = void 0;
|
|
4
|
+
const utils_1 = require("@streamr/utils");
|
|
5
|
+
const ethers_1 = require("ethers");
|
|
6
|
+
const network_contracts_1 = require("@streamr/network-contracts");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const logger = new utils_1.Logger(module);
|
|
9
|
+
const MetadataSchema = zod_1.z.object({
|
|
10
|
+
redundancyFactor: zod_1.z.number()
|
|
11
|
+
.int()
|
|
12
|
+
.gte(1)
|
|
13
|
+
});
|
|
14
|
+
async function fetchRedundancyFactor({ operatorContractAddress, signer }) {
|
|
15
|
+
const operator = new ethers_1.Contract(operatorContractAddress, network_contracts_1.operatorABI, signer);
|
|
16
|
+
const metadataAsString = await operator.metadata();
|
|
17
|
+
if (metadataAsString.length === 0) {
|
|
18
|
+
return 1;
|
|
19
|
+
}
|
|
20
|
+
let metadata;
|
|
21
|
+
try {
|
|
22
|
+
metadata = JSON.parse(metadataAsString);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
logger.warn('Encountered malformed metadata', { operatorContractAddress, metadataAsString });
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
let validatedMetadata;
|
|
29
|
+
try {
|
|
30
|
+
validatedMetadata = MetadataSchema.parse(metadata);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
logger.warn('Encountered invalid metadata', {
|
|
34
|
+
operatorContractAddress,
|
|
35
|
+
metadataAsString,
|
|
36
|
+
reason: err?.reason
|
|
37
|
+
});
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
return validatedMetadata.redundancyFactor;
|
|
41
|
+
}
|
|
42
|
+
exports.fetchRedundancyFactor = fetchRedundancyFactor;
|
|
43
|
+
//# sourceMappingURL=fetchRedundancyFactor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchRedundancyFactor.js","sourceRoot":"","sources":["../../../../src/plugins/operator/fetchRedundancyFactor.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AACvC,mCAAiC;AACjC,kEAAkE;AAElE,6BAA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|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formCoordinationStreamId = void 0;
|
|
4
|
+
const protocol_1 = require("@streamr/protocol");
|
|
5
|
+
function formCoordinationStreamId(operatorContractAddress) {
|
|
6
|
+
return (0, protocol_1.toStreamID)('/operator/coordination', operatorContractAddress);
|
|
7
|
+
}
|
|
8
|
+
exports.formCoordinationStreamId = formCoordinationStreamId;
|
|
9
|
+
//# sourceMappingURL=formCoordinationStreamId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formCoordinationStreamId.js","sourceRoot":"","sources":["../../../../src/plugins/operator/formCoordinationStreamId.ts"],"names":[],"mappings":";;;AACA,gDAAwD;AAExD,SAAgB,wBAAwB,CAAC,uBAAwC;IAC7E,OAAO,IAAA,qBAAU,EAAC,wBAAwB,EAAE,uBAAuB,CAAC,CAAA;AACxE,CAAC;AAFD,4DAEC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { NetworkNodeType, NetworkPeerDescriptor } from '@streamr/sdk';
|
|
3
|
+
export declare const HeartbeatMessageSchema: z.ZodObject<{
|
|
4
|
+
msgType: z.ZodEnum<["heartbeat"]>;
|
|
5
|
+
peerDescriptor: z.ZodObject<{
|
|
6
|
+
nodeId: z.ZodString;
|
|
7
|
+
type: z.ZodOptional<z.ZodNativeEnum<typeof NetworkNodeType>>;
|
|
8
|
+
websocket: z.ZodOptional<z.ZodObject<{
|
|
9
|
+
host: z.ZodString;
|
|
10
|
+
port: z.ZodNumber;
|
|
11
|
+
tls: z.ZodBoolean;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
port: number;
|
|
14
|
+
host: string;
|
|
15
|
+
tls: boolean;
|
|
16
|
+
}, {
|
|
17
|
+
port: number;
|
|
18
|
+
host: string;
|
|
19
|
+
tls: boolean;
|
|
20
|
+
}>>;
|
|
21
|
+
region: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
nodeId: string;
|
|
24
|
+
type?: NetworkNodeType | undefined;
|
|
25
|
+
websocket?: {
|
|
26
|
+
port: number;
|
|
27
|
+
host: string;
|
|
28
|
+
tls: boolean;
|
|
29
|
+
} | undefined;
|
|
30
|
+
region?: number | undefined;
|
|
31
|
+
}, {
|
|
32
|
+
nodeId: string;
|
|
33
|
+
type?: NetworkNodeType | undefined;
|
|
34
|
+
websocket?: {
|
|
35
|
+
port: number;
|
|
36
|
+
host: string;
|
|
37
|
+
tls: boolean;
|
|
38
|
+
} | undefined;
|
|
39
|
+
region?: number | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
}, "strip", z.ZodTypeAny, {
|
|
42
|
+
msgType: "heartbeat";
|
|
43
|
+
peerDescriptor: {
|
|
44
|
+
nodeId: string;
|
|
45
|
+
type?: NetworkNodeType | undefined;
|
|
46
|
+
websocket?: {
|
|
47
|
+
port: number;
|
|
48
|
+
host: string;
|
|
49
|
+
tls: boolean;
|
|
50
|
+
} | undefined;
|
|
51
|
+
region?: number | undefined;
|
|
52
|
+
};
|
|
53
|
+
}, {
|
|
54
|
+
msgType: "heartbeat";
|
|
55
|
+
peerDescriptor: {
|
|
56
|
+
nodeId: string;
|
|
57
|
+
type?: NetworkNodeType | undefined;
|
|
58
|
+
websocket?: {
|
|
59
|
+
port: number;
|
|
60
|
+
host: string;
|
|
61
|
+
tls: boolean;
|
|
62
|
+
} | undefined;
|
|
63
|
+
region?: number | undefined;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
export type HeartbeatMessage = z.infer<typeof HeartbeatMessageSchema>;
|
|
67
|
+
export declare function createHeartbeatMessage(peerDescriptor: NetworkPeerDescriptor): HeartbeatMessage;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHeartbeatMessage = exports.HeartbeatMessageSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const sdk_1 = require("@streamr/sdk");
|
|
6
|
+
exports.HeartbeatMessageSchema = zod_1.z.object({
|
|
7
|
+
msgType: zod_1.z.enum(['heartbeat']),
|
|
8
|
+
peerDescriptor: zod_1.z.object({
|
|
9
|
+
nodeId: zod_1.z.string(),
|
|
10
|
+
type: zod_1.z.optional(zod_1.z.nativeEnum(sdk_1.NetworkNodeType)),
|
|
11
|
+
websocket: zod_1.z.optional(zod_1.z.object({
|
|
12
|
+
host: zod_1.z.string(),
|
|
13
|
+
port: zod_1.z.number(),
|
|
14
|
+
tls: zod_1.z.boolean()
|
|
15
|
+
})),
|
|
16
|
+
region: zod_1.z.optional(zod_1.z.number())
|
|
17
|
+
})
|
|
18
|
+
});
|
|
19
|
+
function createHeartbeatMessage(peerDescriptor) {
|
|
20
|
+
return {
|
|
21
|
+
msgType: 'heartbeat',
|
|
22
|
+
peerDescriptor
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
exports.createHeartbeatMessage = createHeartbeatMessage;
|
|
26
|
+
//# sourceMappingURL=heartbeatUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeatUtils.js","sourceRoot":"","sources":["../../../../src/plugins/operator/heartbeatUtils.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AACvB,sCAAqE;AAExD,QAAA,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,WAAW,CAAC,CAAC;IAC9B,cAAc,EAAE,OAAC,CAAC,MAAM,CAAC;QACrB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;QAClB,IAAI,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,UAAU,CAAC,qBAAe,CAAC,CAAC;QAC/C,SAAS,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,CAAC;YAC3B,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,GAAG,EAAE,OAAC,CAAC,OAAO,EAAE;SACnB,CAAC,CAAC;QACH,MAAM,EAAE,OAAC,CAAC,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC;KACjC,CAAC;CACL,CAAC,CAAA;AAIF,SAAgB,sBAAsB,CAAC,cAAqC;IACxE,OAAO;QACH,OAAO,EAAE,WAAW;QACpB,cAAc;KACjB,CAAA;AACL,CAAC;AALD,wDAKC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EthereumAddress } from '@streamr/utils';
|
|
3
|
+
import { StreamrClient } from '@streamr/sdk';
|
|
4
|
+
import { CreateOperatorFleetStateFn } from './OperatorFleetState';
|
|
5
|
+
import { FindNodesForTargetGivenFleetStateFn, InspectTargetFn, Target } from './inspectionUtils';
|
|
6
|
+
interface InspectOverTimeOpts {
|
|
7
|
+
target: Target;
|
|
8
|
+
streamrClient: StreamrClient;
|
|
9
|
+
createOperatorFleetState: CreateOperatorFleetStateFn;
|
|
10
|
+
getRedundancyFactor: (operatorContractAddress: EthereumAddress) => Promise<number | undefined>;
|
|
11
|
+
sleepTimeInMsBeforeFirstInspection: number;
|
|
12
|
+
heartbeatTimeoutInMs: number;
|
|
13
|
+
inspectionIntervalInMs: number;
|
|
14
|
+
maxInspections: number;
|
|
15
|
+
waitUntilPassOrDone: boolean;
|
|
16
|
+
abortSignal: AbortSignal;
|
|
17
|
+
traceId: string;
|
|
18
|
+
findNodesForTargetGivenFleetStateFn?: FindNodesForTargetGivenFleetStateFn;
|
|
19
|
+
inspectTargetFn?: InspectTargetFn;
|
|
20
|
+
}
|
|
21
|
+
export declare function inspectOverTime(opts: InspectOverTimeOpts): () => Promise<boolean[]>;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.inspectOverTime = void 0;
|
|
7
|
+
const utils_1 = require("@streamr/utils");
|
|
8
|
+
const inspectionUtils_1 = require("./inspectionUtils");
|
|
9
|
+
const formCoordinationStreamId_1 = require("./formCoordinationStreamId");
|
|
10
|
+
const range_1 = __importDefault(require("lodash/range"));
|
|
11
|
+
function inspectOverTime(opts) {
|
|
12
|
+
const task = new InspectionOverTimeTask(opts);
|
|
13
|
+
task.start();
|
|
14
|
+
return async () => {
|
|
15
|
+
if (opts.waitUntilPassOrDone) {
|
|
16
|
+
await task.waitUntilPassOrDone();
|
|
17
|
+
}
|
|
18
|
+
task.destroy();
|
|
19
|
+
return task.calculateResult();
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.inspectOverTime = inspectOverTime;
|
|
23
|
+
class InspectionOverTimeTask {
|
|
24
|
+
target;
|
|
25
|
+
streamrClient;
|
|
26
|
+
createOperatorFleetState;
|
|
27
|
+
getRedundancyFactor;
|
|
28
|
+
sleepTimeInMsBeforeFirstInspection;
|
|
29
|
+
heartbeatTimeoutInMs;
|
|
30
|
+
inspectionIntervalInMs;
|
|
31
|
+
maxInspections;
|
|
32
|
+
abortSignal;
|
|
33
|
+
findNodesForTargetGivenFleetStateFn;
|
|
34
|
+
inspectTargetFn;
|
|
35
|
+
logger;
|
|
36
|
+
fleetState;
|
|
37
|
+
inspectionResults = new Array();
|
|
38
|
+
abortController = new AbortController();
|
|
39
|
+
passedSingleInspectionGate = new utils_1.Gate(false);
|
|
40
|
+
doneGate = new utils_1.Gate(false);
|
|
41
|
+
constructor({ target, streamrClient, createOperatorFleetState, getRedundancyFactor, sleepTimeInMsBeforeFirstInspection, heartbeatTimeoutInMs, inspectionIntervalInMs, maxInspections, abortSignal: userAbortSignal, traceId, findNodesForTargetGivenFleetStateFn = inspectionUtils_1.findNodesForTargetGivenFleetState, inspectTargetFn = inspectionUtils_1.inspectTarget, }) {
|
|
42
|
+
this.target = target;
|
|
43
|
+
this.streamrClient = streamrClient;
|
|
44
|
+
this.createOperatorFleetState = createOperatorFleetState;
|
|
45
|
+
this.getRedundancyFactor = getRedundancyFactor;
|
|
46
|
+
this.sleepTimeInMsBeforeFirstInspection = sleepTimeInMsBeforeFirstInspection;
|
|
47
|
+
this.heartbeatTimeoutInMs = heartbeatTimeoutInMs;
|
|
48
|
+
this.inspectionIntervalInMs = inspectionIntervalInMs;
|
|
49
|
+
this.maxInspections = maxInspections;
|
|
50
|
+
this.abortSignal = (0, utils_1.composeAbortSignals)(userAbortSignal, this.abortController.signal);
|
|
51
|
+
this.findNodesForTargetGivenFleetStateFn = findNodesForTargetGivenFleetStateFn;
|
|
52
|
+
this.inspectTargetFn = inspectTargetFn;
|
|
53
|
+
this.logger = new utils_1.Logger(module, { traceId });
|
|
54
|
+
this.abortSignal.addEventListener('abort', async () => {
|
|
55
|
+
await this.fleetState?.destroy();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
calculateResult() {
|
|
59
|
+
const passCount = this.inspectionResults.filter((pass) => pass).length;
|
|
60
|
+
this.logger.info('Inspection done', {
|
|
61
|
+
passFraction: `${passCount}/${this.inspectionResults.length}`,
|
|
62
|
+
inspectionResults: this.inspectionResults
|
|
63
|
+
});
|
|
64
|
+
return this.inspectionResults;
|
|
65
|
+
}
|
|
66
|
+
start() {
|
|
67
|
+
this.run().catch((err) => {
|
|
68
|
+
if (!(err instanceof utils_1.AbortError) && err?.reason !== 'AbortError') {
|
|
69
|
+
this.logger.warn('Error encountered', { err });
|
|
70
|
+
this.destroy();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
waitUntilPassOrDone() {
|
|
75
|
+
return Promise.race([
|
|
76
|
+
this.doneGate.waitUntilOpen(),
|
|
77
|
+
this.passedSingleInspectionGate.waitUntilOpen()
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
destroy() {
|
|
81
|
+
this.abortController.abort();
|
|
82
|
+
}
|
|
83
|
+
async run() {
|
|
84
|
+
this.logger.info('Start', {
|
|
85
|
+
target: this.target,
|
|
86
|
+
heartbeatTimeoutInMs: this.heartbeatTimeoutInMs,
|
|
87
|
+
inspectionIntervalInMs: this.inspectionIntervalInMs,
|
|
88
|
+
maxInspections: this.maxInspections
|
|
89
|
+
});
|
|
90
|
+
await this.initializeNewOperatorFleetState();
|
|
91
|
+
this.logger.info('Sleep', { timeInMs: this.sleepTimeInMsBeforeFirstInspection });
|
|
92
|
+
await (0, utils_1.wait)(this.sleepTimeInMsBeforeFirstInspection, this.abortSignal);
|
|
93
|
+
for (const attemptNo of (0, range_1.default)(1, this.maxInspections + 1)) {
|
|
94
|
+
const startTime = Date.now();
|
|
95
|
+
this.logger.info('Inspecting target', { attemptNo, target: this.target });
|
|
96
|
+
const onlineNodeDescriptors = await this.findNodesForTargetGivenFleetStateFn(this.target, this.fleetState, this.getRedundancyFactor, this.logger);
|
|
97
|
+
this.abortSignal.throwIfAborted();
|
|
98
|
+
const pass = await this.inspectTargetFn({
|
|
99
|
+
target: this.target,
|
|
100
|
+
targetPeerDescriptors: onlineNodeDescriptors,
|
|
101
|
+
streamrClient: this.streamrClient,
|
|
102
|
+
abortSignal: this.abortSignal,
|
|
103
|
+
logger: this.logger
|
|
104
|
+
});
|
|
105
|
+
this.inspectionResults.push(pass);
|
|
106
|
+
if (pass) {
|
|
107
|
+
this.passedSingleInspectionGate.open();
|
|
108
|
+
}
|
|
109
|
+
const timeElapsedInMs = Date.now() - startTime;
|
|
110
|
+
this.logger.info('Inspected target', {
|
|
111
|
+
attemptNo,
|
|
112
|
+
pass,
|
|
113
|
+
timeElapsedInMs,
|
|
114
|
+
target: this.target
|
|
115
|
+
});
|
|
116
|
+
if (attemptNo !== this.maxInspections) {
|
|
117
|
+
// TODO: remove when NET-1169 landed;
|
|
118
|
+
// workaround subscribe bug in @streamr/sdk (sometimes messages don't come thru to heartbeat stream)
|
|
119
|
+
if (this.fleetState?.getNodeIds().length === 0) {
|
|
120
|
+
this.logger.info('Destroying and re-creating fleet state');
|
|
121
|
+
if (this.fleetState !== undefined) {
|
|
122
|
+
await this.fleetState.destroy();
|
|
123
|
+
}
|
|
124
|
+
this.abortSignal.throwIfAborted();
|
|
125
|
+
await this.initializeNewOperatorFleetState();
|
|
126
|
+
this.abortSignal.throwIfAborted();
|
|
127
|
+
}
|
|
128
|
+
const sleepTime = Math.max(this.inspectionIntervalInMs - timeElapsedInMs, 0);
|
|
129
|
+
this.logger.info('Sleep', { timeInMs: sleepTime });
|
|
130
|
+
await (0, utils_1.wait)(sleepTime, this.abortSignal);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.doneGate.open();
|
|
134
|
+
}
|
|
135
|
+
async initializeNewOperatorFleetState() {
|
|
136
|
+
this.fleetState = this.createOperatorFleetState((0, formCoordinationStreamId_1.formCoordinationStreamId)(this.target.operatorAddress));
|
|
137
|
+
await this.fleetState.start();
|
|
138
|
+
this.logger.info('Waiting for fleet state');
|
|
139
|
+
await Promise.race([
|
|
140
|
+
this.fleetState.waitUntilReady(),
|
|
141
|
+
(0, utils_1.wait)(this.heartbeatTimeoutInMs, this.abortSignal)
|
|
142
|
+
]);
|
|
143
|
+
this.logger.info('Wait done for fleet state', { onlineNodeCount: this.fleetState.getNodeIds().length });
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=inspectOverTime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspectOverTime.js","sourceRoot":"","sources":["../../../../src/plugins/operator/inspectOverTime.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAqG;AAGrG,uDAM0B;AAC1B,yEAAqE;AACrE,yDAAgC;AAkBhC,SAAgB,eAAe,CAAC,IAAyB;IACrD,MAAM,IAAI,GAAG,IAAI,sBA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MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,sBAAsB,GAAG,eAAe,EAAE,CAAC,CAAC,CAAA;gBAC5E,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAA;gBAClD,MAAM,IAAA,YAAI,EAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;YAC3C,CAAC;QACL,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;IAEO,KAAK,CAAC,+BAA+B;QACzC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,wBAAwB,CAAC,IAAA,mDAAwB,EAAC,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC,CAAA;QACtG,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;QAC7B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAA;QAC3C,MAAM,OAAO,CAAC,IAAI,CAAC;YACf,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE;YAChC,IAAA,YAAI,EAAC,IAAI,CAAC,oBAAoB,EAAE,IAAI,CAAC,WAAW,CAAC;SACpD,CAAC,CAAA;QACF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,EAAE,EAAE,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,CAAC,CAAA;IAC3G,CAAC;CACJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EthereumAddress } from '@streamr/utils';
|
|
3
|
+
import { StreamPartAssignments } from './StreamPartAssignments';
|
|
4
|
+
import { StreamrClient } from '@streamr/sdk';
|
|
5
|
+
import { findTarget } from './inspectionUtils';
|
|
6
|
+
import { ContractFacade } from './ContractFacade';
|
|
7
|
+
import { CreateOperatorFleetStateFn } from './OperatorFleetState';
|
|
8
|
+
export declare function inspectRandomNode(operatorContractAddress: EthereumAddress, contractFacade: ContractFacade, assignments: StreamPartAssignments, streamrClient: StreamrClient, heartbeatTimeoutInMs: number, getRedundancyFactor: (operatorContractAddress: EthereumAddress) => Promise<number | undefined>, createOperatorFleetState: CreateOperatorFleetStateFn, abortSignal: AbortSignal, findTargetFn?: typeof findTarget): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inspectRandomNode = void 0;
|
|
4
|
+
const utils_1 = require("@streamr/utils");
|
|
5
|
+
const protocol_1 = require("@streamr/protocol");
|
|
6
|
+
const inspectionUtils_1 = require("./inspectionUtils");
|
|
7
|
+
const inspectOverTime_1 = require("./inspectOverTime");
|
|
8
|
+
async function inspectRandomNode(operatorContractAddress, contractFacade, assignments, streamrClient, heartbeatTimeoutInMs, getRedundancyFactor, createOperatorFleetState, abortSignal, findTargetFn = inspectionUtils_1.findTarget) {
|
|
9
|
+
const traceId = (0, utils_1.randomString)(6);
|
|
10
|
+
const logger = new utils_1.Logger(module, { traceId });
|
|
11
|
+
logger.info('Select a random operator to inspect');
|
|
12
|
+
const target = await findTargetFn(operatorContractAddress, contractFacade, assignments, logger);
|
|
13
|
+
if (target === undefined) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
logger.debug('Target established', { target });
|
|
17
|
+
const consumeResults = (0, inspectOverTime_1.inspectOverTime)({
|
|
18
|
+
target,
|
|
19
|
+
streamrClient,
|
|
20
|
+
createOperatorFleetState,
|
|
21
|
+
getRedundancyFactor,
|
|
22
|
+
sleepTimeInMsBeforeFirstInspection: 0,
|
|
23
|
+
heartbeatTimeoutInMs,
|
|
24
|
+
inspectionIntervalInMs: 8 * 60 * 1000,
|
|
25
|
+
maxInspections: 10,
|
|
26
|
+
waitUntilPassOrDone: true,
|
|
27
|
+
abortSignal,
|
|
28
|
+
traceId
|
|
29
|
+
});
|
|
30
|
+
const results = await consumeResults();
|
|
31
|
+
if (results.some((pass) => pass)) {
|
|
32
|
+
logger.info('Not raising flag', { target });
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const flagAlreadyRaised = await contractFacade.hasOpenFlag(target.operatorAddress, target.sponsorshipAddress);
|
|
36
|
+
if (flagAlreadyRaised) {
|
|
37
|
+
logger.info('Not raising flag (target already has open flag)', { target });
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
logger.info('Raise flag', { target });
|
|
41
|
+
await contractFacade.flag(target.sponsorshipAddress, target.operatorAddress, protocol_1.StreamPartIDUtils.getStreamPartition(target.streamPart));
|
|
42
|
+
}
|
|
43
|
+
exports.inspectRandomNode = inspectRandomNode;
|
|
44
|
+
//# sourceMappingURL=inspectRandomNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspectRandomNode.js","sourceRoot":"","sources":["../../../../src/plugins/operator/inspectRandomNode.ts"],"names":[],"mappings":";;;AAAA,0CAAsE;AAGtE,gDAAqD;AACrD,uDAA8C;AAG9C,uDAAmD;AAE5C,KAAK,UAAU,iBAAiB,CACnC,uBAAwC,EACxC,cAA8B,EAC9B,WAAkC,EAClC,aAA4B,EAC5B,oBAA4B,EAC5B,mBAA8F,EAC9F,wBAAoD,EACpD,WAAwB,EACxB,YAAY,GAAG,4BAAU;IAEzB,MAAM,OAAO,GAAG,IAAA,oBAAY,EAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IAC9C,MAAM,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAA;IAElD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,uBAAuB,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;IAC/F,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACvB,OAAM;IACV,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IAE9C,MAAM,cAAc,GAAG,IAAA,iCAAe,EAAC;QACnC,MAAM;QACN,aAAa;QACb,wBAAwB;QACxB,mBAAmB;QACnB,kCAAkC,EAAE,CAAC;QACrC,oBAAoB;QACpB,sBAAsB,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;QACrC,cAAc,EAAE,EAAE;QAClB,mBAAmB,EAAE,IAAI;QACzB,WAAW;QACX,OAAO;KACV,CAAC,CAAA;IAEF,MAAM,OAAO,GAAG,MAAM,cAAc,EAAE,CAAA;IACtC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;QAC3C,OAAM;IACV,CAAC;IAED,MAAM,iBAAiB,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAA;IAC7G,IAAI,iBAAiB,EAAE,CAAC;QACpB,MAAM,CAAC,IAAI,CAAC,iDAAiD,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;QAC1E,OAAM;IACV,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,CAAC,CAAA;IACrC,MAAM,cAAc,CAAC,IAAI,CACrB,MAAM,CAAC,kBAAkB,EACzB,MAAM,CAAC,eAAe,EACtB,4BAAiB,CAAC,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAC1D,CAAA;AACL,CAAC;AArDD,8CAqDC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { NetworkPeerDescriptor, StreamrClient } from '@streamr/sdk';
|
|
3
|
+
import { OperatorFleetState } from './OperatorFleetState';
|
|
4
|
+
import { StreamPartID } from '@streamr/protocol';
|
|
5
|
+
import { EthereumAddress, Logger } from '@streamr/utils';
|
|
6
|
+
import { StreamPartAssignments } from './StreamPartAssignments';
|
|
7
|
+
import { ContractFacade } from './ContractFacade';
|
|
8
|
+
export type FindNodesForTargetGivenFleetStateFn = typeof findNodesForTargetGivenFleetState;
|
|
9
|
+
export type InspectTargetFn = typeof inspectTarget;
|
|
10
|
+
export interface Target {
|
|
11
|
+
sponsorshipAddress: EthereumAddress;
|
|
12
|
+
operatorAddress: EthereumAddress;
|
|
13
|
+
streamPart: StreamPartID;
|
|
14
|
+
}
|
|
15
|
+
export declare function findTarget(myOperatorContractAddress: EthereumAddress, contractFacade: ContractFacade, assignments: StreamPartAssignments, logger: Logger): Promise<Target | undefined>;
|
|
16
|
+
export declare function findNodesForTargetGivenFleetState(target: Target, targetOperatorFleetState: OperatorFleetState, getRedundancyFactor: (operatorContractAddress: EthereumAddress) => Promise<number | undefined>, logger: Logger): Promise<NetworkPeerDescriptor[]>;
|
|
17
|
+
export declare function inspectTarget({ target, targetPeerDescriptors, streamrClient, abortSignal, logger }: {
|
|
18
|
+
target: Target;
|
|
19
|
+
targetPeerDescriptors: NetworkPeerDescriptor[];
|
|
20
|
+
streamrClient: StreamrClient;
|
|
21
|
+
abortSignal: AbortSignal;
|
|
22
|
+
logger: Logger;
|
|
23
|
+
}): Promise<boolean>;
|