Class: Mempool

mempool.Mempool

new Mempool(options)

Represents a mempool.

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Description
name String <nullable>

Database name.

location String <nullable>

Database file location.

db String <nullable>

Database backend ("memory" by default).

limitFree Boolean <nullable>
limitFreeRelay Number <nullable>
maxSize Number <nullable>

Max pool size (default ~300mb).

relayPriority Boolean <nullable>
requireStandard Boolean <nullable>
rejectAbsurdFees Boolean <nullable>
relay Boolean <nullable>
Properties:
Name Type Description
loaded Boolean
db Object
size Number
totalOrphans Number
locker Lock
freeCount Number
lastTime Number
maxSize Number
minRelayFee Rate
Source:
Fires:
  • Mempool#event:open
  • Mempool#event:error
  • Mempool#event:tx
  • Mempool#event:add tx
  • Mempool#event:remove tx

Methods

(private) _addBlock(block, txs) → {Promise}

Notify the mempool that a new block has come without a lock.

Parameters:
Name Type Description
block ChainEntry
txs Array:.<TX:>
Source:
Returns:
Type
Promise

(private) _addTX(tx) → {Promise}

Add a transaction to the mempool without a lock.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise

(private) _countAncestors(tx, count, set) → {Number}

Traverse ancestors and count.

Parameters:
Name Type Description
tx TX
count Number
set Object
Source:
Returns:
Type
Number

(private) _countDescendants(tx, count, set) → {Number}

Count the highest number of descendants a transaction may have.

Parameters:
Name Type Description
tx TX
count Number
set Object
Source:
Returns:
Type
Number

(private) _getAncestors(tx, entries, set) → {Array:.<MempoolEntry:>}

Get all transaction ancestors.

Parameters:
Name Type Description
tx TX
entries Array:.<MempoolEntry:>
set Object
Source:
Returns:
Type
Array:.<MempoolEntry:>

_getDescendants(tx, entries, set) → {Array:.<MempoolEntry:>}

Get all a transaction descendants.

Parameters:
Name Type Description
tx TX
entries Array:.<MempoolEntry:>
set Object
Source:
Returns:
Type
Array:.<MempoolEntry:>

(private) _removeBlock(block, txs) → {Promise}

Notify the mempool that a block has been disconnected without a lock.

Parameters:
Name Type Description
block ChainEntry
txs Array:.<TX:>
Source:
Returns:
Type
Promise

(private) _reset()

Reset the mempool without a lock.

Source:

addBlock(block, txs) → {Promise}

Notify the mempool that a new block has come in (removes all transactions contained in the block from the mempool).

Parameters:
Name Type Description
block ChainEntry
txs Array:.<TX:>
Source:
Returns:
Type
Promise

addEntry(entry, view) → {Promise}

Add a transaction to the mempool without performing any validation. Note that this method does not lock the mempool and may lend itself to race conditions if used unwisely. This function will also resolve orphans if possible (the resolved orphans will be validated).

Parameters:
Name Type Description
entry MempoolEntry
view CoinView
Source:
Returns:
Type
Promise

addTX(tx) → {Promise}

Add a transaction to the mempool. Note that this will lock the mempool until the transaction is fully processed.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Promise

countAncestors(tx) → {Number}

Count the highest number of ancestors a transaction may have.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Number

countDescendants(tx) → {Number}

Count the highest number of descendants a transaction may have.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Number

(private) exists(hash) → {Boolean}

Test the mempool to see if it contains a transaction or an orphan.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Boolean

findMissing(tx, view) → {Array:.<Hash:>}

Find missing outpoints.

Parameters:
Name Type Description
tx TX
view CoinView
Source:
Returns:
Type
Array:.<Hash:>

getAncestors(tx) → {Array:.<MempoolEntry:>}

Get all transaction ancestors.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Array:.<MempoolEntry:>

getBalance() → {Amount}

Return the full balance of all unspents in the mempool (not very useful in practice, only used for testing).

Source:
Returns:
Type
Amount

getCoin(hash, index) → {Coin}

Retrieve a coin from the mempool (unspents only).

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
Type
Coin

getCoinsByAddress(addresses) → {Array:.<Coin:>}

Find all coins pertaining to a certain address.

Parameters:
Name Type Description
addresses Array:.<Address:>
Source:
Returns:
Type
Array:.<Coin:>

getCoinView(tx, view) → {Promise}

Get coin viewpoint (lock).

Parameters:
Name Type Description
tx TX
view CoinView
Source:
Returns:
  • Returns CoinView.
Type
Promise

getDepends(tx) → {Array:.<Hash:>}

Find a unconfirmed transactions that this transaction depends on.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Array:.<Hash:>

getDescendants(tx) → {Array:.<MempoolEntry:>}

Get all a transaction descendants.

Parameters:
Name Type Description
tx TX
Source:
Returns:
Type
Array:.<MempoolEntry:>

getEntry(hash) → {MempoolEntry}

Retrieve a transaction from the mempool.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
MempoolEntry

getHistory() → {Array:.<TX:>}

Retrieve all transactions from the mempool.

Source:
Returns:
Type
Array:.<TX:>

getMeta(hash) → {TXMeta}

Retrieve a transaction from the mempool.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
TXMeta

getMetaByAddress(addresses) → {Array:.<TXMeta:>}

Find all transactions pertaining to a certain address.

Parameters:
Name Type Description
addresses Array:.<Address:>
Source:
Returns:
Type
Array:.<TXMeta:>

getOrphan(hash) → {TX}

Retrieve an orphan transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
TX

getSize() → {Number}

Calculate the memory usage of the entire mempool.

Source:
See:
  • DynamicMemoryUsage()
Returns:

Usage in bytes.

