lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Migrate from `ethereum-types` to `alloy-primitives`

Open eserilev opened this issue 1 year ago • 11 comments

Issue Addressed

partially #6022

Proposed Changes

Migrate LH from ethereum-types to alloy-primitives

Additional Info

Some of the dependencies are referencing branches from my repo. I've opened PR's that need to be merged into those repos so we can revert back to referencing the sigp repos.

I've attempted to patch in some dependencies, but quickly faced some cyclic dep issues that I was unable to resolve

eserilev avatar Jul 11 '24 14:07 eserilev

I tried investigating the circular dependency issue that crops up when using [patch].

I think it is down to how Cargo handles optional dependencies, and possibly the ethereum_ssz?/arbitrary dependency here:

https://github.com/alloy-rs/core/blob/6540523385ea10c9adce31beae7106cfa7da770f/crates/primitives/Cargo.toml#L96-L105

I made a minimal test case here, and it is very broken, even without the ? syntax:

https://github.com/michaelsproul/circular-test

I think our two options are:

  1. Tolerate the existence of two ethereum_ssz crates in the build tree until alloy-primitives is updated to not depend on ethereum_ssz at all. If we bump the ethereum_ssz version to 0.6 on the alloy branch, and depend on that version in Lighthouse, then the ethereum_ssz dep of alloy-primitives will not get patched.
  2. Raise a PR to alloy-primitives to remove the ethereum_ssz dep, and make this part of the patch section. This probably needs to be the long-term solution, so maybe we should start working on this even if we take option (1) for now.

michaelsproul avatar Jul 30 '24 06:07 michaelsproul

Related Cargo issue:

  • https://github.com/rust-lang/cargo/issues/6743

michaelsproul avatar Jul 30 '24 06:07 michaelsproul

Thanks for taking a look at this @michaelsproul

For option (2), removing the ethereum_ssz dep, I think this means we'll need to impl ssz Encode & Decode directly in the alloy_primitives crate. Does that sound correct?

eserilev avatar Jul 30 '24 14:07 eserilev

I think we should move the SSZ impls that are currently in alloy-primitives into ethereum_ssz itself.

E.g. implementing Decode/Encode for H256 should be in ethereum_ssz

michaelsproul avatar Jul 30 '24 14:07 michaelsproul

I went ahead and made some progress on option (2)

  • PR to alloy https://github.com/alloy-rs/core/pull/701
  • PR to ethereum_ssz https://github.com/sigp/ethereum_ssz/pull/26

I've also patched in the relevant deps into Lighthouse. No more circular dependency issues!

eserilev avatar Jul 30 '24 16:07 eserilev

I've released preliminary versions of all our crates which we can use in this PR. I think we could merge it to unstable and then come back for the coordinated release to remove ethereum_ssz 0.5.4 later.

michaelsproul avatar Aug 20 '24 05:08 michaelsproul

sounds good, will resolve the conflicts and get those dependencies pointed to the right versions

eserilev avatar Aug 20 '24 05:08 eserilev

Updated to point to the correct dependencies and resolved all conflicts. Since we're not patching any deps in anymore, we're actually ok to use the existing alloy-primitives crate.

eserilev avatar Aug 20 '24 20:08 eserilev

I've just released new versions of all the packages depending on alloy-primitives 0.8, so we should be able to cut out the duplicate version of ethereum_ssz now!

Can you bump every dep by +0.1.0?

michaelsproul avatar Aug 23 '24 06:08 michaelsproul

we cant bump alloy-primitives to 0.8 until this gets merged: https://github.com/alloy-rs/alloy/pull/1167

alloy-consensus still depends on alloy-primitives 0.7.7 and theres some diff between alloy_primitives::TxKind on 0.7 vs 0.8 that causes issues

maybe theres a way to work around this issue? not 100% sure. We can either wait for the new alloy release or figure out a workaround

EDIT: in 11d8a26 I've commented out the problematic code and added a TODO to reintroduce it once alloy cuts a new release

eserilev avatar Aug 23 '24 20:08 eserilev

fyi new alloy-rs/alloy crate release coming later today, tmrw at the latest

mattsse avatar Aug 27 '24 11:08 mattsse

alloy cut a release so were no longer blocked by that

eserilev avatar Aug 28 '24 21:08 eserilev

this should be ready for another review!

eserilev avatar Sep 01 '24 17:09 eserilev

@mergify queue

michaelsproul avatar Sep 02 '24 07:09 michaelsproul

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 99e53b88c3bd2e3af5aefe2e86bb0804556d8d8c

mergify[bot] avatar Sep 02 '24 07:09 mergify[bot]