From 6e802197d1ae72e13339695ecd5f8739c35f7485 Mon Sep 17 00:00:00 2001 From: AShulpekov Date: Thu, 28 Apr 2022 21:45:45 +0300 Subject: [PATCH 1/3] MILLIX-172: optimization --- api/P2LMh8NsUTkpWAH3/index.js | 39 +++++++-------------------- api/QISzUVake29059bi/index.js | 10 +++++-- core/wallet/wallet.js | 50 +++++++++++++++++++---------------- 3 files changed, 44 insertions(+), 55 deletions(-) diff --git a/api/P2LMh8NsUTkpWAH3/index.js b/api/P2LMh8NsUTkpWAH3/index.js index 23e1315e..43e7e223 100644 --- a/api/P2LMh8NsUTkpWAH3/index.js +++ b/api/P2LMh8NsUTkpWAH3/index.js @@ -37,36 +37,15 @@ class _P2LMh8NsUTkpWAH3 extends Endpoint { }); } - if (_.isArray(transactionIdList)) { - async.eachSeries(transactionIdList, (transaction, callback) => { - wallet.resetTransactionValidationByTransactionId(transaction) - .then(() => callback()) - .catch((e) => callback(true, e)); - }, (error, exception) => { - if (error) { - res.send({ - api_status : 'fail', - api_message: `unexpected generic api error: (${exception})` - }); - } - else { - res.send({ - api_status: 'success' - }); - } - }); - - } - else { - wallet.resetTransactionValidationByTransactionId(transactionIdList) - .then(() => res.send({ - api_status: 'success' - })) - .catch(e => res.send({ - api_status : 'fail', - api_message: `unexpected generic api error: (${e})` - })); - } + let transactionIdSet = new Set(transactionIdList); + wallet.resetTransactionValidationByTransactionId(transactionIdSet) + .then(() => res.send({ + api_status: 'success' + })) + .catch(e => res.send({ + api_status : 'fail', + api_message: `unexpected generic api error: (${e})` + })); } } diff --git a/api/QISzUVake29059bi/index.js b/api/QISzUVake29059bi/index.js index 6e24397e..2c8fe0be 100644 --- a/api/QISzUVake29059bi/index.js +++ b/api/QISzUVake29059bi/index.js @@ -21,8 +21,14 @@ class _QISzUVake29059bi extends Endpoint { * @returns {*} */ handler(app, req, res) { - wallet.resetTransactionValidationRejected(); - res.send({success: true}); + wallet.resetTransactionValidationRejected() + .then(() => res.send({ + api_status: 'success' + })) + .catch(e => res.send({ + api_status : 'fail', + api_message: `unexpected generic api error: (${e})` + })); } } diff --git a/core/wallet/wallet.js b/core/wallet/wallet.js index b9ce1a65..796588cb 100644 --- a/core/wallet/wallet.js +++ b/core/wallet/wallet.js @@ -689,37 +689,41 @@ class Wallet { return walletTransactionConsensus; } - resetTransactionValidationByTransactionId(transactionID) { + resetTransactionValidationByTransactionId(transactionList) { return database.applyShards(shardID => { - const transactionRepository = database.getRepository('transaction', shardID); - return transactionRepository.getTransactionObject(transactionID) - .then((transaction) => { - if (transaction) { // transaction data not found - return transactionRepository.resetTransaction(transactionID) - .then(() => { - return this.resetValidation(new Set([transaction.transaction_id]), shardID); - }); - } - }); + return this.resetTransactionValidation(new Set(transactionList), shardID); + }); + } + + resetTransactionValidation(transactionSet, shardId) { + return new Promise(resolve => { + const transactionRepository = database.getRepository('transaction', shardId); + async.eachSeries(transactionSet, (transaction, callback) => { + walletTransactionConsensus.removeFromRejectedTransactions(transaction); + walletTransactionConsensus.removeFromRetryTransactions(transaction); + transactionRepository.resetTransaction(transaction) + .then(() => callback()) + .catch(() => { + callback() + }); + }, () => { + this.resetValidation(transactionSet, shardId).then(() => { + resolve(transactionSet); + }); + }); }); + } resetTransactionValidationRejected() { walletTransactionConsensus.resetTransactionValidationRejected(); - database.applyShards(shardID => { + return database.applyShards(shardID => { const transactionRepository = database.getRepository('transaction', shardID); return transactionRepository.listWalletTransactionOutputNotSpent(this.defaultKeyIdentifier) - .then(transactions => new Promise(resolve => { - async.eachSeries(transactions, (transaction, callback) => { - walletTransactionConsensus.removeFromRejectedTransactions(transaction.transaction_id); - walletTransactionConsensus.removeFromRetryTransactions(transaction.transaction_id); - transactionRepository.resetTransaction(transaction.transaction_id) - .then(() => callback()) - .catch(() => callback()); - }, () => resolve(new Set(_.map(transactions, t => t.transaction_id)))); - })) - .then(rootTransactions => this.resetValidation(rootTransactions, shardID)); - }).then(_ => _); + .then(transactions => { + return this.resetTransactionValidation(new Set(_.map(transactions, t => t.transaction_id)), shardID) + }); + }); } resetValidation(rootTransactions, shardID) { From 05c25f5ec073615b8c3ad3c06ffc6c7b937d4e29 Mon Sep 17 00:00:00 2001 From: AShulpekov Date: Fri, 29 Apr 2022 15:04:04 +0300 Subject: [PATCH 2/3] MILLIX-172: optimization --- core/wallet/wallet.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/wallet/wallet.js b/core/wallet/wallet.js index 796588cb..58ff0a95 100644 --- a/core/wallet/wallet.js +++ b/core/wallet/wallet.js @@ -702,12 +702,19 @@ class Wallet { walletTransactionConsensus.removeFromRejectedTransactions(transaction); walletTransactionConsensus.removeFromRetryTransactions(transaction); transactionRepository.resetTransaction(transaction) - .then(() => callback()) + .then(() => { + console.log('[api]', 'resetTransaction success', transaction, shardId) + callback() + }) .catch(() => { + console.log('[api]', 'resetTransaction error', transaction, shardId) callback() }); }, () => { + console.log('[api]', 'resetValidation', transactionSet) + this.resetValidation(transactionSet, shardId).then(() => { + resolve(transactionSet); }); }); @@ -745,9 +752,13 @@ class Wallet { }).catch(() => callback()); }, () => { async.eachSeries(listInputTransactionIdSpendingTransaction, (transactionID, callback) => { - transactionRepository.resetTransaction(transactionID) - .then(() => callback()) - .catch(() => callback()); + if (!visited.has(transactionID)) { + transactionRepository.resetTransaction(transactionID) + .then(() => callback()) + .catch(() => callback()); + } else { + callback(); + } }, () => { if (listInputTransactionIdSpendingTransaction.size > 0) { dfs(listInputTransactionIdSpendingTransaction, visited); From ed0a790232cc47f1f1f7d7917bb9408db103f858 Mon Sep 17 00:00:00 2001 From: AShulpekov Date: Fri, 29 Apr 2022 15:50:56 +0300 Subject: [PATCH 3/3] MILLIX-172: remove console.logs --- core/wallet/wallet.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/core/wallet/wallet.js b/core/wallet/wallet.js index 58ff0a95..5ddd4b7c 100644 --- a/core/wallet/wallet.js +++ b/core/wallet/wallet.js @@ -702,19 +702,10 @@ class Wallet { walletTransactionConsensus.removeFromRejectedTransactions(transaction); walletTransactionConsensus.removeFromRetryTransactions(transaction); transactionRepository.resetTransaction(transaction) - .then(() => { - console.log('[api]', 'resetTransaction success', transaction, shardId) - callback() - }) - .catch(() => { - console.log('[api]', 'resetTransaction error', transaction, shardId) - callback() - }); + .then(() => callback()) + .catch(() => callback()); }, () => { - console.log('[api]', 'resetValidation', transactionSet) - this.resetValidation(transactionSet, shardId).then(() => { - resolve(transactionSet); }); });