v30.3-roots.1 · Commit 3: [PATCH 03/68] feat(policy): preserve Roots relay and network controls on Core 30.3
src/policy/coin_age_priority.cpp
Before: /dev/null · After: src/policy/coin_age_priority.cpp
File metadata
new file mode 100644 index 0000000000000000000000000000000000000000..fd8e962fbdaef4c8bed587b1863cfae77b8c1484
Download original patch · Release notes
Diff rows 1–58 of 58. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. The two line-number columns refer to before and after.
src/policy/coin_age_priority.cpp
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Copyright (c) 2012-2017 The Bitcoin Core developers
|
|
2
|
+
// Distributed under the MIT software license, see the accompanying
|
|
3
|
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
4
|
+
|
|
5
|
+
#include <policy/coin_age_priority.h>
|
|
6
|
+
|
|
7
|
+
#include <coins.h>
|
|
8
|
+
#include <primitives/transaction.h>
|
|
9
|
+
#include <util/check.h>
|
|
10
|
+
|
|
11
|
+
unsigned int CalculateModifiedSize(const CTransaction& tx, unsigned int nTxSize)
|
|
12
|
+
{
|
|
13
|
+
// In order to avoid disincentivizing cleaning up the UTXO set we don't count
|
|
14
|
+
// the constant overhead for each txin and up to 110 bytes of scriptSig (which
|
|
15
|
+
// is enough to cover a compressed pubkey p2sh redemption) for priority.
|
|
16
|
+
// Providing any more cleanup incentive than making additional inputs free would
|
|
17
|
+
// risk encouraging people to create junk outputs to redeem later.
|
|
18
|
+
Assert(nTxSize > 0);
|
|
19
|
+
for (std::vector<CTxIn>::const_iterator it(tx.vin.begin()); it != tx.vin.end(); ++it)
|
|
20
|
+
{
|
|
21
|
+
unsigned int offset = 41U + std::min(110U, (unsigned int)it->scriptSig.size());
|
|
22
|
+
if (nTxSize > offset)
|
|
23
|
+
nTxSize -= offset;
|
|
24
|
+
}
|
|
25
|
+
return nTxSize;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
double ComputePriority2(double inputs_coin_age, unsigned int mod_vsize)
|
|
29
|
+
{
|
|
30
|
+
if (mod_vsize == 0) return 0.0;
|
|
31
|
+
|
|
32
|
+
return inputs_coin_age / mod_vsize;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
double ReversePriority2(const double coin_age_priority, const unsigned int mod_vsize)
|
|
36
|
+
{
|
|
37
|
+
return coin_age_priority * mod_vsize;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
CoinAgeCache GetCoinAge(const CTransaction &tx, const CCoinsViewCache& view, int nHeight)
|
|
41
|
+
{
|
|
42
|
+
CoinAgeCache r{COIN_AGE_CACHE_ZERO};
|
|
43
|
+
if (tx.IsCoinBase()) {
|
|
44
|
+
return r;
|
|
45
|
+
}
|
|
46
|
+
for (const CTxIn& txin : tx.vin)
|
|
47
|
+
{
|
|
48
|
+
const Coin& coin = view.AccessCoin(txin.prevout);
|
|
49
|
+
if (coin.IsSpent()) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (coin.nHeight <= nHeight) {
|
|
53
|
+
r.inputs_coin_age += (double)(coin.out.nValue) * (nHeight - coin.nHeight);
|
|
54
|
+
r.in_chain_input_value += coin.out.nValue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return r;
|
|
58
|
+
}
|