Skip to content

Commit

Permalink
Count confidence relative to latest block height
Browse files Browse the repository at this point in the history
Problem: One transaction can belong to multiple wallets so it would
count the depth twice for each block

Solution: Count depth as current block height - seen block height + 1

Cherry pick bisq-network@6c709b5
  • Loading branch information
sqrrm authored and oscarguindzberg committed Dec 20, 2018
1 parent 9d04071 commit ba5e10f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,9 @@ public synchronized String toString() {
*
* @return the new depth
*/
public synchronized int incrementDepthInBlocks() {
return ++this.depth;
public synchronized int incrementDepthInBlocks(int height) {
this.depth = height - getAppearedAtChainHeight() + 1;
return this.depth;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/bitcoinj/wallet/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2127,7 +2127,7 @@ public void notifyNewBestBlock(StoredBlock block) throws VerificationException {
// included once again. We could have a separate was-in-chain-and-now-isn't confidence type
// but this way is backwards compatible with existing software, and the new state probably
// wouldn't mean anything different to just remembering peers anyway.
if (confidence.incrementDepthInBlocks() > context.getEventHorizon())
if (confidence.incrementDepthInBlocks(block.getHeight()) > context.getEventHorizon())
confidence.clearBroadcastBy();
confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
}
Expand Down

0 comments on commit ba5e10f

Please sign in to comment.