-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(revm): Integrate BundleBuilder #4647
feat(revm): Integrate BundleBuilder #4647
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
... and 478 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
thx for taking this on! some questions and nits.
bin/reth/src/init.rs
Outdated
|
||
for (address, account) in &genesis.alloc { | ||
let bytecode_hash = if let Some(code) = &account.code { | ||
let bytecode = Bytecode::new_raw(code.0.clone()); | ||
let hash = bytecode.hash_slow(); | ||
contracts.insert(hash, bytecode); | ||
bundle_builder = bundle_builder.contract(hash, bytecode.0); |
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.
nit (cc @rakita) we should make the fn contract
on the bundle builder work with something like AsRef
so that you don't need to do .0
here
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.
should I create an issue on Revm for this?
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.
yeah
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.
created here: bluealloy/revm#782
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.
It feels strange to do AsRef when we need a type. Would recommend adding Into
for reth Bytecode.
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.
thanks, I added a .into()
and the related impl from Bytecode
for RevmBytecode
.
bin/reth/src/init.rs
Outdated
@@ -114,39 +111,30 @@ pub fn insert_genesis_state<DB: Database>( | |||
m.iter() | |||
.map(|(key, value)| { | |||
let value = U256::from_be_bytes(value.0); | |||
(*key, (U256::ZERO, value)) | |||
(U256::from_be_bytes(key.0), (U256::ZERO, value)) |
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.
won't be necessary post alloy transition
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.
alloy transition is now done, can you check if you can get rid of this change now?
@@ -56,44 +42,6 @@ impl BundleStateWithReceipts { | |||
Self { bundle, receipts, first_block } | |||
} | |||
|
|||
/// Create new bundle state with receipts. | |||
pub fn new_init( |
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.
great!
bundle_builder = bundle_builder.state_original_account_info( | ||
address, | ||
into_revm_acc(old_info.unwrap_or_default()), | ||
); | ||
bundle_builder = bundle_builder.state_present_account_info( | ||
address, | ||
into_revm_acc(new_info.unwrap_or_default()), |
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.
Given the introduction of these, shouldn't let mut state
be unnecessary, and as a result all the match state.entry
calls? I would think that the bundle builder would be able to recognize where to put these internally, otherwise we're now double counting
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.
yes you're right. I am now working on it. I'll soon push the update
address, | ||
if let Some(old_info) = old_info { | ||
Some(Some(into_revm_acc(old_info))) | ||
} else { | ||
Some(None) | ||
}, | ||
); |
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.
still don't love the Option<Option> in this API, would really like to do something about it -- cc @rakita for more thoughts
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.
for this one we should change the revert_account_info
. I could try think something about it today
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.
Can you simplify this with a old_info.map(into_revm_acc)
?
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.
Yes, this could be Some(old_info.map(into_revm_acc))
Right now I simply solved the problem related to |
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.
ok w/ me @rakita do you mind taking a look at this as well? @alessandromazza98 also pls rebase to main and check if we can get rid of type conversions
bin/reth/src/init.rs
Outdated
@@ -114,39 +111,30 @@ pub fn insert_genesis_state<DB: Database>( | |||
m.iter() | |||
.map(|(key, value)| { | |||
let value = U256::from_be_bytes(value.0); | |||
(*key, (U256::ZERO, value)) | |||
(U256::from_be_bytes(key.0), (U256::ZERO, value)) |
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.
alloy transition is now done, can you check if you can get rid of this change now?
entry.get_mut().0 = old_storage.value; | ||
} | ||
}; | ||
let present_info = plain_accounts_cursor.seek_exact(address)?.map(|kv| kv.1); |
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.
Does this part seems okay, we now always override the present and original state, while previously we did it only if there is no account inside state let account_state = match state.entry(address) {
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.
ok, should have solved it now. I added a Vec<Address>
that saves all seen addresses so that it's possible to filter out accounts already previously seen.
Hi, sorry for delay, I was off this weekend. Yes, I'm gonna work on final comments and reviews |
8b4b0d5
to
960f4c2
Compare
I rebased on main and deleted type conversions whenever possible. I also created the issue for Revm in order to be able to use the When merged (if it's all right) I can also update this PR to use only |
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.
Just so we dont merge it, and not check if there is a bug here #4647 (comment)
.push(old_storage); | ||
if !addresses_seen.contains(&address) { | ||
let present_info = plain_accounts_cursor.seek_exact(address)?.map(|kv| kv.1); | ||
bundle_builder = bundle_builder.state_original_account_info( |
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.
And you would need to save the address as seen here:
addresses_seen.push(address);
I would try to get this information from BundleBuilder
sa previously we would use state
, although this approach with addresses_seen
does the job
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.
Trying to use the BundleBuilder
I would like to use the states
field that actually contains all addresses seen, but its fields are private and not accessible and there aren't getter functions for it. Should I add a getter for states
to the BundleBuilder
?
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.
getter would be good
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 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.
ok, now is it better to wait for next release of Revm and update the release in the general Cargo.toml or should I use the last commit in the specific Cargo.toml of provider folder in Reth in order to use the newly added getter?
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.
You can specify the commit.
let new_info = plain_accounts_cursor.seek_exact(address)?.map(|kv| kv.1); | ||
bundle_builder = bundle_builder.state_present_account_info( | ||
address, | ||
into_revm_acc(new_info.unwrap_or_default()), |
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.
This line does not look good. Having Some
and having AccountInfo::default
are two different account states. Should probably be handled differently
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.
Looked at the BundleBuilder and in this case it would create Some(AccountInfo::default())
and I assume we would expect None
:
https://github.com/bluealloy/revm/blob/main/crates/revm/src/db/states/bundle_state.rs#L166-L167
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.
yes makes sense. I think it should work if first checking if new_info
(or old_info
and present_info
later in the code) is Some
and only if it is so, then do bundle_builder.state_present_account_info()
.
Hi @rakita I pushed my last two commits. In the second one I update the Cargo.toml globally in order to use the So right now the ci does not succeed for that reason. And I cannot use the update version of So maybe would be better to use the What do you think? |
Hows it looking @alessandromazza98? Happy to help out on this |
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.
Merged with main and left comments.
if let Some(old_info) = old_info { | ||
bundle_builder = | ||
bundle_builder.state_original_account_info(address, into_revm_acc(old_info)); |
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.
This seems not correct, the Option around old_info
is not properly used here, the Option represents if account was Some or None. I need to check original_account_info inside builder, maybe logic is there that would make this okay.
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.
Scratch the last sentence, there is a problem here as we don't remove old_info from original_state. In essence, leaving the previous value where it should be removed (Set to None).
} | ||
let state_changeset = bundle_state.clone().into_plain_state(OriginalValuesKnown::No); | ||
// revert account if needed. | ||
for (address, account) in state_changeset.accounts { |
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 this okay, or is there a better way, doesn't the bundle builder have all the needed info so we could skip both the cloning and the into_plain_state
?
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.
I mean by is it okay what happens if previous bundle state does not have account it would be None, but present plain state would contain it (it should remove it)?
} else if existing_entry.is_some() { | ||
plain_accounts_cursor.delete_current()?; | ||
} | ||
let state_changeset = bundle_state.clone().into_plain_state(OriginalValuesKnown::No); |
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.
it is called state_changeset but function is into_plain_state
Hey @alessandromazza98 given we have @rakita comments above, anything blocking? Else @idatsy feel free to take over if Ale is not able to complete this |
Closing this as stale. Feel free to let us know on the original issue if you end up picking this up again 😊 Thank you for taking a stab at it |
Closes #4614
Not 100% sure everything is correct. Let me know WDYT, thanks!