From 9e782688136cb99e43da2085dd370138c30330f1 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 24 Jul 2013 16:17:47 +0200 Subject: [PATCH] Wallet: don't crash if receivePending is called twice with the same tx, even if the override flag is on. --- core/src/main/java/com/google/bitcoin/core/Wallet.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Wallet.java b/core/src/main/java/com/google/bitcoin/core/Wallet.java index b702bed0..c7bd3f2b 100644 --- a/core/src/main/java/com/google/bitcoin/core/Wallet.java +++ b/core/src/main/java/com/google/bitcoin/core/Wallet.java @@ -647,6 +647,13 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi lock.lock(); try { tx.verify(); + // Ignore it if we already know about this transaction. Receiving a pending transaction never moves it + // between pools. + EnumSet containingPools = getContainingPools(tx); + if (!containingPools.equals(EnumSet.noneOf(Pool.class))) { + log.debug("Received tx we already saw in a block or created ourselves: " + tx.getHashAsString()); + return; + } // Repeat the check of relevancy here, even though the caller may have already done so - this is to avoid // race conditions where receivePending may be being called in parallel. if (!overrideIsRelevant && !isPendingTransactionRelevant(tx)) @@ -691,7 +698,7 @@ public class Wallet implements Serializable, BlockChainListener, PeerFilterProvi receivePending(tx, dependencies, false); } - private static AnalysisResult analyzeTransactionAndDependencies(Transaction tx, List dependencies) { + private static AnalysisResult analyzeTransactionAndDependencies(Transaction tx, @Nullable List dependencies) { AnalysisResult result = new AnalysisResult(); if (tx.isTimeLocked()) result.timeLocked = tx;