Commit graph

111 commits

Author SHA1 Message Date
Suhas Daftuar 76a76321d2 Remove work limit in UpdateForDescendants()
The work limit served to prevent the descendant walking algorithm from doing
too much work by marking the parent transaction as dirty.  However to implement
ancestor tracking, it's not possible to similarly mark those descendant
transactions as dirty without having to calculate them to begin with.

This commit removes the work limit altogether.  With appropriate
chain limits (-limitdescendantcount) the concern about doing too much
work inside this function should be mitigated.
2016-03-14 12:13:31 -04:00
Suhas Daftuar 5de2baa138 Rename CTxMemPool::remove -> removeRecursive
remove is no longer called non-recursively, so simplify the logic
and eliminate an unnecessary parameter
2016-03-14 12:11:09 -04:00
Suhas Daftuar 086da92ea7 Add tags to mempool's mapTx indices 2016-02-16 12:35:16 -05:00
Wladimir J. van der Laan 605c17844e
Merge pull request #7205
fa71669 [devtools] Use git pretty-format for year parsing (MarcoFalke)
fa24439 Bump copyright headers to 2015 (MarcoFalke)
fa6ad85 [devtools] Rewrite fix-copyright-headers.py (MarcoFalke)
2016-01-05 14:11:40 +01:00
MarcoFalke fa24439ff3 Bump copyright headers to 2015 2015-12-13 18:08:39 +01:00
Suhas Daftuar eb306664e7 Fix mempool limiting for PrioritiseTransaction
Redo the feerate index to be based on mining score, rather than fee.

Update mempool_packages.py to test prioritisetransaction's effect on
package scores.
2015-12-02 12:59:30 -05:00
Matt Corallo b2e74bd292 Get the set of now-uncacheable-txn from CTxMemPool::TrimToSize 2015-12-01 15:50:39 -08:00
Alex Morcos 1f09287c66 Make accessing mempool parents and children public 2015-12-01 10:10:25 -05:00
Alex Morcos 7230187b1d Add TxPriority class and comparator 2015-12-01 10:10:25 -05:00
Alex Morcos f3fe83673e Add a score index to the mempool.
The score index is meant to represent the order of priority for being included in a block for miners.  Initially this is set to the transactions modified (by any feeDelta) fee rate.  Index improvements and unit tests by sdaftuar.
2015-12-01 10:10:25 -05:00
Alex Morcos c49d5bc9e6 Store the total sig op count of a tx.
Store sum of legacy and P2SH sig op counts.  This is calculated in AcceptToMemory pool and storing it saves redoing the expensive calculation in block template creation.
2015-12-01 10:10:25 -05:00
Suhas Daftuar 2d8860e820 Fix removeForReorg to use MedianTimePast 2015-11-30 14:35:17 -05:00
Suhas Daftuar 7e49f5f8b4 Track coinbase spends in CTxMemPoolEntry
This allows us to optimize CTxMemPool::removeForReorg.
2015-11-30 13:12:53 -05:00
Matt Corallo 9b060e5cfb Fix removal of time-locked transactions during reorg 2015-11-30 13:02:04 -05:00
Alex Morcos c0353064dd Change GetPriority calculation.
Compute the value of inputs that already are in the chain at time of mempool entry and only increase priority due to aging for those inputs.  This effectively changes the CTxMemPoolEntry's GetPriority calculation from an upper bound to a lower bound.
2015-11-19 21:44:35 -05:00
Alex Morcos 71f1d9fd4a Modify variable names for entry height and priority 2015-11-19 21:28:01 -05:00
Alex Morcos 5945819717 Remove default arguments for CTxMemPoolEntry() 2015-11-19 21:28:01 -05:00
Wladimir J. van der Laan 0e935865b9
Merge pull request #6871
63b5840 Fix usage of local python-bitcoinlib (Peter Todd)
16a2f93 Fix incorrect locking of mempool during RBF replacement (Peter Todd)
97203f5 Port test to rpc-test framework (Suhas Daftuar)
20367d8 Add test for max replacement limit (Suhas Daftuar)
73d9040 Improve RBF replacement criteria (Suhas Daftuar)
b272ecf Reject replacements that add new unconfirmed inputs (Peter Todd)
fc8c19a Prevent low feerate txs from (directly) replacing high feerate txs (Peter Todd)
0137e6f Add tests for transaction replacement (Peter Todd)
5891f87 Add opt-in full-RBF to mempool (Peter Todd)
2015-11-27 13:20:39 +01:00
Alex Morcos 22eca7da22 Add smart fee estimation functions
These are more useful fee and priority estimation functions. If there is no fee/pri high enough for the target you are aiming for, it will give you the estimate for the lowest target that you can reliably obtain.  This is better than defaulting to the minimum.  It will also pass back the target for which it returned an answer.
2015-11-16 15:33:06 -05:00
Suhas Daftuar 73d904009d Improve RBF replacement criteria
Fix the calculation of conflicting size/conflicting fees.
2015-11-10 14:14:07 -05:00
Pieter Wuille e9e616323b Make -checkmempool=1 not fail through int32 overflow 2015-10-28 03:07:59 +01:00
Pieter Wuille e06c14fb59
Merge pull request #6776
ab1f560 Support -checkmempool=N, which runs checks on average once every N transactions (Pieter Wuille)
2015-10-28 02:25:06 +01:00
Jonas Schnelli 0d699fc821
fix locking issue with new mempool limiting
Current master crashes on OSX with an exception: "boost: mutex lock failed in pthread_mutex_lock: Invalid argument"
2015-10-26 14:58:17 +01:00
Pieter Wuille ab1f56072a Support -checkmempool=N, which runs checks on average once every N transactions 2015-10-20 18:59:08 +02:00
Matt Corallo 2bc50187ee Fix comment formatting tabs 2015-10-14 12:46:20 -07:00
Matt Corallo 074cb155c2 Add reasonable test case for mempool trimming 2015-10-13 01:39:38 -07:00
Matt Corallo 794a8cec5d Implement on-the-fly mempool size limitation.
After each transaction which is added to mempool, we first call
Expire() to remove old transactions, then throwing away the
lowest-feerate transactions.

