@socket.tech/dl-common 1.0.7 → 1.0.9

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.
Files changed (186) hide show
  1. package/dist/index.js +14 -30
  2. package/dist/utils/discord.d.ts +2 -2
  3. package/dist/utils/discord.js +11 -3
  4. package/dist/utils/test.d.ts +1 -0
  5. package/dist/utils/test.js +10 -0
  6. package/package.json +2 -2
  7. package/dist/dl-common/constants/confirmations.d.ts +0 -5
  8. package/dist/dl-common/constants/confirmations.js +0 -17
  9. package/dist/dl-common/constants/enums.d.ts +0 -44
  10. package/dist/dl-common/constants/enums.js +0 -52
  11. package/dist/dl-common/constants/index.d.ts +0 -3
  12. package/dist/dl-common/constants/index.js +0 -19
  13. package/dist/dl-common/constants/types.d.ts +0 -126
  14. package/dist/dl-common/constants/types.js +0 -45
  15. package/dist/dl-common/constants/waitTime.d.ts +0 -8
  16. package/dist/dl-common/constants/waitTime.js +0 -49
  17. package/dist/dl-common/index.d.ts +0 -4
  18. package/dist/dl-common/index.js +0 -20
  19. package/dist/dl-common/models/attestSignature.d.ts +0 -35
  20. package/dist/dl-common/models/attestSignature.js +0 -53
  21. package/dist/dl-common/models/attestation.d.ts +0 -70
  22. package/dist/dl-common/models/attestation.js +0 -86
  23. package/dist/dl-common/models/index.d.ts +0 -7
  24. package/dist/dl-common/models/index.js +0 -23
  25. package/dist/dl-common/models/lastBlock.d.ts +0 -28
  26. package/dist/dl-common/models/lastBlock.js +0 -27
  27. package/dist/dl-common/models/message.d.ts +0 -166
  28. package/dist/dl-common/models/message.js +0 -183
  29. package/dist/dl-common/models/packet.d.ts +0 -241
  30. package/dist/dl-common/models/packet.js +0 -250
  31. package/dist/dl-common/models/proposal.d.ts +0 -127
  32. package/dist/dl-common/models/proposal.js +0 -141
  33. package/dist/dl-common/models/switchboard.d.ts +0 -69
  34. package/dist/dl-common/models/switchboard.js +0 -92
  35. package/dist/dl-common/models/transaction.d.ts +0 -0
  36. package/dist/dl-common/models/transaction.js +0 -280
  37. package/dist/dl-common/services/cacheService.d.ts +0 -14
  38. package/dist/dl-common/services/cacheService.js +0 -77
  39. package/dist/dl-common/services/eventBridgeService.d.ts +0 -8
  40. package/dist/dl-common/services/eventBridgeService.js +0 -40
  41. package/dist/dl-common/services/index.d.ts +0 -3
  42. package/dist/dl-common/services/index.js +0 -20
  43. package/dist/dl-common/services/queueService.d.ts +0 -10
  44. package/dist/dl-common/services/queueService.js +0 -62
  45. package/dist/dl-common/utils/address.d.ts +0 -2
  46. package/dist/dl-common/utils/address.js +0 -8
  47. package/dist/dl-common/utils/axios.d.ts +0 -2
  48. package/dist/dl-common/utils/axios.js +0 -54
  49. package/dist/dl-common/utils/dataStructHelper.d.ts +0 -2
  50. package/dist/dl-common/utils/dataStructHelper.js +0 -10
  51. package/dist/dl-common/utils/discord.d.ts +0 -2
  52. package/dist/dl-common/utils/discord.js +0 -35
  53. package/dist/dl-common/utils/ethersAwsKmsSigner.d.ts +0 -2
  54. package/dist/dl-common/utils/ethersAwsKmsSigner.js +0 -26
  55. package/dist/dl-common/utils/eventGetter.d.ts +0 -4
  56. package/dist/dl-common/utils/eventGetter.js +0 -50
  57. package/dist/dl-common/utils/extraUtils.d.ts +0 -32
  58. package/dist/dl-common/utils/extraUtils.js +0 -103
  59. package/dist/dl-common/utils/idUtils.d.ts +0 -14
  60. package/dist/dl-common/utils/idUtils.js +0 -50
  61. package/dist/dl-common/utils/index.d.ts +0 -13
  62. package/dist/dl-common/utils/index.js +0 -29
  63. package/dist/dl-common/utils/relaySigner.d.ts +0 -21
  64. package/dist/dl-common/utils/relaySigner.js +0 -68
  65. package/dist/dl-common/utils/s3Service.d.ts +0 -5
  66. package/dist/dl-common/utils/s3Service.js +0 -45
  67. package/dist/dl-common/utils/secretManagerService.d.ts +0 -2
  68. package/dist/dl-common/utils/secretManagerService.js +0 -33
  69. package/dist/dl-common/utils/signer/adapter.d.ts +0 -18
  70. package/dist/dl-common/utils/signer/adapter.js +0 -71
  71. package/dist/dl-common/utils/signer/address.d.ts +0 -10
  72. package/dist/dl-common/utils/signer/address.js +0 -42
  73. package/dist/dl-common/utils/signer/asn1-parser.d.ts +0 -11
  74. package/dist/dl-common/utils/signer/asn1-parser.js +0 -80
  75. package/dist/dl-common/utils/signer/crypto.d.ts +0 -6
  76. package/dist/dl-common/utils/signer/crypto.js +0 -34
  77. package/dist/dl-common/utils/signer/index.d.ts +0 -4
  78. package/dist/dl-common/utils/signer/index.js +0 -20
  79. package/dist/dl-common/utils/signer/kms-ethers-signer.d.ts +0 -19
  80. package/dist/dl-common/utils/signer/kms-ethers-signer.js +0 -32
  81. package/dist/dl-common/utils/signer/kms-signer.d.ts +0 -14
  82. package/dist/dl-common/utils/signer/kms-signer.js +0 -46
  83. package/dist/dl-common/utils/signer/signature.d.ts +0 -17
  84. package/dist/dl-common/utils/signer/signature.js +0 -65
  85. package/dist/dl-common/utils/signer/signer.d.ts +0 -7
  86. package/dist/dl-common/utils/signer/signer.js +0 -2
  87. package/dist/dl-common/utils/time.d.ts +0 -2
  88. package/dist/dl-common/utils/time.js +0 -7
  89. package/dist/src/constants/batcherModes.d.ts +0 -7
  90. package/dist/src/constants/batcherModes.js +0 -56
  91. package/dist/src/constants/config.d.ts +0 -39
  92. package/dist/src/constants/config.js +0 -77
  93. package/dist/src/constants/enums.d.ts +0 -21
  94. package/dist/src/constants/enums.js +0 -27
  95. package/dist/src/constants/gasEstimation.d.ts +0 -8
  96. package/dist/src/constants/gasEstimation.js +0 -61
  97. package/dist/src/constants/index.d.ts +0 -11
  98. package/dist/src/constants/index.js +0 -28
  99. package/dist/src/constants/limits.d.ts +0 -21
  100. package/dist/src/constants/limits.js +0 -91
  101. package/dist/src/constants/prometheus.config.d.ts +0 -43
  102. package/dist/src/constants/prometheus.config.js +0 -316
  103. package/dist/src/constants/relayer.d.ts +0 -6
  104. package/dist/src/constants/relayer.js +0 -15
  105. package/dist/src/constants/s3Config.d.ts +0 -13
  106. package/dist/src/constants/s3Config.js +0 -61
  107. package/dist/src/constants/stageConfig.d.ts +0 -7
  108. package/dist/src/constants/stageConfig.js +0 -24
  109. package/dist/src/constants/types.d.ts +0 -45
  110. package/dist/src/constants/types.js +0 -2
  111. package/dist/src/constants/watchers.d.ts +0 -15
  112. package/dist/src/constants/watchers.js +0 -137
  113. package/dist/src/controllers/index.d.ts +0 -0
  114. package/dist/src/controllers/index.js +0 -3
  115. package/dist/src/db/associations.d.ts +0 -1
  116. package/dist/src/db/associations.js +0 -46
  117. package/dist/src/db/connection.d.ts +0 -4
  118. package/dist/src/db/connection.js +0 -73
  119. package/dist/src/db/index.d.ts +0 -2
  120. package/dist/src/db/index.js +0 -18
  121. package/dist/src/db/init.d.ts +0 -2
  122. package/dist/src/db/init.js +0 -27
  123. package/dist/src/handlers/common.d.ts +0 -2
  124. package/dist/src/handlers/common.js +0 -59
  125. package/dist/src/handlers/cronHandler.d.ts +0 -10
  126. package/dist/src/handlers/cronHandler.js +0 -268
  127. package/dist/src/handlers/executeHandler.d.ts +0 -3
  128. package/dist/src/handlers/executeHandler.js +0 -66
  129. package/dist/src/handlers/handler.d.ts +0 -2
  130. package/dist/src/handlers/handler.js +0 -29
  131. package/dist/src/handlers/proposeHandler.d.ts +0 -3
  132. package/dist/src/handlers/proposeHandler.js +0 -69
  133. package/dist/src/handlers/routes.d.ts +0 -2
  134. package/dist/src/handlers/routes.js +0 -26
  135. package/dist/src/handlers/sealHandler.d.ts +0 -4
  136. package/dist/src/handlers/sealHandler.js +0 -245
  137. package/dist/src/handlers/statusHandler.d.ts +0 -5
  138. package/dist/src/handlers/statusHandler.js +0 -116
  139. package/dist/src/handlers/taskHandler.d.ts +0 -2
  140. package/dist/src/handlers/taskHandler.js +0 -110
  141. package/dist/src/handlers/testHandler.d.ts +0 -4
  142. package/dist/src/handlers/testHandler.js +0 -99
  143. package/dist/src/main.d.ts +0 -0
  144. package/dist/src/main.js +0 -12
  145. package/dist/src/relayers/common.d.ts +0 -7
  146. package/dist/src/relayers/common.js +0 -55
  147. package/dist/src/relayers/index.d.ts +0 -2
  148. package/dist/src/relayers/index.js +0 -19
  149. package/dist/src/relayers/proposeRelayer.d.ts +0 -7
  150. package/dist/src/relayers/proposeRelayer.js +0 -587
  151. package/dist/src/relayers/sealRelayer.d.ts +0 -8
  152. package/dist/src/relayers/sealRelayer.js +0 -276
  153. package/dist/src/services/attestService.d.ts +0 -45
  154. package/dist/src/services/attestService.js +0 -269
  155. package/dist/src/services/batcherService.d.ts +0 -9
  156. package/dist/src/services/batcherService.js +0 -197
  157. package/dist/src/services/executeService.d.ts +0 -16
  158. package/dist/src/services/executeService.js +0 -209
  159. package/dist/src/services/gasEstimationService.d.ts +0 -3
  160. package/dist/src/services/gasEstimationService.js +0 -12
  161. package/dist/src/services/index.d.ts +0 -4
  162. package/dist/src/services/index.js +0 -23
  163. package/dist/src/services/indexSealService.d.ts +0 -15
  164. package/dist/src/services/indexSealService.js +0 -120
  165. package/dist/src/services/proposalCheckService.d.ts +0 -9
  166. package/dist/src/services/proposalCheckService.js +0 -119
  167. package/dist/src/services/sealService.d.ts +0 -27
  168. package/dist/src/services/sealService.js +0 -190
  169. package/dist/src/statusTrackers/failedMessage.d.ts +0 -8
  170. package/dist/src/statusTrackers/failedMessage.js +0 -72
  171. package/dist/src/statusTrackers/failedPacket.d.ts +0 -13
  172. package/dist/src/statusTrackers/failedPacket.js +0 -110
  173. package/dist/src/statusTrackers/index.d.ts +0 -3
  174. package/dist/src/statusTrackers/index.js +0 -26
  175. package/dist/src/statusTrackers/message.d.ts +0 -4
  176. package/dist/src/statusTrackers/message.js +0 -257
  177. package/dist/src/statusTrackers/packet.d.ts +0 -33
  178. package/dist/src/statusTrackers/packet.js +0 -477
  179. package/dist/src/utils/chain-utils.d.ts +0 -5
  180. package/dist/src/utils/chain-utils.js +0 -42
  181. package/dist/src/utils/index.d.ts +0 -2
  182. package/dist/src/utils/index.js +0 -18
  183. package/dist/src/utils/logger.d.ts +0 -9
  184. package/dist/src/utils/logger.js +0 -9
  185. package/dist/utils/signer/socketSigner.d.ts +0 -32
  186. package/dist/utils/signer/socketSigner.js +0 -121
