Skip to content

Commit 5afc0ab

Browse files
committed
Merge rust-bitcoin#45: node: Remove default feature
bd8bdb4 Remove default feature (Tobin C. Harding) 8054514 node: Allow unused_imports module wide (Tobin C. Harding) Pull request description: The default feature in node overides an explicit version feature. This is a footgun. Currently the logic around using `bitcoind` from the environment is borked. Also, features in the `node` crate are unusual in that at least one version feature is expected. Lets make this a build requirement. Maintain the current behaviour in relation to `--all-features` i.e., all features implies latest version 28.0 - Remove `default` feature - Remove `download` from version number features - Use `compile_error` to catch missing version feature Fix: rust-bitcoin#40 ACKs for top commit: apoelstra: ACK bd8bdb4; successfully ran local tests; thanks, I think this is the right approach Tree-SHA512: 5b62b3fbd6b77eeed7f8830e6aedabdf0281e5b1f171df3bab55986a2c3860c8bfb97d21619c3c2c4f10c5e369e996840c3f7e3890f943330a930a7476f96826
2 parents 4492a25 + bd8bdb4 commit 5afc0ab

File tree

4 files changed

+51
-68
lines changed

4 files changed

+51
-68
lines changed

integration_test/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ TODO = [] # This is a dirty hack while writing the tests.
5151
[dependencies]
5252
bitcoin = { version = "0.32.0", default-features = false, features = ["std", "serde"] }
5353
client = { package = "corepc-client", version = "0.5.0", default-features = false, features = ["client-sync"] }
54-
node = { package = "corepc-node", version = "0.5.0", default-features = false, features = [] }
54+
node = { package = "corepc-node", version = "0.5.0", default-features = false, features = ["download"] }
5555
rand = "0.8.5"
5656
env_logger = "0.9.0"
5757

node/Cargo.toml

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,36 +35,37 @@ anyhow = "1.0.66"
3535

3636
# Please note, in this crate the version features are mutally exclusive.
3737
#
38-
# - `cargo test --all-features` is the same as `cargo test --features=v28_0`
39-
# - To use --no-default-features you must configure the bitcoind binary to be version 28 either by having `bitcoind` in your path or using `BITCOIND_EXE=/path/to/bitcoind`.
40-
# - `cargo test --no-default-features` uses `v28_0` also.
38+
# - `cargo test --features=27_2,download` to download Bitcoin Core binary v27.
39+
# - `cargo test --all-features` is the same as `cargo test --features=download,v28_0`
40+
# - `cargo test --features=28_0` to use `bitcoind`.
41+
#
42+
# If you do not enable `download` then you must configure the bitcoind binary by `bitcoind` in your
43+
# path or using `BITCOIND_EXE=/path/to/bitcoind`. Note also that the feature enabled should match
44+
# the version from `bitcoind --version`.
4145
[features]
42-
default = ["28_0"]
43-
44-
# download is not supposed to be used directly only through selecting one of the version feature
4546
download = ["bitcoin_hashes", "flate2", "tar", "minreq", "zip"]
4647

4748
# We support all minor releases of the latest three versions.
48-
28_0 = ["download", "27_2"]
49-
27_2 = ["download", "27_1"]
50-
27_1 = ["download", "27_0"]
51-
27_0 = ["download", "26_2"]
52-
26_2 = ["download", "26_1"]
53-
26_1 = ["download", "26_0"]
54-
26_0 = ["download", "25_2"]
55-
# We only support the latest minor version for older versions.
56-
25_2 = ["download", "24_2"]
57-
24_2 = ["download", "23_2"]
58-
23_2 = ["download", "22_1"]
59-
22_1 = ["download", "0_21_2"]
60-
0_21_2 = ["download", "0_20_2"]
61-
0_20_2 = ["download", "0_19_1"]
62-
0_19_1 = ["download", "0_18_1"]
63-
0_18_1 = ["download", "0_17_1"]
64-
0_17_1 = ["download"]
49+
28_0 = ["27_2"]
50+
27_2 = ["27_1"]
51+
27_1 = ["27_0"]
52+
27_0 = ["26_2"]
53+
26_2 = ["26_1"]
54+
26_1 = ["26_0"]
55+
26_0 = ["25_2"]
6556