After throwing away transactions by feerate, we set the minimum
relay fee to the maximum fee transaction-and-dependant-set we
removed, plus the default minimum relay fee.

After the next block is received, the minimum relay fee is allowed
to decrease exponentially. Its halflife defaults to 12 hours, but
is decreased to 6 hours if the mempool is smaller than half its
maximum size, and 3 hours if the mempool is smaller than a quarter
its maximum size.

The minimum -maxmempool size is 40*-limitdescendantsize, as it is
easy for an attacker to play games with the cheapest
-limitdescendantsize transactions. -maxmempool defaults to 300MB.

This disables high-priority transaction relay when the min relay
fee adjustment is >0 (ie when the mempool is full). When the relay
fee adjustment drops below the default minimum relay fee / 2 it is
set to 0 (re-enabling priority-based free relay).
2015-10-13 01:39:27 -07:00
Matt Corallo e8bcdce8a2 Track (and define) ::minRelayTxFee in CTxMemPool 2015-10-13 01:00:19 -07:00
Matt Corallo 9c9b66f771 Fix calling mempool directly, instead of pool, in ATMP 2015-10-13 00:44:03 -07:00
Pieter Wuille 49b6fd5663 Add Mempool Expire function to remove old transactions
(note the 9x multiplier on (void*)'s for CTxMemPool::DynamicMemoryUsage
 was accidentally introduced in 5add7a7 but should have waited for this
 commit which adds the extra index)
2015-10-13 00:44:03 -07:00
Suhas Daftuar 78b82f4a16 Reverse the sort on the mempool's feerate index 2015-10-13 00:44:03 -07:00
Suhas Daftuar 60de0d5826 Fix mempool package tracking edge case
CalculateMemPoolAncestors was always looping over a transaction's inputs
to find in-mempool parents.  When adding a new transaction, this is the
correct behavior, but when removing a transaction, we want to use the
ancestor set that would be calculated by walking mapLinks (which should
in general be the same set, except during a reorg when the mempool is
in an inconsistent state, and the mapLinks-based calculation would be the
correct one).
2015-09-23 15:30:41 -04:00
Suhas Daftuar 5add7a74a6 Track transaction packages in CTxMemPoolEntry
Associate with each CTxMemPoolEntry all the size/fees of descendant
mempool transactions.  Sort mempool by max(feerate of entry, feerate
of descendants).  Update statistics on-the-fly as transactions enter
or leave the mempool.

