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
2 changes: 2 additions & 0 deletions builds/gnu/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ src_libbitcoin_database_la_SOURCES = \
${srcdir}/../../src/memory/mman.cpp \
${srcdir}/../../src/memory/mstage.cpp \
${srcdir}/../../src/memory/utilities.cpp \
${srcdir}/../../src/types/envelope.cpp \
${srcdir}/../../src/types/history.cpp \
${srcdir}/../../src/types/multisig_view.cpp \
${srcdir}/../../src/types/unspent.cpp
Expand Down Expand Up @@ -325,6 +326,7 @@ include_bitcoin_database_types_HEADERS = \
${srcdir}/../../include/bitcoin/database/types/associations.hpp \
${srcdir}/../../include/bitcoin/database/types/block_state.hpp \
${srcdir}/../../include/bitcoin/database/types/difference_set.hpp \
${srcdir}/../../include/bitcoin/database/types/envelope.hpp \
${srcdir}/../../include/bitcoin/database/types/fee_rate.hpp \
${srcdir}/../../include/bitcoin/database/types/header_state.hpp \
${srcdir}/../../include/bitcoin/database/types/history.hpp \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<ObjectFileName>$(IntDir)src_memory_utilities.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\..\..\src\settings.cpp" />
<ClCompile Include="..\..\..\..\src\types\envelope.cpp" />
<ClCompile Include="..\..\..\..\src\types\history.cpp" />
<ClCompile Include="..\..\..\..\src\types\multisig_view.cpp" />
<ClCompile Include="..\..\..\..\src\types\unspent.cpp" />
Expand Down Expand Up @@ -212,6 +213,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\associations.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\block_state.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\difference_set.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\envelope.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\fee_rate.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\header_state.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\history.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<ClCompile Include="..\..\..\..\src\settings.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\types\envelope.cpp">
<Filter>src\types</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\types\history.cpp">
<Filter>src\types</Filter>
</ClCompile>
Expand Down Expand Up @@ -356,6 +359,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\difference_set.hpp">
<Filter>include\bitcoin\database\types</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\envelope.hpp">
<Filter>include\bitcoin\database\types</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\fee_rate.hpp">
<Filter>include\bitcoin\database\types</Filter>
</ClInclude>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<ObjectFileName>$(IntDir)src_memory_utilities.obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\..\..\src\settings.cpp" />
<ClCompile Include="..\..\..\..\src\types\envelope.cpp" />
<ClCompile Include="..\..\..\..\src\types\history.cpp" />
<ClCompile Include="..\..\..\..\src\types\multisig_view.cpp" />
<ClCompile Include="..\..\..\..\src\types\unspent.cpp" />
Expand Down Expand Up @@ -212,6 +213,7 @@
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\associations.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\block_state.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\difference_set.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\envelope.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\fee_rate.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\header_state.hpp" />
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\history.hpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<ClCompile Include="..\..\..\..\src\settings.cpp">
<Filter>src</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\types\envelope.cpp">
<Filter>src\types</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\src\types\history.cpp">
<Filter>src\types</Filter>
</ClCompile>
Expand Down Expand Up @@ -356,6 +359,9 @@
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\difference_set.hpp">
<Filter>include\bitcoin\database\types</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\envelope.hpp">
<Filter>include\bitcoin\database\types</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\include\bitcoin\database\types\fee_rate.hpp">
<Filter>include\bitcoin\database\types</Filter>
</ClInclude>
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <bitcoin/database/types/associations.hpp>
#include <bitcoin/database/types/block_state.hpp>
#include <bitcoin/database/types/difference_set.hpp>
#include <bitcoin/database/types/envelope.hpp>
#include <bitcoin/database/types/fee_rate.hpp>
#include <bitcoin/database/types/header_state.hpp>
#include <bitcoin/database/types/history.hpp>
Expand Down
5 changes: 1 addition & 4 deletions include/bitcoin/database/impl/query/archive/chain_writer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,6 @@ code CLASS::set_code(const block& block, const header_link& key,
// Optional hash, only has value on height intervals.
auto interval = create_interval(key, height);

// Depth is only set by writer for genesis (is_zero(tx_fks[0])).
const auto depth = store_.interval_depth();

using bytes = linkage<schema::size>::integer;
const auto light = possible_narrow_cast<bytes>(
block.serialized_size(false));
Expand All @@ -418,7 +415,7 @@ code CLASS::set_code(const block& block, const header_link& key,
count,
tx_fks,
std::move(interval),
depth
store_.envelope()
}) ? error::success : error::txs_txs_put;
// ========================================================================
}
Expand Down
7 changes: 1 addition & 6 deletions include/bitcoin/database/impl/query/archive/wire_writer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,6 @@ code CLASS::set_code(const block_view& block, const header_link& key,
// Optional hash, only has value on height intervals.
auto interval = create_interval(key, height);

// Depth/forks only set by writer for genesis (is_zero(tx_fks[0])).
const auto depth = store_.interval_depth();
const auto forks = store_.fork_flags();

using bytes = linkage<schema::size>::integer;
const auto count = possible_narrow_cast<unsigned_type<schema::count_>>(txs);
const auto light = possible_narrow_cast<bytes>(block.serialized_size(false));
Expand Down Expand Up @@ -343,8 +339,7 @@ code CLASS::set_code(const block_view& block, const header_link& key,
count,
tx_fks,
std::move(interval),
depth,
forks
store_.envelope()
}) ? error::success : error::txs_txs_put;
// ========================================================================
}
Expand Down
6 changes: 2 additions & 4 deletions include/bitcoin/database/impl/query/initialize.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ namespace database {
// Initialization (natural-keyed).
// ----------------------------------------------------------------------------

// server (warning)
TEMPLATE
uint32_t CLASS::initialized_forks() const NOEXCEPT
const database::envelope& CLASS::envelope() const NOEXCEPT
{
table::txs::get_genesis_forks txs{};
return store_.txs.at(to_txs(0), txs) ? txs.forks : store_.fork_flags();
return store_.envelope();
}

// server/dumps
Expand Down
3 changes: 1 addition & 2 deletions include/bitcoin/database/impl/query/merkle.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ size_t CLASS::interval_span() const NOEXCEPT
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();
return store_.interval_depth();
}

