@@ -26,36 +26,6 @@ static uint64_t GetBogoSize(const CScript& scriptPubKey)
26
26
scriptPubKey.size () /* scriptPubKey */ ;
27
27
}
28
28
29
- static void ApplyHash (CCoinsStats& stats, CHashWriter& ss, const uint256& hash, const std::map<uint32_t , Coin>& outputs, std::map<uint32_t , Coin>::const_iterator it)
30
- {
31
- if (it == outputs.begin ()) {
32
- ss << hash;
33
- ss << VARINT (it->second .nHeight * 2 + it->second .fCoinBase ? 1u : 0u );
34
- }
35
-
36
- ss << VARINT (it->first + 1 );
37
- ss << it->second .out .scriptPubKey ;
38
- ss << VARINT_MODE (it->second .out .nValue , VarIntMode::NONNEGATIVE_SIGNED);
39
-
40
- if (it == std::prev (outputs.end ())) {
41
- ss << VARINT (0u );
42
- }
43
- }
44
-
45
- static void ApplyHash (CCoinsStats& stats, std::nullptr_t , const uint256& hash, const std::map<uint32_t , Coin>& outputs, std::map<uint32_t , Coin>::const_iterator it) {}
46
-
47
- static void ApplyHash (CCoinsStats& stats, MuHash3072& muhash, const uint256& hash, const std::map<uint32_t , Coin>& outputs, std::map<uint32_t , Coin>::const_iterator it)
48
- {
49
- COutPoint outpoint = COutPoint (hash, it->first );
50
- Coin coin = it->second ;
51
-
52
- CDataStream ss (SER_DISK, PROTOCOL_VERSION);
53
- ss << outpoint;
54
- ss << static_cast <uint32_t >(coin.nHeight * 2 + coin.fCoinBase );
55
- ss << coin.out ;
56
- muhash.Insert (MakeUCharSpan (ss));
57
- }
58
-
59
29
// ! Warning: be very careful when changing this! assumeutxo and UTXO snapshot
60
30
// ! validation commitments are reliant on the hash constructed by this
61
31
// ! function.
@@ -68,14 +38,45 @@ static void ApplyHash(CCoinsStats& stats, MuHash3072& muhash, const uint256& has
68
38
// ! It is also possible, though very unlikely, that a change in this
69
39
// ! construction could cause a previously invalid (and potentially malicious)
70
40
// ! UTXO snapshot to be considered valid.
71
- template <typename T>
72
- static void ApplyStats (CCoinsStats& stats, T& hash_obj, const uint256& hash, const std::map<uint32_t , Coin>& outputs)
41
+ static void ApplyHash (CHashWriter& ss, const uint256& hash, const std::map<uint32_t , Coin>& outputs)
42
+ {
43
+ for (auto it = outputs.begin (); it != outputs.end (); ++it) {
44
+ if (it == outputs.begin ()) {
45
+ ss << hash;
46
+ ss << VARINT (it->second .nHeight * 2 + it->second .fCoinBase ? 1u : 0u );
47
+ }
48
+
49
+ ss << VARINT (it->first + 1 );
50
+ ss << it->second .out .scriptPubKey ;
51
+ ss << VARINT_MODE (it->second .out .nValue , VarIntMode::NONNEGATIVE_SIGNED);
52
+
53
+ if (it == std::prev (outputs.end ())) {
54
+ ss << VARINT (0u );
55
+ }
56
+ }
57
+ }
58
+
59
+ static void ApplyHash (std::nullptr_t , const uint256& hash, const std::map<uint32_t , Coin>& outputs) {}
60
+
61
+ static void ApplyHash (MuHash3072& muhash, const uint256& hash, const std::map<uint32_t , Coin>& outputs)
62
+ {
63
+ for (auto it = outputs.begin (); it != outputs.end (); ++it) {
64
+ COutPoint outpoint = COutPoint (hash, it->first );
65
+ Coin coin = it->second ;
66
+
67
+ CDataStream ss (SER_DISK, PROTOCOL_VERSION);
68
+ ss << outpoint;
69
+ ss << static_cast <uint32_t >(coin.nHeight * 2 + coin.fCoinBase );
70
+ ss << coin.out ;
71
+ muhash.Insert (MakeUCharSpan (ss));
72
+ }
73
+ }
74
+
75
+ static void ApplyStats (CCoinsStats& stats, const uint256& hash, const std::map<uint32_t , Coin>& outputs)
73
76
{
74
77
assert (!outputs.empty ());
75
78
stats.nTransactions ++;
76
79
for (auto it = outputs.begin (); it != outputs.end (); ++it) {
77
- ApplyHash (stats, hash_obj, hash, outputs, it);
78
-
79
80
stats.nTransactionOutputs ++;
80
81
stats.nTotalAmount += it->second .out .nValue ;
81
82
stats.nBogoSize += GetBogoSize (it->second .out .scriptPubKey );
@@ -107,7 +108,8 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats&
107
108
Coin coin;
108
109
if (pcursor->GetKey (key) && pcursor->GetValue (coin)) {
109
110
if (!outputs.empty () && key.hash != prevkey) {
110
- ApplyStats (stats, hash_obj, prevkey, outputs);
111
+ ApplyStats (stats, prevkey, outputs);
112
+ ApplyHash (hash_obj, prevkey, outputs);
111
113
outputs.clear ();
112
114
}
113
115
prevkey = key.hash ;
@@ -119,7 +121,8 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats&
119
121
pcursor->Next ();
120
122
}
121
123
if (!outputs.empty ()) {
122
- ApplyStats (stats, hash_obj, prevkey, outputs);
124
+ ApplyStats (stats, prevkey, outputs);
125
+ ApplyHash (hash_obj, prevkey, outputs);
123
126
}
124
127
125
128
FinalizeHash (hash_obj, stats);
0 commit comments