capitalisk-dex 17.2.1 → 17.3.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/defaults/config.js +3 -0
- package/index.js +73 -21
- package/package.json +1 -1
package/defaults/config.js
CHANGED
|
@@ -7,8 +7,11 @@ module.exports = {
|
|
|
7
7
|
multisigFlushInterval: 15000,
|
|
8
8
|
multisigReadyDelay: 5000,
|
|
9
9
|
multisigMaxBatchSize: 25,
|
|
10
|
+
multisigRetryInterval: 60000,
|
|
10
11
|
recentTransfersExpiry: 1800000,
|
|
11
12
|
signatureFlushInterval: 5000,
|
|
13
|
+
signatureReadyDelay: 10000,
|
|
14
|
+
signatureRetryInterval: 60000,
|
|
12
15
|
signatureMaxBatchSize: 400,
|
|
13
16
|
orderBookSnapshotFinality: 303,
|
|
14
17
|
orderBookUpdateSnapshotDirPath: 'dex-update-snapshots',
|
package/index.js
CHANGED
|
@@ -23,6 +23,9 @@ const CIPHER_KEY = CAPITALISK_DEX_PASSWORD ? crypto.scryptSync(CAPITALISK_DEX_PA
|
|
|
23
23
|
const CIPHER_IV = Buffer.alloc(16, 0);
|
|
24
24
|
const DEFAULT_INIT_RETRY_DELAY = 5000;
|
|
25
25
|
const DEFAULT_MULTISIG_READY_DELAY = 5000;
|
|
26
|
+
const DEFAULT_MULTISIG_RETRY_INTERVAL = 60000;
|
|
27
|
+
const DEFAULT_SIGNATURE_READY_DELAY = 10000;
|
|
28
|
+
const DEFAULT_SIGNATURE_RETRY_INTERVAL = 60000;
|
|
26
29
|
const DEFAULT_PROTOCOL_EXCLUDE_REASON = false;
|
|
27
30
|
const DEFAULT_PROTOCOL_MAX_ARGUMENT_LENGTH = 64;
|
|
28
31
|
const DEFAULT_PRICE_DECIMAL_PRECISION = 4;
|
|
@@ -110,6 +113,9 @@ module.exports = class CapitaliskDEXModule {
|
|
|
110
113
|
this.quoteAddress = quoteChainOptions.multisigAddress;
|
|
111
114
|
this.initRetryDelay = this.options.initRetryDelay || DEFAULT_INIT_RETRY_DELAY;
|
|
112
115
|
this.multisigReadyDelay = this.options.multisigReadyDelay || DEFAULT_MULTISIG_READY_DELAY;
|
|
116
|
+
this.signatureReadyDelay = this.options.signatureReadyDelay || DEFAULT_SIGNATURE_READY_DELAY;
|
|
117
|
+
this.multisigRetryInterval = this.options.multisigRetryInterval || DEFAULT_MULTISIG_RETRY_INTERVAL;
|
|
118
|
+
this.signatureRetryInterval = this.options.signatureRetryInterval || DEFAULT_SIGNATURE_RETRY_INTERVAL;
|
|
113
119
|
|
|
114
120
|
this.priceDecimalPrecision = this.options.priceDecimalPrecision == null ?
|
|
115
121
|
DEFAULT_PRICE_DECIMAL_PRECISION : this.options.priceDecimalPrecision;
|
|
@@ -805,9 +811,16 @@ module.exports = class CapitaliskDEXModule {
|
|
|
805
811
|
processedSignerAddressSet.add(signerAddress);
|
|
806
812
|
transaction.signatures.push(signaturePacket);
|
|
807
813
|
|
|
814
|
+
let now = Date.now();
|
|
815
|
+
|
|
816
|
+
if (transfer.signatureBroadcastTimestamps[signerAddress] == null) {
|
|
817
|
+
transfer.signatureBroadcastTimestamps[signerAddress] = now;
|
|
818
|
+
}
|
|
819
|
+
|
|
808
820
|
let signatureQuota = this._getSignatureQuota(targetChain, transaction);
|
|
809
821
|
if (signatureQuota >= 0 && transfer.readyTimestamp == null) {
|
|
810
|
-
transfer.readyTimestamp =
|
|
822
|
+
transfer.readyTimestamp = now;
|
|
823
|
+
transfer.multisigBroadcastTimestamp = now + this.multisigReadyDelay;
|
|
811
824
|
}
|
|
812
825
|
}
|
|
813
826
|
|
|
@@ -822,43 +835,61 @@ module.exports = class CapitaliskDEXModule {
|
|
|
822
835
|
}
|
|
823
836
|
|
|
824
837
|
flushPendingMultisigTransactions() {
|
|
825
|
-
let
|
|
838
|
+
let transfersToBroadcastPerChain = {};
|
|
826
839
|
let now = Date.now();
|
|
827
840
|
|
|
828
841
|
for (let transfer of this.pendingTransfers.values()) {
|
|
829
|
-
if (transfer.
|
|
830
|
-
if (!
|
|
831
|
-
|
|
842
|
+
if (transfer.multisigBroadcastTimestamp != null && transfer.multisigBroadcastTimestamp <= now) {
|
|
843
|
+
if (!transfersToBroadcastPerChain[transfer.targetChain]) {
|
|
844
|
+
transfersToBroadcastPerChain[transfer.targetChain] = [];
|
|
832
845
|
}
|
|
833
|
-
|
|
846
|
+
transfersToBroadcastPerChain[transfer.targetChain].push(transfer);
|
|
834
847
|
}
|
|
835
848
|
}
|
|
836
849
|
|
|
837
|
-
let chainSymbolList = Object.keys(
|
|
850
|
+
let chainSymbolList = Object.keys(transfersToBroadcastPerChain);
|
|
838
851
|
for (let chainSymbol of chainSymbolList) {
|
|
839
|
-
let
|
|
840
|
-
|
|
852
|
+
let transfersToBroadcast = transfersToBroadcastPerChain[chainSymbol]
|
|
853
|
+
.slice(0, this.options.multisigMaxBatchSize);
|
|
854
|
+
|
|
855
|
+
for (let transfer of transfersToBroadcast) {
|
|
856
|
+
transfer.multisigBroadcastTimestamp = now + this.multisigRetryInterval;
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
let transactionsToBroadcast = transfersToBroadcast
|
|
860
|
+
.map(transfer => transfer.transaction);
|
|
841
861
|
this._broadcastTransactionsToChain(chainSymbol, transactionsToBroadcast);
|
|
842
862
|
}
|
|
843
863
|
}
|
|
844
864
|
|
|
845
865
|
flushPendingSignatures() {
|
|
846
|
-
let
|
|
866
|
+
let pendingSignatureInfoList = [];
|
|
867
|
+
let now = Date.now();
|
|
847
868
|
|
|
848
869
|
for (let transfer of this.pendingTransfers.values()) {
|
|
849
870
|
for (let signaturePacket of transfer.transaction.signatures) {
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
871
|
+
let broadcastTimestamp = transfer.signatureBroadcastTimestamps[signaturePacket.signerAddress];
|
|
872
|
+
if (broadcastTimestamp != null && broadcastTimestamp <= now) {
|
|
873
|
+
pendingSignatureInfoList.push({
|
|
874
|
+
signaturePacket,
|
|
875
|
+
transactionId: transfer.transaction.id,
|
|
876
|
+
transfer
|
|
877
|
+
});
|
|
878
|
+
}
|
|
854
879
|
}
|
|
855
880
|
}
|
|
856
881
|
|
|
857
|
-
if (
|
|
858
|
-
let
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
882
|
+
if (pendingSignatureInfoList.length) {
|
|
883
|
+
let signatureInfosToBroadcast = pendingSignatureInfoList.slice(0, this.options.signatureMaxBatchSize);
|
|
884
|
+
for (let signatureInfo of signatureInfosToBroadcast) {
|
|
885
|
+
let { signaturePacket, transfer } = signatureInfo;
|
|
886
|
+
transfer.signatureBroadcastTimestamps[signaturePacket.signerAddress] = Date.now() + this.signatureRetryInterval;
|
|
887
|
+
}
|
|
888
|
+
let signaturesToBroadcast = signatureInfosToBroadcast.map(signatureInfo => {
|
|
889
|
+
let { transfer, ...signatureData } = signatureInfo;
|
|
890
|
+
return signatureData;
|
|
891
|
+
});
|
|
892
|
+
this._broadcastSignaturesToSubnet(signaturesToBroadcast);
|
|
862
893
|
}
|
|
863
894
|
}
|
|
864
895
|
|
|
@@ -2036,10 +2067,27 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2036
2067
|
let currentBlock = await this._getBlockAtHeight(chainSymbol, fromHeight);
|
|
2037
2068
|
|
|
2038
2069
|
while (currentBlock) {
|
|
2039
|
-
let blocksToProcess = await this._getBlocksBetweenHeights(chainSymbol, currentBlock.height, toHeight, readMaxBlocks, false);
|
|
2040
2070
|
this.logger.info(
|
|
2041
2071
|
`Chain ${chainSymbol}: Processing blocks between heights ${currentBlock.height} and ${toHeight} as part of dividend calculation`
|
|
2042
2072
|
);
|
|
2073
|
+
let blocksToProcess;
|
|
2074
|
+
try {
|
|
2075
|
+
blocksToProcess = await this._getBlocksBetweenHeights(chainSymbol, currentBlock.height, toHeight, readMaxBlocks, false);
|
|
2076
|
+
} catch (error) {
|
|
2077
|
+
this.logger.error(
|
|
2078
|
+
`Chain ${
|
|
2079
|
+
chainSymbol
|
|
2080
|
+
}: Failed to fetch blocks between heights ${
|
|
2081
|
+
currentBlock.height
|
|
2082
|
+
} and ${
|
|
2083
|
+
toHeight
|
|
2084
|
+
} during dividend calculation because of error: ${
|
|
2085
|
+
error.message
|
|
2086
|
+
}`
|
|
2087
|
+
);
|
|
2088
|
+
await wait(this.options.readBlocksInterval);
|
|
2089
|
+
continue;
|
|
2090
|
+
}
|
|
2043
2091
|
for (let block of blocksToProcess) {
|
|
2044
2092
|
if (block.numberOfTransactions === 0) {
|
|
2045
2093
|
continue;
|
|
@@ -2706,6 +2754,7 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2706
2754
|
if (this.pendingTransfers.has(preparedTxn.id)) {
|
|
2707
2755
|
this.pendingTransfers.delete(preparedTxn.id);
|
|
2708
2756
|
}
|
|
2757
|
+
let now = Date.now();
|
|
2709
2758
|
let transfer = {
|
|
2710
2759
|
id: preparedTxn.id,
|
|
2711
2760
|
transaction: preparedTxn,
|
|
@@ -2713,7 +2762,10 @@ module.exports = class CapitaliskDEXModule {
|
|
|
2713
2762
|
targetChain,
|
|
2714
2763
|
processedSignerAddressSet,
|
|
2715
2764
|
height: transactionData.height,
|
|
2716
|
-
timestamp:
|
|
2765
|
+
timestamp: now,
|
|
2766
|
+
signatureBroadcastTimestamps: {
|
|
2767
|
+
[multisigSignaturePacket.signerAddress]: now + this.signatureReadyDelay
|
|
2768
|
+
},
|
|
2717
2769
|
...extraTransferData
|
|
2718
2770
|
};
|
|
2719
2771
|
this.pendingTransfers.set(preparedTxn.id, transfer);
|