Class: Mempool

mempool~Mempool(options)

Mempool Represents a mempool.

Constructor

new Mempool(options)

Create a mempool.

Extends:
  • EventEmitter
Parameters:
Name Type Description
options Object
Source:

Extends

  • EventEmitter

Methods

(async, private) _addAirdrop(proof, idnullable) → {Promise}

Add an airdrop proof to the mempool without a lock.

Parameters:
Name Type Attributes Description
proof AirdropProof
id Number <nullable>
Source:
Returns:
Type
Promise

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

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

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

(async, private) _addClaim(claim, idnullable) → {Promise}

Add a claim to the mempool without a lock.

Parameters:
Name Type Attributes Description
claim Claim
id Number <nullable>
Source:
Returns:
Type
Promise

(async, private) _addTX(tx, idnullable) → {Promise}

Add a transaction to the mempool without a lock.

Parameters:
Name Type Attributes Description
tx TX
id Number <nullable>
Source:
Returns:
Type
Promise

(private) _countAncestors(entry, set, child, map) → {Number}

Traverse ancestors and count.

Parameters:
Name Type Description
entry MempoolEntry
set Object
child MempoolEntry
map function
Source:
Returns:
Type
Number

(private) _countDescendants(entry, set) → {Number}

Count the highest number of descendants a transaction may have.

Parameters:
Name Type Description
entry MempoolEntry
set Object
Source:
Returns:
Type
Number

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

Get all transaction ancestors.

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

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

Get all a transaction descendants.

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

(async, private) _handleReorg() → {Promise}

Sanitize the mempool after a reorg.

Source:
Returns:
Type
Promise

