Class TxConfidenceTable

java.lang.Object
org.bitcoinj.core.TxConfidenceTable

public class TxConfidenceTable extends 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.

  • Field Details

    • lock

      protected final ReentrantLock lock
    • MAX_SIZE

      public static final int MAX_SIZE
      The 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 most MAX_SIZE entries. You should normally use this constructor.
  • Method Details

    • numBroadcastPeers

      public int numBroadcastPeers(Sha256Hash txHash)
      Returns the number of peers that have seen the given hash recently.
    • seen

      public TransactionConfidence seen(Sha256Hash hash, PeerAddress byPeer)
      Called by peers when they see a transaction advertised in an "inv" message. It passes the data on to the relevant TransactionConfidence object, creating it if needed.
      Returns:
      the number of peers that have now announced this hash (including the caller)
    • getOrCreate

      public 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.
    • get

      @Nullable public 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.