66-
doc = [] # used only for documentation building
57+
# We only support the latest minor version for older versions.
58+
25_2 = ["24_2"]
59+
24_2 = ["23_2"]
60+
23_2 = ["22_1"]
61+
22_1 = ["0_21_2"]
62+
0_21_2 = ["0_20_2"]
63+
0_20_2 = ["0_19_1"]
64+
0_19_1 = ["0_18_1"]
65+
0_18_1 = ["0_17_1"]
66+
0_17_1 = []
6767

68+
doc = [] # Used only for documentation building.
6869

6970
[package.metadata.docs.rs]
7071
features = ["download", "doc", "28_0"]

node/src/client_versions.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,55 @@
11
// The version specific client and json types.
22
//
3-
// **THIS IS AVAILABLE FOR ALL VERSION NUMBER FEATURES** (eg `25_0`, `24_2` etc). This crate is
3+
// **THIS IS AVAILABLE FOR ALL VERSION NUMBER FEATURES** (eg `25_2`, `28_0` etc). This crate is
44
// unusual in that it expects exactly one version number feature to be selected, docs.rs is not set
55
// up to handle such oddity.
66

7+
#![allow(unused_imports)] // Not all users need the json types.
8+
79
#[cfg(feature = "28_0")]
8-
#[allow(unused_imports)] // Not all users need the json types.
910
pub use corepc_client::{client_sync::v28::{Client, AddressType}, types::v28 as types};
1011

1112
#[cfg(all(feature = "27_2", not(feature = "28_0")))]
12-
#[allow(unused_imports)] // Not all users need the json types.
1313
pub use corepc_client::{client_sync::v27::{Client, AddressType}, types::v27 as types};
1414

1515
#[cfg(all(feature = "27_1", not(feature = "27_2")))]
16-
#[allow(unused_imports)] // Not all users need the json types.
1716
pub use corepc_client::{client_sync::v27::{Client, AddressType}, types::v27 as types};
1817

1918
#[cfg(all(feature = "27_0", not(feature = "27_1")))]
20-
#[allow(unused_imports)] // Not all users need the json types.
2119
pub use corepc_client::{client_sync::v27::{Client, AddressType}, types::v27 as types};
2220

2321
#[cfg(all(feature = "26_2", not(feature = "27_0")))]
24-
#[allow(unused_imports)] // Not all users need the json types.
2522
pub use corepc_client::{client_sync::v26::{Client, AddressType}, types::v26 as types};
2623

2724
#[cfg(all(feature = "26_1", not(feature = "26_2")))]
28-
#[allow(unused_imports)] // Not all users need the json types.
2925
pub use corepc_client::{client_sync::v26::{Client, AddressType}, types::v26 as types};
3026

3127
#[cfg(all(feature = "26_0", not(feature = "26_1")))]
32-
#[allow(unused_imports)] // Not all users need the json types.
3328
pub use corepc_client::{client_sync::v26::{Client, AddressType}, types::v26 as types};
3429

3530
#[cfg(all(feature = "25_2", not(feature = "26_0")))]
36-
#[allow(unused_imports)] // Not all users need the json types.
3731
pub use corepc_client::{client_sync::v25::{Client, AddressType}, types::v25 as types};
3832

3933
#[cfg(all(feature = "24_2", not(feature = "25_2")))]
40-
#[allow(unused_imports)] // Not all users need the json types.
4134
pub use corepc_client::{client_sync::v24::{Client, AddressType}, types::v24 as types};
4235

4336
#[cfg(all(feature = "23_2", not(feature = "24_2")))]
44-
#[allow(unused_imports)] // Not all users need the json types.
4537
pub use corepc_client::{client_sync::v23::{Client, AddressType}, types::v23 as types};
4638

4739
#[cfg(all(feature = "22_1", not(feature = "23_2")))]
48-
#[allow(unused_imports)] // Not all users need the json types.
4940
pub use corepc_client::{client_sync::v22::{Client, AddressType}, types::v22 as types};
5041

