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
1 change: 0 additions & 1 deletion include/bitcoin/node/chasers/chaser_snapshot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class BCN_API chaser_snapshot
void do_snapshot(height_t height) NOEXCEPT;

// These are thread safe.
const size_t top_checkpoint_;
const uint64_t snapshot_bytes_;
const size_t snapshot_valid_;
const size_t snapshot_confirm_;
Expand Down
26 changes: 16 additions & 10 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
if (closed())
return;

// position is top of the set of contiguously valid blocks starting from
// the provided top checkpoint or position, considers milestones and state.
const auto& query = archive();
set_position(query.get_top_valid_from(std::max(position(), checkpoint())));
// position is top of the set of contiguously valid associated blocks
// scanning from the provided position, considering milestones and state.
set_position(archive().get_top_valid_from(position(), checkpoint()));

// Scan from candidate height to first confirmed, return links and work.
uint256_t work{};
Expand All @@ -158,7 +157,6 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
if (fork.empty())
return;

// Determine if fork has more work than confirmed branch.
bool strong{};
const auto fork_point = position() - fork.size();
if (!get_is_strong(strong, work, fork_point))
Expand All @@ -167,16 +165,19 @@ void chaser_confirm::do_bump(height_t) NOEXCEPT
return;
}

if (strong)
reorganize(fork, fork_point);
// Fork does not have more work than the confirmed branch.
if (!strong)
return;

reorganize(fork, fork_point);
}

