diff --git a/core/src/main/java/org/bitcoinj/core/Transaction.java b/core/src/main/java/org/bitcoinj/core/Transaction.java index 557896fa7fc..0d4d7bc1631 100644 --- a/core/src/main/java/org/bitcoinj/core/Transaction.java +++ b/core/src/main/java/org/bitcoinj/core/Transaction.java @@ -1159,13 +1159,20 @@ public TransactionConfidence getConfidence(Context context) { public TransactionConfidence getConfidence(TxConfidenceTable table) { TransactionConfidence confidenceInTable = table.getOrCreate(getHash()); if (confidence == null) { + // Use the confidence from the table as that is all we have confidence = confidenceInTable; } else { // Check the confidence in the Context confidence table is the same object if (System.identityHashCode(confidence) != System.identityHashCode(confidenceInTable)) { log.debug("Confidence in tx has identity {} but the one in the confidence table is {}", System.identityHashCode(confidence), System.identityHashCode(confidenceInTable)); - log.debug("Using the one in the confidence table"); - confidence = confidenceInTable; + + if (ConfidenceType.UNKNOWN.equals(confidenceInTable.getConfidenceType())) { + // Do not override an extant confidence if the confidenceType is Unknown + log.debug("Not overriding confidence as confidenceType is Unknown"); + } else { + log.debug("Using the one in the confidence table"); + confidence = confidenceInTable; + } } } log.debug("TransactionConfidence for transaction with hash {} has identity {}", this.getHashAsString(), System.identityHashCode(confidence)); diff --git a/core/src/main/java/org/bitcoinj/store/WalletProtobufSerializer.java b/core/src/main/java/org/bitcoinj/store/WalletProtobufSerializer.java index c4f3a364635..318d55d520f 100644 --- a/core/src/main/java/org/bitcoinj/store/WalletProtobufSerializer.java +++ b/core/src/main/java/org/bitcoinj/store/WalletProtobufSerializer.java @@ -701,6 +701,7 @@ private void readConfidence(Transaction tx, Protos.TransactionConfidence confide confidenceType = ConfidenceType.UNKNOWN; break; } confidence.setConfidenceType(confidenceType); + if (confidenceProto.hasAppearedAtHeight()) { if (confidence.getConfidenceType() != ConfidenceType.BUILDING) { log.warn("Have appearedAtHeight but not BUILDING for tx {}", tx.getHashAsString());