@dashevo/dapi-client 5.0.2 → 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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/dapi-client",
3
- "version": "5.0.2",
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.2",
30
- "@dashevo/dash-spv": "6.0.2",
29
+ "@dashevo/dapi-grpc": "5.0.3",
30
+ "@dashevo/dash-spv": "6.0.3",
31
31
  "@dashevo/dashcore-lib": "~0.26.1",
32
- "@dashevo/grpc-common": "5.0.2",
33
- "@dashevo/wasm-dpp": "5.0.2",
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",