15#include <boost/test/unit_test.hpp>
21#include <unordered_set>
28 util::NotNull pool{std::make_shared<ThreadPool>(
"fetch_test")};
33CBlock CreateBlock() noexcept
35 static constexpr auto NUM_TXS{100};
46 tx.
vin.emplace_back(txid, 0);
59 std::unordered_set<Txid, SaltedCoinsCacheHasher> txids{};
60 txids.reserve(block.
vtx.size() - 1);
62 for (
const auto& in : tx->vin) {
63 if (txids.contains(in.prevout.hash))
continue;
69 cache.AddCoin(in.prevout, std::move(coin),
true);
81 std::unordered_set<Txid, SaltedCoinsCacheHasher> txids{};
82 txids.reserve(block.
vtx.size() - 1);
84 for (
const auto& tx : block.vtx) {
85 if (tx->IsCoinBase()) {
88 for (
const auto& in : tx->vin) {
89 const auto& outpoint{in.prevout};
109 const auto block{CreateBlock()};
115 const auto& outpoint{block.
vtx[1]->vin[0].prevout};
123 for (
const auto& tx : block.
vtx) {
124 for (
const auto& in : tx->
vin) {
137 const auto block{CreateBlock()};
145 const auto& outpoint{block.
vtx[1]->vin[0].prevout};
156 const auto block{CreateBlock()};
164 for (
const auto& tx : block.
vtx) {
165 for (
const auto& in : tx->
vin) {
166 const auto&
c{
view.AccessCoin(in.prevout)};
178 const auto block{CreateBlock()};
183 for (
const auto& tx : block.
vtx) {
184 for (
const auto& in : tx->
vin) {
185 const auto&
c{
view.AccessCoin(in.prevout)};
206 main_cache.AddCoin(outpoint, std::move(coin),
true);
227 const auto block{CreateBlock()};
233 std::unordered_set<Txid, SaltedCoinsCacheHasher> txids;
234 txids.reserve(block.
vtx.size() - 1);
235 for (
const auto& tx : block.
vtx | std::views::drop(1)) {
236 for (
const auto& input : tx->
vin) {
237 if (!txids.contains(input.prevout.hash))
fetched_inputs.push_back(input.prevout);
259 const auto block{CreateBlock()};
265 for (
const bool use_flush : {
false,
true,
false}) {
286 const auto block{CreateBlock()};
299 const auto block{CreateBlock()};
constexpr int32_t DEFAULT_PREVOUTFETCH_THREADS
std::vector< CTransactionRef > vtx
CCoinsView that adds a memory cache for transactions to another CCoinsView.
void SetBestBlock(const uint256 &block_hash)
unsigned int GetCacheSize() const
Size of the cache (in number of transaction outputs)
bool HaveCoinInCache(const COutPoint &outpoint) const
Check if we have the given utxo already loaded in this cache.
const Coin & AccessCoin(const COutPoint &output) const
Return a reference to Coin in the cache, or coinEmpty if not found.
CCoinsView backed by the coin database (chainstate/)
Pure abstract view on the open txout dataset.
An outpoint - a combination of a transaction hash and an index n into its vout.
CTxOut out
unspent transaction output
CCoinsViewCache subclass that asynchronously fetches most block input prevouts in parallel during Con...
ResetGuard StartFetching(const CBlock &block LIFETIMEBOUND) noexcept
Start fetching inputs from block.
static transaction_identifier FromUint256(const uint256 &id)
static const uint256 ZERO
NotNull is intended to be used to denote that a smart pointer type can not hold a nullptr value.
BOOST_AUTO_TEST_CASE(fetch_inputs_from_db)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_GT(excessive_headers.size(), MAX_HEADERS_SIZE)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
A mutable version of CTransaction.
Txid GetHash() const
Compute the hash of this CMutableTransaction.
BOOST_CHECK_NE(OneL.ToString(), ArrayToString(ZeroArray, 32))
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.