5142
#[cfg(all(feature = "0_21_2", not(feature = "22_1")))]
52-
#[allow(unused_imports)] // Not all users need the json types.
5343
pub use corepc_client::{client_sync::v21::{Client, AddressType}, types::v21 as types};
5444

5545
#[cfg(all(feature = "0_20_2", not(feature = "0_21_2")))]
56-
#[allow(unused_imports)] // Not all users need the json types.
5746
pub use corepc_client::{client_sync::v20::{Client, AddressType}, types::v20 as types};
5847

5948
#[cfg(all(feature = "0_19_1", not(feature = "0_20_2")))]
60-
#[allow(unused_imports)] // Not all users need the json types.
6149
pub use corepc_client::{client_sync::v19::{Client, AddressType}, types::v19 as types};
6250

6351
#[cfg(all(feature = "0_18_1", not(feature = "0_19_1")))]
64-
#[allow(unused_imports)] // Not all users need the json types.
6552
pub use corepc_client::{client_sync::v18::{Client, AddressType}, types::v18 as types};
6653

6754
#[cfg(all(feature = "0_17_1", not(feature = "0_18_1")))]
68-
#[allow(unused_imports)] // Not all users need the json types.
6955
pub use corepc_client::{client_sync::v17::{Client, AddressType}, types::v17 as types};
70-
71-
// To make --no-default-features work we have to re-export a the types, use most recent version same as we do for all features.
72-
#[cfg(all(not(feature = "28_0"), not(feature = "27_1"), not(feature = "27_0"), not(feature = "26_2"), not(feature = "26_1"), not(feature = "26_0"), not(feature = "25_2"), not(feature = "24_2"), not(feature = "23_2"), not(feature = "22_1"), not(feature = "0_21_2"), not(feature = "0_20_2"), not(feature = "0_19_1"), not(feature = "0_18_1"), not(feature = "0_17_1")))]
73-
#[allow(unused_imports)] // Not all users need the json types.
74-
pub use corepc_client::{client_sync::v28::{Client, AddressType}, types::v28 as types};

node/src/versions.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
// An explicit version of Bitcoin Core must be selected by enabling some feature.
2+
// We check this here instead of in `lib.rs` because this file is included in `build.rs`.
3+
#[cfg(all(
4+
not(feature = "28_0"),
5+
not(feature = "27_2"),
6+
not(feature = "27_1"),
7+
not(feature = "27_0"),
8+
not(feature = "26_2"),
9+
not(feature = "26_1"),
10+
not(feature = "26_0"),
11+
not(feature = "25_2"),
12+
not(feature = "24_2"),
13+
not(feature = "23_2"),
14+
not(feature = "22_1"),
15+
not(feature = "0_21_2"),
16+
not(feature = "0_20_2"),
17+
not(feature = "0_19_1"),
18+
not(feature = "0_18_1"),
19+
not(feature = "0_17_1")
20+
))]
21+
compile_error!("enable a feature in order to select the version of Bitcoin Core to use");
22+
123
#[cfg(feature = "28_0")]
224
pub const VERSION: &str = "28.0";
325

@@ -45,24 +67,3 @@ pub const VERSION: &str = "0.18.1";
4567

4668
#[cfg(all(feature = "0_17_1", not(feature = "0_18_1")))]
4769
pub const VERSION: &str = "0.17.1";
48-
49-
// To make --no-default-features work we have to enable some feature, use most recent version same as for default.
50-
#[cfg(all(
51-
not(feature = "28_0"),
52-
not(feature = "27_1"),
53-
not(feature = "27_0"),
54-
not(feature = "26_2"),
55-
not(feature = "26_1"),
56-
not(feature = "26_0"),
57-
not(feature = "25_2"),
58-
not(feature = "24_2"),
59-
not(feature = "23_2"),
60-
not(feature = "22_1"),
61-
not(feature = "0_21_2"),
62-
not(feature = "0_20_2"),
63-
not(feature = "0_19_1"),
64-
not(feature = "0_18_1"),
65-
not(feature = "0_17_1")
66-
))]
67-
#[allow(dead_code)] // for --no-default-features
68-
pub const VERSION: &str = "28.0";

0 commit comments

Comments
 (0)