Bitcoin Core 32.1.0
P2P Digital Currency
Loading...
Searching...
No Matches
coinscache_sim.cpp File Reference
#include <coins.h>
#include <crypto/sha256.h>
#include <kernel/chainstatemanager_opts.h>
#include <primitives/block.h>
#include <primitives/transaction.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/fuzz/util.h>
#include <test/util/setup_common.h>
#include <util/threadpool.h>
#include <cassert>
#include <cstdint>
#include <memory>
#include <optional>
#include <vector>
Include dependency graph for coinscache_sim.cpp:

Go to the source code of this file.

Functions

 StartPoolIfNeeded ()
sim_caches[0] Wipe ()
FuzzedDataProvider provider (buffer.data(), buffer.size())
 LIMITED_WHILE (provider.remaining_bytes(), 10000)
 for (const auto &cache :caches)
 for (unsigned sim_idx=1;sim_idx<=caches.size();++sim_idx)
 for (uint32_t outpointidx=0;outpointidx< NUM_OUTPOINTS;++outpointidx)
 while (!fetch_scopes.empty()) fetch_scopes.pop_back()

Variables

static const PrecomputedData data
 Precomputed COutPoint and CCoins values.
CoinsViewBottom bottom
 Dummy coinsview instance (base of the hierarchy).
std::vector< std::unique_ptr< CCoinsViewCache > > caches
 Real CCoinsViewCache objects.
std::vector< std::unique_ptr< OverlayFetchScope > > fetch_scopes
 Long-lived StartFetching guards, parallel to caches (entries are nullptr unless corresponding level is a CoinsViewOverlay).
CacheLevel sim_caches [MAX_CACHES+1]
 Simulated cache data (sim_caches[0] matches bottom, sim_caches[i+1] matches caches[i]).
uint32_t current_height = 1U
 Current height in the simulation.
auto lookup
 Helper lookup function in the simulated cache stack.
auto flush
 Flush changes in top cache to the one below.
const auto make_fetch_scope
 Helper creating a fetch scope for the top cache (which must be a CoinsViewOverlay).

Function Documentation

◆ for() [1/3]

for ( const auto &cache :caches )

Definition at line 480 of file coinscache_sim.cpp.

◆ for() [2/3]

for ( )

Definition at line 508 of file coinscache_sim.cpp.

Here is the call graph for this function:

◆ for() [3/3]

for ( unsigned sim_idx = 1; sim_idx <= caches.size(); ++sim_idx)

Definition at line 485 of file coinscache_sim.cpp.

Here is the call graph for this function:

◆ LIMITED_WHILE()

LIMITED_WHILE ( provider. remaining_bytes(),
10000  )

Definition at line 277 of file coinscache_sim.cpp.

Here is the call graph for this function:

◆ provider()

FuzzedDataProvider provider ( buffer. data(),
buffer. size() )

◆ StartPoolIfNeeded()

StartPoolIfNeeded ( )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ while()

while ( !fetch_scopes. empty())

◆ Wipe()

sim_caches[0] Wipe ( )

Variable Documentation

◆ bottom

CoinsViewBottom bottom

Dummy coinsview instance (base of the hierarchy).

Definition at line 226 of file coinscache_sim.cpp.

◆ caches

std::vector<std::unique_ptr<CCoinsViewCache> > caches

Real CCoinsViewCache objects.

Definition at line 228 of file coinscache_sim.cpp.

◆ current_height

uint32_t current_height = 1U

Current height in the simulation.

Definition at line 234 of file coinscache_sim.cpp.

◆ data

const PrecomputedData data
static

Precomputed COutPoint and CCoins values.

Definition at line 223 of file coinscache_sim.cpp.

◆ fetch_scopes

std::vector<std::unique_ptr<OverlayFetchScope> > fetch_scopes

Long-lived StartFetching guards, parallel to caches (entries are nullptr unless corresponding level is a CoinsViewOverlay).

Definition at line 230 of file coinscache_sim.cpp.

◆ flush

auto flush
Initial value:
= [&]() {
assert(caches.size() >= 1);
auto& cache = sim_caches[caches.size()];
auto& prev_cache = sim_caches[caches.size() - 1];
for (uint32_t outpointidx = 0; outpointidx < NUM_OUTPOINTS; ++outpointidx) {
if (cache.entry[outpointidx].entrytype != EntryType::NONE) {
prev_cache.entry[outpointidx] = cache.entry[outpointidx];
cache.entry[outpointidx].entrytype = EntryType::NONE;
}
}
}
std::vector< std::unique_ptr< CCoinsViewCache > > caches
Real CCoinsViewCache objects.
CacheLevel sim_caches[MAX_CACHES+1]
Simulated cache data (sim_caches[0] matches bottom, sim_caches[i+1] matches caches[i]).
assert(!tx.IsCoinBase())

Flush changes in top cache to the one below.

Definition at line 256 of file coinscache_sim.cpp.

◆ lookup

auto lookup
Initial value:
= [&](uint32_t outpointidx, int sim_idx = -1) -> std::optional<std::pair<coinidx_type, uint32_t>> {
uint32_t cache_idx = sim_idx == -1 ? caches.size() : sim_idx;
while (true) {
const auto& entry = sim_caches[cache_idx].entry[outpointidx];
if (entry.entrytype == EntryType::UNSPENT) {
return {{entry.coinidx, entry.height}};
} else if (entry.entrytype == EntryType::SPENT) {
return std::nullopt;
};
if (cache_idx == 0) break;
--cache_idx;
}
return std::nullopt;
}

Helper lookup function in the simulated cache stack.

Definition at line 240 of file coinscache_sim.cpp.

◆ make_fetch_scope

const auto make_fetch_scope
Initial value:
{[&] {
auto& overlay{static_cast<CoinsViewOverlay&>(*caches.back())};
return std::make_unique<OverlayFetchScope>(overlay, data.block);
}}
CCoinsViewCache subclass that asynchronously fetches most block input prevouts in parallel during Con...
Definition coins.h:656
static const PrecomputedData data
Precomputed COutPoint and CCoins values.

Helper creating a fetch scope for the top cache (which must be a CoinsViewOverlay).

Definition at line 269 of file coinscache_sim.cpp.

◆ sim_caches

CacheLevel sim_caches[MAX_CACHES+1]

Simulated cache data (sim_caches[0] matches bottom, sim_caches[i+1] matches caches[i]).

Definition at line 232 of file coinscache_sim.cpp.