@ercworldio/blockchain-shared 1.0.8 → 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.
|
@@ -15,10 +15,24 @@ declare class ScheduleTransactionService {
|
|
|
15
15
|
/**
|
|
16
16
|
* Locks and returns schedule-transaction jobs currently in the "confirming" status for the
|
|
17
17
|
* given blockchain. Unlike the "queued" lockers, this does NOT transition the job's status -
|
|
18
|
-
* the caller decides whether to mark it "completed"
|
|
19
|
-
*
|
|
18
|
+
* the caller decides whether to mark it "completed" once the on-chain transaction has been
|
|
19
|
+
* checked. A job is only eligible while its retry_count is below max_attempts - once a job
|
|
20
|
+
* has failed to confirm that many times it is left alone (still "confirming") rather than
|
|
21
|
+
* picked up again, since re-submitting an already-broadcast withdrawal is not safe.
|
|
20
22
|
*/
|
|
21
|
-
static get_and_lock_confirming_jobs_with_details: (pool: Pool, blockchain: BlockchainType, limit?: number, lock_minutes?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ConfirmingScheduleJob[]>;
|
|
23
|
+
static get_and_lock_confirming_jobs_with_details: (pool: Pool, blockchain: BlockchainType, limit?: number, lock_minutes?: number, max_attempts?: number, lock_metadata?: ClaimJobLockMetadata) => Promise<ConfirmingScheduleJob[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Records a failed confirmation attempt (reverted, RPC error, or never showed up on-chain)
|
|
26
|
+
* without transitioning the job's status - it stays "confirming" so it is never picked back
|
|
27
|
+
* up by the "queued" scheduler. Only retry_count/error_message move, so
|
|
28
|
+
* get_and_lock_confirming_jobs_with_details' max_attempts cap is what eventually stops
|
|
29
|
+
* further confirmation checks.
|
|
30
|
+
*/
|
|
31
|
+
static mark_confirmation_attempt_failed: (pool: Pool, jobs: {
|
|
32
|
+
requestId: number;
|
|
33
|
+
operationType: OperationType;
|
|
34
|
+
error_message?: string;
|
|
35
|
+
}[]) => Promise<void>;
|
|
22
36
|
/**
|
|
23
37
|
* Requeues all jobs in the given status to "queued"
|
|
24
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScheduleTransactionService.d.ts","sourceRoot":"","sources":["../../../../src/services/db/timelock/ScheduleTransactionService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACH,uBAAuB,EACvB,iCAAiC,EACjC,kBAAkB,EAClB,mBAAmB,EACnB,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,cAAM,0BAA0B;IAE5B,MAAM,CAAC,2BAA2B,GAAU,MAAM,IAAI,EAAE,QAAO,MAAW,EAAE,YAAW,MAAY,EAAE,gBAAe,oBAA0F,KAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC,CA4CjP;IAGD,2GAA2G;IAC3G,MAAM,CAAC,wCAAwC,GAC3C,MAAM,IAAI,EACV,QAAO,MAAW,EAClB,YAAW,MAAY,EACvB,gBAAe,oBAA0F,KAC1G,OAAO,CAAC,iCAAiC,EAAE,CAAC,CAqH9C;IAGD,qFAAqF;IACrF,MAAM,CAAC,6CAA6C,GAChD,MAAM,IAAI,EACV,QAAO,MAAW,EAClB,YAAW,MAAY,EACvB,gBAAe,oBAA0F,KAC1G,OAAO,CAAC,iCAAiC,EAAE,CAAC,CAQ9C;IAGD
|
|
1
|
+
{"version":3,"file":"ScheduleTransactionService.d.ts","sourceRoot":"","sources":["../../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U,MAAM,IAAI,EAAE,UAAU,uBAAuB,EAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAmB5F;IAKD;;;;OAIG;IACH,MAAM,CAAC,mBAAmB,GACtB,MAAM,IAAI,EACV,MAAM,MAAM,EACZ,YAAW,MAAW,EACtB,UAAS,kBAAuB,KACjC,OAAO,CAAC,SAAS,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAgE1C;IAGF;;;OAGG;IACH,MAAM,CAAC,sBAAsB,GACzB,MAAM,IAAI,EACV,MAAM,MAAM,EACZ,YAAW,MAAW,EACtB,UAAS,yBAA8B,KACxC,OAAO,CAAC,SAAS,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAqD7C;CAEL;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -176,10 +176,12 @@ ScheduleTransactionService.get_and_lock_available_jobs_with_details_depr = (pool
|
|
|
176
176
|
/**
|
|
177
177
|
* Locks and returns schedule-transaction jobs currently in the "confirming" status for the
|
|
178
178
|
* given blockchain. Unlike the "queued" lockers, this does NOT transition the job's status -
|
|
179
|
-
* the caller decides whether to mark it "completed"
|
|
180
|
-
*
|
|
179
|
+
* the caller decides whether to mark it "completed" once the on-chain transaction has been
|
|
180
|
+
* checked. A job is only eligible while its retry_count is below max_attempts - once a job
|
|
181
|
+
* has failed to confirm that many times it is left alone (still "confirming") rather than
|
|
182
|
+
* picked up again, since re-submitting an already-broadcast withdrawal is not safe.
|
|
181
183
|
*/
|
|
182
|
-
ScheduleTransactionService.get_and_lock_confirming_jobs_with_details = (pool_1, blockchain_1, ...args_1) => __awaiter(void 0, [pool_1, blockchain_1, ...args_1], void 0, function* (pool, blockchain, limit = 10, lock_minutes = 5, lock_metadata = { lock_owner: "schedule-tx-worker", lock_reason: "confirm-schedule-tx" }) {
|
|
184
|
+
ScheduleTransactionService.get_and_lock_confirming_jobs_with_details = (pool_1, blockchain_1, ...args_1) => __awaiter(void 0, [pool_1, blockchain_1, ...args_1], void 0, function* (pool, blockchain, limit = 10, lock_minutes = 5, max_attempts = 5, lock_metadata = { lock_owner: "schedule-tx-worker", lock_reason: "confirm-schedule-tx" }) {
|
|
183
185
|
const res = yield pool.query(`
|
|
184
186
|
WITH candidates AS (
|
|
185
187
|
SELECT j.id
|
|
@@ -188,6 +190,7 @@ ScheduleTransactionService.get_and_lock_confirming_jobs_with_details = (pool_1,
|
|
|
188
190
|
WHERE sjs.status = 'confirming'
|
|
189
191
|
AND j.tx_hash IS NOT NULL
|
|
190
192
|
AND j.blockchain = $1
|
|
193
|
+
AND j.retry_count < $6
|
|
191
194
|
AND (j.lock_expires_at IS NULL OR j.lock_expires_at < NOW())
|
|
192
195
|
ORDER BY j.sent_at ASC NULLS LAST
|
|
193
196
|
LIMIT $2
|
|
@@ -217,9 +220,39 @@ ScheduleTransactionService.get_and_lock_confirming_jobs_with_details = (pool_1,
|
|
|
217
220
|
j.sent_at AS "sentAt",
|
|
218
221
|
j.updated_at AS "updatedAt",
|
|
219
222
|
j.retry_count AS "retryCount";
|
|
220
|
-
`, [blockchain, limit, lock_minutes, lock_metadata.lock_owner, lock_metadata.lock_reason]);
|
|
223
|
+
`, [blockchain, limit, lock_minutes, lock_metadata.lock_owner, lock_metadata.lock_reason, max_attempts]);
|
|
221
224
|
return res.rows;
|
|
222
225
|
});
|
|
226
|
+
/**
|
|
227
|
+
* Records a failed confirmation attempt (reverted, RPC error, or never showed up on-chain)
|
|
228
|
+
* without transitioning the job's status - it stays "confirming" so it is never picked back
|
|
229
|
+
* up by the "queued" scheduler. Only retry_count/error_message move, so
|
|
230
|
+
* get_and_lock_confirming_jobs_with_details' max_attempts cap is what eventually stops
|
|
231
|
+
* further confirmation checks.
|
|
232
|
+
*/
|
|
233
|
+
ScheduleTransactionService.mark_confirmation_attempt_failed = (pool, jobs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
234
|
+
if (jobs.length === 0)
|
|
235
|
+
return;
|
|
236
|
+
const requestIds = jobs.map(j => j.requestId);
|
|
237
|
+
const operationTypes = jobs.map(j => j.operationType);
|
|
238
|
+
const errorMessages = jobs.map(j => { var _b; return (_b = j.error_message) !== null && _b !== void 0 ? _b : null; });
|
|
239
|
+
yield pool.query(`
|
|
240
|
+
UPDATE multisig.schedule_transaction_jobs AS t
|
|
241
|
+
SET
|
|
242
|
+
retry_count = retry_count + 1,
|
|
243
|
+
error_message = COALESCE(c.error_message, t.error_message),
|
|
244
|
+
last_error_at = CURRENT_TIMESTAMP,
|
|
245
|
+
updated_at = CURRENT_TIMESTAMP
|
|
246
|
+
FROM (
|
|
247
|
+
SELECT
|
|
248
|
+
UNNEST($1::int[]) AS request_id,
|
|
249
|
+
UNNEST($2::int[]) AS operation_type,
|
|
250
|
+
UNNEST($3::text[]) AS error_message
|
|
251
|
+
) AS c
|
|
252
|
+
WHERE t.request_id = c.request_id
|
|
253
|
+
AND t.operation_type = c.operation_type
|
|
254
|
+
`, [requestIds, operationTypes, errorMessages]);
|
|
255
|
+
});
|
|
223
256
|
/**
|
|
224
257
|
* Requeues all jobs in the given status to "queued"
|
|
225
258
|
*/
|