// protected
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/impl/query/unspent.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ bool CLASS::is_bip30_exception(bool& out,
return true;

// With the rule unconfigured duplicates are unconstrained (no exception).
if (!script::is_enabled(initialized_forks(), chain::flags::bip30_rule))
if (!store_.envelope().forks.bip30)
return true;

const auto key = get_header_key(link);
Expand Down
8 changes: 5 additions & 3 deletions include/bitcoin/database/impl/store/store.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace database {
TEMPLATE
CLASS::store(const settings& config) NOEXCEPT
: configuration_(config),
envelope_(config.envelope),

// Archive.
// ------------------------------------------------------------------------
Expand Down Expand Up @@ -132,6 +133,7 @@ CLASS::store(const settings& config) NOEXCEPT
filter_bk(filter_bk_head_, filter_bk_body_, config.filter_bk.buckets),
filter_tx(filter_tx_head_, filter_tx_body_, config.filter_tx.buckets)
{
envelope_.set(config);
}

TEMPLATE
Expand All @@ -151,13 +153,13 @@ uint8_t CLASS::interval_depth() const NOEXCEPT
{
// Configuration uses uint16_t because of boost parser bug for single byte.
// But 2^255 is sufficient given that interval is limited by chain length.
return system::limit<uint8_t>(configuration_.interval_depth);
return system::limit<uint8_t>(envelope_.interval_depth);
}

TEMPLATE
uint32_t CLASS::fork_flags() const NOEXCEPT
const database::envelope& CLASS::envelope() const NOEXCEPT
{
return configuration_.fork_flags;
return envelope_;
}

TEMPLATE
Expand Down
13 changes: 13 additions & 0 deletions include/bitcoin/database/impl/store/store_open.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ code CLASS::open(const event_handler& handler) NOEXCEPT
verify(ec, filter_bk, table_t::filter_bk_table);
verify(ec, filter_tx, table_t::filter_tx_table);

if (!ec)
{
// The stored creation envelope governs, configuration is not read.
table::txs::get_envelope genesis{};
if (!is_zero(txs.body_size()))
{
if (txs.at(zero, genesis))
envelope_ = genesis.envelope;
else
ec = error::verify_table;
}
}

if (ec)
{
/* code */ unload_close(handler);
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class query
/// Count of puts not resulting in table body search to detect duplication.
size_t negative_search_count() const NOEXCEPT;

/// Forks configured at store creation.
uint32_t initialized_forks() const NOEXCEPT;
/// Settings envelope stored at store creation.
const database::envelope& envelope() const NOEXCEPT;

/// Store extent.
/// -----------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions include/bitcoin/database/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define LIBBITCOIN_DATABASE_SETTINGS_HPP

#include <bitcoin/database/define.hpp>
#include <bitcoin/database/types/envelope.hpp>
#include <bitcoin/database/memory/settings.hpp>

#include <filesystem>
Expand Down Expand Up @@ -66,8 +67,8 @@ struct BCD_API settings
/// Depth of merkle tree interval caching (used at store create only).
uint16_t interval_depth{ max_uint8 };

/// Fork flags upon store creation (used at store create only).
uint32_t fork_flags{};
/// Creation settings envelope (used at store create only).
database::envelope envelope{};

/// Path to the database directory.
std::filesystem::path path{ "bitcoin" };
Expand Down
7 changes: 5 additions & 2 deletions include/bitcoin/database/store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ class store
/// Depth of electrum merkle tree interval caching upon store creation.
uint8_t interval_depth() const NOEXCEPT;

/// Fork flags upon store creation.
uint32_t fork_flags() const NOEXCEPT;
/// Settings envelope stored at store creation.
const database::envelope& envelope() const NOEXCEPT;

/// Determine if the store is non-empty/initialized.
bool is_dirty() const NOEXCEPT;
Expand Down Expand Up @@ -124,6 +124,9 @@ class store
// This is thread safe.
const settings& configuration_;

// This is set at create/open and read-only thereafter.
database::envelope envelope_{};

/// Archives.
/// -----------------------------------------------------------------------
// These are thread safe.
Expand Down
12 changes: 1 addition & 11 deletions include/bitcoin/database/tables/archives/header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,7 @@ struct header
return sink;
}

inline bool operator==(const record& other) const NOEXCEPT
{
return ctx == other.ctx
&& milestone == other.milestone
&& parent_fk == other.parent_fk
&& version == other.version
&& timestamp == other.timestamp
&& bits == other.bits
&& nonce == other.nonce
&& merkle_root == other.merkle_root;
}
inline bool operator==(const record&) const NOEXCEPT = default;

context ctx{};
bool milestone{};
Expand Down
6 changes: 1 addition & 5 deletions include/bitcoin/database/tables/archives/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ struct input
return sink;
}

inline bool operator==(const slab& other) const NOEXCEPT
{
return script == other.script
&& witness == other.witness;
}
inline bool operator==(const slab&) const NOEXCEPT = default;

system::chain::script script{};
system::chain::witness witness{};
Expand Down
13 changes: 2 additions & 11 deletions include/bitcoin/database/tables/archives/ins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ struct ins_point
return index == system::chain::point::null_index;
}

