capitalisk-dex 18.0.2 → 18.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.
- package/index.js +25 -9
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -142,6 +142,10 @@ module.exports = class CapitaliskDEXModule {
|
|
|
142
142
|
quoteMinPartialTake: BigInt(quoteChainOptions.minPartialTake || 0),
|
|
143
143
|
priceDecimalPrecision: this.priceDecimalPrecision
|
|
144
144
|
});
|
|
145
|
+
this.initialHeights = {
|
|
146
|
+
[this.baseChainSymbol]: 0,
|
|
147
|
+
[this.quoteChainSymbol]: 0
|
|
148
|
+
};
|
|
145
149
|
this.processedHeights = {
|
|
146
150
|
[this.baseChainSymbol]: 0,
|
|
147
151
|
[this.quoteChainSymbol]: 0
|
|
@@ -1239,6 +1243,8 @@ module.exports = class CapitaliskDEXModule {
|
|
|
1239
1243
|
}
|
|
1240
1244
|
}
|
|
1241
1245
|
|
|
1246
|
+
this.initialHeights = {...this.processedHeights};
|
|
1247
|
+
|
|
1242
1248
|
while (true) {
|
|
1243
1249
|
try {
|
|
1244
1250
|
let [baseChainMaxBlock, quoteChainMaxBlock] = await Promise.all([
|
|
@@ -1448,7 +1454,7 @@ module.exports = class CapitaliskDEXModule {
|
|
|
1448
1454
|
if (
|
|
1449
1455
|
!this.passiveMode &&
|
|
1450
1456
|
this.options.dexDisabledFromHeight != null &&
|
|
1451
|
-
chainHeight
|
|
1457
|
+
chainHeight === this.options.dexDisabledFromHeight
|
|
1452
1458
|
) {
|
|
1453
1459
|
let currentOrderBook = this.tradeEngine.getSnapshot();
|
|
1454
1460
|
this.tradeEngine.clear();
|
|
@@ -2195,11 +2201,17 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2195
2201
|
this.updater.revertActiveUpdate();
|
|
2196
2202
|
process.exit();
|
|
2197
2203
|
}
|
|
2198
|
-
|
|
2199
|
-
let lastProcessedHeights =
|
|
2204
|
+
|
|
2205
|
+
let lastProcessedHeights = this.revertToSafeSnapshot();
|
|
2200
2206
|
this.processedHeights[this.baseChainSymbol] = lastProcessedHeights.baseChainHeight;
|
|
2201
2207
|
this.processedHeights[this.quoteChainSymbol] = lastProcessedHeights.quoteChainHeight;
|
|
2202
2208
|
|
|
2209
|
+
for (let [txnId, transfer] of this.pendingTransfers) {
|
|
2210
|
+
if (transfer.height >= this.processedHeights[transfer.targetChain]) {
|
|
2211
|
+
this.pendingTransfers.delete(txnId);
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
|
|
2203
2215
|
let [baseChainNewTipBlock, quoteChainNewTipBlock] = await Promise.all([
|
|
2204
2216
|
this._getBlockAtHeight(this.baseChainSymbol, this.processedHeights[this.baseChainSymbol]),
|
|
2205
2217
|
this._getBlockAtHeight(this.quoteChainSymbol, this.processedHeights[this.quoteChainSymbol])
|
|
@@ -2238,12 +2250,12 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2238
2250
|
quoteChainLastProcessedBlock.id !== quoteChainLastDEXProcessedBlock.id
|
|
2239
2251
|
);
|
|
2240
2252
|
if (this.isBaseChainForked) {
|
|
2241
|
-
this.logger.
|
|
2253
|
+
this.logger.error(
|
|
2242
2254
|
`A fork was detected on the ${this.baseChainSymbol} chain at height ${baseChainLastDEXProcessedBlock.height}`
|
|
2243
2255
|
);
|
|
2244
2256
|
}
|
|
2245
2257
|
if (this.isQuoteChainForked) {
|
|
2246
|
-
this.logger.
|
|
2258
|
+
this.logger.error(
|
|
2247
2259
|
`A fork was detected on the ${this.quoteChainSymbol} chain at height ${quoteChainLastDEXProcessedBlock.height}`
|
|
2248
2260
|
);
|
|
2249
2261
|
}
|
|
@@ -2823,17 +2835,21 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2823
2835
|
return {baseChainHeight, quoteChainHeight};
|
|
2824
2836
|
}
|
|
2825
2837
|
|
|
2826
|
-
|
|
2838
|
+
revertToSafeSnapshot() {
|
|
2827
2839
|
if (this.finalizedSnapshot) {
|
|
2828
2840
|
this.lastSnapshot = this.finalizedSnapshot;
|
|
2829
2841
|
}
|
|
2842
|
+
let baseChainHeight;
|
|
2843
|
+
let quoteChainHeight;
|
|
2830
2844
|
if (!this.lastSnapshot) {
|
|
2831
2845
|
this.tradeEngine.clear();
|
|
2832
|
-
|
|
2846
|
+
baseChainHeight = this.initialHeights[this.baseChainSymbol];
|
|
2847
|
+
quoteChainHeight = this.initialHeights[this.quoteChainSymbol];
|
|
2848
|
+
return {baseChainHeight, quoteChainHeight};
|
|
2833
2849
|
}
|
|
2834
2850
|
this.tradeEngine.setSnapshot(this.lastSnapshot.orderBook);
|
|
2835
|
-
|
|
2836
|
-
|
|
2851
|
+
baseChainHeight = this.lastSnapshot.chainHeights[this.baseChainSymbol];
|
|
2852
|
+
quoteChainHeight = this.lastSnapshot.chainHeights[this.quoteChainSymbol];
|
|
2837
2853
|
return {baseChainHeight, quoteChainHeight};
|
|
2838
2854
|
}
|
|
2839
2855
|
|