Also add ancestor and descendant limiting, so that transactions can
be rejected if the number or size of unconfirmed ancestors exceeds
a target, or if adding a transaction would cause some other mempool
entry to have too many (or too large) a set of unconfirmed in-
mempool descendants.
2015-09-19 13:25:48 -04:00
Ashley Holman 34628a1807 TxMemPool: Change mapTx to a boost::multi_index_container
Indexes on:
- Tx Hash
- Fee Rate (fee-per-kb)
2015-09-19 13:22:40 -04:00
Pieter Wuille 5098c47b24 Implement accurate memory accounting for mempool 2015-07-10 10:49:31 -04:00
Alex Morcos b649e03954 Create new BlockPolicyEstimator for fee estimates
This class groups transactions that have been confirmed in blocks into buckets, based on either their fee or their priority.  Then for each bucket, the class calculates what percentage of the transactions were confirmed within various numbers of blocks.  It does this by keeping an exponentially decaying moving history for each bucket and confirm block count of the percentage of transactions in that bucket that were confirmed within that number of blocks.

-Eliminate txs which didn't have all inputs available at entry from fee/pri calcs

-Add dynamic breakpoints and tracking of confirmation delays in mempool transactions

-Remove old CMinerPolicyEstimator and CBlockAverage code

-New smartfees.py

-Pass a flag to the estimation code, using IsInitialBlockDownload as a proxy for when we are still catching up and we shouldn't be counting how many blocks it takes for transactions to be included.

-Add a policyestimator unit test
2015-05-13 10:36:24 -04:00
sandakersmann f914f1a746
Added "Core" to copyright headers
Github-Pull: #5494
Rebased-From: 15de949bb9277e442302bdd8dee299a8d6deee60
2014-12-19 19:55:32 +01:00
Matt Corallo 723d12c098 Remove txn which are invalidated by coinbase maturity during reorg 2014-12-08 14:05:42 -08:00
Luke Dashjr d227011184 MOVEONLY: core/ -> primitives/ 2014-12-03 10:52:58 +00:00
Cozz Lovan c1c9d5b415 [Qt] Add Smartfee to GUI 2014-11-19 16:04:53 +01:00
Michael Ford 7329fdd1ba Update comments in txmempool to be doxygen compatible
Fix typo in Read() error message
2014-11-17 10:29:09 +08:00
jtimon 4a3587d8db MOVEONLY: Separate CTransaction and dependencies from core 2014-10-27 13:54:37 +01:00
jtimon eda3733091 MOVEONLY: Move CFeeRate and Amount constants to amount.o 2014-10-27 13:54:37 +01:00
Cory Fields fa7361907a boost: split stream classes out of serialize.h
serialization now has no dependencies.
2014-10-22 15:21:06 -04:00
jtimon e8ea0fd19e MOVEONLY: CInPoint from core to txmempool 2014-10-17 01:58:43 +02:00
Pieter Wuille d4a42334d4
Merge pull request #4834
7c70438 Get rid of the dummy CCoinsViewCache constructor arg (Pieter Wuille)
ed27e53 Add coins_tests with a large randomized CCoinViewCache test. (Pieter Wuille)
058b08c Do not keep fully spent but unwritten CCoins entries cached. (Pieter Wuille)
c9d1a81 Get rid of CCoinsView's SetCoins and SetBestBlock. (Pieter Wuille)
f28aec0 Use ModifyCoins instead of mutable GetCoins. (Pieter Wuille)
2014-10-08 14:58:16 -07:00
Mark Friedenbach a372168e77 Use a typedef for monetary values 2014-09-26 15:42:04 -07:00
Pieter Wuille 7c70438dc6 Get rid of the dummy CCoinsViewCache constructor arg 2014-09-24 03:19:04 +02:00
Alex Morcos c26649f9ed Track modified size in TxMemPoolEntry so that we can correctly compute priority. 2014-09-08 11:28:46 -04:00
Philip Kaufmann 093303a887 add missing header end comments
- ensures a consistent usage in header files
- also add a blank line after the copyright header where missing
- also remove orphan new-lines at the end of some files
2014-08-28 22:25:21 +02:00
Daniel Kraft d0867acb0e Use const CCoinsView's at some places.
At some places where it is possible (e. g., CheckInputs), use a const
version of CCoinsView instead of a non-const one.
2014-08-26 11:29:18 +02:00
Daniel Kraft a3dc587a62 Make appropriate getter-routines "const" in CCoinsView.
Mark the "Get"/"Have" routines in CCoinsView and subclasses as "const".
2014-08-26 11:29:18 +02:00
Jeff Garzik 6f2c26a457 Closely track mempool byte total. Add "getmempoolinfo" RPC.
Goal:  Gain live insight into the mempool.  Groundwork for future work
that caps mempool size.
2014-08-14 12:34:38 -04:00
Gavin Andresen 13fc83c77b
Move fee policy out of core 2014-07-03 14:42:16 -04:00
Luke Dashjr 2a72d4591f JSON-RPC method: prioritisetransaction <txid> <priority delta> <priority tx fee>
Accepts the transaction into mined blocks at a higher (or lower) priority
2014-06-26 11:49:46 +00:00
Gavin Andresen 171ca7745e estimatefee / estimatepriority RPC methods
New RPC methods: return an estimate of the fee (or priority) a
transaction needs to be likely to confirm in a given number of
blocks.

