-
Notifications
You must be signed in to change notification settings - Fork 852
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 v2 #6505
Code storage by hash v2 #6505
Conversation
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: Jason Frame <[email protected]>
|
Hi @jframe, since this PR changes the format, I think we need to introduce a new version in the database metadata. |
I think it is a good idea. Will sync up with you on this. Don't think it needs to go in this PR though as this is experimental and doesn't seem right to bake in database versions as part of an experimental feature. But before it's production ready would like to have database versioning for code storage column family in Bonsai to prevent db compatibility issues. |
Confirmed on test nodes that restart issue no longer occurs |
Signed-off-by: Jason Frame <[email protected]>
|
||
public static boolean isCodeHashValue(final byte[] key, final byte[] value) { | ||
final Hash valueHash = Hash.hash(Bytes.wrap(value)); | ||
return Bytes.wrap(key).equals(valueHash); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no risk to find a key value that match for codeByHash but it's codeByAddress in reality ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this can happen in reality. To do that would need to be able to predict the address and have that as the runtime code. I've gone through the scenarios for create and create2 and I can't see a case where this could happen. In the case of create it's not possible to predict the address since it hashes the nonce and sender address and applies the etherum address rule. In the case of the create2 it is more interesting since we can control the inputs, but I still don't think it's possible since you would need the initCode to create a contract with the runtime code of the address which is not possible to predict in advance although we can calculate it in the case of create2.
Also would prefer to replace this detection with the database metadata approach once that is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we know when it will be available ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. Think it's still a work in progress https://github.com/fab-10/besu/tree/database-metadata-refactor. So might be a little while off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it working fine with a call to resyncWorldstate API RPC ? should be fine just to be sure
Tested with resyncWorldState API RPC and it's working fine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the tests and the code seems good for me
PR description
This is a redo of #5889 including a fix for detection of existing storage.
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
CODE_HASH_COUNT
is using 38 MiB.