In order for filtered block download to function efficiently, the number of matched transactions in any given
* block should be less than (with some headroom) the maximum size of the MemoryPool used by the Peer
- * doing the downloading (default is {@link MemoryPool#MAX_SIZE}). See the comment in processBlock(FilteredBlock)
+ * doing the downloading (default is {@link TxConfidencePool#MAX_SIZE}). See the comment in processBlock(FilteredBlock)
* for more information on this restriction.
*
*
randomNonce is a tweak for the hash function used to prevent some theoretical DoS attacks.
diff --git a/core/src/main/java/org/bitcoinj/core/MemoryPoolMessage.java b/core/src/main/java/org/bitcoinj/core/MemoryPoolMessage.java
index 5c90fbbd..a56d3ecf 100644
--- a/core/src/main/java/org/bitcoinj/core/MemoryPoolMessage.java
+++ b/core/src/main/java/org/bitcoinj/core/MemoryPoolMessage.java
@@ -22,7 +22,7 @@ import java.io.OutputStream;
/**
* The "mempool" message asks a remote peer to announce all transactions in its memory pool, possibly restricted by
* any Bloom filter set on the connection. The list of transaction hashes comes back in an inv message. Note that
- * this is different to the {@link MemoryPool} object which doesn't try to keep track of all pending transactions,
+ * this is different to the {@link TxConfidencePool} object which doesn't try to keep track of all pending transactions,
* it's just a holding area for transactions that a part of the app may find interesting. The mempool message has
* no fields.
*/
diff --git a/core/src/main/java/org/bitcoinj/core/NetworkParameters.java b/core/src/main/java/org/bitcoinj/core/NetworkParameters.java
index a1486d0e..535e98fd 100644
--- a/core/src/main/java/org/bitcoinj/core/NetworkParameters.java
+++ b/core/src/main/java/org/bitcoinj/core/NetworkParameters.java
@@ -77,6 +77,7 @@ public abstract class NetworkParameters implements Serializable {
protected byte[] alertSigningKey;
protected int bip32HeaderPub;
protected int bip32HeaderPriv;
+ transient protected TxConfidencePool confidencePool;
/**
* See getId(). This may be null for old deserialized wallets. In that case we derive it heuristically
@@ -97,6 +98,7 @@ public abstract class NetworkParameters implements Serializable {
protected NetworkParameters() {
alertSigningKey = SATOSHI_KEY;
genesisBlock = createGenesis(this);
+ confidencePool = new TxConfidencePool();
}
private static Block createGenesis(NetworkParameters n) {
@@ -356,4 +358,8 @@ public abstract class NetworkParameters implements Serializable {
public int getBip32HeaderPriv() {
return bip32HeaderPriv;
}
+
+ public TxConfidencePool getConfidencePool() {
+ return confidencePool;
+ }
}
diff --git a/core/src/main/java/org/bitcoinj/core/Peer.java b/core/src/main/java/org/bitcoinj/core/Peer.java
index afe274b1..7329e763 100644
--- a/core/src/main/java/org/bitcoinj/core/Peer.java
+++ b/core/src/main/java/org/bitcoinj/core/Peer.java
@@ -89,7 +89,7 @@ public class Peer extends PeerSocketHandler {
private final AtomicInteger blocksAnnounced = new AtomicInteger();
// A class that tracks recent transactions that have been broadcast across the network, counts how many
// peers announced them and updates the transaction confidence data. It is passed to each Peer.
- private final MemoryPool memoryPool;
+ private final TxConfidencePool confidencePool;
// Each wallet added to the peer will be notified of downloaded transaction data.
private final CopyOnWriteArrayList wallets;
// A time before which we only download block headers, after that point we download block bodies.
@@ -179,7 +179,7 @@ public class Peer extends PeerSocketHandler {
* used to keep track of which peers relayed transactions and offer more descriptive logging.
*/
public Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress,
- @Nullable AbstractBlockChain chain, @Nullable MemoryPool mempool) {
+ @Nullable AbstractBlockChain chain, @Nullable TxConfidencePool mempool) {
this(params, ver, remoteAddress, chain, mempool, true);
}
@@ -198,7 +198,7 @@ public class Peer extends PeerSocketHandler {
* used to keep track of which peers relayed transactions and offer more descriptive logging.
*/
public Peer(NetworkParameters params, VersionMessage ver, PeerAddress remoteAddress,
- @Nullable AbstractBlockChain chain, @Nullable MemoryPool mempool, boolean downloadTxDependencies) {
+ @Nullable AbstractBlockChain chain, @Nullable TxConfidencePool mempool, boolean downloadTxDependencies) {
super(params, remoteAddress);
this.params = Preconditions.checkNotNull(params);
this.versionMessage = Preconditions.checkNotNull(ver);
@@ -211,7 +211,7 @@ public class Peer extends PeerSocketHandler {
this.isAcked = false;
this.pendingPings = new CopyOnWriteArrayList();
this.wallets = new CopyOnWriteArrayList();
- this.memoryPool = mempool;
+ this.confidencePool = mempool;
}
/**
@@ -583,9 +583,9 @@ public class Peer extends PeerSocketHandler {
lock.lock();
try {
log.debug("{}: Received tx {}", getAddress(), tx.getHashAsString());
- if (memoryPool != null) {
+ if (confidencePool != null) {
// We may get back a different transaction object.
- tx = memoryPool.seen(tx, getAddress());
+ tx = confidencePool.seen(tx, getAddress());
}
fTx = tx;
// Label the transaction as coming in from the P2P network (as opposed to being created by us, direct import,
@@ -686,7 +686,7 @@ public class Peer extends PeerSocketHandler {
*
Note that dependencies downloaded this way will not trigger the onTransaction method of event listeners.
*/
public ListenableFuture> downloadDependencies(Transaction tx) {
- checkNotNull(memoryPool, "Must have a configured MemoryPool object to download dependencies.");
+ checkNotNull(confidencePool, "Must have a configured MemoryPool object to download dependencies.");
TransactionConfidence.ConfidenceType txConfidence = tx.getConfidence().getConfidenceType();
Preconditions.checkArgument(txConfidence != TransactionConfidence.ConfidenceType.BUILDING);
log.info("{}: Downloading dependencies of {}", getAddress(), tx.getHashAsString());
@@ -712,7 +712,7 @@ public class Peer extends PeerSocketHandler {
private ListenableFuture