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
18 changes: 9 additions & 9 deletions include/bitcoin/database/impl/query/batch/silent.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ bool CLASS::scan_silent(const stopper& cancel,
return !cancel;
}

// Rows are in validation order, so the rows of confirmed blocks are selected
// by tx link from the range and only the selected rows are scanned. A block's
// txs are a few runs of consecutive links, so membership is a search of runs.
// Rows are in validation order, so the rows of confirmed blocks in the cut are
// selected by tx link from the range, along with all unconfirmed rows, and only
// the selected rows are scanned. A block's txs are a few runs of consecutive
// links, so membership is a search of runs.
TEMPLATE
bool CLASS::scan_silent(const stopper& cancel,
const system::scan::batch::receiver& keys, size_t first, size_t last,
Expand Down Expand Up @@ -114,19 +115,18 @@ bool CLASS::scan_silent(const stopper& cancel,
merged.emplace_back(low, high);
}

const auto latch = is_pooling() ? get_latch_tx() : max_size_t;
const auto selected = [&](link_t link) NOEXCEPT
{
if (link >= latch)
return true;

const auto it = std::upper_bound(merged.cbegin(), merged.cend(), link,
[](link_t value, const run_t& run) NOEXCEPT
{
return value < run.first;
});

return it != merged.cbegin() && link <= std::prev(it)->second;
if (it != merged.cbegin() && link <= std::prev(it)->second)
return true;

return to_block(link).is_terminal();
};

const auto correlate_ptr = store_.scan.correlate.get_memory();
Expand Down Expand Up @@ -265,7 +265,7 @@ size_t CLASS::get_silent_floor(size_t start, bool time) const NOEXCEPT
if (time && !get_mtp_height(height, start))
height = max_size_t;

return get_scan_floor(height).value;
return get_scan_floor(height);
}

// Rows are allocated zero-filled and a nonzero correlate publishes the row.
Expand Down
17 changes: 3 additions & 14 deletions include/bitcoin/database/impl/query/consensus/consensus_strong.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,10 @@ TEMPLATE
bool CLASS::set_strong(const header_link& link, const tx_links& fks,
bool positive) NOEXCEPT
{
using namespace system;
using link_t = table::strong::link;
using element_t = table::strong::record;

// Preallocate all strong records for the block and reuse memory ptr.
const auto records = possible_narrow_cast<link_t::integer>(fks.size());
auto record = store_.strong.allocate(records);
const auto ptr = store_.strong.get_memory();

const table::strong::replace element{ {}, table::strong::merge(positive, link) };
for (const auto& fk: fks)
if (!store_.strong.put(ptr, record++, tx_link{ fk }, element_t
{
{},
table::strong::merge(positive, link)
})) return false;
if (!store_.strong.set(fk, element))
return false;

return true;
}
Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/database/impl/query/extent.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ DEFINE_BUCKETS(tx)

DEFINE_HEADMAP_BUCKETS(candidate)
DEFINE_HEADMAP_BUCKETS(confirmed)
DEFINE_BUCKETS(strong)
DEFINE_HEADMAP_BUCKETS(strong)
DEFINE_BUCKETS(scan)
DEFINE_HEADMAP_BUCKETS(state)
DEFINE_BUCKETS(duplicate)
Expand All @@ -230,7 +230,6 @@ DEFINE_RECORDS(ins)
DEFINE_RECORDS(outs)
DEFINE_RECORDS(tx)

