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

Fix issues when LIB recorded from previous shutdown is at the edge of a gap #213

Merged
merged 5 commits into from
May 8, 2024

Conversation

yarkinwho
Copy link
Contributor

Resolves #209

@yarkinwho yarkinwho requested a review from elmato April 28, 2024 12:26
auto res = silkworm::db::read_canonical_header(txn, start_height);
if(!res) return {};

for (int i = 0; i < 32; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use !is_zero(res->prev_randao)

// the search process simple.
SILK_INFO << "Search for block containing a valid eos id. Start from:" << "#" << start_height;
silkworm::db::ROTxn txn(db_env);
do {
Copy link
Contributor

@elmato elmato May 6, 2024

Choose a reason for hiding this comment

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

why not just use while(start_height>0) and decrement start_height inside the while body?

while(--start_height > 0);
return {};
}

Copy link
Contributor

@elmato elmato May 6, 2024

Choose a reason for hiding this comment

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

// Alternative implementation

std::optional<silkworm::BlockHeader> res;
while(start_height>0) {
  res = silkworm::db::read_canonical_header(txn, start_height);
  if(res && !is_zero(res->prev_randao)) {
     break;
  }
 --start_height;
}
return res;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed as this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactor to do while again to handle the genesis case properly.

@yarkinwho yarkinwho requested a review from elmato May 7, 2024 11:43
@yarkinwho yarkinwho merged commit 6ae64ba into main May 8, 2024
6 checks passed
@yarkinwho yarkinwho deleted the yarkin/lib_fix branch May 8, 2024 00:03
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.

The start from LIB logic cannot recover from shutdown when LIB happen to be the first on after a gap
2 participants