NethermindEth / juno

Starknet client implementation.
https://juno.nethermind.io
Apache License 2.0
382 stars 164 forks source link

Investigate dependencies of Rust code in go packages #2084

Open kirugan opened 3 weeks ago

kirugan commented 3 weeks ago

Context: the Starknet P2P explorer uses Juno as an external library for some of its features, but it's not as simple as doing go get, as it's required to compile the Rust dependencies.

For example, here's a snippet of the build process if Juno is used as a library (without the additional Rust compilation):

...
26.31 /usr/bin/ld: cannot find -ljuno_starknet_compiler_rs: No such file or directory
26.31 /usr/bin/ld: cannot find -ljuno_starknet_core_rs: No such file or directory
26.31 /usr/bin/ld: /tmp/go-link-3421764336/000026.o: in function `mygetgrouplist':
26.31 /_/GOROOT/src/os/user/getgrouplist_unix.go:15: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
26.31 /usr/bin/ld: /tmp/go-link-3421764336/000025.o: in function `mygetgrgid_r':
26.31 /_/GOROOT/src/os/user/cgo_lookup_cgo.go:45: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
...

List of packages that is used right now:

github.com/NethermindEth/juno/utils
github.com/NethermindEth/juno/clients/feeder
github.com/NethermindEth/juno/starknetdata/feeder

These packages shouldn't require rust code at all (especially utils package). We need to investigate what's going on

ShantelPeters commented 3 weeks ago

Can I work on this ?

onlydustapp[bot] commented 3 weeks ago

Hey @ShantelPeters! Thanks for showing interest. We've created an application for you to contribute to Juno. Go check it out on OnlyDust!

weiihann commented 3 weeks ago

Did some investigations:

github.com/NethermindEth/juno/clients/feeder

That's why the following errors occur:

26.31 /usr/bin/ld: cannot find -ljuno_starknet_compiler_rs: No such file or directory
26.31 /usr/bin/ld: cannot find -ljuno_starknet_core_rs: No such file or directory

So compilation is needed for packages core and starknet, which require Rust dependencies.

Some solutions in mind:

  1. Move the Rust code to its own packages for core and starknet
    • starknet contains the Compile function, in which only rpc and adapters/p2p2core are using it, we can move it to a separate package (i.e. compiler) without much issues
    • core contains cairo0classHash function, in which Cairo0Class from core is using it. It's slightly tricky, but I think we can move Cairo0Class to a separate package.

I'm not sure if this is the most elegant solution, as that means we have to be more careful about the dependencies of the packages. Perhaps I'll attempt to implement the solution and raise a PR.