capitalisk-dex 18.0.1 → 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 +32 -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
|
|
@@ -832,6 +836,13 @@ module.exports = class CapitaliskDEXModule {
|
|
|
832
836
|
break;
|
|
833
837
|
}
|
|
834
838
|
this.pendingTransfers.delete(txnId);
|
|
839
|
+
this.logger.error(
|
|
840
|
+
`Outbound multisig transaction ${
|
|
841
|
+
txnId
|
|
842
|
+
} expired before it could be processed by the ${
|
|
843
|
+
transfer.targetChain
|
|
844
|
+
} blockchain`
|
|
845
|
+
);
|
|
835
846
|
}
|
|
836
847
|
}
|
|
837
848
|
|
|
@@ -1232,6 +1243,8 @@ module.exports = class CapitaliskDEXModule {
|
|
|
1232
1243
|
}
|
|
1233
1244
|
}
|
|
1234
1245
|
|
|
1246
|
+
this.initialHeights = {...this.processedHeights};
|
|
1247
|
+
|
|
1235
1248
|
while (true) {
|
|
1236
1249
|
try {
|
|
1237
1250
|
let [baseChainMaxBlock, quoteChainMaxBlock] = await Promise.all([
|
|
@@ -1441,7 +1454,7 @@ module.exports = class CapitaliskDEXModule {
|
|
|
1441
1454
|
if (
|
|
1442
1455
|
!this.passiveMode &&
|
|
1443
1456
|
this.options.dexDisabledFromHeight != null &&
|
|
1444
|
-
chainHeight
|
|
1457
|
+
chainHeight === this.options.dexDisabledFromHeight
|
|
1445
1458
|
) {
|
|
1446
1459
|
let currentOrderBook = this.tradeEngine.getSnapshot();
|
|
1447
1460
|
this.tradeEngine.clear();
|
|
@@ -2188,11 +2201,17 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2188
2201
|
this.updater.revertActiveUpdate();
|
|
2189
2202
|
process.exit();
|
|
2190
2203
|
}
|
|
2191
|
-
|
|
2192
|
-
let lastProcessedHeights =
|
|
2204
|
+
|
|
2205
|
+
let lastProcessedHeights = this.revertToSafeSnapshot();
|
|
2193
2206
|
this.processedHeights[this.baseChainSymbol] = lastProcessedHeights.baseChainHeight;
|
|
2194
2207
|
this.processedHeights[this.quoteChainSymbol] = lastProcessedHeights.quoteChainHeight;
|
|
2195
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
|
+
|
|
2196
2215
|
let [baseChainNewTipBlock, quoteChainNewTipBlock] = await Promise.all([
|
|
2197
2216
|
this._getBlockAtHeight(this.baseChainSymbol, this.processedHeights[this.baseChainSymbol]),
|
|
2198
2217
|
this._getBlockAtHeight(this.quoteChainSymbol, this.processedHeights[this.quoteChainSymbol])
|
|
@@ -2231,12 +2250,12 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2231
2250
|
quoteChainLastProcessedBlock.id !== quoteChainLastDEXProcessedBlock.id
|
|
2232
2251
|
);
|
|
2233
2252
|
if (this.isBaseChainForked) {
|
|
2234
|
-
this.logger.
|
|
2253
|
+
this.logger.error(
|
|
2235
2254
|
`A fork was detected on the ${this.baseChainSymbol} chain at height ${baseChainLastDEXProcessedBlock.height}`
|
|
2236
2255
|
);
|
|
2237
2256
|
}
|
|
2238
2257
|
if (this.isQuoteChainForked) {
|
|
2239
|
-
this.logger.
|
|
2258
|
+
this.logger.error(
|
|
2240
2259
|
`A fork was detected on the ${this.quoteChainSymbol} chain at height ${quoteChainLastDEXProcessedBlock.height}`
|
|
2241
2260
|
);
|
|
2242
2261
|
}
|
|
@@ -2816,17 +2835,21 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2816
2835
|
return {baseChainHeight, quoteChainHeight};
|
|
2817
2836
|
}
|
|
2818
2837
|
|
|
2819
|
-
|
|
2838
|
+
revertToSafeSnapshot() {
|
|
2820
2839
|
if (this.finalizedSnapshot) {
|
|
2821
2840
|
this.lastSnapshot = this.finalizedSnapshot;
|
|
2822
2841
|
}
|
|
2842
|
+
let baseChainHeight;
|
|
2843
|
+
let quoteChainHeight;
|
|
2823
2844
|
if (!this.lastSnapshot) {
|
|
2824
2845
|
this.tradeEngine.clear();
|
|
2825
|
-
|
|
2846
|
+
baseChainHeight = this.initialHeights[this.baseChainSymbol];
|
|
2847
|
+
quoteChainHeight = this.initialHeights[this.quoteChainSymbol];
|
|
2848
|
+
return {baseChainHeight, quoteChainHeight};
|
|
2826
2849
|
}
|
|
2827
2850
|
this.tradeEngine.setSnapshot(this.lastSnapshot.orderBook);
|
|
2828
|
-
|
|
2829
|
-
|
|
2851
|
+
baseChainHeight = this.lastSnapshot.chainHeights[this.baseChainSymbol];
|
|
2852
|
+
quoteChainHeight = this.lastSnapshot.chainHeights[this.quoteChainSymbol];
|
|
2830
2853
|
return {baseChainHeight, quoteChainHeight};
|
|
2831
2854
|
}
|
|
2832
2855
|
|