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

IF: Change Fork_db root to store block state #2284

Merged
merged 3 commits into from
Mar 6, 2024
Merged

Conversation

greg7mdp
Copy link
Contributor

@greg7mdp greg7mdp commented Mar 6, 2024

Resolves #2283 .

Removes fork_database::get_block_header and simplifies create_block_state_i.

The only difference between fork_database::get_block_header and fork_database::get_block was that the former checked the root. It was also relying on the fact that block_state is public block_header_state to return the same pointer downcasted.

I have added an optional check_root parameter to fork_database::get_block instead.

This allowed to make create_block_state_i a template instead of having two separate implementations.

New disk format and compatibility mode will be addressed in #2285 .

@greg7mdp greg7mdp marked this pull request as draft March 6, 2024 14:49
@greg7mdp greg7mdp marked this pull request as ready for review March 6, 2024 15:33
@greg7mdp greg7mdp requested review from heifner, arhag and linh2931 and removed request for arhag March 6, 2024 15:33
libraries/chain/controller.cpp Outdated Show resolved Hide resolved
@@ -18,6 +18,8 @@ namespace eosio::chain {
/**
* History:
* Version 1: initial version of the new refactored fork database portable format
* Version 2: Savanna version, store either `block_state`, `block_state_legacy` or both versions,
* root is full `block_state`, not just the header.
Copy link
Member

Choose a reason for hiding this comment

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

You didn't update max_supported_version. As implemented, it looks like this implementation can read version 1. However, a version 1 written by this implementation will not be readable by leap v5 or before. Not really sure we really need to support downgrading a node back to pre leap v6. A version dump would allow for a better error message in pre leap v6 (Unsupported version of fork database file).

Copy link
Member

Choose a reason for hiding this comment

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

Note I'm working on #2141 which has the test coverage fork database writing/reading. Would really like this tested with the test cases that are being restored in #2141.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You didn't update max_supported_version. As implemented, it looks like this implementation can read version 1.

The compatibility work will be addressed in a separate issue #2285. The current version (even before this PR) is not compatible with the leap5 format either (for example if starting from a post-transition snapshot).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note I'm working on #2141 which has the test coverage fork database writing/reading. Would really like this tested with the test cases that are being restored in #2141.

This PR does not address the pre-existing file format issue which will be addressed in #2285.

index.clear();
root = std::make_shared<bs_t>();
static_cast<bhs_t&>(*root) = root_bhs;
root = root_bsp;
bs_accessor_t::set_valid(*root, true);
Copy link
Member

Choose a reason for hiding this comment

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

Should only set valid if this was a version 1 root_bsp from open_impl. Otherwise, it should already be valid. Could assert it is valid and set the valid in open_impl if a block_header_state was read instead of a block_state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite sure why, but it appears that validated is not set on root after loading a fork_db when running tests with this PR's code, se the set_valid is necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Set valid is only necessary when loading a version 1 fork database which does not have all the block_state (doesn't read in validated.). I think you should move the set valid into open_impl and assert in reset_root_impl.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set valid is only necessary when loading a version 1 fork database which does not have all the block_state (doesn't read in validated.). I think you should move the set valid into open_impl and assert in reset_root_impl.

I tried that but many tests fail when I do that.

Copy link
Member

Choose a reason for hiding this comment

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

Glancing at the tests, I think I know why. I can address that in #2141

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm curious to know what the issue could be?

Copy link
Member

Choose a reason for hiding this comment

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

Mock block_state rely on this to set valid. Those need to set valid outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mock block_state rely on this to set valid. Those need to set valid outside.

Thanks, that makes sense.

@greg7mdp greg7mdp linked an issue Mar 6, 2024 that may be closed by this pull request
@ericpassmore
Copy link
Contributor

ericpassmore commented Mar 6, 2024

Note:start
group: IF
category: INTERNALS
summary: Simplify fork db consolidating on fork_database get_block
Note:end

@@ -11,6 +11,7 @@ namespace eosio::chain {
using block_branch_t = std::vector<signed_block_ptr>;
enum class mark_valid_t { no, yes };
enum class ignore_duplicate_t { no, yes };
enum class check_root_t { no, yes };
Copy link
Member

Choose a reason for hiding this comment

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

Minor thing, but seems like this should be called include_root_t

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's actually the named I used first, but it felt wrong for some reason and I prefer check_root_t. If you want to change it later I'm fine with it.

@greg7mdp greg7mdp merged commit c90680d into hotstuff_integration Mar 6, 2024
30 checks passed
@greg7mdp greg7mdp deleted the gh_2283 branch March 6, 2024 18:59
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.

IF: Change Fork_db root to store block state
4 participants