@dashevo/dapi-client 5.0.1 → 5.0.3

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.
@@ -10,6 +10,10 @@ const BlockHeadersReader = require('./BlockHeadersReader');
10
10
  * @property {number} [targetBatchSize=100000] a target batch size per stream
11
11
  * @property {number} [fromBlockHeight=1] a target batch size per stream
12
12
  * @property {number} [maxRetries=10] max amount of retries per stream connection
13
+ * @property {number} [powTargetSpacing] devnets only: the -powtargetspacing the
14
+ * devnet was started with
15
+ * @property {number} [minimumDifficultyBlocks] devnets only: the
16
+ * -minimumdifficultyblocks the devnet was started with
13
17
  */
14
18
  const defaultOptions = {
15
19
  network: 'testnet',
@@ -49,7 +53,11 @@ class BlockHeadersProvider extends EventEmitter {
49
53
  ...options,
50
54
  };
51
55
 
52
- this.spvChain = new SpvChain(this.options.network, 100);
56
+ const { powTargetSpacing, minimumDifficultyBlocks } = this.options;
57
+ const devnetOptions = powTargetSpacing !== undefined || minimumDifficultyBlocks !== undefined
58
+ ? { powTargetSpacing, minimumDifficultyBlocks }
59
+ : undefined;
60
+ this.spvChain = new SpvChain(this.options.network, 100, devnetOptions);
53
61
 
54
62
  this.state = STATES.IDLE;
55
63
 
@@ -177,13 +185,17 @@ class BlockHeadersProvider extends EventEmitter {
177
185
  return;
178
186
  }
179
187
 
180
- if (this.state === STATES.HISTORICAL_SYNC) {
181
- this.blockHeadersReader.stopReadingHistorical();
182
- } else if (this.state === STATES.CONTINUOUS_SYNC) {
183
- this.blockHeadersReader.unsubscribeFromNew();
184
- }
188
+ // errorHandler() already destroyed the reader, whose streams stopped
189
+ // before it reported the error
190
+ if (this.blockHeadersReader) {
191
+ if (this.state === STATES.HISTORICAL_SYNC) {
192
+ this.blockHeadersReader.stopReadingHistorical();
193
+ } else if (this.state === STATES.CONTINUOUS_SYNC) {
194
+ this.blockHeadersReader.unsubscribeFromNew();
195
+ }
185
196
 
186
- this.destroyReader();
197
+ this.destroyReader();
198
+ }
187
199
 
188
200
  this.state = STATES.IDLE;
189
201
 
@@ -191,6 +203,12 @@ class BlockHeadersProvider extends EventEmitter {
191
203
  }
192
204
 
193
205
  errorHandler(e) {
206
+ // The reader stops its streams before it reports an error, but an error
207
+ // handling the headers they deliver leaves them running
208
+ if (this.blockHeadersReader) {
209
+ this.blockHeadersReader.stopReadingHistorical();
210
+ this.blockHeadersReader.unsubscribeFromNew();
211
+ }
194
212
  this.destroyReader();
195
213
  this.emit(EVENTS.ERROR, e);
196
214
  }
package/lib/DAPIClient.js CHANGED
@@ -81,7 +81,13 @@ class DAPIClient extends EventEmitter {
81
81
  );
82
82
 
83
83
  this.blockHeadersProvider.on(BlockHeadersProvider.EVENTS.ERROR, (e) => {
84
- this.emit(EVENTS.ERROR, e);
84
+ // An 'error' event nobody listens to throws and takes the process down.
85
+ // Header sync users such as wallet-lib listen on the provider itself.
86
+ if (this.listenerCount(EVENTS.ERROR) > 0) {
87
+ this.emit(EVENTS.ERROR, e);
88
+ } else {
89
+ this.logger.error(`Block headers provider error: ${e.message}`, { error: e });
90
+ }
85
91
  });
86
92
  }
87
93
 
