aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorFabian Jahr <fjahr@protonmail.com>2020-01-24 18:56:47 +0100
committerFabian Jahr <fjahr@protonmail.com>2021-04-19 20:28:48 +0200
commitdd58a4de21469d6d848ae309edc47f558628221d (patch)
tree6b914fa5b525d73db702bd454cd7a467fac63a73 /src/node
parenta8a46c4b3cfda4b95c92a36f8cebd3606377e57d (diff)
downloadbitcoin-dd58a4de21469d6d848ae309edc47f558628221d.tar.xz
index: Add Coinstats index
The index holds the values previously calculated in coinstats.cpp for each block, representing the state of the UTXO set at each height.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/coinstats.cpp19
-rw-r--r--src/node/coinstats.h7
2 files changed, 18 insertions, 8 deletions
diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp
index b17a475ca3..a9af53ca80 100644
--- a/src/node/coinstats.cpp
+++ b/src/node/coinstats.cpp
@@ -16,14 +16,22 @@
#include <map>
// Database-independent metric indicating the UTXO set size
-static uint64_t GetBogoSize(const CScript& scriptPubKey)
+uint64_t GetBogoSize(const CScript& script_pub_key)
{
return 32 /* txid */ +
4 /* vout index */ +
4 /* height + coinbase */ +
8 /* amount */ +
2 /* scriptPubKey len */ +
- scriptPubKey.size() /* scriptPubKey */;
+ script_pub_key.size() /* scriptPubKey */;
+}
+
+CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin) {
+ CDataStream ss(SER_DISK, PROTOCOL_VERSION);
+ ss << outpoint;
+ ss << static_cast<uint32_t>(coin.nHeight * 2 + coin.fCoinBase);
+ ss << coin.out;
+ return ss;
}
//! Warning: be very careful when changing this! assumeutxo and UTXO snapshot
@@ -63,12 +71,7 @@ static void ApplyHash(MuHash3072& muhash, const uint256& hash, const std::map<ui
for (auto it = outputs.begin(); it != outputs.end(); ++it) {
COutPoint outpoint = COutPoint(hash, it->first);
Coin coin = it->second;
-
- CDataStream ss(SER_DISK, PROTOCOL_VERSION);
- ss << outpoint;
- ss << static_cast<uint32_t>(coin.nHeight * 2 + coin.fCoinBase);
- ss << coin.out;
- muhash.Insert(MakeUCharSpan(ss));
+ muhash.Insert(MakeUCharSpan(TxOutSer(outpoint, coin)));
}
}
diff --git a/src/node/coinstats.h b/src/node/coinstats.h
index 85896a2a1d..826df2fd73 100644
--- a/src/node/coinstats.h
+++ b/src/node/coinstats.h
@@ -7,6 +7,9 @@
#define BITCOIN_NODE_COINSTATS_H
#include <amount.h>
+#include <chain.h>
+#include <coins.h>
+#include <streams.h>
#include <uint256.h>
#include <cstdint>
@@ -42,4 +45,8 @@ struct CCoinsStats
//! Calculate statistics about the unspent transaction output set
bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, const std::function<void()>& interruption_point = {});
+uint64_t GetBogoSize(const CScript& script_pub_key);
+
+CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin);
+
#endif // BITCOIN_NODE_COINSTATS_H