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

check root block num before returning it when include_root_t::yes #234

Merged
merged 2 commits into from
Jun 4, 2024

Conversation

spoonincode
Copy link
Member

Without this change it's possible for forkdb to return a block that does not match the block number requested which is causing a ship test malfunction.

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!

@spoonincode spoonincode requested a review from greg7mdp June 4, 2024 16:38
@spoonincode spoonincode merged commit 76f33e1 into main Jun 4, 2024
36 checks passed
@spoonincode spoonincode deleted the check_root_bnum_forkdb branch June 4, 2024 17:56
Copy link
Member

@linh2931 linh2931 left a comment

Choose a reason for hiding this comment

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

Good catch. Could have a unit test in the future.

@ericpassmore
Copy link
Contributor

Note:start
group: STABILITY
category: INTERNALS
summary: Fix sporadic issues, update ForkDB to return block matching block number.
Note:end

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.

5 participants