mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 10:45:51 +00:00
Delete broadcastBy data once a tx is buried under >100 blocks, as a memory saving. Remove TODO as the code is fairly clear these days.
This commit is contained in:
parent
3a9a47b67a
commit
0ba5f61c88
@ -339,9 +339,11 @@ public class TransactionConfidence implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* Called by the wallet when the tx appears on the best chain and a new block is added to the top. Updates the
|
* Called by the wallet when the tx appears on the best chain and a new block is added to the top. Updates the
|
||||||
* internal counter that tracks how deeply buried the block is.
|
* internal counter that tracks how deeply buried the block is.
|
||||||
|
*
|
||||||
|
* @return the new depth
|
||||||
*/
|
*/
|
||||||
public synchronized void incrementDepthInBlocks() {
|
public synchronized int incrementDepthInBlocks() {
|
||||||
this.depth++;
|
return ++this.depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -365,6 +367,15 @@ public class TransactionConfidence implements Serializable {
|
|||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erases the set of broadcast/seen peers. This cannot be called whilst the confidence is PENDING. It is useful
|
||||||
|
* for saving memory and wallet space once a tx is buried so deep it doesn't seem likely to go pending again.
|
||||||
|
*/
|
||||||
|
public void clearBroadcastBy() {
|
||||||
|
checkState(getConfidenceType() != ConfidenceType.PENDING);
|
||||||
|
broadcastBy.clear();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this transaction has been overridden by a double spend (is dead), this call returns the overriding transaction.
|
* If this transaction has been overridden by a double spend (is dead), this call returns the overriding transaction.
|
||||||
* Note that this call <b>can return null</b> if you have migrated an old wallet, as pre-Jan 2012 wallets did not
|
* Note that this call <b>can return null</b> if you have migrated an old wallet, as pre-Jan 2012 wallets did not
|
||||||
|
@ -1883,7 +1883,6 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
|||||||
setLastBlockSeenHash(newBlockHash);
|
setLastBlockSeenHash(newBlockHash);
|
||||||
setLastBlockSeenHeight(block.getHeight());
|
setLastBlockSeenHeight(block.getHeight());
|
||||||
setLastBlockSeenTimeSecs(block.getHeader().getTimeSeconds());
|
setLastBlockSeenTimeSecs(block.getHeader().getTimeSeconds());
|
||||||
// TODO: Clarify the code below.
|
|
||||||
// Notify all the BUILDING transactions of the new block.
|
// Notify all the BUILDING transactions of the new block.
|
||||||
// This is so that they can update their depth.
|
// This is so that they can update their depth.
|
||||||
Set<Transaction> transactions = getTransactions(true);
|
Set<Transaction> transactions = getTransactions(true);
|
||||||
@ -1892,9 +1891,20 @@ public class Wallet extends BaseTaggableObject implements Serializable, BlockCha
|
|||||||
// tx was already processed in receive() due to it appearing in this block, so we don't want to
|
// tx was already processed in receive() due to it appearing in this block, so we don't want to
|
||||||
// increment the tx confidence depth twice, it'd result in miscounting.
|
// increment the tx confidence depth twice, it'd result in miscounting.
|
||||||
ignoreNextNewBlock.remove(tx.getHash());
|
ignoreNextNewBlock.remove(tx.getHash());
|
||||||
} else if (tx.getConfidence().getConfidenceType() == ConfidenceType.BUILDING) {
|
} else {
|
||||||
tx.getConfidence().incrementDepthInBlocks();
|
TransactionConfidence confidence = tx.getConfidence();
|
||||||
confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
|
if (confidence.getConfidenceType() == ConfidenceType.BUILDING) {
|
||||||
|
// Erase the set of seen peers once the tx is so deep that it seems unlikely to ever go
|
||||||
|
// pending again. We could clear this data the moment a tx is seen in the block chain, but
|
||||||
|
// in cases where the chain re-orgs, this would mean that wallets would perceive a newly
|
||||||
|
// pending tx has zero confidence at all, which would not be right: we expect it to be
|
||||||
|
// 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() > 100)
|
||||||
|
confidence.clearBroadcastBy();
|
||||||
|
confidenceChanged.put(tx, TransactionConfidence.Listener.ChangeReason.DEPTH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user