@clonegod/ttd-sui-common 1.0.43 → 1.0.46

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.
@@ -75,30 +75,35 @@ class SimpleRedisClient {
75
75
  const lock_value = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
76
76
  let retries = 0;
77
77
  let acquired = false;
78
- let first_try_time = Date.now();
79
- let get_lock_time = 0;
78
+ let lock_start_time = Date.now();
79
+ let lock_acquired_time = 0;
80
80
  try {
81
81
  while (retries < this.lockMaxRetries) {
82
82
  acquired = yield this.acquireLock(lock_key, lock_value);
83
- if (acquired)
83
+ if (acquired) {
84
+ lock_acquired_time = Date.now();
84
85
  break;
86
+ }
85
87
  yield new Promise(resolve => setTimeout(resolve, this.lockRetryDelayMs));
88
+ (0, dist_1.log_warn)(`withLock failed: lock_key=${lock_key}, lock_value=${lock_value}, retry times=${retries}`);
86
89
  retries++;
87
90
  }
88
91
  if (acquired) {
89
- get_lock_time = Date.now();
90
92
  return yield callback();
91
93
  }
92
94
  }
93
95
  finally {
94
96
  if (acquired) {
97
+ (0, dist_1.log_info)('start release lock');
95
98
  const release_delay = parseInt(process.env.NONCE_LOCK_RELEASE_DELAY_MS || String(release_lock_delay_ms));
96
- yield (0, dist_1.sleep)(release_delay);
99
+ if (release_delay > 0) {
100
+ yield (0, dist_1.sleep)(release_delay);
101
+ }
97
102
  yield this.releaseLock(lock_key, lock_value);
98
- (0, dist_1.log_info)(`withLock success: lock_key=${lock_key}, lock_value=${lock_value}, retry times=${retries}, get lock take ${get_lock_time - first_try_time}ms, release_delay=${release_delay}ms, hold lock ${Date.now() - get_lock_time}ms`);
103
+ (0, dist_1.log_info)(`withLock success: lock_key=${lock_key}, retry_times=${retries + 1}, get_lock=${lock_acquired_time - lock_start_time}ms, hold_lock=${Date.now() - lock_acquired_time}ms`);
99
104
  }
100
105
  else {
101
- (0, dist_1.log_warn)(`withLock failed: lock_key=${lock_key}, lock_value=${lock_value}, retry times=${retries}, took ${Date.now() - first_try_time}ms`);
106
+ (0, dist_1.log_warn)(`withLock failed: lock_key=${lock_key}, retry_times=${retries + 1}, total_time=${Date.now() - lock_start_time}ms`);
102
107
  }
103
108
  }
104
109
  });
@@ -57,6 +57,7 @@ class TransactionResultChecker extends trade_1.AbstractTransactionResultCheck {
57
57
  }
58
58
  on_subscibe_transaction() {
59
59
  this.event_emitter.once(`SUI_TX_RESULT_${this.txid}`, (response) => __awaiter(this, void 0, void 0, function* () {
60
+ var _a, _b, _c, _d, _e;
60
61
  (0, dist_1.log_info)(`receive tx result notification, txid=${this.txid}`);
61
62
  if (response.transaction) {
62
63
  this.processTransactionResult(response, 'grpc');
@@ -66,7 +67,13 @@ class TransactionResultChecker extends trade_1.AbstractTransactionResultCheck {
66
67
  (0, dist_1.log_info)(`re-fetch tx result by ledgerService start, i=${i}, txid=${this.txid}`);
67
68
  try {
68
69
  let txReceipt = yield this.leadgerService.getTransaction(this.txid, ['*']);
69
- if (txReceipt) {
70
+ if (!txReceipt) {
71
+ continue;
72
+ }
73
+ const success = (_c = (_b = (_a = txReceipt.transaction) === null || _a === void 0 ? void 0 : _a.effects) === null || _b === void 0 ? void 0 : _b.status) === null || _c === void 0 ? void 0 : _c.success;
74
+ const balance_changes = (_e = (_d = txReceipt.transaction) === null || _d === void 0 ? void 0 : _d.balance_changes) === null || _e === void 0 ? void 0 : _e.length;
75
+ const isValidResult = !success || (success && balance_changes.length > 0);
76
+ if (isValidResult) {
70
77
  this.processTransactionResult(txReceipt, 'grpc2');
71
78
  break;
72
79
  }
@@ -22,14 +22,14 @@ class SuiTransactionParser {
22
22
  }
23
23
  parseTransaction(receipt, poolInfo) {
24
24
  return __awaiter(this, void 0, void 0, function* () {
25
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
25
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
26
26
  try {
27
- if (((_c = (_b = (_a = receipt.transaction) === null || _a === void 0 ? void 0 : _a.effects) === null || _b === void 0 ? void 0 : _b.status) === null || _c === void 0 ? void 0 : _c.success) !== true || ((_e = (_d = receipt.transaction) === null || _d === void 0 ? void 0 : _d.balance_changes) === null || _e === void 0 ? void 0 : _e.length) === 0) {
27
+ if (((_c = (_b = (_a = receipt.transaction) === null || _a === void 0 ? void 0 : _a.effects) === null || _b === void 0 ? void 0 : _b.status) === null || _c === void 0 ? void 0 : _c.success) !== true) {
28
28
  console.log('Transaction failed', {
29
- txid: (_f = receipt.transaction) === null || _f === void 0 ? void 0 : _f.digest,
30
- success: (_j = (_h = (_g = receipt.transaction) === null || _g === void 0 ? void 0 : _g.effects) === null || _h === void 0 ? void 0 : _h.status) === null || _j === void 0 ? void 0 : _j.success,
31
- balance_changes: (_l = (_k = receipt.transaction) === null || _k === void 0 ? void 0 : _k.balance_changes) === null || _l === void 0 ? void 0 : _l.length,
32
- reason: (_q = (_p = (_o = (_m = receipt.transaction) === null || _m === void 0 ? void 0 : _m.effects) === null || _o === void 0 ? void 0 : _o.status) === null || _p === void 0 ? void 0 : _p.error) === null || _q === void 0 ? void 0 : _q.kind
29
+ txid: (_d = receipt.transaction) === null || _d === void 0 ? void 0 : _d.digest,
30
+ success: (_g = (_f = (_e = receipt.transaction) === null || _e === void 0 ? void 0 : _e.effects) === null || _f === void 0 ? void 0 : _f.status) === null || _g === void 0 ? void 0 : _g.success,
31
+ balance_changes: (_j = (_h = receipt.transaction) === null || _h === void 0 ? void 0 : _h.balance_changes) === null || _j === void 0 ? void 0 : _j.length,
32
+ reason: (_o = (_m = (_l = (_k = receipt.transaction) === null || _k === void 0 ? void 0 : _k.effects) === null || _l === void 0 ? void 0 : _l.status) === null || _m === void 0 ? void 0 : _m.error) === null || _o === void 0 ? void 0 : _o.kind
33
33
  });
34
34
  throw new Error('Transaction failed');
35
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sui-common",
3
- "version": "1.0.43",
3
+ "version": "1.0.46",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",