Skip to content
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

refactor(neard): decouple into individual crates #4292

Merged
merged 20 commits into from
May 27, 2021

Conversation

miraclx
Copy link
Contributor

@miraclx miraclx commented May 10, 2021

Dissociates neard into its binary and library constituents, with the binary depending on the library. Fixes #4233.

The intent is to have the binary named neard and the library named nearcore. However, because the workspace is itself nearcore, we can either move the library into the root or use a different name for either the workspace or the library itself.

@miraclx miraclx requested review from frol and bowenwang1996 May 10, 2021 01:09
neard/bin/Cargo.toml Outdated Show resolved Hide resolved
@matklad
Copy link
Contributor

matklad commented May 11, 2021

However, because the workspace is itself nearcore

I feel that that's unfortunate. The root of our workspace is a crate, but this crate only contains integration tests, it isn't a binary or a library. That's surprising (most big projects are set-up differently) and obscures the actual dependencies between the things.

The typical setup is to make the root of the workspace a "virtual manifest", without the [package] section. See examples: rust-analyzer, rustc, substrate, firecracker. That way, you don't have "primary" crate, which often makes sense for large projects, as they have several entry points. cargo test in the workspace by default test everything. And you get somewhat more sane --feature flag behavior (with the second version of feature resolver, we should be able to even get rid of foo = [bar/foo, baz/foo] feature propagations).

Large project with non-virtual manifest typically have a top-level crate of substance, with src top-level directory which contains stuff, like cargo.

So, if we want to introduce a genuine nearcore library, I would suggest to get rid of tests-only top-level package first. Between "let's make top-level nearcore a real library" and "let's have a virtual manifest", I think "virtual manifest" has more benefits, as we do have several entry points (neard, params estimator, tools like genesis-populate).

I understand that this derails immediate work of extracing a library out of neard, but "fix workspace, then split neard" seems to be less work overall.

@matklad
Copy link
Contributor

matklad commented May 11, 2021

Here's a my suggested plan for virtual manifest:

  • check which tooling depends on the project layout and might break. Quick look at pipeline.yml shows that it should work with virtual manifest as is, but we might have some other automation.a
  • move tests from /test folder somewhere -- either to some of the existing packages (neard perhaps?) or into a new integration-tests package
  • re-read the features chapter of the cargo book, especially this section: https://doc.rust-lang.org/cargo/reference/features.html#resolver-version-2-command-line-flags
  • check that features in top-level toml will work when we switch to virtual manifest (with resolevr = "2" that should be the case)
  • add [workspace] resolver = "2" to the top-level toml
  • remove [package], [dependencies], [features] section from top-level toml ([profile] should stay)
  • check that everything works as expected.

Is this reasonable? Let's do a checklist to make sure we decide one way or another:

Do you agree that we should move to virtual manifest setup before introducing proper nearcore library? Check the box if you do!

(tagging a couple of folks who I know have opinions about code organization)

@frol
Copy link
Collaborator

frol commented May 11, 2021

I totally agree with the proposals from @matklad.

I don't expect any breakage from dropping [package] from the workspace Cargo.toml, and I even consider it is a great thing to do since it was quite confusing when you would call cargo test or cargo build which did nothing useful.

I suggest we move the current tests/ into nearcore (lib crate) if possible, otherwise fall back to neard (bin).

@bowenwang1996
Copy link
Collaborator

Yeah agree with what @frol said. Don't expect anything to break with virtual manifest

Copy link
Collaborator

@frol frol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are on the right track! Once CI is green, we can merge it

neard/Cargo.toml Outdated Show resolved Hide resolved
@frol frol marked this pull request as ready for review May 25, 2021 12:30
@frol frol requested review from ailisp and chefsale as code owners May 25, 2021 12:30
Copy link
Contributor

@chefsale chefsale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just please take a look into the tests why are they failing. Seems after second restart they failed again, so maybe one third time? And ask @bowenwang1996 to maybe take a look as well.

Copy link
Member

@ailisp ailisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

.buildkite/pipeline.yml Show resolved Hide resolved
chain/client/Cargo.toml Show resolved Hide resolved
neard/Cargo.toml Show resolved Hide resolved
neard/Cargo.toml Show resolved Hide resolved
@miraclx miraclx requested review from bowenwang1996 and matklad May 26, 2021 15:39
Copy link
Member

@khorolets khorolets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

protocol_feature_cap_max_gas_price = ["near-primitives/protocol_feature_cap_max_gas_price", "neard/protocol_feature_cap_max_gas_price", "near-chain/protocol_feature_cap_max_gas_price"]

# enable this to build neard with wasmer 1.0 runner
# now if none of wasmer0_default, wasmer1_default or wasmtime_default is enabled, wasmer0 would be default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those features are needed, why they are removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I didn't notice that! I think it'd be good indeed to move this over to neard/Cargo.toml instead of just deleting.

That being said, I wouldn't block on that, as the following now works without feature forwarding:

cargo build -p neard --features node-runtime/wasmer1_default

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olonho Great catch!

It seems it should be in both nearcore (defined as node-runtime/wasmer1_default) and in neard (defined as nearcore/wasmer1_default).

miraclx added 2 commits May 27, 2021 11:44
stays consistent with previous behaviour

should be better cleaned out after near#4325 is resolved
@frol frol added the automerge label May 27, 2021
@near-bulldozer near-bulldozer bot merged commit 7d16cf5 into near:master May 27, 2021
@miraclx miraclx deleted the near(d)ecouple branch May 27, 2021 11:53
near-bulldozer bot pushed a commit that referenced this pull request Jun 2, 2021
We're sort of in a weird spot as it is, we have features within `nearcore` that are required but can't be enabled if they depend on crates listed under `dev-dependencies` (bug in cargo: rust-lang/cargo#6915). Temporarily listing them under `dependencies`, fixed the CI testing failures we had while working on #4292 (same error @ailisp highlighted: #4333 (comment)), but as pointed out in #4331 (comment), this method should be out of the question. If we remove it, however, we can't work with the tests that depend on those features.

This PR moves the _previously top-level_ tests into a new crate to have better dependency and feature handling as @matklad suggested

> * [move tests from `/test` folder somewhere -- either to some of the existing packages (neard perhaps?) or into a new `integration-tests` package](#4292 (comment))

This would ensure we have dependencies like `testlib`, `runtime-params-estimator` and `restored-receipts-verifier` that are only needed for testing and depend on nearcore without cyclic dependency issues while having all features relevant to testing in order.

The features within `neard` have been reduced to proxies to `nearcore` features, which partially resolves #4325 (though the intent for that has morphed a bit). This also makes for a cleaner dependency graph from `neard` perspective, removing extraneous dependencies that were previously required.

I also noticed removed the `old_tests` feature that should've been removed along with the rest of it in #928.

Updated some docs and code comments referencing the old `neard` path too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Decouple nearcore into a lib-crate
9 participants