Mike Hearn created the first version of this method for estimating fees.
It works as follows:

For transactions that took 1 to N (I picked N=25) blocks to confirm,
keep N buckets with at most 100 entries in each recording the
fees-per-kilobyte paid by those transactions.

(separate buckets are kept for transactions that confirmed because
they are high-priority)

The buckets are filled as blocks are found, and are saved/restored
in a new fee_estiamtes.dat file in the data directory.

A few variations on Mike's initial scheme:

To estimate the fee needed for a transaction to confirm in X buckets,
all of the samples in all of the buckets are used and a median of
all of the data is used to make the estimate. For example, imagine
25 buckets each containing the full 100 entries. Those 2,500 samples
are sorted, and the estimate of the fee needed to confirm in the very
next block is the 50'th-highest-fee-entry in that sorted list; the
estimate of the fee needed to confirm in the next two blocks is the
150'th-highest-fee-entry, etc.

That algorithm has the nice property that estimates of how much fee
you need to pay to get confirmed in block N will always be greater
than or equal to the estimate for block N+1. It would clearly be wrong
to say "pay 11 uBTC and you'll get confirmed in 3 blocks, but pay
12 uBTC and it will take LONGER".

A single block will not contribute more than 10 entries to any one
bucket, so a single miner and a large block cannot overwhelm
the estimates.
2014-06-06 10:44:57 -04:00
Gavin Andresen 93a18a3650 Remove CWalletTx::vfSpent
Use the spent outpoint multimap to figure out which wallet transaction
outputs are unspent, instead of a vfSpent array that is saved
to disk.
2014-02-26 11:53:51 -05:00
Gavin Andresen 4d707d5120 Add verbose boolean to getrawmempool
Also changes mempool to store CTxMemPoolEntries
to keep track of when they enter/exit the pool.
2013-11-30 15:42:10 +10:00
Pieter Wuille a0fa20a12b Move CCoins-related logic to coins.{cpp.h} 2013-11-10 19:37:56 +01:00
Brandon Dahler 51ed9ec971 Cleanup code using forward declarations.
Use misc methods of avoiding unnecesary header includes.
Replace int typedefs with int##_t from stdint.h.
Replace PRI64[xdu] with PRI[xdu]64 from inttypes.h.
Normalize QT_VERSION ifs where possible.
Resolve some indirect dependencies as direct ones.
Remove extern declarations from .cpp files.
2013-11-10 09:36:28 -06:00
Gavin Andresen 319b11607f Refactor: CTxMempool class to its own txmempool.{cpp,h} 2013-11-04 11:27:02 +10:00