Class TxConfidenceTable

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

    • Field Detail

      • lock

        protected final java.util.concurrent.locks.ReentrantLock lock
      • MAX_SIZE

        public static final int MAX_SIZE
        The max size of a table created with the no-args constructor.
        See Also:
        Constant Field Values
    • Constructor Detail

      • TxConfidenceTable

        public TxConfidenceTable​(int size)
        Creates a table that will track at most the given number of transactions (allowing you to bound memory usage).
        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 Detail

      • 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.
        the number of peers that have now announced this hash (including the caller)