@@ -61,9 +61,8 @@ function createDAPIAddressProviderFromOptions(options) {
61
61
  if (options.seeds) {
62
62
  let dapiAddressesWhiteList = options.dapiAddressesWhiteList || [];
63
63
 
64
- // Since we don't have PoSe atm, 3rd party masternodes sometimes provide wrong data
65
- // that breaks test suite and application logic. Temporary solution is to hardcode
66
- // reliable DCG testnet masternodes to connect. Should be removed when PoSe is introduced.
64
+ // On testnet, connect only to the evonodes in networkConfigs.testnet.dapiAddressesWhiteList
65
+ // unless a whitelist is passed.
67
66
  const network = networks.get(options.network);
68
67
  let isRegtest = false;
69
68
  if (network) {
@@ -9,34 +9,53 @@ module.exports = {
9
9
  'seed-1.pshenmic.dev:1443',
10
10
  ],
11
11
  network: 'testnet',
12
- // Since we don't have PoSe atm, 3rd party masternodes sometimes provide wrong data
13
- // that breaks test suite and application logic. Temporary solution is to hardcode
14
- // reliable DCG testnet masternodes to connect. Should be removed when PoSe is introduced.
12
+ // Snapshot of testnet evonodes that were enabled and passed the version check.
13
+ // Regenerate it when it goes stale: if none of these is in the masternode list,
14
+ // default discovery fails with NoAvailableAddressesError.
15
15
  // Generate list with:
16
16
  // curl https://quorums.testnet.networks.dash.org/masternodes | jq 'select(.success) | .data | map(select(.status=="ENABLED" and .versionCheck=="success") | .address | sub(":[0-9]+$"; ":1443")) | sort_by( split(":")[0] | split(".") | map(tonumber) )' // eslint-disable-line max-len
17
17
  dapiAddressesWhiteList: [
18
- '34.214.48.68:1443',
19
- '35.82.197.197:1443',
20
- '35.85.21.179:1443',
21
- '35.163.144.230:1443',
22
- '35.164.23.245:1443',
23
- '35.167.145.149:1443',
24
- '44.227.137.77:1443',
25
- '44.228.242.181:1443',
26
- '44.239.39.153:1443',
27
- '44.240.98.102:1443',
28
- '52.10.229.11:1443',
29
- '52.12.176.90:1443',
30
- '52.13.132.146:1443',
31
- '52.24.124.162:1443',
32
- '52.33.28.47:1443',
33
- '52.34.144.50:1443',
34
- '52.43.13.92:1443',
35
- '52.43.86.231:1443',
36
- '54.68.235.201:1443',
37
- '54.149.33.167:1443',
38
- '54.187.14.232:1443',
39
- '54.201.32.131:1443',
18
+ '68.67.122.1:1443',
19
+ '68.67.122.2:1443',
20
+ '68.67.122.3:1443',
21
+ '68.67.122.4:1443',
22
+ '68.67.122.5:1443',
23
+ '68.67.122.6:1443',
24
+ '68.67.122.7:1443',
25
+ '68.67.122.8:1443',
26
+ '68.67.122.9:1443',
27
+ '68.67.122.10:1443',
28
+ '68.67.122.11:1443',
29
+ '68.67.122.12:1443',
30
+ '68.67.122.13:1443',
31
+ '68.67.122.14:1443',
32
+ '68.67.122.15:1443',
33
+ '68.67.122.16:1443',
34
+ '68.67.122.17:1443',
35
+ '68.67.122.18:1443',
36
+ '68.67.122.19:1443',
37
+ '68.67.122.20:1443',
38
+ '68.67.122.21:1443',
39
+ '68.67.122.22:1443',
40
+ '68.67.122.23:1443',
41
+ '68.67.122.24:1443',
42
+ '68.67.122.25:1443',
43
+ '68.67.122.26:1443',
44
+ '68.67.122.27:1443',
45
+ '68.67.122.28:1443',
46
+ '68.67.122.29:1443',
47
+ '85.209.243.1:1443',
48
+ '85.209.243.2:1443',
49
+ '85.209.243.3:1443',
50
+ '85.209.243.4:1443',
51
+ '85.209.243.5:1443',
52
+ '85.209.243.6:1443',
53
+ '85.209.243.7:1443',
54
+ '85.209.243.8:1443',
55
+ '85.209.243.9:1443',
56
+ '85.209.243.10:1443',
57
+ '87.229.22.126:1443',
58
+ '206.245.167.63:1443',
40
59
  ],
41
60
  },
42
61
  local: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "Client library used to access Dash DAPI endpoints",
5
5
  "main": "lib/index.js",
6
6
  "contributors": [
@@ -26,11 +26,11 @@
26
26
  }
27
27
  ],
28
28
  "dependencies": {
29
- "@dashevo/dapi-grpc": "5.0.1",
30
- "@dashevo/dash-spv": "6.0.1",
31
- "@dashevo/dashcore-lib": "~0.22.0",
32
- "@dashevo/grpc-common": "5.0.1",
33
- "@dashevo/wasm-dpp": "5.0.1",
29
+ "@dashevo/dapi-grpc": "5.0.3",
30
+ "@dashevo/dash-spv": "6.0.3",
31
+ "@dashevo/dashcore-lib": "~0.26.1",
32
+ "@dashevo/grpc-common": "5.0.3",
33
+ "@dashevo/wasm-dpp": "5.0.3",
34
34
  "cbor": "^8.0.0",
35
35
  "google-protobuf": "^3.12.2",
36
36
  "undici": "^6.28.1",