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;
66 cache.EmplaceCoinInternalDANGER(in.prevout, std::move(coin));
77 std::unordered_set<Txid, SaltedCoinsCacheHasher> txids{};
78 txids.reserve(block.
vtx.size() - 1);
80 for (
const auto& tx : block.vtx) {
81 if (tx->IsCoinBase()) {
84 for (
const auto& in : tx->vin) {
85 const auto& outpoint{in.prevout};
105 const auto block{CreateBlock()};
111 const auto& outpoint{block.
vtx[1]->vin[0].prevout};
119 for (
const auto& tx : block.
vtx) {
120 for (
const auto& in : tx->
vin) {
133 const auto block{CreateBlock()};
141 const auto& outpoint{block.
vtx[1]->vin[0].prevout};
152 const auto block{CreateBlock()};
160 for (
const auto& tx : block.
vtx) {
161 for (
const auto& in : tx->
vin) {
162 const auto&
c{
view.AccessCoin(in.prevout)};
174 const auto block{CreateBlock()};
179 for (
const auto& tx : block.
vtx) {
180 for (
const auto& in : tx->
vin) {
181 const auto&
c{
view.AccessCoin(in.prevout)};
223 const auto block{CreateBlock()};
229 std::unordered_set<Txid, SaltedCoinsCacheHasher> txids;
230 txids.reserve(block.
vtx.size() - 1);
231 for (
const auto& tx : block.
vtx | std::views::drop(1)) {
232 for (
const auto& input : tx->
vin) {
233 if (!txids.contains(input.prevout.hash))
fetched_inputs.push_back(input.prevout);
255 const auto block{CreateBlock()};
261 for (
const bool use_flush : {
false,
true,
false}) {
282 const auto block{CreateBlock()};
295 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.