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
4 changes: 0 additions & 4 deletions include/bitcoin/node/protocols/protocol_block_out_106.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class BCN_API protocol_block_out_106
protocol_block_out_106(const auto& session,
const network::channel::ptr& channel) NOEXCEPT
: node::protocol_peer(session, channel),
top_checkpoint_height_(
session->system_settings().top_checkpoint().height()),
node_pruned_(session->node_settings().limited_blocks),
node_witness_(session->node_settings().provide_witness),
network::tracker<protocol_block_out_106>(session->log)
Expand Down Expand Up @@ -85,11 +83,9 @@ class BCN_API protocol_block_out_106
private:
using inventory = network::messages::peer::inventory;

bool is_under_checkpoint(const database::header_link& link) NOEXCEPT;
inventory create_inventory(const get_blocks& locator) const NOEXCEPT;

// These are thread safe.
const size_t top_checkpoint_height_;
const bool node_pruned_;
const bool node_witness_;
};
Expand Down
58 changes: 23 additions & 35 deletions src/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ void chaser_confirm::do_bumped(height_t) NOEXCEPT
// Guarded by candidate interlock.
size_t fork_point{};
const auto& query = archive();
auto fork = query.get_validated_fork(fork_point, checkpoint(),
silent_limit());
auto fork = query.get_validated_fork(fork_point, silent_limit());

