Class TxConfidenceTable
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.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final ReentrantLock
static final int
The max size of a table created with the no-args constructor. -
Constructor Summary
ConstructorDescriptionCreates a table that will track at mostMAX_SIZE
entries.TxConfidenceTable
(int size) Creates a table that will track at most the given number of transactions (allowing you to bound memory usage). -
Method Summary
Modifier and TypeMethodDescriptionget
(Sha256Hash hash) Returns theTransactionConfidence
for the given hash if we have downloaded it, or null if that tx hash is unknown to the system at this time.getOrCreate
(Sha256Hash hash) Returns theTransactionConfidence
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.seen
(Sha256Hash hash, PeerAddress byPeer) Called by peers when they see a transaction advertised in an "inv" message.
-
Field Details
-
lock
-
MAX_SIZE
public static final int MAX_SIZEThe max size of a table created with the no-args constructor.- See Also:
-
-
Constructor Details
-
TxConfidenceTable
public TxConfidenceTable(int size) Creates a table that will track at most the given number of transactions (allowing you to bound memory usage).- Parameters:
size
- Max number of transactions to track. The table will fill up to this size then stop growing.
-
TxConfidenceTable
public TxConfidenceTable()Creates a table that will track at mostMAX_SIZE
entries. You should normally use this constructor.
-
-
Method Details
-
numBroadcastPeers
Returns the number of peers that have seen the given hash recently. -
seen
Called by peers when they see a transaction advertised in an "inv" message. It passes the data on to the relevantTransactionConfidence
object, creating it if needed.- Returns:
- the number of peers that have now announced this hash (including the caller)
-
getOrCreate
Returns theTransactionConfidence
for the given hash if we have downloaded it, or null if that tx hash is unknown to the system at this time. -
get
Returns theTransactionConfidence
for the given hash if we have downloaded it, or null if that tx hash is unknown to the system at this time.
-