@@ -1,276 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.markSealRecentError = exports.isRecentSealError = exports.checkAndSeal = exports.relaySealBatch = exports.relaySeal = void 0;
4
- const utils_1 = require("../utils");
5
- const utils_2 = require("../../dl-common/utils");
6
- const constants_1 = require("../constants");
7
- const models_1 = require("../../dl-common/models");
8
- const sequelize_1 = require("sequelize");
9
- const db_1 = require("../db");
10
- const prometheus_config_1 = require("../constants/prometheus.config");
11
- const services_1 = require("../../dl-common/services");
12
- const common_1 = require("./common");
13
- const recentSealErrorRedisKey = "recentSealError";
14
- const relaySeal = async (chainSlug) => {
15
- if (!constants_1.sealRelayMode) {
16
- (0, utils_1.logInfo)({ info: "SEAL_MODE_DISABLED", messageIds: [], packetIds: [] });
17
- return;
18
- }
19
- const chainSlugs = chainSlug != null ? [chainSlug] : constants_1.supportedChainSlugs;
20
- const packetsPerChain = await getPendingSealPackets(chainSlugs);
21
- await Promise.all(chainSlugs.map(async (chainSlug) => {
22
- var _a;
23
- try {
24
- if (!constants_1.supportedChainSlugs.includes(chainSlug))
25
- return;
26
- if (!((_a = packetsPerChain[chainSlug]) === null || _a === void 0 ? void 0 : _a.length))
27
- return;
28
- (0, utils_1.logInfo)({
29
- info: "SEAL_RELAYING",
30
- chainSlug,
31
- packetIds: packetsPerChain[chainSlug].map((p) => p.packetId),
32
- messageIds: [],
33
- });
34
- const socketAddress = (0, common_1.getSocketAddress)(chainSlug);
35
- const socketBatcher = await (0, common_1.getSocketBatcher)(chainSlug, { type: "sealBatch" }, true);
36
- const recentSealError = await (0, exports.isRecentSealError)();
37
- const packets = packetsPerChain[chainSlug];
38
- // If we faced a recent seal error, send seal txns in separate batches based on dstChainSlug, so 1 dst chain doesnt lead to stuck sealing for all chains
39
- if (recentSealError || constants_1.separateSealRelayMode) {
40
- (0, utils_1.logInfo)({
41
- info: "RELAYING_SEAL_FOR_INDIVIDUAL_SIBLINGS",
42
- reason: recentSealError
43
- ? "recentSealError"
44
- : "separateSealRelayMode",
45
- messageIds: [],
46
- packetIds: [],
47
- });
48
- const dstChainPackets = {};
49
- packets.map((packet) => {
50
- if (!dstChainPackets[packet.dstChainSlug])
51
- dstChainPackets[packet.dstChainSlug] = [];
52
- dstChainPackets[packet.dstChainSlug].push(packet);
53
- });
54
- for (const dstChainSlug in dstChainPackets) {
55
- await (0, exports.relaySealBatch)(chainSlug, socketAddress, socketBatcher, dstChainPackets[dstChainSlug]);
56
- // this is temp solution to avoid nonce issue at relayer. should be solved at relayer.
57
- (0, utils_1.logInfo)({
58
- info: "SEAL_RELAYED",
59
- chainSlug,
60
- packetIds: dstChainPackets[dstChainSlug].map((p) => p.packetId),
61
- messageIds: [],
62
- });
63
- await (0, utils_2.sleep)(1000);
64
- }
65
- }
66
- else {
67
- (0, utils_1.logInfo)({
68
- info: "RELAYING_SEAL_FOR_ALL_SIBLINGS",
69
- messageIds: [],
70
- packetIds: [],
71
- });
72
- await (0, exports.relaySealBatch)(chainSlug, socketAddress, socketBatcher, packets);
73
- (0, utils_1.logInfo)({
74
- info: "SEAL_RELAYED",
75
- chainSlug,
76
- packetIds: packets.map((p) => p.packetId),
77
- messageIds: [],
78
- });
79
- }
80
- }
81
- catch (error) {
82
- console.log(chainSlug, " error in relaySeal: ", error);
83
- }
84
- }));
85
- };
86
- exports.relaySeal = relaySeal;
87
- const relaySealBatch = async (chainSlug, socketAddress, socketBatcher, packets) => {
88
- if (packets && packets.length > 0) {
89
- const packetsAsChunks = [...(0, utils_2.chunks)(packets, constants_1.sealBatchRelayLimit)];
90
- for (const chunk of packetsAsChunks) {
91
- await sendSealBatch(chainSlug, chunk, socketAddress, socketBatcher);
92
- }
93
- }
94
- };
95
- exports.relaySealBatch = relaySealBatch;
96
- const getPendingSealPackets = async (srcChainSlugs) => {
97
- const packets = await models_1.Packet.findAll({
98
- limit: constants_1.sealBatchQueryLimit,
99
- where: {
100
- srcChainSlug: {
101
- [sequelize_1.Op.in]: srcChainSlugs,
102
- },
103
- dstChainSlug: {
104
- [sequelize_1.Op.in]: constants_1.supportedChainSlugs,
105
- },
106
- isFilled: true,
107
- isSealed: false,
108
- sealRelayStatus: {
109
- [sequelize_1.Op.notIn]: [
110
- models_1.SealRelayStatus.SEALED,
111
- models_1.SealRelayStatus.SEALING,
112
- models_1.SealRelayStatus.SEAL_FAILED,
113
- ],
114
- },
115
- },
116
- attributes: [
117
- "id",
118
- "srcChainSlug",
119
- "dstChainSlug",
120
- "packetId",
121
- "root",
122
- "capacitorPacketCount",
123
- "srcCapacitor",
124
- "outboundTime",
125
- "sealSignature",
126
- ],
127
- order: [
128
- [
129
- db_1.attesterDBInst.cast(db_1.attesterDBInst.col("capacitorPacketCount"), "BIGINT"),
130
- "ASC",
131
- ],
132
- ],
133
- });
134
- const packetsPerChain = {};
135
- packets.map((packet) => {
136
- if (!packetsPerChain[packet.srcChainSlug])
137
- packetsPerChain[packet.srcChainSlug] = [];
138
- packetsPerChain[packet.srcChainSlug].push(packet);
139
- });
140
- if (packets.length > 0)
141
- console.log("pending seal packets count: ", packets.length);
142
- return packetsPerChain;
143
- };
144
- const sendSealBatch = async (chainSlug, packets, socketAddress, socketBatcher
145
- // metric: SocketMetric
146
- ) => {
147
- const sealBatchDataArgs = [];
148
- let packetRowIds = [];
149
- let isSuccessful = true;
150
- let txHash = "";
151
- let txId = "";
152
- try {
153
- const metrics = [];
154
- packetRowIds = packets.map((packet) => packet.id);
155
- const packetIds = packets.map((p) => p.packetId);
156
- console.log({ action: "seal", chainSlug, packetIds });
157
- for (const packet of packets) {
158
- if (packet.sealSignature === undefined ||
159
- packet.sealSignature === null ||
160
- packet.sealSignature.length == 0) {
161
- throw {
162
- message: "packet.sealSignature is empty for packet " +
163
- packet.packetId +
164
- " on chain " +
165
- chainSlug +
166
- "!",
167
- };
168
- }
169
- sealBatchDataArgs.push([0, packet.srcCapacitor, packet.sealSignature]);
170
- metrics.push({
171
- labels: {
172
- [prometheus_config_1.Labels.SRC_CHAIN_SLUG]: packet.srcChainSlug,
173
- },
174
- timeDiff: (0, utils_2.currentTimestampInSeconds)() - packet.outboundTime,
175
- });
176
- }
177
- const srcChainSlug = packets[0].srcChainSlug;
178
- if (sealBatchDataArgs.length === 0)
179
- return;
180
- console.log("sending seal batch transaction");
181
- const txn = await socketBatcher.sealBatch(socketAddress, sealBatchDataArgs);
182
- console.log("sent seal batch transaction", txHash);
183
- txHash = txn.hash;
184
- // @ts-expect-error
185
- txId = txn.txId;
186
- metrics.map((m) => {
187
- (0, prometheus_config_1.observeHistogram)(prometheus_config_1.relayMetrics.sealRelay.txDiffHistogram, m);
188
- });
189
- utils_1.logger.info(`seal-batch-relayer completed batch transaction: ${txHash} while sealing on chain: ${srcChainSlug} for ${packets.length} packets`);
190
- }
191
- catch (err) {
192
- utils_1.logger.error("sealBatch: Failed to relay sealBatch for packets", err);
193
- isSuccessful = false;
194
- await (0, exports.markSealRecentError)();
195
- }
196
- // if the seal-batch transaction is successful, then retain the existing status which is `SEALING`
197
- // if the transactionHash exists then it will be updated as `sealTxHash` else it will be empty
198
- try {
199
- const sealRelayStatus = isSuccessful
200
- ? models_1.SealRelayStatus.SEALING
201
- : models_1.SealRelayStatus.NO;
202
- await models_1.Packet.update({
203
- sealTxId: txId,
204
- sealTxHash: txHash,
205
- sealRelayStatus,
206
- }, {
207
- where: {
208
- id: {
209
- [sequelize_1.Op.in]: packetRowIds,
210
- },
211
- },
212
- });
213
- }
214
- catch (err) {
215
- utils_1.logger.error(`Failed to update the transactionHash and isRelaying Status after sealBatch call for srcChainSlug: ${chainSlug}`, err);
216
- }
217
- return txHash;
218
- };
219
- const checkAndSeal = async () => {
220
- var _a, _b, _c;
221
- try {
222
- // check if any pending message on any chain. If found, add message to queue
223
- // and return.
224
- const packetsPerChain = await getPendingSealPackets(constants_1.supportedChainSlugs);
225
- const packetCountPerChain = {};
226
- for (const chainSlug in packetsPerChain) {
227
- if (!((_a = packetsPerChain[chainSlug]) === null || _a === void 0 ? void 0 : _a.length))
228
- continue;
229
- packetCountPerChain[chainSlug] = packetsPerChain[chainSlug].length;
230
- }
231
- for (const chainSlug of constants_1.supportedChainSlugs) {
232
- if (!((_b = packetsPerChain[chainSlug]) === null || _b === void 0 ? void 0 : _b.length))
233
- continue;
234
- (0, utils_1.logInfo)({
235
- info: "QUEUING_SEAL",
236
- chainSlug,
237
- packetCount: (_c = packetsPerChain[chainSlug]) === null || _c === void 0 ? void 0 : _c.length,
238
- packetIds: packetsPerChain[chainSlug].map((p) => p.packetId),
239
- messageIds: [],
240
- });
241
- await (0, services_1.sendStandardSqsMessage)(constants_1.SQS_BASE_URL + constants_1.QueueName.BATCHER_TASK_QUEUE, {
242
- type: constants_1.TaskNames.RELAY_SEAL,
243
- data: {
244
- chainSlug,
245
- counter: Math.floor(Math.random() * 100),
246
- },
247
- });
248
- (0, utils_1.logInfo)({
249
- info: "QUEUED_SEAL",
250
- chainSlug,
251
- packetCountPerChain,
252
- packetIds: packetsPerChain[chainSlug].map((p) => p.packetId),
253
- messageIds: [],
254
- });
255
- // @review why break?
256
- break;
257
- }
258
- }
259
- catch (error) {
260
- console.log("error in checkAndPropose: ", error);
261
- }
262
- };
263
- exports.checkAndSeal = checkAndSeal;
264
- const isRecentSealError = async () => {
265
- // seal can get blocked due to following reasons - seal tx pending, seal tx failed, seal tx reverting. try to cover all the cases here.
266
- const isRecentError = await (0, services_1.getKey)(recentSealErrorRedisKey);
267
- if (isRecentError)
268
- return true;
269
- return false;
270
- };
271
- exports.isRecentSealError = isRecentSealError;
272
- const markSealRecentError = async () => {
273
- console.log("marking recent seal error");
274
- await (0, services_1.setKey)(recentSealErrorRedisKey, Date.now(), 30 * 60);
275
- };
276
- exports.markSealRecentError = markSealRecentError;
@@ -1,45 +0,0 @@
1
- import { type TripReason, AttestSignature, type AttestRequest, type AttestResponse } from "../../dl-common";
2
- import { type PacketProposalCounts, type PacketAttestSignatures, type PacketMessageAttestJoin } from "../constants";
3
- export interface AttestSignatureDbUpdate {
4
- signature: string;
5
- packetId: string;
6
- watcherId: string;
7
- root: string;
8
- proposalCount: number;
9
- }
10
- interface PacketDbUpdates {
11
- packetId: string;
12
- tripReason: TripReason;
13
- }
14
- type PacketRequestData = Record<string, AttestRequest>;
15
- type SignaturesRequiredCount = Record<string, number>;
16
- export declare const getAndSaveAttestSignatures: (packets: PacketMessageAttestJoin[], packetProposalCounts: PacketProposalCounts) => Promise<PacketAttestSignatures>;
17
- export declare const processWatcherSignatures: (watcherId: string, attestSignaturesResponse: AttestResponse[], packetAttestSignatures: PacketAttestSignatures, packetRequestData: PacketRequestData) => Promise<{
18
- watcherAttestSignatureDbUpdates: AttestSignatureDbUpdate[];
19
- watcherPacketDbUpdates: PacketDbUpdates[];
20
- packetAttestSignatures: PacketAttestSignatures;
21
- }>;
22
- export declare const savePacketUpdates: (dbUpdates: PacketDbUpdates[]) => Promise<void>;
23
- export declare const saveAttestSignatureUpdates: (dbUpdates: AttestSignatureDbUpdate[]) => Promise<void>;
24
- export declare const getWatcherRequestData: (packets: PacketMessageAttestJoin[], packetProposalCounts: PacketProposalCounts) => Promise<{
25
- watcherRequestData: Record<string, AttestRequest[]>;
26
- packetRequestData: PacketRequestData;
27
- signaturesRequiredCount: SignaturesRequiredCount;
28
- packetAttestSignatures: PacketAttestSignatures;
29
- }>;
30
- export declare const removePacketsWithIncompleteSignatures: (packetAttestSignatures: PacketAttestSignatures, signaturesRequiredCount: SignaturesRequiredCount) => Promise<PacketAttestSignatures>;
31
- export declare const getWatcherSignatures: (watcherId: string, attestRequests: AttestRequest[]) => Promise<{
32
- success: boolean;
33
- attestSignaturesResponse?: undefined;
34
- } | {
35
- success: boolean;
36
- attestSignaturesResponse: AttestResponse[];
37
- }>;
38
- export declare const findWatcherSignatureInDb: (packetId: string, proposalCount: number, root: string, watcherId: string, currentDBAttestSignatures?: AttestSignature[]) => {
39
- isSignaturePresent: boolean;
40
- signature: string;
41
- } | {
42
- isSignaturePresent: boolean;
43
- signature: null;
44
- };
45
- export {};
@@ -1,269 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findWatcherSignatureInDb = exports.getWatcherSignatures = exports.removePacketsWithIncompleteSignatures = exports.getWatcherRequestData = exports.saveAttestSignatureUpdates = exports.savePacketUpdates = exports.processWatcherSignatures = exports.getAndSaveAttestSignatures = void 0;
4
- const utils_1 = require("../utils");
5
- const dl_common_1 = require("../../dl-common");
6
- const constants_1 = require("../constants");
7
- const dl_core_1 = require("@socket.tech/dl-core");
8
- const watchers_1 = require("../constants/watchers");
9
- const getAndSaveAttestSignatures = async (packets, packetProposalCounts) => {
10
- const attestSignatureDbUpdates = [];
11
- const packetDbUpdates = [];
12
- let watcherAttestSignatureDbUpdates = [];
13
- let watcherPacketDbUpdates = [];
14
- // If attestRelayMode is false, return empty packetAttestSignatures
15
- if (!constants_1.attestRelayMode) {
16
- (0, utils_1.logInfo)({
17
- info: "ATTEST_RELAY_MODE_DISABLED",
18
- messageIds: [],
19
- packetIds: [],
20
- });
21
- return {};
22
- }
23
- const end = constants_1.relayMetrics.attestRelay.signHistogram.startTimer({
24
- [constants_1.Labels.DST_CHAIN_SLUG]: packets[0].dstChainSlug,
25
- });
26
- (0, utils_1.logInfo)({
27
- info: "ATTEST_SIGNATURE_FETCH",
28
- packetIds: packets.map((a) => a.packetId),
29
- messageIds: [],
30
- });
31
- let { watcherRequestData, packetRequestData, signaturesRequiredCount, packetAttestSignatures, } = await (0, exports.getWatcherRequestData)(packets, packetProposalCounts);
32
- await Promise.all(Object.keys(watcherRequestData).map(async (watcherId) => {
33
- const attestRequests = watcherRequestData[watcherId];
34
- const { success, attestSignaturesResponse } = await (0, exports.getWatcherSignatures)(watcherId, attestRequests);
35
- if (!success || !attestSignaturesResponse)
36
- return;
37
- ({
38
- watcherPacketDbUpdates,
39
- watcherAttestSignatureDbUpdates,
40
- packetAttestSignatures,
41
- } = await (0, exports.processWatcherSignatures)(watcherId, attestSignaturesResponse, packetAttestSignatures, packetRequestData));
42
- attestSignatureDbUpdates.push(...watcherAttestSignatureDbUpdates);
43
- packetDbUpdates.push(...watcherPacketDbUpdates);
44
- }));
45
- packetAttestSignatures = await (0, exports.removePacketsWithIncompleteSignatures)(packetAttestSignatures, signaturesRequiredCount);
46
- // console.log({ packetAttestSignatures });
47
- // store attest signatures
48
- await (0, exports.saveAttestSignatureUpdates)(attestSignatureDbUpdates);
49
- await (0, exports.savePacketUpdates)(packetDbUpdates);
50
- end();
51
- (0, utils_1.logInfo)({
52
- info: "ATTEST_SIGNATURE_FETCHED",
53
- packetIds: packets.map((a) => a.packetId),
54
- messageIds: [],
55
- });
56
- // console.log("fetching attest signatures time taken: ", Date.now() - start);
57
- return packetAttestSignatures;
58
- };
59
- exports.getAndSaveAttestSignatures = getAndSaveAttestSignatures;
60
- const processWatcherSignatures = async (watcherId, attestSignaturesResponse, packetAttestSignatures, packetRequestData) => {
61
- const watcherAttestSignatureDbUpdates = [];
62
- const watcherPacketDbUpdates = [];
63
- for (const attestSignature of attestSignaturesResponse) {
64
- const { proposalValid } = attestSignature;
65
- if (proposalValid) {
66
- const { packetId, signature } = attestSignature;
67
- packetAttestSignatures[packetId].push(signature);
68
- const { root, proposalCount } = packetRequestData[packetId];
69
- watcherAttestSignatureDbUpdates.push({
70
- packetId,
71
- signature,
72
- watcherId,
73
- root,
74
- proposalCount,
75
- });
76
- }
77
- else {
78
- const { packetId, reason } = attestSignature;
79
- watcherPacketDbUpdates.push({ packetId, tripReason: reason });
80
- }
81
- }
82
- return {
83
- watcherAttestSignatureDbUpdates,
84
- watcherPacketDbUpdates,
85
- packetAttestSignatures,
86
- };
87
- };
88
- exports.processWatcherSignatures = processWatcherSignatures;
89
- const savePacketUpdates = async (dbUpdates) => {
90
- try {
91
- (0, utils_1.logInfo)({
92
- info: "STORED_TRIP_REASON",
93
- packetIds: dbUpdates.map((a) => a.packetId),
94
- messageIds: [],
95
- });
96
- if (dbUpdates.length === 0)
97
- return;
98
- // TODO: fix this
99
- // @ts-expect-error
100
- await dl_common_1.Packet.bulkCreate(dbUpdates, {
101
- updateOnDuplicate: ["tripReason"],
102
- });
103
- (0, utils_1.logInfo)({
104
- info: "STORED_TRIP_REASON",
105
- packetIds: dbUpdates.map((a) => a.packetId),
106
- messageIds: [],
107
- });
108
- }
109
- catch (error) {
110
- utils_1.logger.error("Error while saving packet trip reason updates", error);
111
- throw new Error(`Error while saving packet trip reason updates ${error === null || error === void 0 ? void 0 : error.message}`);
112
- }
113
- };
114
- exports.savePacketUpdates = savePacketUpdates;
115
- const saveAttestSignatureUpdates = async (dbUpdates) => {
116
- try {
117
- (0, utils_1.logInfo)({
118
- info: "STORING_ATTEST_SIG",
119
- packetIds: dbUpdates.map((a) => a.packetId),
120
- messageIds: [],
121
- });
122
- if (dbUpdates.length === 0)
123
- return;
124
- // TODO: fix this
125
- // @ts-expect-error
126
- await dl_common_1.AttestSignature.bulkCreate(dbUpdates, {
127
- updateOnDuplicate: ["signature", "root"],
128
- });
129
- (0, utils_1.logInfo)({
130
- info: "STORED_ATTEST_SIG",
131
- packetIds: dbUpdates.map((a) => a.packetId),
132
- messageIds: [],
133
- });
134
- }
135
- catch (error) {
136
- utils_1.logger.error("Error while saving new attest signature updates", error);
137
- throw new Error(`Error while saving new attest signature updates ${error === null || error === void 0 ? void 0 : error.message}`);
138
- }
139
- };
140
- exports.saveAttestSignatureUpdates = saveAttestSignatureUpdates;
141
- const getWatcherRequestData = async (packets, packetProposalCounts) => {
142
- const watcherRequestData = {};
143
- const packetRequestData = {};
144
- const signaturesRequiredCount = {};
145
- const packetAttestSignatures = {};
146
- packets.map((packet) => {
147
- if (packet.isAttested) {
148
- return;
149
- }
150
- // If integration type is not fast or fast2, no point in sending request to watcher.
151
- // This might be updated when adding new switchboard types.
152
- if (![dl_core_1.IntegrationTypes.fast, dl_core_1.IntegrationTypes.fast2].includes(packet.integrationType))
153
- return;
154
- if (!packetAttestSignatures[packet.packetId])
155
- packetAttestSignatures[packet.packetId] = [];
156
- const currentDBAttestSignatures = packet.AttestSignatures;
157
- const watcherIds = (0, watchers_1.getWatchers)(packet.srcChainSlug, packet.dstChainSlug, packet.dstSwitchboard);
158
- if (watcherIds.length === 0)
159
- return;
160
- signaturesRequiredCount[packet.packetId] = watcherIds.length;
161
- for (const watcherId of watcherIds) {
162
- if (!watcherRequestData[watcherId])
163
- watcherRequestData[watcherId] = [];
164
- const { dstChainSlug, dstSwitchboard, packetId, root } = packet;
165
- const proposalCount = packetProposalCounts[packetId].count;
166
- const { isSignaturePresent, signature } = (0, exports.findWatcherSignatureInDb)(packetId, proposalCount, root, watcherId, currentDBAttestSignatures);
167
- if (isSignaturePresent && signature) {
168
- packetAttestSignatures[packetId].push(signature);
169
- continue;
170
- }
171
- const requestData = {
172
- packetId,
173
- root,
174
- switchboardAddress: dstSwitchboard,
175
- dstChainSlug,
176
- proposalCount: packetProposalCounts[packetId].count,
177
- };
178
- watcherRequestData[watcherId].push(requestData);
179
- // this might get overwritten, but as same data for all watchers for a packetId, no issues
180
- packetRequestData[packetId] = requestData;
181
- }
182
- });
183
- return {
184
- watcherRequestData,
185
- packetRequestData,
186
- signaturesRequiredCount,
187
- packetAttestSignatures,
188
- };
189
- };
190
- exports.getWatcherRequestData = getWatcherRequestData;
191
- const removePacketsWithIncompleteSignatures = async (packetAttestSignatures, signaturesRequiredCount) => {
192
- const packetIds = Object.keys(packetAttestSignatures);
193
- packetIds.forEach((packetId) => {
194
- const signaturesCount = packetAttestSignatures[packetId].length;
195
- const isEnoughSignatures = signaturesCount === signaturesRequiredCount[packetId];
196
- // remove the packets having incomplete signatures from packetAttestSignatures object
197
- if (!isEnoughSignatures)
198
- delete packetAttestSignatures[packetId];
199
- });
200
- return packetAttestSignatures;
201
- };
202
- exports.removePacketsWithIncompleteSignatures = removePacketsWithIncompleteSignatures;
203
- const getWatcherSignatures = async (watcherId, attestRequests) => {
204
- if (attestRequests.length === 0) {
205
- return { success: false };
206
- }
207
- const { baseUrl, authToken } = watchers_1.watchers[watcherId];
208
- if (!baseUrl) {
209
- console.log("baseUrl not present for watcher: ", watcherId);
210
- return { success: false };
211
- }
212
- const url = baseUrl + "/attest";
213
- (0, utils_1.logInfo)({
214
- info: "FETCH_ATTEST_SIG",
215
- packetIds: attestRequests.map((a) => a.packetId),
216
- url,
217
- watcherId,
218
- messageIds: [],
219
- });
220
- const response = await (0, dl_common_1.axiosPost)(url, attestRequests, {
221
- headers: {
222
- "x-api-key": authToken,
223
- },
224
- });
225
- if (!response.success || !(response === null || response === void 0 ? void 0 : response.result)) {
226
- (0, utils_1.logError)({
227
- info: "ERROR_IN_FETCH_ATTEST_SIG",
228
- packetIds: attestRequests.map((a) => a.packetId),
229
- url,
230
- watcherId,
231
- response,
232
- messageIds: [],
233
- });
234
- return { success: false };
235
- }
236
- (0, utils_1.logInfo)({
237
- info: "FETCHED_ATTEST_SIG",
238
- packetIds: attestRequests.map((a) => a.packetId),
239
- messageIds: [],
240
- });
241
- const attestSignaturesResponse = response === null || response === void 0 ? void 0 : response.result;
242
- return { success: true, attestSignaturesResponse };
243
- };
244
- exports.getWatcherSignatures = getWatcherSignatures;
245
- const findWatcherSignatureInDb = (packetId, proposalCount, root, watcherId, currentDBAttestSignatures) => {
246
- if (currentDBAttestSignatures === null || currentDBAttestSignatures === void 0 ? void 0 : currentDBAttestSignatures.length) {
247
- // number of signatures per packet are going to be small, so this should not affect performance
248
- const watcherSignatures = currentDBAttestSignatures.filter((obj) => obj.watcherId === watcherId &&
249
- obj.proposalCount === proposalCount &&
250
- obj.root === root &&
251
- obj.packetId === packetId);
252
- if (watcherSignatures.length > 0) {
253
- if (watcherSignatures.length === 1)
254
- return {
255
- isSignaturePresent: true,
256
- signature: watcherSignatures[0].signature,
257
- };
258
- const signature = watcherSignatures[0].signature;
259
- for (let i = 1; i < watcherSignatures.length; i++) {
260
- if (watcherSignatures[i].signature !== signature) {
261
- throw new Error("multiple watcher signatures: " + packetId);
262
- }
263
- }
264
- return { isSignaturePresent: true, signature };
265
- }
266
- }
267
- return { isSignaturePresent: false, signature: null };
268
- };
269
- exports.findWatcherSignatureInDb = findWatcherSignatureInDb;
@@ -1,9 +0,0 @@
1
- import { type ChainSlug } from "@socket.tech/dl-core";
2
- import { type PacketAttestSignatures, type PacketProposalCounts, type PacketMessageAttestJoin, type BatchData } from "../constants";
3
- export declare const calculateBatchGasLimit: (dstChainSlug: ChainSlug, currentBatch: BatchData) => Promise<BatchData>;
4
- export declare const checkGasLimitAndAddToBatch: (dstChainSlug: ChainSlug, currentGasLimit: number, currentBatch: BatchData, batchArgsArray: BatchData[]) => Promise<{
5
- currentGasLimit: number;
6
- batchArgsArray: BatchData[];
7
- currentBatch: BatchData;
8
- }>;
9
- export declare const getBatchDataArgs: (packets: PacketMessageAttestJoin[], packetAttestSignatures: PacketAttestSignatures, packetProposalCounts: PacketProposalCounts) => Promise<BatchData[]>;