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. |
| 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. |
|
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? |
|
Latest force push takes suggestions from @tcharding's commit. Read bitcoind and electrsd side by side to pick what seemed appropriate. Also fixes the README instructions. |
jamillambert
left a comment
There was a problem hiding this comment.
The lockfiles should be in Include electrsd in workspace 10a2bf0, currently they are not correct for all the patches until then.
Done in latest force push |
jamillambert
left a comment
There was a problem hiding this comment.
ACK d2c019a
Thanks for sticking with it.
|
Further follow ups if you want them, just things I noticed during this round of review.
//! Electrsd
//!
//! Utility to run a regtest electrsd process, useful in integration testing environment.
mod error;
mod ext;
mod versions;
pub extern crate bitcoind;
pub extern corepc_client;
pub extern crate electrum_client;
use std::env;
use std::ffi::OsStr;
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};
use std::time::Duration;
use bitcoind::anyhow::Context;
use bitcoind::serde_json::Value;
use bitcoind::tempfile::TempDir;
use bitcoind::{anyhow, get_available_port, BitcoinD};
use electrum_client::raw_client::{ElectrumPlaintextStream, RawClient};
use log::{debug, error, warn};
#[rustfmt::skip] // Keep pubic re-exports separate.
pub use error::Error;
|
| let p2p_socket; | ||
| if cfg!(feature = "electrs_0_8_10") | ||
| || cfg!(feature = "esplora_a33e97e1") | ||
| || cfg!(feature = "legacy") | ||
| if !cfg!(feature = "all_features") | ||
| && cfg!(any( | ||
| feature = "electrs_0_8_10", | ||
| feature = "esplora_a33e97e1", | ||
| feature = "legacy", | ||
| )) |
There was a problem hiding this comment.
Mate this sort of if/not/not/if feature gating is what we are trying to get away from. The reason is that it is way too hard to read. I had to spend 3 minutes trying to workout what it means and IIUC, and its telling that I'm not even 100% sure, its also broken.
For any build that does not use --all-features the first clause is false which makes the && always false which makes the outer ! always true. But anyway we want it simple, brain-dead-simple is the mantra.
There was a problem hiding this comment.
I see didn't make it simple enough. I'll make intermediary boolean logic variables so that this and other conditions read like:
if !is_all_features_test && should_version_use_jsonrpc_import {The assumption here is that all feature tests would enable all flags, so we must specifically root it out.
However the boolean logic is correct. You can prove it by running locally:
cargo test --all-features
cargo test --no-default-features --features bitcoind_22_1,bitcoind_download,electrs_
0_9_11
cargo test --no-default-features --features bitcoind_22_1,bitcoind_download,electrs_
0_9_1
cargo test --no-default-features --features bitcoind_22_1,bitcoind_download,electrs_
0_8_10
cargo test --no-default-features --features bitcoind_22_1,bitcoind_download,esplora_a33e97e1
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.
Mirror the bitcoind build script.
The previous examples would not run.
|
First force push: made the feature gating more readable and applied the suggestions for lib.rs header and crate re-exports. |
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.