public class TxConfidenceTable
extends java.lang.Object
Tracks transactions that are being announced across the network. Typically one is created for you by a
PeerGroup
and then given to each Peer to update. The current purpose is to let Peers update the confidence
(number of peers broadcasting). It helps address an attack scenario in which a malicious remote peer (or several)
feeds you invalid transactions, eg, ones that spend coins which don't exist. If you don't see most of the peers
announce the transaction within a reasonable time, it may be that the TX is not valid. Alternatively, an attacker
may control your entire internet connection: in this scenario counting broadcasting peers does not help you.
It is not at this time directly equivalent to the Bitcoin Core memory pool, which tracks all transactions not currently included in the best chain - it's simply a cache.
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.locks.ReentrantLock |
lock |
static int |
MAX_SIZE
The max size of a table created with the no-args constructor.
|
Constructor and Description |
---|
TxConfidenceTable()
Creates a table that will track at most
MAX_SIZE entries. |
TxConfidenceTable(int size)
Creates a table that will track at most the given number of transactions (allowing you to bound memory
usage).
|
Modifier and Type | Method and Description |
---|---|
TransactionConfidence |
get(Sha256Hash hash)
Returns the
TransactionConfidence for the given hash if we have downloaded it, or null if that tx hash
is unknown to the system at this time. |
TransactionConfidence |
getOrCreate(Sha256Hash hash)
Returns the
TransactionConfidence for the given hash if we have downloaded it, or null if that tx hash
is unknown to the system at this time. |
int |
numBroadcastPeers(Sha256Hash txHash)
Returns the number of peers that have seen the given hash recently.
|
TransactionConfidence |
seen(Sha256Hash hash,
PeerAddress byPeer)
Called by peers when they see a transaction advertised in an "inv" message.
|
protected java.util.concurrent.locks.ReentrantLock lock
public static final int MAX_SIZE
public TxConfidenceTable(int size)
size
- Max number of transactions to track. The table will fill up to this size then stop growing.public TxConfidenceTable()
MAX_SIZE
entries. You should normally use
this constructor.public int numBroadcastPeers(Sha256Hash txHash)
public TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer)
TransactionConfidence
object, creating it if needed.public TransactionConfidence getOrCreate(Sha256Hash hash)
TransactionConfidence
for the given hash if we have downloaded it, or null if that tx hash
is unknown to the system at this time.@Nullable public TransactionConfidence get(Sha256Hash hash)
TransactionConfidence
for the given hash if we have downloaded it, or null if that tx hash
is unknown to the system at this time.