DEFINE_RECORDS(strong)
DEFINE_RECORDS(scan)
DEFINE_RECORDS(scan_prefix)
DEFINE_RECORDS(ecdsa0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,11 @@ tx_links CLASS::to_duplicates(const hash_digest& tx_hash) const NOEXCEPT
TEMPLATE
header_link CLASS::to_block(const tx_link& link) const NOEXCEPT
{
table::strong::record strong{};
if (!store_.strong.find(link, strong) || !strong.positive())
const auto strong = store_.strong.at(link);
if (!table::strong::positive(strong))
return {};

return strong.header_fk();
return table::strong::header_fk(strong);
}

// utilities
Expand Down
6 changes: 2 additions & 4 deletions include/bitcoin/database/impl/store/store.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ CLASS::store(const settings& config) NOEXCEPT
candidate_head_(head(config.path / schema::dir::heads, schema::indexes::candidate), head_settings<schema::height::cell>(config.candidate), sequential),
confirmed_head_(head(config.path / schema::dir::heads, schema::indexes::confirmed), head_settings<schema::height::cell>(config.confirmed), sequential),

strong_head_(head(config.path / schema::dir::heads, schema::indexes::strong), head_settings(config.strong), random),
strong_body_(body(config.path, schema::indexes::strong), config.strong, sequential, staged),
strong_head_(head(config.path / schema::dir::heads, schema::indexes::strong), head_settings<schema::strong::cell>(config.strong), random),
scan_head_(head(config.path / schema::dir::heads, schema::indexes::scan), head_settings(config.scan), random),
scan_body_(body(config.path, schema::indexes::scan), config.scan, sequential, staged),
scan_prefix_head_(head(config.path / schema::dir::heads, schema::indexes::scan_prefix), head_settings(config.scan), sequential),
Expand Down Expand Up @@ -157,7 +156,7 @@ CLASS::store(const settings& config) NOEXCEPT

candidate(candidate_head_),
confirmed(confirmed_head_),
strong(strong_head_, strong_body_, config.strong.buckets, config.strong.expected),
strong(strong_head_),
scan(scan_head_, scan_body_, config.scan.buckets),
scan_prefix(scan_prefix_head_, scan_prefix_body_),

Expand Down Expand Up @@ -193,7 +192,6 @@ CLASS::store(const settings& config) NOEXCEPT
envelope_.ins_k = possible_narrow_cast<uint8_t>(ins.filter_k());
envelope_.outs_k = possible_narrow_cast<uint8_t>(outs.filter_k());
envelope_.tx_k = possible_narrow_cast<uint8_t>(tx.filter_k());
envelope_.strong_k = possible_narrow_cast<uint8_t>(strong.filter_k());
envelope_.duplicate_k = possible_narrow_cast<uint8_t>(duplicate.filter_k());
envelope_.pool_k = possible_narrow_cast<uint8_t>(pool.filter_k());
envelope_.wtxid_k = possible_narrow_cast<uint8_t>(wtxid.filter_k());
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/store/store_create.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ code CLASS::create_load(const event_handler& handler) NOEXCEPT
create(ec, candidate_head_, table_t::candidate_head);
create(ec, confirmed_head_, table_t::confirmed_head);
create(ec, strong_head_, table_t::strong_head);
create(ec, strong_body_, table_t::strong_body);
create(ec, scan_head_, table_t::scan_head);
create(ec, scan_body_, table_t::scan_body);
create(ec, scan_prefix_head_, table_t::scan_prefix_head);
Expand Down
2 changes: 0 additions & 2 deletions include/bitcoin/database/impl/store/store_open.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ code CLASS::load_envelope() NOEXCEPT
!ins.set_buckets(envelope_.ins_buckets) ||
!outs.set_buckets(envelope_.outs_buckets) ||
!tx.set_buckets(envelope_.tx_buckets) ||
!strong.set_buckets(envelope_.strong_buckets) ||
!duplicate.set_buckets(envelope_.duplicate_buckets) ||
!pool.set_buckets(envelope_.pool_buckets) ||
!wtxid.set_buckets(envelope_.wtxid_buckets))
Expand All @@ -223,7 +222,6 @@ code CLASS::load_envelope() NOEXCEPT
!ins.set_filter_k(envelope_.ins_k) ||
!outs.set_filter_k(envelope_.outs_k) ||
!tx.set_filter_k(envelope_.tx_k) ||
!strong.set_filter_k(envelope_.strong_k) ||
!duplicate.set_filter_k(envelope_.duplicate_k) ||
!pool.set_filter_k(envelope_.pool_k) ||
!wtxid.set_filter_k(envelope_.wtxid_k))
Expand Down
2 changes: 0 additions & 2 deletions include/bitcoin/database/impl/store/store_open_load.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ code CLASS::open_load(const event_handler& handler) NOEXCEPT
open(ec, candidate_head_, table_t::candidate_head);
open(ec, confirmed_head_, table_t::confirmed_head);
open(ec, strong_head_, table_t::strong_head);
open(ec, strong_body_, table_t::strong_body);
open(ec, scan_head_, table_t::scan_head);
open(ec, scan_body_, table_t::scan_body);
open(ec, scan_prefix_head_, table_t::scan_prefix_head);
Expand Down Expand Up @@ -146,7 +145,6 @@ code CLASS::open_load(const event_handler& handler) NOEXCEPT
load(ec, candidate_head_, table_t::candidate_head);
load(ec, confirmed_head_, table_t::confirmed_head);
load(ec, strong_head_, table_t::strong_head);
load(ec, strong_body_, table_t::strong_body);
load(ec, scan_head_, table_t::scan_head);
load(ec, scan_body_, table_t::scan_body);
load(ec, scan_prefix_head_, table_t::scan_prefix_head);
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/store/store_reload.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ code CLASS::reload(const event_handler& handler) NOEXCEPT
reload(ec, candidate_head_, table_t::candidate_head);
reload(ec, confirmed_head_, table_t::confirmed_head);
reload(ec, strong_head_, table_t::strong_head);
reload(ec, strong_body_, table_t::strong_body);
reload(ec, scan_head_, table_t::scan_head);
reload(ec, scan_body_, table_t::scan_body);
reload(ec, scan_prefix_head_, table_t::scan_prefix_head);
Expand Down
3 changes: 0 additions & 3 deletions include/bitcoin/database/impl/store/store_report.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void CLASS::report(const error_handler& handler) const NOEXCEPT
report(*outs_body_, table_t::outs_body);
report(tx_body_, table_t::tx_body);
report(txs_body_, table_t::txs_body);
report(strong_body_, table_t::strong_body);
report(scan_body_, table_t::scan_body);
report(scan_prefix_body_, table_t::scan_prefix_body);
report(ecdsa0_body_, table_t::ecdsa0_body);
Expand Down Expand Up @@ -94,7 +93,6 @@ code CLASS::get_fault() const NOEXCEPT
if ((ec = candidate_head_.get_fault())) return ec;
if ((ec = confirmed_head_.get_fault())) return ec;
if ((ec = strong_head_.get_fault())) return ec;
if ((ec = strong_body_.get_fault())) return ec;
if ((ec = scan_head_.get_fault())) return ec;
if ((ec = scan_body_.get_fault())) return ec;
if ((ec = scan_prefix_head_.get_fault())) return ec;
Expand Down Expand Up @@ -169,7 +167,6 @@ size_t CLASS::get_space() const NOEXCEPT
space(candidate_head_);
space(confirmed_head_);
space(strong_head_);
space(strong_body_);
space(scan_head_);
space(scan_body_);
space(scan_prefix_head_);
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/store/store_snapshot.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ code CLASS::snapshot(const event_handler& handler, bool prune) NOEXCEPT
flush(ec, tx_body_, table_t::tx_body);
flush(ec, txs_body_, table_t::txs_body);

