From 33119a459261ae15d457419bf2fe25a6f515af53 Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 10 Mar 2020 16:19:08 -0700 Subject: [PATCH 1/2] fix(pool): always define wallets on acceptChainedBlock --- .../core-transaction-pool/processor.test.ts | 1 + .../core-transaction-pool/src/connection.ts | 21 +++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/__tests__/integration/core-transaction-pool/processor.test.ts b/__tests__/integration/core-transaction-pool/processor.test.ts index 80af570165..a81a4f2728 100644 --- a/__tests__/integration/core-transaction-pool/processor.test.ts +++ b/__tests__/integration/core-transaction-pool/processor.test.ts @@ -100,6 +100,7 @@ describe("Transaction Guard", () => { const transaction = TransactionFactory.transfer(walletGen.address, 2 * 100000000) .withNetwork("unitnet") + .withNonce(wallet.nonce.plus(1)) .withPassphrase(walletGen.passphrase) .build()[0]; diff --git a/packages/core-transaction-pool/src/connection.ts b/packages/core-transaction-pool/src/connection.ts index f0170b79ad..992e58c11a 100644 --- a/packages/core-transaction-pool/src/connection.ts +++ b/packages/core-transaction-pool/src/connection.ts @@ -216,19 +216,14 @@ export class Connection implements TransactionPool.IConnection { transaction.typeGroup, ); - const senderWallet: State.IWallet = this.walletManager.hasByPublicKey(senderPublicKey) - ? this.walletManager.findByPublicKey(senderPublicKey) - : undefined; - - const recipientWallet: State.IWallet = this.walletManager.hasByAddress(data.recipientId) - ? this.walletManager.findByAddress(data.recipientId) - : undefined; - await transactionHandler.applyToRecipient(transaction, this.walletManager); + const senderWallet: State.IWallet = this.walletManager.findByPublicKey(senderPublicKey); + const recipientWallet: State.IWallet = this.walletManager.findByAddress(data.recipientId); + if (exists) { this.removeTransaction(transaction); - } else if (senderWallet) { + } else { try { await transactionHandler.throwIfCannotBeApplied( transaction, @@ -239,11 +234,9 @@ export class Connection implements TransactionPool.IConnection { } catch (error) { this.walletManager.forget(data.senderPublicKey); - if (recipientWallet) { - recipientWallet.publicKey - ? this.walletManager.forget(recipientWallet.publicKey) - : this.walletManager.forgetByAddress(recipientWallet.address); - } + recipientWallet.publicKey + ? this.walletManager.forget(recipientWallet.publicKey) + : this.walletManager.forgetByAddress(recipientWallet.address); this.logger.error( `[Pool] Cannot apply transaction ${transaction.id} when trying to accept ` + From d7172ed30ee6de69cdf7031729d6b7b15fc0a00e Mon Sep 17 00:00:00 2001 From: Dean Date: Tue, 10 Mar 2020 16:50:49 -0700 Subject: [PATCH 2/2] fix(pool): recipientWallet can be undefined --- packages/core-transaction-pool/src/connection.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/core-transaction-pool/src/connection.ts b/packages/core-transaction-pool/src/connection.ts index 992e58c11a..504db79c3e 100644 --- a/packages/core-transaction-pool/src/connection.ts +++ b/packages/core-transaction-pool/src/connection.ts @@ -219,11 +219,14 @@ export class Connection implements TransactionPool.IConnection { await transactionHandler.applyToRecipient(transaction, this.walletManager); const senderWallet: State.IWallet = this.walletManager.findByPublicKey(senderPublicKey); - const recipientWallet: State.IWallet = this.walletManager.findByAddress(data.recipientId); + + const recipientWallet: State.IWallet = this.walletManager.hasByAddress(data.recipientId) + ? this.walletManager.findByAddress(data.recipientId) + : undefined; if (exists) { this.removeTransaction(transaction); - } else { + } else if (senderWallet) { try { await transactionHandler.throwIfCannotBeApplied( transaction, @@ -234,9 +237,11 @@ export class Connection implements TransactionPool.IConnection { } catch (error) { this.walletManager.forget(data.senderPublicKey); - recipientWallet.publicKey - ? this.walletManager.forget(recipientWallet.publicKey) - : this.walletManager.forgetByAddress(recipientWallet.address); + if (recipientWallet) { + recipientWallet.publicKey + ? this.walletManager.forget(recipientWallet.publicKey) + : this.walletManager.forgetByAddress(recipientWallet.address); + } this.logger.error( `[Pool] Cannot apply transaction ${transaction.id} when trying to accept ` +