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
29 changes: 20 additions & 9 deletions include/bitcoin/database/impl/query/archive_write.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ bool CLASS::set(const transaction& tx) NOEXCEPT
}

TEMPLATE
bool CLASS::set(const block& block, bool strong, bool bypass) NOEXCEPT
bool CLASS::set(const block& block, bool strong, bool bypass,
size_t height) NOEXCEPT
{
// This sets only the txs of a block with header/context already archived.
return !set_code(block, strong, bypass);
return !set_code(block, strong, bypass, height);
}

// set transaction
Expand Down Expand Up @@ -338,7 +339,8 @@ code CLASS::set_code(header_link& out_fk, const block& block,
const context& ctx, bool milestone, bool strong) NOEXCEPT
{
const auto ec = set_code(out_fk, block.header(), ctx, milestone);
return ec ? ec : set_code(block, out_fk, strong, strong || milestone);
return ec ? ec : set_code(block, out_fk, strong, strong || milestone,
ctx.height);
}

// set txs from block
Expand All @@ -348,26 +350,27 @@ code CLASS::set_code(header_link& out_fk, const block& block,
// releases all memory for parts of itself, due to the custom allocator.

TEMPLATE
code CLASS::set_code(const block& block, bool strong, bool bypass) NOEXCEPT
code CLASS::set_code(const block& block, bool strong, bool bypass,
size_t height) NOEXCEPT
{
header_link unused{};
return set_code(unused, block, strong, bypass);
return set_code(unused, block, strong, bypass, height);
}

TEMPLATE
code CLASS::set_code(header_link& out_fk, const block& block, bool strong,
bool bypass) NOEXCEPT
bool bypass, size_t height) NOEXCEPT
{
out_fk = to_header(block.get_hash());
if (out_fk.is_terminal())
return error::txs_header;

return set_code(block, out_fk, strong, bypass);
return set_code(block, out_fk, strong, bypass, height);
}

TEMPLATE
code CLASS::set_code(const block& block, const header_link& key,
bool strong, bool bypass) NOEXCEPT
bool strong, bool bypass, size_t /* height */) NOEXCEPT
{
using namespace system;
if (key.is_terminal())
Expand All @@ -392,6 +395,13 @@ code CLASS::set_code(const block& block, const header_link& key,
const auto size = block.serialized_size(true);
const auto wire = possible_narrow_cast<bytes>(size);

// TODO: compute and set interval hash for interval blocks as configured.
// TODO: create query to walk header.parent across full interval to collect
// TODO: merkle leaves and compute intermediate merkle root. This requires
// TODO: header.parent link traversal only, with read of hash for each. The
// TODO: full interval of hashes (e.g. 2048) is preallocated to a vector.
std::optional<hash_digest> interval{};

// ========================================================================
const auto scope = store_.get_transactor();
constexpr auto positive = true;
Expand All @@ -407,7 +417,8 @@ code CLASS::set_code(const block& block, const header_link& key,
{},
wire,
count,
tx_fks
tx_fks,
std::move(interval)
}) ? error::success : error::txs_txs_put;
// ========================================================================
}
Expand Down
10 changes: 6 additions & 4 deletions include/bitcoin/database/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,8 @@ class query
bool set(const block& block, const context& ctx,
bool milestone, bool strong) NOEXCEPT;
bool set(const transaction& tx) NOEXCEPT;
bool set(const block& block, bool strong, bool bypass) NOEXCEPT;
bool set(const block& block, bool strong, bool bypass,
size_t height) NOEXCEPT;

/// Set transaction.
code set_code(const transaction& tx) NOEXCEPT;
Expand All @@ -438,11 +439,12 @@ class query
const chain_context& ctx, bool milestone, bool strong) NOEXCEPT;

/// Set block.txs (headers-first).
code set_code(const block& block, bool strong, bool bypass) NOEXCEPT;
code set_code(const block& block, bool strong, bool bypass,
size_t height) NOEXCEPT;
code set_code(header_link& out_fk, const block& block, bool strong,
bool bypass) NOEXCEPT;
bool bypass, size_t height) NOEXCEPT;
code set_code(const block& block, const header_link& key, bool strong,
bool bypass) NOEXCEPT;
bool bypass, size_t height) NOEXCEPT;

/// Context.
/// -----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/database/tables/archives/input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct input
struct get_ptrs
: public schema::input
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
Expand All @@ -103,7 +103,7 @@ struct input
struct get_script
: public schema::input
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
Expand All @@ -122,7 +122,7 @@ struct input
struct get_witness
: public schema::input
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/database/tables/archives/ins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct ins
struct put_ref
: public schema::ins
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
return system::possible_narrow_cast<link::integer>(tx_.inputs());
}
Expand Down
10 changes: 5 additions & 5 deletions include/bitcoin/database/tables/archives/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct output
struct only
: public schema::output
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
Expand Down Expand Up @@ -115,7 +115,7 @@ struct output
struct get_script
: public schema::output
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
Expand All @@ -136,7 +136,7 @@ struct output
struct get_parent_value
: public schema::output
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
Expand All @@ -156,7 +156,7 @@ struct output
struct get_parent
: public schema::output
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
Expand All @@ -174,7 +174,7 @@ struct output
struct get_value
: public schema::output
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
BC_ASSERT(false);
return {};
Expand Down
6 changes: 3 additions & 3 deletions include/bitcoin/database/tables/archives/outs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct outs
struct record
: public schema::outs
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
return system::possible_narrow_cast<link::integer>(out_fks.size());
}
Expand Down Expand Up @@ -80,7 +80,7 @@ struct outs
struct get_output
: public schema::outs
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
return 1;
}
Expand All @@ -97,7 +97,7 @@ struct outs
struct put_ref
: public schema::outs
{
link count() const NOEXCEPT
inline link count() const NOEXCEPT
{
return system::possible_narrow_cast<link::integer>(tx_.outputs());
}
Expand Down
Loading
Loading