Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/bitcoin/database/impl/query/archive/chain_writer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ code CLASS::set_code(const tx_link& tx_fk, const transaction& tx,
const auto coinbase = tx.is_coinbase();

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Allocate contiguously and store inputs.
input_link in_fk{};
Expand Down Expand Up @@ -283,7 +283,7 @@ code CLASS::set_code(header_link& out_fk, const header& header,
return system::error::orphan_block;

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean single allocation failure (e.g. disk full).
out_fk = store_.header.put_link(key, table::header::put_ref
Expand Down Expand Up @@ -405,7 +405,7 @@ code CLASS::set_code(const block& block, const header_link& key,
(block.serialized_size(true));

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();
constexpr auto positive = true;

// Transactor assures cannot be restored without txs, as required to unset.
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/impl/query/archive/wire_writer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ code CLASS::set_code(const tx_link& tx_fk, const transaction_view& tx,
const auto coinbase = tx.is_coinbase();

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Allocate contiguously and store inputs.
input_link in_fk{};
Expand Down Expand Up @@ -273,7 +273,7 @@ code CLASS::set_code(const block_view& block, const header_link& key,
(block.serialized_size(true));

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();
constexpr auto positive = true;

// Transactor assures cannot be restored without txs, as required to unset.
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/database/impl/query/batch/ecdsa.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ TEMPLATE
bool CLASS::purge_ecdsa_signatures() NOEXCEPT
{
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();
return store_.ecdsa.truncate(0);
// ========================================================================
}
Expand All @@ -84,7 +84,7 @@ bool CLASS::set_signature(const hash_digest& digest,

// Caller must guard reads, this is writing into hot storage.
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

using namespace system;
const auto row = possible_narrow_cast<ecdsa_link::integer>(one);
Expand Down Expand Up @@ -120,7 +120,7 @@ bool CLASS::set_signatures(const hash_digest& digest,

// Caller must guard reads, this is writing into hot storage.
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

using namespace system;
const auto rows = possible_narrow_cast<ecdsa_link::integer>(count);
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/impl/query/batch/prevalid.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TEMPLATE
bool CLASS::purge_prevalids() NOEXCEPT
{
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();
return store_.prevalid.truncate(0);
// ========================================================================
}
Expand All @@ -58,7 +58,7 @@ TEMPLATE
bool CLASS::set_prevalids(const header_links& links) NOEXCEPT
{
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean single allocation failure (e.g. disk full).
const table::prevalid::put_refs prevalids{ {}, links };
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/database/impl/query/batch/schnorr.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ TEMPLATE
bool CLASS::purge_schnorr_signatures() NOEXCEPT
{
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();
return store_.schnorr.truncate(0);
// ========================================================================
}
Expand All @@ -83,7 +83,7 @@ bool CLASS::set_signature(const hash_digest& digest, const ec_xonly& point,

// Caller must guard reads, this is writing into hot storage.
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

using namespace system;
const auto row = possible_narrow_cast<schnorr_link::integer>(one);
Expand Down Expand Up @@ -114,7 +114,7 @@ bool CLASS::set_signatures(const threshold& batch,

// Caller must guard reads, this is writing into hot storage.
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

using namespace system;
const auto& set = batch.tuples;
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/impl/query/batch/silent.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ bool CLASS::set_silent(const tx_link& link,

// TODO: caller must guard reads, this is writing into hot storage.
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

using namespace system;
auto rows = possible_narrow_cast<silent_link::integer>(prefixes.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ code CLASS::get_prevouts(point_sets& sets, size_t points,
// Transactor required for prevout read because of pruning.
// ========================================================================
{
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

if (!store_.prevout.at(prevout, cache))
return error::integrity_get_prevouts;
Expand Down Expand Up @@ -90,7 +90,7 @@ bool CLASS::set_prevouts(const header_link& link, const block& block) NOEXCEPT
const auto prevout = to_prevout(link);

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean single allocation failure (e.g. disk full).
const table::prevout::slab_put_ref prevouts{ {}, doubles, block };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ bool CLASS::set_block_state(const header_link& link,
const auto record = to_validated_bk(link);

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean single allocation failure (e.g. disk full).
return store_.validated_bk.put(record,
Expand Down Expand Up @@ -290,7 +290,7 @@ bool CLASS::set_tx_state(const tx_link& link, const context& ctx,
using sigs = linkage<schema::sigops>;

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();
using namespace system;

// Clean single allocation failure (e.g. disk full).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ bool CLASS::set_strong(const header_link& link) NOEXCEPT
BC_ASSERT(!is_zero(txs.number) && txs.coinbase_fk != tx_link::terminal);

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean allocation failure (e.g. disk full).
return set_strong(link, txs.number, txs.coinbase_fk , true);
Expand All @@ -159,7 +159,7 @@ bool CLASS::set_unstrong(const header_link& link) NOEXCEPT
BC_ASSERT(!is_zero(txs.number) && txs.coinbase_fk != tx_link::terminal);

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean allocation failure (e.g. disk full).
return set_strong(link, txs.number, txs.coinbase_fk, false);
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/impl/query/filters.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool CLASS::set_filter_body(const header_link& link,
return true;

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean single allocation failure (e.g. disk full).
return store_.filter_tx.put(to_filter_tx(link), table::filter_tx::put_ref
Expand Down Expand Up @@ -209,7 +209,7 @@ bool CLASS::set_filter_head(const header_link& link, const hash_digest& head,
return true;

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean single allocation failure (e.g. disk full).
return store_.filter_bk.put(to_filter_bk(link), table::filter_bk::put_ref
Expand Down
8 changes: 4 additions & 4 deletions include/bitcoin/database/impl/query/height.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ bool CLASS::push_candidate(const header_link& link) NOEXCEPT
return false;

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean single allocation failure (e.g. disk full).
const table::height::record candidate{ {}, link };
Expand All @@ -58,7 +58,7 @@ bool CLASS::pop_candidate() NOEXCEPT

// Clean single allocation failure (e.g. disk full).
// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Candidate pop implies reorg or disorg, which implies future duplicates.
store_.set_dirty();
Expand All @@ -82,7 +82,7 @@ bool CLASS::push_confirmed(const header_link& link, bool strong) NOEXCEPT
return false;

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// This reservation guard assumes no concurrent writes to the table.
if (strong && !set_strong(link, txs.number, txs.coinbase_fk, true))
Expand All @@ -107,7 +107,7 @@ bool CLASS::pop_confirmed() NOEXCEPT
return {};

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

// Clean single allocation failure.
if (!set_strong(link, txs.number, txs.coinbase_fk, false))
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/impl/query/initialize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ bool CLASS::initialize(const block& genesis) NOEXCEPT
// TODO: add genesis block filter_tx head and body when filter_tx is enabled.

// ========================================================================
const auto scope = store_.get_transactor();
const auto scope = get_transactor();

if (!set(genesis, context{}, false, false))
return false;
Expand Down
33 changes: 33 additions & 0 deletions include/bitcoin/database/impl/query/merkle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,39 @@ code CLASS::get_merkle_subroots(hashes& roots, size_t waypoint) const NOEXCEPT
return error::success;
}

// ----------------------------------------------------------------------------

TEMPLATE
size_t CLASS::interval_span() const NOEXCEPT
{
if (const auto span = span_.load(std::memory_order_relaxed);
is_nonzero(span))
return span;

// initialize_span() never returns zero.
span_.store(initialize_span(), std::memory_order_relaxed);
return span_;
}

// protected
TEMPLATE
size_t CLASS::interval_depth() const NOEXCEPT
{
table::txs::get_genesis_depth txs{};
return store_.txs.at(to_txs(0), txs) ? txs.depth : store_.interval_depth();
}

// protected
TEMPLATE
size_t CLASS::initialize_span() const NOEXCEPT
{
// span of zero (overflow) is disallowed (division by zero).
// span of one (2^0) caches every block (no optimization, wasted storage).
// span greater than top height eliminates caching (no optimization).
const auto span = system::power2(interval_depth());
return is_zero(span) ? max_size_t : span;
}

} // namespace database
} // namespace libbitcoin

Expand Down
29 changes: 2 additions & 27 deletions include/bitcoin/database/impl/query/query.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,9 @@ CLASS::query(Store& store) NOEXCEPT
}

TEMPLATE
size_t CLASS::interval_span() const NOEXCEPT
typename CLASS::transactor CLASS::get_transactor() const NOEXCEPT
{
if (const auto span = span_.load(std::memory_order_relaxed);
is_nonzero(span))
return span;

// initialize_span() never returns zero.
span_.store(initialize_span(), std::memory_order_relaxed);
return span_;
}

// protected
TEMPLATE
size_t CLASS::interval_depth() const NOEXCEPT
{
table::txs::get_genesis_depth txs{};
return store_.txs.at(to_txs(0), txs) ? txs.depth : store_.interval_depth();
}

// protected
TEMPLATE
size_t CLASS::initialize_span() const NOEXCEPT
{
// span of zero (overflow) is disallowed (division by zero).
// span of one (2^0) caches every block (no optimization, wasted storage).
// span greater than top height eliminates caching (no optimization).
const auto span = system::power2(interval_depth());
return is_zero(span) ? max_size_t : span;
return store_.get_transactor();
}

TEMPLATE
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/impl/store/store.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void CLASS::set_dirty() NOEXCEPT
}

TEMPLATE
const typename CLASS::transactor CLASS::get_transactor() NOEXCEPT
typename CLASS::transactor CLASS::get_transactor() NOEXCEPT
{
return transactor{ transactor_mutex_ };
}
Expand Down
4 changes: 4 additions & 0 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class query
{
public:
DELETE_COPY_MOVE_DESTRUCT(query);
using transactor = typename Store::transactor;

/// Chain type aliases.
using block = system::chain::block;
Expand Down Expand Up @@ -65,6 +66,9 @@ class query
/// Store management from query-holder (not store owner) context.
/// -----------------------------------------------------------------------

/// Get a transactor object.
transactor get_transactor() const NOEXCEPT;

/// Get first fault code, or disk_full if none and full, or success.
code get_code() const NOEXCEPT;

Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class store
size_t get_space() const NOEXCEPT;

/// Get a transactor object.
const transactor get_transactor() NOEXCEPT;
transactor get_transactor() NOEXCEPT;

protected:
using path = std::filesystem::path;
Expand Down
Loading