Bitcoin Core 31.99.0
P2P Digital Currency
Functions | Variables
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)
 

Variables

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

Function Documentation

◆ for() [1/3]

for ( const auto &cache :caches  )

Definition at line 477 of file coinscache_sim.cpp.

Here is the caller graph for this function:

◆ for() [2/3]

for ( )

Definition at line 505 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 482 of file coinscache_sim.cpp.

Here is the call graph for this function:

◆ LIMITED_WHILE()

LIMITED_WHILE ( provider.  remaining_bytes(),
10000   
)

Definition at line 271 of file coinscache_sim.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ provider()

FuzzedDataProvider provider ( buffer.  data(),
buffer.  size() 
)
Here is the caller graph for this function:

◆ StartPoolIfNeeded()

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

◆ 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.

◆ 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]).
@ NONE
Definition: categories.h:15
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;
}
constexpr CAmount SPENT

Helper lookup function in the simulated cache stack.

Definition at line 240 of file coinscache_sim.cpp.

◆ overlay_fetch_scope

std::unique_ptr<OverlayFetchScope> overlay_fetch_scope

Long-lived StartFetching guard (nullptr unless corresponding level is a CoinsViewOverlay).

Definition at line 230 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.