Type
Number

getSnapshot() → {Array:.<Hash:>}

Get a snapshot of all transaction hashes in the mempool. Used for generating INV packets in response to MEMPOOL packets.

Source:
Returns:
Type
Array:.<Hash:>

getSpent(hash, index) → {MempoolEntry}

Get an output's spender entry.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
Type
MempoolEntry

getSpentTX(hash, index) → {MempoolEntry}

Get an output's spender transaction.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
Type
MempoolEntry

getTX(hash) → {TX}

Retrieve a transaction from the mempool.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
TX

getTXByAddress(addresses) → {Array:.<TX:>}

Find all transactions pertaining to a certain address.

Parameters:
Name Type Description
addresses Array:.<Address:>
Source:
Returns:
Type
Array:.<TX:>

handleOrphans(tx) → {Promise}

Resolve orphans and attempt to add to mempool.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns TX[].
Type
Promise

has(hash) → {Boolean}

Test the mempool to see if it contains a transaction or an orphan.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Boolean

hasOrphan(hash) → {Boolean}

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Boolean

hasReject(hash) → {Boolean}

Test the mempool to see if it contains a recent reject.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Boolean

hasTX(hash) → {Boolean}

Test the mempool to see if it contains a transaction.

Parameters:
Name Type Description
hash Hash
Source:
Returns:
Type
Boolean

(private) indexEntry(entry, view)

Index an entry by address.

Parameters:
Name Type Description
entry MempoolEntry
view CoinView
Source:

isDoubleSpend(tx) → {Promise}

Test all of a transactions outpoints to see if they are doublespends. Note that this will only test against the mempool spents, not the blockchain's. The blockchain spents are not checked against because the blockchain does not maintain a spent list. The transaction will be seen as an orphan rather than a double spend.

Parameters:
Name Type Description
tx TX
Source:
Returns:
  • Returns Boolean.
Type
Promise

isSpent(hash, index) → {Boolean}

Check to see if a coin has been spent. This differs from ChainDB#isSpent in that it actually maintains a map of spent coins, whereas ChainDB may return true for transaction outputs that never existed.

Parameters:
Name Type Description
hash Hash
index Number
Source:
Returns:
Type
Boolean

limitOrphans()

Purge orphan transactions from the mempool.

Source:

limitSize(entryHash) → {Promise}

Ensure the size of the mempool stays below 300mb.

Parameters:
Name Type Description
entryHash Hash

TX that initiated the trim.

Source:
Returns:
Type
Promise

memUsage(tx) → {Number}

Calculate the memory usage of a transaction. Note that this only calculates the JS heap size. Sizes of buffers are ignored (the v8 heap is what we care most about). All numbers are based on the output of v8 heap snapshots of TX objects.

Parameters:
Name Type Description
tx TX
Source:
Returns:

Usage in bytes.

Type
Number

removeBlock(block, txs) → {Promise}

Notify the mempool that a block has been disconnected from the main chain (reinserts transactions into the mempool).

Parameters:
Name Type Description
block ChainEntry
txs Array:.<TX:>
Source:
Returns:
Type
Promise

(private) removeDoubleSpends(tx)

Recursively remove double spenders of a mined transaction's outpoints.

Parameters:
Name Type Description
tx TX
Source:

removeEntry(entry, limit)

Remove a transaction from the mempool. Generally only called when a new block is added to the main chain.

Parameters:
Name Type Description
entry MempoolEntry
limit Boolean
Source:

removeOrphan(tx)

Remove a transaction from the mempool.

Parameters:
Name Type Description
tx Hash
Source:

(private) removeSpenders(entry)

Recursively remove spenders of a transaction.

Parameters:
Name Type Description
entry MempoolEntry
Source:

reset() → {Promise}

Reset the mempool.

Source:
Returns:
Type
Promise

resolveOrphans(tx) → {Array:.<TX:>}

Potentially resolve any transactions that redeem the passed-in transaction. Deletes all orphan entries and returns orphan hashes.

Parameters:
Name Type Description
tx TX
Source:
Returns:

Resolved

Type
Array:.<TX:>

storeOrphan(tx)

Store an orphaned transaction.

Parameters:
Name Type Description
tx TX
Source:

(private) trackEntry(entry, view)

Map a transaction to the mempool.

Parameters:
Name Type Description
entry MempoolEntry
view CoinView
Source:

(private) unindexEntry(entry)

Unindex an entry by address.

Parameters:
Name Type Description
entry MempoolEntry
Source:

(private) untrackEntry(entry)

Unmap a transaction from the mempool.

Parameters:
Name Type Description
entry MempoolEntry
Source:

verify(tx, view) → {Promise}

Verify a transaction with mempool standards.

Parameters:
Name Type Description
tx TX
view CoinView
Source:
Returns:
Type
Promise

verifyFinal(tx, flags) → {Promise}

Check locktime on a transaction against the current tip.

Parameters:
Name Type Description
tx TX
flags LockFlags
Source:
Returns:
  • Returns Boolean.
Type
Promise

verifyInputs(tx, view, flags) → {Promise}

Verify inputs for standard and mandatory flags on failure.

Parameters:
Name Type Description
tx TX
view CoinView
flags VerifyFlags
Source:
Returns:
Type
Promise

verifyLocks(tx, view, flags) → {Promise}

Check sequence locks on a transaction against the current tip.

Parameters:
Name Type Description
tx TX
view CoinView
flags LockFlags
Source:
Returns:
  • Returns Boolean.
Type
Promise

verifyResult(tx, view, flags) → {Promise}

Verify inputs, return a boolean instead of an error based on success.

Parameters:
Name Type Description
tx TX
view CoinView
flags VerifyFlags
Source:
Returns:
Type
Promise