0

I'm reading a rust project. Deleting the workspace cargo.toml and run test in eth_rpc_client gives out following error. I'm speculating if there's something around patch.crate-io, but cargo.toml of eth_rpc_client use same version as workspace does.

➜  eth_rpc_client git:(master) ✗ cargo test
    Updating crates.io index
    Updating git repository `https://github.com/aurora-is-near/lighthouse.git`
error: failed to select a version for the requirement `eth2_hashing = "^0.3.0"`
candidate versions found which didn't match: 0.2.0, 0.1.0
location searched: crates.io index
required by package `merkle_proof v0.2.0 (https://github.com/aurora-is-near/lighthouse.git?tag=v3.5.1-wasm#ce4e2b44)`
    ... which satisfies git dependency `merkle_proof` of package `eth_rpc_client v0.1.0 (/Users/paulyu/paul_playground/rainbow-bridge/eth2near/eth_rpc_client)`
.
├── Cargo.lock
├── Cargo.toml // workspace cargo.toml
├── contract_wrapper
├── eth2-contract-init
├── eth2near-block-relay
├── eth2near-block-relay-rs
├── eth_rpc_client
├── ethashproof
├── finality-update-verify
├── logger
├── rust-toolchain
└── target

workspace Cargo.toml

[workspace]

members = [
    "contract_wrapper",
    "eth2-contract-init",
    "eth2near-block-relay-rs",
    "eth_rpc_client",
    "finality-update-verify",
    "logger",
]

[patch]
[patch.crates-io]
eth2_ssz = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"  }
eth2_ssz_types = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"  }
eth2_hashing = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"  }
tree_hash = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"}
tree_hash_derive = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm"}
eth2_serde_utils = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
eth2_ssz_derive = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }

package Cargo.toml

[package]
name = "eth_rpc_client"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
types =  { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
tree_hash = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
merkle_proof = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
eth2_hashing = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
eth2_ssz = { git = "https://github.com/aurora-is-near/lighthouse.git", tag = "v3.5.1-wasm" }
log = { version = "0.4", features = ["std", "serde"] }
serde_json = "1.0.74"
serde = { version = "1.0", features = ["derive"] }
ethereum-types = { version = "0.14.1", features = ["rlp", "serialize"],  default-features = false }
reqwest = { version = "0.11", features = ["blocking"] }
eth-types = { path = "../../contracts/near/eth-types/" }
contract_wrapper = { path = "../contract_wrapper" }
clap = { version = "3.1.6", features = ["derive"] }
tokio = { version = "1.1", features = ["macros", "rt", "time"] }
env_logger = "0.9.0"
borsh = "0.9.3"
futures = { version = "0.3.21", default-features = false }
async-std = "1.12.0"
hex = "*"
toml = "0.5.9"
finality-update-verify = { path = "../finality-update-verify" }
atomic_refcell = "0.1.8"
bitvec = "*"

prometheus = { version = "0.9", features = ["process"] }
lazy_static = "1.4"
warp = "0.2"
thread = "*"
dotenv = "0.15.0"

ref: https://github.com/aurora-is-near/rainbow-bridge/tree/master/eth2near

Paul Yu
  • 15
  • 4
  • "Deleting Cargo.toml" isn't a thing that's supposed to work. What do you want to accomplish? – drewtato Apr 20 '23 at 01:24
  • I was trying to take part of the functionality from this project and implement my own stuff, and I didn’t add workspace cargo. Then it spins off this question – Paul Yu Apr 20 '23 at 01:44

1 Answers1

1

Yes, the [patch] section is very important.

The eth2_hashing dependency in your eth_rpc_client crate points to the correct GitHub repository, but that's not what is causing the error. Notice the "required by package merkle_proof" in the error message. If we look at the Cargo.toml of the merkle_proof package, it contains:

[dependencies]
eth2_hashing = "0.3.0"

This will try to look for version 0.3.0 of it on crates.io, which doesn't exist. Having the [patch] section will essentially redirect where that package is found.

To resolve this, you can either change all the packages in your GitHub repository to point to each other explicitly, or include a [patch.crates-io] in your eth_rpc_client package. If you have multiple packages needing it, consider keeping them in a workspace so you can have your patches all in one place.

kmdreko
  • 42,554
  • 6
  • 57
  • 106
  • May I clarify “ change all the packages in your GitHub repository to point to each other explicitly” do you mean point to each other correctly? Like having Merkle_tree point to 0.2.0 (available version on crate io)? – Paul Yu Apr 20 '23 at 03:13
  • I was under the impression you had forked the whole lighthouse repository and thus should make all your forked packages point to other forked packages. But if the ones hosted on crates.io are sufficient then that is easiest. – kmdreko Apr 20 '23 at 03:16