// Pop confirmed chain from top down to above fork point, save popped.
void chaser_confirm::reorganize(header_links& fork, size_t fork_point) NOEXCEPT
{
BC_ASSERT(stranded());
const auto& query = archive();

const auto& query = archive();
auto height = query.get_top_confirmed();
if (height < fork_point)
{
Expand Down Expand Up @@ -214,8 +215,8 @@ void chaser_confirm::organize(header_links& fork, const header_links& popped,
size_t fork_point) NOEXCEPT
{
BC_ASSERT(stranded());
auto& query = archive();

auto& query = archive();
auto height = fork_point;
while (!fork.empty())
{
Expand Down Expand Up @@ -324,6 +325,7 @@ void chaser_confirm::organize(header_links& fork, const header_links& popped,

bool chaser_confirm::set_regressed(height_t candidate_height) NOEXCEPT
{
BC_ASSERT(stranded());
auto& query = archive();
const auto link = query.to_candidate(candidate_height);
return query.set_unstrong(link) || (query.get_block_state(link) ==
Expand All @@ -333,6 +335,7 @@ bool chaser_confirm::set_regressed(height_t candidate_height) NOEXCEPT
bool chaser_confirm::set_reorganized(const header_link& link,
height_t confirmed_height) NOEXCEPT
{
BC_ASSERT(stranded());
auto& query = archive();
if (!query.pop_confirmed() || !query.set_unstrong(link))
return false;
Expand All @@ -346,6 +349,7 @@ bool chaser_confirm::set_reorganized(const header_link& link,
bool chaser_confirm::set_organized(const header_link& link,
height_t confirmed_height, bool bypassed) NOEXCEPT
{
BC_ASSERT(stranded());
auto& query = archive();
if ((!bypassed && !query.set_strong(link)) || !query.push_confirmed(link))
return false;
Expand All @@ -361,8 +365,8 @@ bool chaser_confirm::set_organized(const header_link& link,
bool chaser_confirm::roll_back(const header_links& popped, size_t fork_point,
size_t top) NOEXCEPT
{
BC_ASSERT(stranded());
const auto& query = archive();

for (auto height = top; height > fork_point; --height)
if (!set_reorganized(query.to_confirmed(height), height))
return false;
Expand All @@ -381,6 +385,7 @@ bool chaser_confirm::roll_back(const header_links& popped, size_t fork_point,
bool chaser_confirm::get_fork_work(uint256_t& fork_work, header_links& fork,
height_t fork_top) const NOEXCEPT
{
BC_ASSERT(stranded());
const auto& query = archive();
header_link link{};
fork_work = zero;
Expand Down Expand Up @@ -413,6 +418,7 @@ bool chaser_confirm::get_fork_work(uint256_t& fork_work, header_links& fork,
bool chaser_confirm::get_is_strong(bool& strong, const uint256_t& fork_work,
size_t fork_point) const NOEXCEPT
{
BC_ASSERT(stranded());
uint256_t confirmed_work{};
const auto& query = archive();

Expand Down
11 changes: 5 additions & 6 deletions src/chasers/chaser_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

chaser_snapshot::chaser_snapshot(full_node& node) NOEXCEPT
: chaser(node),
top_checkpoint_(node.config().bitcoin.top_checkpoint().height()),
snapshot_bytes_(node.config().node.snapshot_bytes),
snapshot_valid_(node.config().node.snapshot_valid),
snapshot_confirm_(node.config().node.snapshot_confirm),
Expand All @@ -58,11 +57,11 @@ code chaser_snapshot::start() NOEXCEPT
bytes_ = archive().store_body_size();

if (enabled_valid_)
valid_ = std::max(archive().get_top_confirmed(), top_checkpoint_);
////valid_ = std::max(archive().get_top_validated(), top_checkpoint_);
valid_ = std::max(archive().get_top_confirmed(), checkpoint());
////valid_ = std::max(archive().get_top_validated(), checkpoint());

if (enabled_confirm_)
confirm_ = std::max(archive().get_top_confirmed(), top_checkpoint_);
confirm_ = std::max(archive().get_top_confirmed(), checkpoint());

if (enabled_bytes_ || enabled_valid_)
{
Expand Down Expand Up @@ -201,10 +200,10 @@ void chaser_snapshot::do_snapshot(size_t height) NOEXCEPT

if (enabled_valid_)
valid_ = height;
////valid_ = std::max(query.get_top_validated(), top_checkpoint_);
////valid_ = std::max(query.get_top_validated(), checkpoint());

if (enabled_confirm_)
valid_ = std::max(query.get_top_confirmed(), top_checkpoint_);
valid_ = std::max(query.get_top_confirmed(), checkpoint());
}

bool chaser_snapshot::update_bytes() NOEXCEPT
Expand Down
7 changes: 4 additions & 3 deletions src/chasers/chaser_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ bool chaser_validate::handle_event(const code&, chase event_,
void chaser_validate::do_regressed(height_t branch_point) NOEXCEPT
{
BC_ASSERT(stranded());

if (branch_point >= position())
return;

Expand Down Expand Up @@ -237,6 +236,7 @@ void chaser_validate::validate_block(const header_link& link,
complete_block(ec, link, ctx.height, bypass);
}

// Unstranded (concurrent by block).
code chaser_validate::populate(bool bypass, const chain::block& block,
const chain::context& ctx) NOEXCEPT
{
Expand All @@ -263,6 +263,7 @@ code chaser_validate::populate(bool bypass, const chain::block& block,
return system::error::success;
}

// Unstranded (concurrent by block).
code chaser_validate::validate(bool bypass, const chain::block& block,
const database::header_link& link, const chain::context& ctx) NOEXCEPT
{
Expand Down Expand Up @@ -291,7 +292,7 @@ code chaser_validate::validate(bool bypass, const chain::block& block,
return error::success;
}

// Completes off strand.
// May or may not be stranded.
void chaser_validate::complete_block(const code& ec, const header_link& link,
size_t height, bool bypassed) NOEXCEPT
{
Expand Down Expand Up @@ -328,7 +329,7 @@ void chaser_validate::complete_block(const code& ec, const header_link& link,
handle_event(ec, chase::bump, height_t{});
}

// strand
// strand - overridden due to independent priority thread pool
// ----------------------------------------------------------------------------

network::asio::strand& chaser_validate::strand() NOEXCEPT
Expand Down
Loading