electrsd: include in workspace and CI#570
Conversation
|
One thing I thought to include is a default electrsd version, like bitcoind in Edit: I suppose we need the default so tests work with an explicit version. |
2a42a61 to
4c939ef
Compare
|
Latest force push improves the legibility of the solution, sets a default electrs version, reworked the version feature graph so the |
af412f2 to
6e540e4
Compare
|
Needs rebase mate. Out of interest what made you go with |
6e540e4 to
8343421
Compare
|
Great point, I made a mistake regarding EDIT: The problem with v0.10.6 in CI was caused by using the legacy |
8343421 to
12645ba
Compare
|
On the latest rebase:
|
eca4af4 to
70b269f
Compare
|
Can we separate the fmt changes from actual code changes in c61ea18 |
70b269f to
28022c5
Compare
|
Latest rebase: |
3866f93 to
cd0ddfe
Compare
|
Latest rebase updates lockfiles because of upstream changes to fix ci |
| #[cfg(not(feature = "electrs_0_8_10"))] | ||
| #[cfg(any(feature = "electrs_0_9_1", not(feature = "electrs_0_8_10")))] |
There was a problem hiding this comment.
Can you explain what you want to achieve with this feature gate please?
There was a problem hiding this comment.
E.g "I want this code block to run for these versions: a, b, c"
There was a problem hiding this comment.
So bitcoind feature gates, which served as a model for making electrsd features, are organized into a chain:
30_2 = ["30_0"]
30_0 = ["29_0"]
...
0_18_1 = ["0_17_2"]
0_17_2 = []In bitcoind's file client_versions.rs:48, you can find a similar example of this gate:
#[cfg(all(feature = "0_21_2", not(feature = "22_1")))]
pub use corepc_client::{client_sync::v21::*, types::v21 as vtype};So the pattern is all(X, not(Y)).
Now imagine I want the negation of a particular version. Say, I need not(version X).
I would express that in feature gates as not(all(X, not(Y)))
But you mentioned above its hard to understand what that means and I agree.
So I did not(all(X, not(Y))) = any(not(X), Y) = any(Y, not(X)) (De Morgan's laws) such as in:
#[cfg(any(feature = "electrs_0_9_1", not(feature = "electrs_0_8_10")))]Would you prefer if I experimented with some less complex ways of solving the problem? I suppose I'd need to break away from the bitcoind solution and design a new feature flag solution. We do things this way to prevent users from enabling 2 flags at the same time, and the program not knowing which to use.
The alternative would be writing an "O(n²)" solution where every flag is checked against every other flag to ensure the same functionality. On a new electrsd version N, the versions file would be incremented in at least N lines of code.
There was a problem hiding this comment.
Could this check be done in one place, e.g. build.rs and a new feature created like electrs_0_8_10_only then all of the any not feature gates changes can be feature = "electrs_0_8_10_only" etc. The new const bools can also then be removed.
There was a problem hiding this comment.
That's a good solution, I implemented it on the latest force push.
|
No need for the last patch mate, we have #571 ready to release that change. I was planning on merging this after that release. |
| let mut cookie_value; | ||
| #[cfg(feature = "legacy")] | ||
| { | ||
| let cookie_value = if cfg!(feature = "esplora_a33e97e1_only") { |
There was a problem hiding this comment.
Cool, this is clear! Way better than not(electrs_0_8_10).
|
Sorry for the iterations, this feature gating and weird feature setup (caused by the repo not you) is hard to get right. I'm going to need to come back to this with fresh eyes. |
| electrs_0_10_6 = ["download"] | ||
|
|
||
| bitcoind_download = ["bitcoind/download", "download"] | ||
| default = ["electrs_0_10_6", "download"] |
There was a problem hiding this comment.
Why is default to enable download? We don't do that in bitcoind, there was some reason we stopped doing so but I forget right now.
There was a problem hiding this comment.
I'll remove it. I left it in because a few weeks ago, the download came by default for every feature flag of elecstrd, and some other PR removed, but I had left it on by default.
| - run: cd electrsd && cargo test --features ${{ matrix.features }} | ||
| - run: cd electrsd && RUST_LOG=debug cargo test --features ${{ matrix.features }} |
There was a problem hiding this comment.
Why do we need this when its set above? Does RUST_LOG: debug not work?
There was a problem hiding this comment.
But in test-electrs-no-download its not set. Can we pick one way and do it uniform?
There was a problem hiding this comment.
Oh my bad, I had missed it. Will put it on env for every electrsd job.
| 'cfg(feature, values("electrs_0_9_11_only", "electrs_0_9_1_only", "electrs_0_8_10_only", "esplora_a33e97e1_only"))', | ||
| 'cfg(esplora_a33e97e1)', |
There was a problem hiding this comment.
We shouldn't need the last one because its a feature, right?
There was a problem hiding this comment.
Actually we don't need any of these do we because of the loop in build.rs?
There was a problem hiding this comment.
+ for v in versions {
+ println!("cargo:rustc-check-cfg=cfg({}_only)", v);
+ }There was a problem hiding this comment.
I think I had put it because of some cargo check or lint warning, but I can't reproduce it anymore, so I'm dropping the change.
| let env_name = format!("CARGO_FEATURE_{}", v.to_uppercase()); | ||
| if std::env::var_os(&env_name).is_some() { | ||
| // Emits cfg for the highest enabled version only and then returns. | ||
| println!("cargo:rustc-cfg={}_only", v); |
There was a problem hiding this comment.
| println!("cargo:rustc-cfg={}_only", v); | |
| println!("cargo:rustc-cfg={}_and_below", v); |
I think I finally get it. The 'only' was throwing me off before big time.
There was a problem hiding this comment.
Sorry, but the _only indeed means only a specific version. The latest change should clear up the confusion, because this older version was not using the only properly. It was an error.
|
Sorry got to run half way through review. |
|
Wrong button. |
|
Force-pushed. Changes:
|
| #[cfg(all( | ||
| not(feature = "electrs_0_8_10"), | ||
| not(feature = "electrs_0_9_1"), | ||
| not(feature = "electrs_0_9_11"), | ||
| not(feature = "electrs_0_10_6"), | ||
| not(feature = "esplora_a33e97e1"), | ||
| ))] |
There was a problem hiding this comment.
| #[cfg(all( | |
| not(feature = "electrs_0_8_10"), | |
| not(feature = "electrs_0_9_1"), | |
| not(feature = "electrs_0_9_11"), | |
| not(feature = "electrs_0_10_6"), | |
| not(feature = "esplora_a33e97e1"), | |
| ))] | |
| #[cfg(not(feature = "esplora_a33e97e1"))] |
Recently worked out this can be simplified in bitcoind too. This works because of the cascading features. Same change in this file at the bottom.
There was a problem hiding this comment.
There was another gate I thought was wrong then I realised the same, really the feature means esplora_a33e97e1 and later versions
There was a problem hiding this comment.
Cascading features were removed entirely in the latest version.
| const VERSION: &str = "v0.10.6"; | ||
| #[cfg(all(feature = "electrs_0_9_1", not(feature = "electrs_0_9_11")))] | ||
| const VERSION: &str = "v0.9.1"; | ||
| #[cfg(all(feature = "electrs_0_8_10", not(feature = "electrs_0_9_1")))] |
There was a problem hiding this comment.
I agree, this was one of the reasons to have the new feature.
There was a problem hiding this comment.
I have removed these flags. They were too complex. What I did instead if to gate with.
#[cfg(all(feature = "electrs_0_8_10", not(feature = "all_features_test")))]I think this is reasonable because it reads very clear meaning.
|
Reviewed: 285011c |
jamillambert
left a comment
There was a problem hiding this comment.
I am not sure the removal of the legacy feature is a good idea. This could break downstream for no real benefit.
Other than that and the few features gates that should be _only the rest looks good.
Reviewed 285011c
04ae05b to
fded3bb
Compare
|
The latest force push reworks the solution a lot, after some suggestions:
NOTE: cannot move lint for format changes to other PRs because workspace now exercises it, causing CI failures. It is an inseparable part of the PR.
I'm new-ish to OSS, and didn't realize how this would affect downstream. The latest push adds it back and keeps the flag situation intact for downstream. |
Introducing electrsd in workspace cause --all-features tests to enable all electrsd feature flags, this commit creates a new test-only feature that is only enabled on these particular tests. Version compiler constant gets appropriately gates through the new flag so only the latest electsd version is activated. It introduces flag to all version specific call sites.
|
Latest push simple rebase + lockfile update. |
|
Looking good. To review I decided to just hack around and see what feel out. Want to look at the last commit on this branch and pull out any changes that you like? |
Closes #552
This PR includes electrsd in corepc workspace. With this change, now test, lints and formats also consider electrsd.
In order for this inclusion to fit in workspace:
cargo --all-featurestest faced several version conflicts becasue these tests enable all electrsd feature flags at the same time. The solution developed was to create a new test-only feature flag calledall_features_testthat is gets also enabled by default for finer version control, such that only the latest electrsd version runs.All of the commits are ordered to the same end, enabling CI to pass and tests to run.