// Fork may be empty if candidates were reorganized.
if (fork.empty())
Expand Down Expand Up @@ -246,51 +245,40 @@ void chaser_confirm::organize(header_states& fork, const header_links& popped,
auto height = add1(fork_point);

// Continue when suspended as write error terminates synchronous loop.
for (const auto& state: fork)
for (const auto& item: fork)
{
if (closed())
return;

switch (state.ec.value())
if (database::is_bypass(item.state))
{
case database::error::bypassed:
if (!query.set_filter_head(item.link))
{
if (!query.set_filter_head(state.link))
{
fault(error::confirm6);
return;
}

complete_block(error::success, state.link, height, true);
break;
fault(error::confirm6);
return;
}
case database::error::block_valid:
{
// False always sets a store fault (including for disk full).
if (!confirm_block(state.link, height, popped, fork_point))
return;

break;
}
case database::error::block_confirmable:
{
// Previously confirmable is not considered bypass.
complete_block(error::success, state.link, height, false);
break;
}
// error::unassociated
// error::unknown_state
// error::block_prevalid
// error::block_unconfirmable
default:
{
fault(error::confirm7);
complete_block(error::success, item.link, height, true);
}
else if (database::is_confirmable(item.state))
{
// Previously confirmable is not considered bypass.
complete_block(error::success, item.link, height, false);
}
else if (database::is_validated(item.state))
{
// False always sets a store fault (including for disk full).
if (!confirm_block(item.link, height, popped, fork_point))
return;
}
}
else
{
fault(error::confirm7);
return;
}

// After set_block_confirmable.
if (!set_organized(state.link, height++))
if (!set_organized(item.link, height++))
{
fault(error::confirm8);
return;
Expand Down
11 changes: 2 additions & 9 deletions src/chasers/chaser_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,18 +566,11 @@ code chaser_header::duplicate(size_t& height,
const auto id = query.to_header(hash);
if (!id.is_terminal())
{
// database::error::block_unconfirmable
// database::error::block_confirmable
// database::error::block_valid
// database::error::unknown_state (debugging)
// database::error::unvalidated
const auto ec = query.get_header_state(id);

// All header states are duplicates, one implies fail.
if (ec == database::error::block_unconfirmable)
if (query.is_unconfirmable(id))
{
height = query.get_height(id);
return ec;
return database::error::block_unconfirmable;
}

// height set to max_size_t unless unconfirmable.
Expand Down
49 changes: 13 additions & 36 deletions src/chasers/chaser_validate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,53 +208,30 @@ void chaser_validate::do_bumped(height_t height) NOEXCEPT
while ((validate_backlog_ < maximum_backlog_) && !closed() && !suspended())
{
const auto link = query.to_candidate(height);
const auto ec = query.get_block_state(link);
const auto state = query.get_block_state(link);

// Must exit on unassociated so they are not set valid in bypass.
// Given height-based iteration, any block state may be enountered.
if (ec == database::error::unassociated)
if (!database::is_associated(state))
return;

// The last job requiring validation has been posted.
if (height == maximum_height_)
maximum_posted_ = true;

const auto bypass = is_under_checkpoint(height) ||
query.is_milestone(link);
const auto silent = query.is_silent(link, height);
if (database::is_unconfirmable(state))
return;

switch (ec.value())
const auto bypass = database::is_bypass(state);
if (database::is_validated(state) ||
(bypass && !filter_ && !query.is_silent(link, height)))
{
complete_block(error::success, link, height, true);
}
else
{
case database::error::unvalidated:
case database::error::unknown_state:
{
if (bypass && !filter_ && !silent)
{
complete_block(error::success, link, height, true);
}
else
{
++validate_backlog_;
post_block(link, bypass);
}
break;
}
case database::error::block_valid:
case database::error::block_confirmable:
{
complete_block(error::success, link, height, true);
break;
}
case database::error::block_unconfirmable:
{
return;
}
////case database::error::unassociated
default:
{
fault(error::validate1);
return;
}
++validate_backlog_;
post_block(link, bypass);
}

// All posted validations must complete or this is invalid.
Expand Down
6 changes: 3 additions & 3 deletions src/protocols/protocol_block_in_31800.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ bool protocol_block_in_31800::handle_receive_block(const code& ec,
const auto link = it->link;
const auto height = it->context.height;
const auto checked = is_under_checkpoint(height);
const auto bypass = checked || query.is_milestone(link);
const auto bypass = query.is_bypass(link);
if (node_pruned_ && bypass && block.is_segregated())
{
LOGR("Unexpected witness from [" << opposite() << "].");
Expand Down Expand Up @@ -441,8 +441,8 @@ bool protocol_block_in_31800::is_under_checkpoint(size_t height) const NOEXCEPT
type_id protocol_block_in_31800::to_block_type(
const association& item) const NOEXCEPT
{
return node_pruned_ && (is_under_checkpoint(item.context.height) ||
archive().is_milestone(item.link)) ? type_id::block : block_type_;
return node_pruned_ && archive().is_bypass(item.link) ? type_id::block :
block_type_;
}

BC_POP_WARNING()
Expand Down
15 changes: 1 addition & 14 deletions src/protocols/protocol_block_out_106.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ bool protocol_block_out_106::is_servable(const hash_digest& LOG_ONLY(hash),
}

const auto& query = archive();
if (node_pruned_ && (is_under_checkpoint(link) || query.is_milestone(link)))
if (node_pruned_ && query.is_bypass(link))
{
LOGV("Requested pruned block " << encode_hash(hash)
<< " from [" << opposite() << "].");
Expand Down Expand Up @@ -305,19 +305,6 @@ protocol_block_out_106::inventory protocol_block_out_106::create_inventory(
);
}

bool protocol_block_out_106::is_under_checkpoint(
const database::header_link& link) NOEXCEPT
{
const auto height = archive().get_height(link);
if (height.is_terminal())
{
fault(database::error::integrity);
return false;
}

return height <= top_checkpoint_height_;
}

BC_POP_WARNING()
BC_POP_WARNING()
BC_POP_WARNING()
Expand Down
24 changes: 15 additions & 9 deletions test/chasers/chaser_confirm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ static void confirm_uncheckpointed(configuration& config)
config.bitcoin.checkpoints.clear();
}

static bool is_valid_only(database::block_state state)
{
return database::is_validated(state) && !database::is_confirmable(state);
}

struct confirm_setup_fixture
{
DELETE_COPY_MOVE(confirm_setup_fixture);
Expand Down Expand Up @@ -325,11 +330,12 @@ struct confirm_setup_fixture
});
}

bool stated(const chain::block& block, const code& expected)
bool stated(const chain::block& block,
bool(*expected)(database::block_state))
{
return await([&]()
{
return query_.get_block_state(link(block)) == expected;
return expected(query_.get_block_state(link(block)));
});
}
};
Expand Down Expand Up @@ -484,41 +490,41 @@ BOOST_AUTO_TEST_SUITE(chaser_confirm_tests)
////{
//// BOOST_REQUIRE(confirmed(confirm_d2(), 2));
//// BOOST_REQUIRE(confirmed(confirm_d1(), 1));
//// BOOST_REQUIRE(stated(confirm_d2(), database::error::block_confirmable));
//// BOOST_REQUIRE(stated(confirm_d2(), database::is_confirmable));
//// BOOST_REQUIRE(!query_.is_confirmed_block(link(confirm_c1())));
////}

////BOOST_FIXTURE_TEST_CASE(chaser_confirm__start__weaker_candidate_fork__not_reorganized, confirm_weaker_fixture)
////{
//// BOOST_REQUIRE(stated(confirm_d1(), database::error::block_valid));
//// BOOST_REQUIRE(stated(confirm_d1(), is_valid_only));
//// BOOST_REQUIRE(confirmed(confirm_c2(), 2));
//// BOOST_REQUIRE(confirmed(confirm_c1(), 1));
////}

////BOOST_FIXTURE_TEST_CASE(chaser_confirm__start__immature_spend__unconfirmable, confirm_immature_fixture)
////{
//// BOOST_REQUIRE(stated(confirm_e2(), database::error::block_unconfirmable));
//// BOOST_REQUIRE(stated(confirm_e2(), database::is_unconfirmable));
//// BOOST_REQUIRE(confirmed(confirm_d1(), 1));
//// BOOST_REQUIRE_EQUAL(query_.get_top_confirmed(), 1u);
////}

////BOOST_FIXTURE_TEST_CASE(chaser_confirm__start__immature_spend_fork__unconfirmable, confirm_immature_fork_fixture)
////{
//// BOOST_REQUIRE(stated(confirm_e2(), database::error::block_unconfirmable));
//// BOOST_REQUIRE(stated(confirm_e2(), database::is_unconfirmable));
//// BOOST_REQUIRE(await([&]() { return query_.get_top_confirmed() == 1u; }));
//// BOOST_REQUIRE(!query_.is_confirmed_block(link(confirm_e2())));
////}

BOOST_FIXTURE_TEST_CASE(chaser_confirm__start__current_candidates__organized, confirm_current_fixture)
{
BOOST_REQUIRE(confirmed(confirm_d2(), 2));
BOOST_REQUIRE(stated(confirm_d2(), database::error::block_confirmable));
BOOST_REQUIRE(stated(confirm_d2(), database::is_confirmable));
}

BOOST_FIXTURE_TEST_CASE(chaser_confirm__start__valid_candidate_without_filter_body__suspended, confirm_unfiltered_fixture)
{
BOOST_REQUIRE(await([&]() { return node_.suspended(); }));
BOOST_REQUIRE(stated(confirm_d1(), database::error::block_valid));
BOOST_REQUIRE(stated(confirm_d1(), is_valid_only));
BOOST_REQUIRE_EQUAL(query_.get_top_confirmed(), zero);
}

Expand Down Expand Up @@ -574,7 +580,7 @@ BOOST_FIXTURE_TEST_CASE(chaser_confirm__start__bypassed_candidate_unheaded_paren
////BOOST_FIXTURE_TEST_CASE(chaser_confirm__start__valid_candidate_without_prevouts__suspended_unconfirmable, confirm_unprevouted_fixture)
////{
//// BOOST_REQUIRE(await([&]() { return node_.suspended(); }));
//// BOOST_REQUIRE(stated(confirm_e2(), database::error::block_unconfirmable));
//// BOOST_REQUIRE(stated(confirm_e2(), database::is_unconfirmable));
//// BOOST_REQUIRE(await([&]() { return query_.get_top_confirmed() == zero; }));
////}

Expand Down
Loading
Loading