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

Code storage by hash #5889

Merged
merged 51 commits into from
Jan 31, 2024
Merged

Code storage by hash #5889

merged 51 commits into from
Jan 31, 2024

Conversation

jframe
Copy link
Contributor

@jframe jframe commented Sep 18, 2023

PR description

Storing code by hash instead of by address. This is needed so that Besu can serve snapsync as we need to be able to retrieve the code by hash.

After syncing with this change it's not possible to downgrade to an older version of Besu. If we think this is needed I could add a subcommand to do the conversion.

Testing

Screenshot 2023-10-16 at 10 07 15 am

Fixed Issue(s)

fixed #5388

@github-actions
Copy link

github-actions bot commented Sep 18, 2023

  • I thought about documentation and added the doc-change-required label to this PR if updates are required.
  • I thought about the changelog and included a changelog update if required.
  • If my PR includes database changes (e.g. KeyValueSegmentIdentifier) I have thought about compatibility and performed forwards and backwards compatibility tests

@jframe jframe force-pushed the code_storage_by_hash branch 2 times, most recently from b254b42 to 325fc54 Compare September 22, 2023 05:57
@jframe jframe force-pushed the code_storage_by_hash branch 3 times, most recently from a4d26f8 to ea8893e Compare September 29, 2023 00:00
garyschulte added a commit to garyschulte/besu that referenced this pull request Oct 5, 2023
garyschulte added a commit to garyschulte/besu that referenced this pull request Oct 5, 2023
garyschulte added a commit to garyschulte/besu that referenced this pull request Oct 5, 2023
garyschulte added a commit to garyschulte/besu that referenced this pull request Oct 5, 2023
garyschulte added a commit to garyschulte/besu that referenced this pull request Oct 10, 2023
@jframe jframe mentioned this pull request Oct 11, 2023
@jframe jframe changed the title Draft PR: Code storage by hash Code storage by hash Oct 16, 2023
@jframe jframe marked this pull request as ready for review October 16, 2023 04:14
@garyschulte garyschulte mentioned this pull request Jan 12, 2024
final SegmentedKeyValueStorageTransaction transaction,
final Hash accountHash,
final Hash codeHash) {
// TODO JF add reference counting so that code can be removed when there are no more usages
Copy link
Contributor

@garyschulte garyschulte Jan 23, 2024

Choose a reason for hiding this comment

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

👍 , we should like the issue for context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, I'll update the comment with the issue

Copy link
Contributor

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

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

Looks good, the only significant concern is the ability for code storage CLI param to affect besu's worldstate consistency when it is initially synced with a different code storage method

Comment on lines 60 to 64
this.codeStorageStrategy =
useCodeStoredByHash
? new CodeHashCodeStorageStrategy()
: new AccountHashCodeStorageStrategy();

Copy link
Contributor

Choose a reason for hiding this comment

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

can we move this up into FlatDbStrategyProvider, and pass a CodeStorageStrategy rather than a boolean ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 55 to 59
final boolean isCodeStoredByHashEnabled =
dataStorageConfiguration.getUnstable().getBonsaiCodeStoredByCodeHashEnabled();
LOG.info(
"Bonsai flat db mode with code stored using code hash enabled = {}",
isCodeStoredByHashEnabled);
Copy link
Contributor

@garyschulte garyschulte Jan 23, 2024

Choose a reason for hiding this comment

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

the risk of driving this from command line only is that we can fall out of consensus if the user changes this config parameter without resyncing. It isn't fun to plumb in the check but we should try to derive the codehash vs accounthash as it exists in the database and only allow the cli parameter to affect an as-yet-unsynced node.

we already have the notion of using loadFlatDbStrategy(..) in BonsaiWorldStateKeyValueStorage, and it will override the CLI supplied flat db strategy based on what it finds. We can work a code storage check into that method and ensure that we use the correct code storage strategy based on what is in the db, and perhaps log a big ugly warning message if the CLI param does not match the db storage

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added detection code in the FlatDbStrategyProvider which will warn if there is an inconsistency and use the strategy in the database.

import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class BonsaiWorldStateTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we should add a test that asserts the correct FlatDBStrategy (with the correct CodeStorageStrategy) is constructed when the db storage and the cli param disagree.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some tests for that in the FlatDbStrategyProvider since that's where it's created

Copy link
Contributor

@garyschulte garyschulte left a comment

Choose a reason for hiding this comment

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

🚢 great test coverage

@non-fungible-nelson
Copy link
Contributor

💯 🚀

@jframe jframe enabled auto-merge (squash) January 30, 2024 22:27
@jframe jframe disabled auto-merge January 30, 2024 22:43
@jframe jframe enabled auto-merge (squash) January 30, 2024 22:44
@jframe jframe merged commit 9c02518 into hyperledger:main Jan 31, 2024
18 checks passed
jframe added a commit to jframe/besu that referenced this pull request Jan 31, 2024
jframe added a commit that referenced this pull request Jan 31, 2024
This reverts commit 9c02518.

Signed-off-by: Jason Frame <[email protected]>
jframe added a commit to jframe/besu that referenced this pull request Jan 31, 2024
Add a storage mode for Bonsai that can store the code by hash instead of account hash

Signed-off-by: Jason Frame <[email protected]>
@jframe jframe mentioned this pull request Jan 31, 2024
Gabriel-Trintinalia pushed a commit to Gabriel-Trintinalia/besu that referenced this pull request Feb 1, 2024
Add a storage mode for Bonsai that can store the code by hash instead of account hash

Signed-off-by: Jason Frame <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
Gabriel-Trintinalia pushed a commit to Gabriel-Trintinalia/besu that referenced this pull request Feb 1, 2024
…6504)

This reverts commit 9c02518.

Signed-off-by: Jason Frame <[email protected]>
Signed-off-by: Gabriel-Trintinalia <[email protected]>
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.

Change bytecode storage to be by hash as opposed to by address
6 participants