flush(ec, strong_body_, table_t::strong_body);
flush(ec, scan_body_, table_t::scan_body);
flush(ec, scan_prefix_body_, table_t::scan_prefix_body);

Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/impl/store/store_tables.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const CLASS::table_map CLASS::tables
{ table_t::confirmed_head, "confirmed_head" },
{ table_t::strong_table, "strong_table" },
{ table_t::strong_head, "strong_head" },
{ table_t::strong_body, "strong_body" },
{ table_t::scan_table, "scan_table" },
{ table_t::scan_head, "scan_head" },
{ table_t::scan_body, "scan_body" },
Expand Down
2 changes: 0 additions & 2 deletions include/bitcoin/database/impl/store/store_unload_close.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ code CLASS::unload_close(const event_handler& handler) NOEXCEPT
unload(ec, candidate_head_, table_t::candidate_head);
unload(ec, confirmed_head_, table_t::confirmed_head);
unload(ec, strong_head_, table_t::strong_head);
unload(ec, strong_body_, table_t::strong_body);
unload(ec, scan_head_, table_t::scan_head);
unload(ec, scan_body_, table_t::scan_body);
unload(ec, scan_prefix_head_, table_t::scan_prefix_head);
Expand Down Expand Up @@ -133,7 +132,6 @@ code CLASS::unload_close(const event_handler& handler) NOEXCEPT
close(ec, candidate_head_, table_t::candidate_head);
close(ec, confirmed_head_, table_t::confirmed_head);
close(ec, strong_head_, table_t::strong_head);
close(ec, strong_body_, table_t::strong_body);
close(ec, scan_head_, table_t::scan_head);
close(ec, scan_body_, table_t::scan_body);
close(ec, scan_prefix_head_, table_t::scan_prefix_head);
Expand Down
8 changes: 3 additions & 5 deletions include/bitcoin/database/impl/unspent/unspent_reader.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,11 @@ code CLASS::read_blocks(header_links& out,
if (parents.at(at) != parent)
{
parent = parents.at(at);
const auto fk = store_.strong.first(ptr, parent);

table::strong::record strong{};
if (!store_.strong.get(ptr, fk, strong) || !strong.positive())
const auto strong = store_.strong.at(ptr, parent);
if (!table::strong::positive(strong))
return error::branch_inactive;

block = strong.header_fk();
block = table::strong::header_fk(strong);
}

out.at(at) = block;
Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ class query
size_t outs_records() const NOEXCEPT;
size_t tx_records() const NOEXCEPT;

size_t strong_records() const NOEXCEPT;
size_t scan_records() const NOEXCEPT;
size_t scan_prefix_records() const NOEXCEPT;
size_t ecdsa0_records() const NOEXCEPT;
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct BCD_API settings

bucket_table candidate{};
bucket_table confirmed{};
hash_table strong{};
bucket_table strong{};
bucket_table scan{};
hash_table wtxid{};

Expand Down
1 change: 0 additions & 1 deletion include/bitcoin/database/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ class store

// record hashmap
Storage<one> strong_head_;
Storage<one> strong_body_;
Storage<one> scan_head_;
table::scan_storage<Storage> scan_body_;
Storage<one> scan_prefix_head_;
Expand Down
2 changes: 0 additions & 2 deletions include/bitcoin/database/tables/envelope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ struct BCD_API envelope
uint32_t ins_buckets{};
uint32_t outs_buckets{};
uint32_t tx_buckets{};
uint32_t strong_buckets{};
uint32_t duplicate_buckets{};
uint32_t pool_buckets{};
uint32_t wtxid_buckets{};
uint8_t header_k{};
uint8_t ins_k{};
uint8_t outs_k{};
uint8_t tx_k{};
uint8_t strong_k{};
uint8_t duplicate_k{};
uint8_t pool_k{};
uint8_t wtxid_k{};
Expand Down
47 changes: 21 additions & 26 deletions include/bitcoin/database/tables/indexes/strong.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,57 +27,52 @@ namespace libbitcoin {
namespace database {
namespace table {

/// strong is a record hashmap of tx confirmation state.
/// strong is a head-only array of signed header fks indexed by tx.fk.
/// A zero value (the fill) is a negative association to header zero.
struct strong
: public hash_map<schema::strong>
: public value_map<schema::strong>
{
using header = schema::header::link;
using hash_map<schema::strong>::hashmap;
using value = schema::strong::value;
using value_map<schema::strong>::headmap;
static constexpr auto offset = header::bits;
static_assert(offset < to_bits(header::size));

static constexpr header::integer merge(bool positive,
static constexpr value merge(bool positive,
header::integer header_fk) NOEXCEPT
{
using namespace system;
BC_ASSERT_MSG(!get_right(header_fk, offset), "overflow");
return set_right(header_fk, offset, positive);
}

struct record
: public schema::strong
static constexpr bool positive(value signed_block_fk) NOEXCEPT
{
inline bool positive() const NOEXCEPT
{
return system::get_right(signed_block_fk, offset);
}
return system::get_right(signed_block_fk, offset);
}

inline header::integer header_fk() const NOEXCEPT
{
return system::set_right(signed_block_fk, offset, false);
}
static constexpr header::integer header_fk(value signed_block_fk) NOEXCEPT
{
return system::set_right(signed_block_fk, offset, false);
}

/// Replace the association.
struct replace
: public schema::strong
{
inline bool from_data(reader& source) NOEXCEPT
{
signed_block_fk = source.read_little_endian<header::integer, header::size>();
BC_ASSERT(!source || source.get_read_position() == minrow);
source.skip_bytes(cell);
return source;
}

inline bool to_data(finalizer& sink) const NOEXCEPT
inline bool to_data(flipper& sink) const NOEXCEPT
{
sink.write_little_endian<header::integer, header::size>(signed_block_fk);
BC_ASSERT(!sink || sink.get_write_position() == minrow);
sink.write_little_endian<value, cell>(signed_block_fk);
return sink;
}

inline bool operator==(const record& other) const NOEXCEPT
{
return positive() == other.positive()
&& header_fk() == other.header_fk();
}

header::integer signed_block_fk{};
value signed_block_fk{};
};
};

Expand Down
Loading
Loading