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

[4.0] Recreate EOS VM OC code cache if corrupt #1780

Merged
merged 3 commits into from
Oct 17, 2023

Conversation

heifner
Copy link
Member

@heifner heifner commented Oct 16, 2023

On startup recreate the EOS VM OC code cache if it is corrupt. The code cache is strictly a cache and can be recreated at anytime. No reason to stop startup with an error if it is corrupt, simply remove it and start over.

Also when --replay-blockchain is specified remove the code cache as it is likely not going to be useful and better to start from a clean slate.

Resolves #1406

@heifner heifner linked an issue Oct 16, 2023 that may be closed by this pull request
@heifner heifner added the OCI Work exclusive to OCI team label Oct 16, 2023
EOS_ASSERT(!cache_header.dirty, database_exception, "code cache is dirty");
EOS_ASSERT(cache_header.id == header_id, bad_database_version_exception, "existing EOS VM OC code cache not compatible with this version");
EOS_ASSERT(!cache_header.dirty, database_exception, "code cache is dirty");
break;
Copy link
Member

Choose a reason for hiding this comment

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

Was the code originally doing something else -- not immediately seeing the need for the while(true) & break here..

Copy link
Member Author

Choose a reason for hiding this comment

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

Before it would throw on dirty. Now it will attempt to re-create, but still throw if after the create it still hits an issue.

@spoonincode
Copy link
Member

thoughts on need for a unit test?

@heifner
Copy link
Member Author

heifner commented Oct 16, 2023

thoughts on need for a unit test?

Not sure how to create a dirty code cache file in a test. I manually tested with a code cache file that is dirty. I guess we could check a dirty code cache file into the repo for a test like that. Thoughts?

Comment on lines 251 to 271
while (true) {
try {
{
char header_buff[total_header_size];
std::ifstream hs(_cache_file_path.generic_string(), std::ifstream::binary);
hs.read(header_buff, sizeof(header_buff));
EOS_ASSERT(!hs.fail(), bad_database_version_exception, "failed to read code cache header");
memcpy((char*)&cache_header, header_buff + header_offset, sizeof(cache_header));
}

EOS_ASSERT(cache_header.id == header_id, bad_database_version_exception, "existing EOS VM OC code cache not compatible with this version");
EOS_ASSERT(!cache_header.dirty, database_exception, "code cache is dirty");
EOS_ASSERT(cache_header.id == header_id, bad_database_version_exception, "existing EOS VM OC code cache not compatible with this version");
EOS_ASSERT(!cache_header.dirty, database_exception, "code cache is dirty");
break;
} catch (const fc::exception&) {
if (created_file)
throw;

ilog("EOS VM optimized Compiler code cache corrupt, recreating");
create_code_cache_file();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If you wanted to get rid of the while loop, you could do something like this which essentially the same thing, but maybe a little bit more straightforward to understand:

   code_cache_header cache_header;
   auto check_code_cache = [&]() {
      char header_buff[total_header_size];
      std::ifstream hs(_cache_file_path.generic_string(), std::ifstream::binary);
      hs.read(header_buff, sizeof(header_buff));
      EOS_ASSERT(!hs.fail(), bad_database_version_exception, "failed to read code cache header");
      memcpy((char*)&cache_header, header_buff + header_offset, sizeof(cache_header));
         
      EOS_ASSERT(cache_header.id == header_id, bad_database_version_exception, "existing EOS VM OC code cache not compatible with this version");
      EOS_ASSERT(!cache_header.dirty, database_exception, "code cache is dirty");
   };

      
   try {
      check_code_cache();
   } catch (const fc::exception&) {
      if (created_file)
            throw;

      ilog("EOS VM optimized Compiler code cache corrupt, recreating");
      create_code_cache_file();
      check_code_cache();
   }

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@heifner heifner merged commit 7087694 into release/4.0 Oct 17, 2023
16 checks passed
@heifner heifner deleted the GH-1406-code-cache-4.0 branch October 17, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCI Work exclusive to OCI team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replay-blockchain option not purging state code cache
3 participants