Commit graph

111 commits

Author SHA1 Message Date
Dan Raviv 6efc333ffe
Remove redundant explicitly defined copy ctors
CFeeRate and CTxMemPoolEntry have explicitly defined copy ctors which has
the same functionality as the implicit default copy ctors which would
have been generated otherwise.

Besides being redundant, it violates the rule of three
(see https://en.wikipedia.org/wiki/Rule_of_three_(C%2B%2B_programming) ).
(Of course, the rule of three doesn't -really- cause a resource
management issue here, but the reason for that is exactly that there is
no need for an explicit copy ctor in the first place since no resources
are being managed).

CFeeRate has an explicitly defined copy ctor which has the same
functionality as the implicit default copy ctor which would have been
generated otherwise.

-----------------------------

Cherry-picked from: b426e2467

Note:
Solved conflict where upstream moved CFeeRate into ./policy/
whereas we still have it in amount.h/cpp on 1.14.
2021-08-28 21:07:58 +02:00
Michi Lumin d84837a838 Cherry-pick from Bitcoin repo, 1ec0c0a: small changes for OSX build
Cherry-pick from Bitcoin repo, 1ec0c0a: adds "const" suffix to several lines in txmempool.h and miner.h to make this build succeed under OSX w. clang++ and Boost lib 1.66+
2019-03-25 05:36:12 +00:00
Suhas Daftuar d28d583820 Bugfix: PrioritiseTransaction updates the mempool tx counter
The mempool's nTransactionsUpdated is used by getblocktemplate
to trigger new invocations of CreateNewBlock().

Github-Pull: #10196
Rebased-From: 909306cde3770ed7019e7b635e24cedbd9de66ce
2017-04-19 20:10:02 +00:00
practicalswift cc16d99f1d [trivial] Fix typos in comments 2017-01-27 21:22:35 +01:00
Wladimir J. van der Laan ff25c32392 mempool: add notification for added/removed entries
Add notification signals to make it possible to subscribe to mempool
changes:

- NotifyEntryAdded(CTransactionRef)>
- NotifyEntryRemoved(CTransactionRef, MemPoolRemovalReason)>

Also add a mempool removal reason enumeration, which is passed to the
removed notification based on why the transaction was removed from
the mempool.
2017-01-23 15:43:22 -05:00
Wladimir J. van der Laan dd98f04538
Merge #9380: Separate different uses of minimum fees
eb30d1a Introduce -dustrelayfee (Alex Morcos)
7b1add3 Introduce -incrementalrelayfee (Alex Morcos)
daec955 Introduce -blockmintxfee (Alex Morcos)
2017-01-16 19:33:08 +01:00
Alex Morcos 7b1add3c28 Introduce -incrementalrelayfee 2017-01-16 08:39:03 -05:00
Pieter Wuille f646275b90
Merge #9138: Improve fee estimation
44b64b9 Fix edge case with stale fee estimates (Alex Morcos)
78ae62d Add clarifying comments to fee estimation (Alex Morcos)
5fe0f47 Add extra logging to processBlock in fee estimation. (Alex Morcos)
dc008c4 Add IsCurrentForFeeEstimatation (Alex Morcos)
ebafdca Pass pointers to existing CTxMemPoolEntries to fee estimation (Alex Morcos)
d825838 Always update fee estimates on new blocks. (Alex Morcos)
6f06b26 rename bool to validFeeEstimate (Alex Morcos)
84f7ab0 Remove member variable hadNoDependencies from CTxMemPoolEntry (Alex Morcos)
60ac00d Don't track transactions at all during IBD. (Alex Morcos)
4df4479 Remove extraneous LogPrint from fee estimation (Alex Morcos)
2017-01-05 14:22:19 -08:00
Wladimir J. van der Laan ce43630d1e
Merge #8747: [rpc] Fix transaction size comments and RPC help text.
d29505d Fix transaction size comments. Size now refers to virtual size as defined in BIP141. (jonnynewbs)
2017-01-05 12:06:42 +01:00
Alex Morcos d825838e64 Always update fee estimates on new blocks.
All decisions about whether the transactions are valid data points are made at the time the transaction arrives. Updating on blocks all the time will now cause stale fee estimates to decay quickly when we restart a node.
2017-01-04 12:09:34 -05:00
Alex Morcos 6f06b268c1 rename bool to validFeeEstimate 2017-01-04 12:09:33 -05:00
Alex Morcos 84f7ab08d2 Remove member variable hadNoDependencies from CTxMemPoolEntry
Fee estimation can just check its own mapMemPoolTxs to determine the same information.  Note that now fee estimation for block processing must happen before those transactions are removed, but this shoudl be a speedup.
2017-01-04 12:09:33 -05:00
Wladimir J. van der Laan 869781c51c
Merge #9283: A few more CTransactionRef optimizations
91335ba Remove unused MakeTransactionRef overloads (Pieter Wuille)
6713f0f Make FillBlock consume txn_available to avoid shared_ptr copies (Pieter Wuille)
62607d7 Convert COrphanTx to keep a CTransactionRef (Pieter Wuille)
c44e4c4 Make AcceptToMemoryPool take CTransactionRef (Pieter Wuille)
2017-01-04 12:23:10 +01:00
isle2983 27765b6403 Increment MIT Licence copyright header year on files modified in 2016
Edited via:

$ contrib/devtools/copyright_header.py update .
2016-12-31 11:01:21 -07:00
Pieter Wuille c44e4c467c Make AcceptToMemoryPool take CTransactionRef 2016-12-21 18:18:23 -08:00
Wladimir J. van der Laan 5a70572049
Merge #9262: Prefer coins that have fewer ancestors, sanity check txn before ATMP
cee1612 reduce number of lookups in TransactionWithinChainLimit (Gregory Sanders)
af9bedb Test for fix of txn chaining in wallet (Gregory Sanders)
5882c09 CreateTransaction: Don't return success with too-many-ancestor txn (Gregory Sanders)
0b2294a SelectCoinsMinConf: Prefer coins with fewer ancestors (Gregory Sanders)
2016-12-20 13:27:08 +01:00
Gregory Sanders 0b2294a980 SelectCoinsMinConf: Prefer coins with fewer ancestors 2016-12-13 09:41:04 -05:00
jonnynewbs d29505db22 Fix transaction size comments. Size now refers to virtual size as defined in BIP141. 2016-12-08 17:03:57 +00:00
Alex Morcos a874ab5ccf remove internal tracking of mempool conflicts for reporting to wallet 2016-12-05 13:41:25 -05:00
Alex Morcos bf663f8e93 remove external usage of mempool conflict tracking 2016-12-05 13:41:25 -05:00
fsb4000 15fa95d7e5 Fix some typos 2016-11-28 16:16:37 +07:00
Pieter Wuille b4e4ba475a Introduce convenience type CTransactionRef 2016-11-19 17:53:23 -08:00
Pieter Wuille 1662b437b3 Make CBlock::vtx a vector of shared_ptr<CTransaction> 2016-11-19 17:51:09 -08:00
Pieter Wuille c3efb58622 Add feedelta to TxMempoolInfo 2016-10-30 23:12:09 -07:00
Pieter Wuille 0334430b39 Add some missing includes 2016-10-21 19:22:43 -07:00
Pieter Wuille 4100499db4 Return shared_ptr<CTransaction> from mempool removes 2016-10-21 19:22:43 -07:00
Pieter Wuille 51f278329d Make removed and conflicted arguments optional to remove 2016-10-21 19:22:43 -07:00
Wladimir J. van der Laan 5eaaa83ac1 Kill insecure_random and associated global state
There are only a few uses of `insecure_random` outside the tests.
This PR replaces uses of insecure_random (and its accompanying global
state) in the core code with an FastRandomContext that is automatically
seeded on creation.

This is meant to be used for inner loops. The FastRandomContext
can be in the outer scope, or the class itself, then rand32() is used
inside the loop. Useful e.g. for pushing addresses in CNode or the fee
rounding, or randomization for coin selection.

As a context is created per purpose, thus it gets rid of
cross-thread unprotected shared usage of a single set of globals, this
should also get rid of the potential race conditions.

- I'd say TxMempool::check is not called enough to warrant using a special
  fast random context, this is switched to GetRand() (open for
  discussion...)

- The use of `insecure_rand` in ConnectThroughProxy has been replaced by
  an atomic integer counter. The only goal here is to have a different
  credentials pair for each connection to go on a different Tor circuit,
  it does not need to be random nor unpredictable.

- To avoid having a FastRandomContext on every CNode, the context is
  passed into PushAddress as appropriate.

There remains an insecure_random for test usage in `test_random.h`.
2016-10-17 13:08:35 +02:00
Pieter Wuille 6aa28abf53 Use cmpctblock type 2 for segwit-enabled transfer
Contains version negotiation logic by Matt Corallo and bugfixes by
Suhas Daftuar.
2016-10-04 19:10:41 +02:00
jonnynewbs c14ffd524b [trivial] fix mempool comment (outdated by BIP125) 2016-09-26 08:52:52 -04:00
Suhas Daftuar 2c06bae39e Rename "block cost" to "block weight" 2016-07-18 13:28:26 -04:00
Pieter Wuille 2b1f6f9ccf BIP141: Other consensus critical limits, and BIP145
Includes changes by Suhas Daftuar, Luke-jr, and mruddy.
2016-06-22 15:43:00 +02:00
Matt Corallo 811902649d Provide a flat list of txid/terators to txn in CTxMemPool 2016-06-19 23:06:55 -07:00
Pieter Wuille 288d85ddf2 Get rid of CTxMempool::lookup() entirely 2016-06-07 13:44:56 +02:00
Pieter Wuille 8d39d7a2cf Switch CTransaction storage in mempool to std::shared_ptr 2016-06-05 00:31:43 +02:00
Pieter Wuille a82f03393a
Merge #7997: replace mapNextTx with slimmer setSpends
9805f4a mapNextTx: use pointer as key, simplify value (Kaz Wesley)
2016-06-03 01:26:50 +02:00
Kaz Wesley 9805f4af7e mapNextTx: use pointer as key, simplify value
Saves about 10% of application memory usage once the mempool warms up. Since the
mempool is DynamicUsage-regulated, this will translate to a larger mempool in
the same amount of space.

Map value type: eliminate the vin index; no users of the map need to know which
input of the transaction is spending the prevout.

Map key type: replace the COutPoint with a pointer to a COutPoint. A COutPoint
is 36 bytes, but each COutPoint is accessible from the same map entry's value.
A trivial DereferencingComparator functor allows indirect map keys, but the
resulting syntax is misleading: `map.find(&outpoint)`. Implement an indirectmap
that acts as a wrapper to a map that uses a DereferencingComparator, supporting
a syntax that accurately reflect the container's semantics: inserts and
iterators use pointers since they store pointers and need them to remain
constant and dereferenceable, but lookup functions take const references.
2016-06-02 12:31:51 -07:00
Gregory Maxwell 7e908c7b82 Do not use mempool for GETDATA for tx accepted after the last mempool req.
The ability to GETDATA a transaction which has not (yet) been relayed
 is a privacy loss vector.

The use of the mempool for this was added as part of the mempool p2p
 message and is only needed to fetch transactions returned by it.
2016-05-25 18:05:58 +00:00
Pieter Wuille 8cc9cfe160 Switch CTxMempool::mapTx to use a hash index for txids 2016-05-17 20:04:46 +02:00
Wladimir J. van der Laan 3b9a0bf41f
Merge #7840: Several performance and privacy improvements to inv/mempool handling
b559914 Move bloom and feerate filtering to just prior to tx sending. (Gregory Maxwell)
4578215 Return mempool queries in dependency order (Pieter Wuille)
ed70683 Handle mempool requests in send loop, subject to trickle (Pieter Wuille)
dc13dcd Split up and optimize transaction and block inv queues (Pieter Wuille)
f2d3ba7 Eliminate TX trickle bypass, sort TX invs for privacy and priority. (Gregory Maxwell)
2016-05-05 13:14:40 +02:00
Daniel Kraft f7c4f79f07 [trivial] Add missing const qualifiers.
Add some const qualifiers to references that are not modified and should
be marked as const.
2016-04-30 19:25:00 +02:00
Gregory Maxwell f2d3ba7386 Eliminate TX trickle bypass, sort TX invs for privacy and priority.
Previously Bitcoin would send 1/4 of transactions out to all peers
 instantly.  This causes high overhead because it makes >80% of
 INVs size 1.  Doing so harms privacy, because it limits the
 amount of source obscurity a transaction can receive.

These randomized broadcasts also disobeyed transaction dependencies
 and required use of the orphan pool.  Because the orphan pool is
 so small this leads to poor propagation for dependent transactions.

When the bypass wasn't in effect, transactions were sent in the
 order they were received.  This avoided creating orphans but
 undermines privacy fairly significantly.

This commit:
 Eliminates the bypass. The bypass is replaced by halving the
  average delay for outbound peers.

 Sorts candidate transactions for INV by their topological
  depth then by their feerate (then hash); removing the
  information leakage and providing priority service to
  higher fee transactions.

 Limits the amount of transactions sent in a single INV to
  7tx/sec (and twice that for outbound); this limits the
  harm of low fee transaction floods, gives faster relay
  service to higher fee transactions. The 7 sounds lower
  than it really is because received advertisements need
  not be sent, and because the aggregate rate is multipled
  by the number of peers.
2016-04-20 10:26:37 +02:00
MarcoFalke fada0c422c [doc] Fix doxygen comments for members 2016-04-03 11:58:01 +02:00
Alex Morcos 9e072a6e66 Implement "feefilter" P2P message.
The "feefilter" p2p message is used to inform other nodes of your mempool min fee which is the feerate that any new transaction must meet to be accepted to your mempool.  This will allow them to filter invs to you according to this feerate.
2016-03-21 10:46:25 -04:00
Wladimir J. van der Laan 01f4267623
Merge #7594: Mempool: Add tracking of ancestor packages
ce019bf Check all ancestor state in CTxMemPool::check() (Suhas Daftuar)
e2eeb5d Add ancestor feerate index to mempool (Suhas Daftuar)
72abd2c Add ancestor tracking to mempool (Suhas Daftuar)
76a7632 Remove work limit in UpdateForDescendants() (Suhas Daftuar)
5de2baa Rename CTxMemPool::remove -> removeRecursive (Suhas Daftuar)
7659438 CTxMemPool::removeForBlock now uses RemoveStaged (Suhas Daftuar)
2016-03-17 13:33:54 +01:00
Wladimir J. van der Laan 14d6324a24
Merge #7187: Keep reorgs fast for SequenceLocks checks
982670c Add LockPoints (Alex Morcos)
2016-03-16 21:20:04 +01:00
Alex Morcos 982670c333 Add LockPoints
Obtain LockPoints to store in CTxMemPoolEntry and during a reorg, evaluate whether they are still valid and if not, recalculate them.
2016-03-16 16:11:46 -04:00
Suhas Daftuar ce019bf90f Check all ancestor state in CTxMemPool::check() 2016-03-14 12:13:34 -04:00
Suhas Daftuar e2eeb5dda7 Add ancestor feerate index to mempool 2016-03-14 12:13:34 -04:00
Suhas Daftuar 72abd2ce3c Add ancestor tracking to mempool
This implements caching of ancestor state to each mempool entry, similar to
descendant tracking, but also including caching sigops-with-ancestors (as that
metric will be helpful to future code that implements better transaction
selection in CreatenewBlock).
2016-03-14 12:13:33 -04:00