(async, 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

(async, private) _reset()

Reset the mempool without a lock.

Source:

(async) addAirdrop(proof, idnullable) → {Promise}

Add an airdrop proof to the mempool. Note that this will lock the mempool until the transaction is fully processed.

Parameters:
Name Type Attributes Description
proof AirdropProof
id Number <nullable>
Source:
Returns:
Type
Promise

(async) addBlock(block, txs, view) → {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>
view CoinView
Source:
Returns:
Type
Promise

(async) addClaim(claim, idnullable) → {Promise}

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

Parameters:
Name Type Attributes Description
claim Claim
id Number <nullable>
Source:
Returns:
Type
Promise

(async) 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

(async) addTX(tx, idnullable) → {Promise}

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

Parameters:
Name Type Attributes Description
tx TX
id Number <nullable>
Source:
Returns:
Type
Promise

(async) close() → {Promise}

Close the chain, wait for the database to close.

Source:
Returns:
Type
Promise

countAncestors(entry) → {Number}

Count the highest number of ancestors a transaction may have.

Parameters:
Name Type Description
entry MempoolEntry
Source:
Returns:
Type
Number

countDescendants(entry) → {Number}

Count the highest number of descendants a transaction may have.

Parameters:
Name Type Description
entry MempoolEntry
Source:
Returns:
Type
Number

dropAirdrops()

Drop all airdrop proofs.

Source:

dropClaims()

Drop all claims.

Source:

evictEntry(entry)

Remove a transaction from the mempool. Recursively remove its spenders.

Parameters:
Name Type Description
entry MempoolEntry
Source:

(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

getAirdrop(hash) → {TX}

Retrieve a transaction from the mempool.

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

getAncestors(entry) → {Array.<MempoolEntry>}

Get all transaction ancestors.

Parameters:
Name Type Description
entry MempoolEntry
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

getClaim(hash) → {TX}

Retrieve a transaction from the mempool.

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

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(addrs) → {Array.<Coin>}

Find all coins pertaining to a certain address.

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

(async) getCoinView(tx) → {Promise}

Get coin viewpoint (no lock).

Parameters:
Name Type Description
tx TX
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(entry) → {Array.<MempoolEntry>}

Get all a transaction descendants.

Parameters:
Name Type Description
entry MempoolEntry
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(addrs) → {Array.<TXMeta>}

Find all transactions pertaining to a certain address.

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

(async) getNextState() → {DeploymentState}

Get next deployment state.

Source:
Returns:
Type
DeploymentState

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

(async) getSpentView(tx) → {Promise}

Get coin viewpoint (lock).

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

getTX(hash) → {TX}

Retrieve a transaction from the mempool.

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

getTXByAddress(addrs) → {Array.<TX>}

Find all transactions pertaining to a certain address.

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

(async) handleOrphans(parent) → {Promise}

Resolve orphans and attempt to add to mempool.

Parameters:
Name Type Description
parent 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

hasAirdrop(hash) → {Boolean}

Test the mempool to see if it contains an airdrop proof.

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

hasClaim(hash) → {Boolean}

Test the mempool to see if it contains a claim.

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

hasDepends(tx) → {Boolean}

Test whether a transaction has dependencies.

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

hasEntry(hash) → {Boolean}

Test the mempool to see if it contains a transaction.

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

(async) hasHardening() → {Boolean}

Test whether the chain state is hardened.

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

(private) indexEntry(entry, view)

Index an entry by address.

Parameters:
Name Type Description
entry MempoolEntry
view CoinView
Source:

(async, private) insertAirdrop(proof, idnullable) → {Promise}

Add an airdrop proof to the mempool without a lock.

Parameters:
Name Type Attributes Description
proof AirdropProof
id Number <nullable>
Source:
Returns:
Type
Promise

(async, private) insertClaim(claim, idnullable) → {Promise}

Add a claim to the mempool without a lock.

Parameters:
Name Type Attributes Description
claim Claim
id Number <nullable>
Source:
Returns:
Type
Promise

(async, private) insertTX(tx, idnullable) → {Promise}

Add a transaction to the mempool without a lock.

Parameters:
Name Type Attributes Description
tx TX
id Number <nullable>
Source:
Returns:
Type
Promise

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() → {Boolean}

Remove a random orphan transaction from the mempool.

Source:
Returns:
Type
Boolean

limitSize(added) → {Promise}

Ensure the size of the mempool stays below maxSize. Evicts entries by timestamp and cumulative fee rate.

Parameters:
Name Type Description
added MempoolEntry
Source:
Returns:
Type
Promise

maybeOrphan(tx, view, id)

Maybe store an orphaned transaction.

Parameters:
Name Type Description
tx TX
view CoinView
id Number
Source:

(async) open() → {Promise}

Open the chain, wait for the database to load.

Source:
Returns:
Type
Promise

prioritise(entry, pri, fee)

Prioritise transaction.

Parameters:
Name Type Description
entry MempoolEntry
pri Number
fee Amount
Source:

(async) 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) removeDoubleOpens(tx)

Recursively remove double opens.

Parameters:
Name Type Description
tx TX
Source:

(private) removeDoubleSpends(tx)

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

Parameters:
Name Type Description
tx TX
Source:

removeEntry(entry)

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
Source:

removeOrphan(tx) → {Boolean}

Remove a transaction from the mempool.

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

(private) removeSpenders(entry)

Recursively remove spenders of a transaction.

Parameters:
Name Type Description
entry MempoolEntry
Source:

(async) reset() → {Promise}

Reset the mempool.

Source:
Returns:
Type
Promise

resolveOrphans(parent) → {Array.<Orphan>}

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

Parameters:
Name Type Description
parent TX
Source:
Returns:
Type
Array.<Orphan>

trackAirdrop(entry, id)

Track airdrop proof entry.

Parameters:
Name Type Description
entry AirdropEntry
id Number
Source:

trackClaim(entry, id)

Track claim entry.

Parameters:
Name Type Description
entry ClaimEntry
id Number
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:

untrackAirdrop(entry, id)

Untrack airdrop proof entry.

Parameters:
Name Type Description
entry AirdropEntry
id Number
Source:

untrackClaim(entry, id)

Untrack claim entry.

Parameters:
Name Type Description
entry ClaimEntry
id Number
Source:

(private) untrackEntry(entry)

Unmap a transaction from the mempool.

Parameters:
Name Type Description
entry MempoolEntry
Source:

updateAncestors(entry, map) → {Number}

Count the highest number of ancestors a transaction may have. Update descendant fees and size.

Parameters:
Name Type Description
entry MempoolEntry
map function
Source:
Returns:
Type
Number

(async) verify(tx, view) → {Promise}

Verify a transaction with mempool standards.

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

(async) verifyCovenants(tx, view, height, hardened)

Process covenants.

Parameters:
Name Type Description
tx TX
view CoinView
height Number
hardened Boolean
Source:

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

(async) 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

(async) 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