inline bool operator==(const record& other) const NOEXCEPT
{
return hash == other.hash
&& index == other.index;
}
inline bool operator==(const record&) const NOEXCEPT = default;

hash_digest hash{};
ix::integer index{};
Expand Down Expand Up @@ -142,12 +138,7 @@ struct ins_sequence
return sink;
}

inline bool operator==(const record& other) const NOEXCEPT
{
return sequence == other.sequence
&& input_fk == other.input_fk
&& parent_fk == other.parent_fk;
}
inline bool operator==(const record&) const NOEXCEPT = default;

uint32_t sequence{};
in::integer input_fk{};
Expand Down
7 changes: 1 addition & 6 deletions include/bitcoin/database/tables/archives/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,7 @@ struct output
return sink;
}

inline bool operator==(const slab& other) const NOEXCEPT
{
return parent_fk == other.parent_fk
&& value == other.value
&& script == other.script;
}
inline bool operator==(const slab&) const NOEXCEPT = default;

tx::integer parent_fk{};
uint64_t value{};
Expand Down
5 changes: 1 addition & 4 deletions include/bitcoin/database/tables/archives/outs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ struct outs_puts
return sink;
}

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

output_links out_fks{};
};
Expand Down
13 changes: 1 addition & 12 deletions include/bitcoin/database/tables/archives/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,7 @@ struct transaction
return sink;
}

inline bool operator==(const record& other) const NOEXCEPT
{
return coinbase == other.coinbase
&& light == other.light
&& heavy == other.heavy
&& locktime == other.locktime
&& version == other.version
&& ins_count == other.ins_count
&& outs_count == other.outs_count
&& point_fk == other.point_fk
&& outs_fk == other.outs_fk;
}
inline bool operator==(const record&) const NOEXCEPT = default;

bool coinbase{};
bytes::integer light{};
Expand Down
Loading
Loading