Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't include_root_t for controller::fetch_block_id_on_head_branch_by_num() #231

Closed
wants to merge 1 commit into from

Conversation

spoonincode
Copy link
Member

I'm suspicious that this call should not include_root_t::yes because doing so can cause the forkdb to return a block that does not match the block number requested, which is causing a ship test malfunction. Unfortunately it's not entirely clear to me what other side effects switching this will cause; though all tests do pass 😇

Consider a forkdb that is rooted at block 300, has a head that is 300, and no block log exists, something calls get_block_id_for_num(299)

block_id_type controller::get_block_id_for_num( uint32_t block_num )const { try {
const auto& blog_head = my->blog.head();
bool find_in_blog = (blog_head && block_num <= blog_head->block_num());
if( !find_in_blog ) {
std::optional<block_id_type> id = my->fetch_block_id_on_head_branch_by_num(block_num);
if (id) return *id;

so,
std::optional<block_id_type> fetch_block_id_on_head_branch_by_num(uint32_t block_num) const {
return fork_db.apply<std::optional<block_id_type>>([&](const auto& forkdb) -> std::optional<block_id_type> {
auto bsp = forkdb.search_on_head_branch(block_num, include_root_t::yes);

ultimately,
template<class BSP>
BSP fork_database_impl<BSP>::search_on_head_branch_impl( uint32_t block_num, include_root_t include_root ) const {
return search_on_branch_impl(head->id(), block_num, include_root);

notice above that the first parameter will be the block id for block 300. then,
BSP fork_database_impl<BSP>::search_on_branch_impl( const block_id_type& h, uint32_t block_num, include_root_t include_root ) const {
if( include_root == include_root_t::yes && root->id() == h ) {
return root;
}

since root == head && include_root_t the block id for block 300 will be returned. But we asked for block 299!

@@ -1139,7 +1139,7 @@ struct controller_impl {

std::optional<block_id_type> fetch_block_id_on_head_branch_by_num(uint32_t block_num) const {
return fork_db.apply<std::optional<block_id_type>>([&](const auto& forkdb) -> std::optional<block_id_type> {
auto bsp = forkdb.search_on_head_branch(block_num, include_root_t::yes);
auto bsp = forkdb.search_on_head_branch(block_num);
if (bsp) return bsp->id();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fix should be:

if( include_root == include_root_t::yes && root->id() == h ) {
return root;
}

      if( include_root == include_root_t::yes && root->id() == h ) {
         if (root->block_num() == block_num)
            return root;
      }

@spoonincode
Copy link
Member Author

sounds good, replaced by #234

@spoonincode spoonincode closed this Jun 4, 2024
@spoonincode spoonincode deleted the no_include_root_t branch June 13, 2024 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants