-
Notifications
You must be signed in to change notification settings - Fork 36
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: Migrate trie account type and state root functions from alloy #65
Conversation
src/serde/quantity.rs
Outdated
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.
Account
requires alloy-serde::quantity
to serialize the nonce
field, but alloy-trie can not depend on it, so I exported it partially 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.
some nits,
@DaniPopes imo we definitely want this in here, wdyt?
src/account.rs
Outdated
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] | ||
pub struct Account { |
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.
let's also name this TrieAccount here to avoid conflicts
src/serde/quantity.rs
Outdated
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 is too much we only need this for u64, so no need to port the entire trait abstraction, we can just take:
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.
Cargo.toml
Outdated
@@ -37,6 +37,7 @@ derive_more = { version = "1", default-features = false, features = [ | |||
"from", | |||
"not", | |||
] } | |||
itertools = { version = "0.13", default-features = false, optional = true } |
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.
we can actually remove this because we only use one function
#[cfg(feature = "use_alloc")]
fn sorted_unstable_by_key<K, F>(self, f: F) -> VecIntoIter<Self::Item>
where
Self: Sized,
K: Ord,
F: FnMut(&Self::Item) -> K,
{
let mut v = Vec::from_iter(self);
v.sort_unstable_by_key(f);
v.into_iter()
}
and we can do that ourselves
then we also don't need to feature gate the state root functions
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've removed this and handled it internally, while also cleaning up the feature gate: a29f17f
I wonder why https://github.com/alloy-rs/trie/actions/runs/12141835115/job/33856483337
|
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.
please, feature gate any account related code behind ethereum
. this crate is unaware of ethereum's state model, it's only MPT implementation
this has to do with the lockfile fixed on main |
Thanks 🙏 |
51e382e
to
d70e843
Compare
src/root.rs
Outdated
/// Hashes and sorts account keys, then proceeds to calculating the root hash of the state | ||
/// represented as MPT. | ||
/// See [`state_root_unsorted`] for more info. | ||
#[cfg(feature = "ethereum")] | ||
pub fn state_root_ref_unhashed<'a, A: Into<TrieAccount> + Clone + 'a>( |
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.
style nit: let's put all of these in a mod ethereum
and feature gate this instead
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.
lgtm
Migrated trie account type
Account
and state root functions from alloy-rs/alloy.Originally I tried to export them form reth to alloy-rs/alloy, but it's better to do that here.
ref: alloy-rs/alloy#1717 (review)