Skip to content

Commit 78454f3

Browse files
committed
electrsd: include electrsd in workspace
Mirrors bitcoind solution. It also removes default electrs download for non-esplora paths.
1 parent 3656443 commit 78454f3

6 files changed

Lines changed: 65 additions & 38 deletions

File tree

.github/workflows/rust.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
runs-on: ubuntu-latest
3737
env:
3838
BITCOIND_SKIP_DOWNLOAD: "1"
39+
ELECTRSD_SKIP_DOWNLOAD: "1"
3940
strategy:
4041
fail-fast: false
4142
matrix:
@@ -61,6 +62,7 @@ jobs:
6162
runs-on: ubuntu-latest
6263
env:
6364
BITCOIND_SKIP_DOWNLOAD: "1"
65+
ELECTRSD_SKIP_DOWNLOAD: "1"
6466
strategy:
6567
fail-fast: false
6668
matrix:
@@ -78,6 +80,7 @@ jobs:
7880
runs-on: ubuntu-latest
7981
env:
8082
BITCOIND_SKIP_DOWNLOAD: "1"
83+
ELECTRSD_SKIP_DOWNLOAD: "1"
8184
strategy:
8285
fail-fast: false
8386
matrix:

Cargo.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
[workspace]
2-
members = ["bitcoind", "bitreq", "client", "fuzz", "jsonrpc", "types"]
3-
exclude = ["integration_test", "verify", "electrsd"]
2+
members = [
3+
"bitcoind",
4+
"bitreq",
5+
"client",
6+
"electrsd",
7+
"fuzz",
8+
"jsonrpc",
9+
"types",
10+
]
11+
exclude = ["integration_test", "verify"]
412
resolver = "2"
513

614
[workspace.metadata.rbmt.toolchains]

electrsd/Cargo.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,15 @@ bitreq = { version = "0.3.5", path = "../bitreq", default-features = false, opti
3535
] }
3636

3737
[features]
38-
default = ["electrs_0_10_6", "download"]
39-
# download is not supposed to be used directly only through selecting one of the version feature
4038
download = ["bitcoin_hashes", "zip", "bitreq"]
41-
42-
esplora_a33e97e1 = ["download"]
43-
electrs_0_8_10 = ["download"]
44-
electrs_0_9_1 = ["download"]
45-
electrs_0_9_11 = ["download"]
46-
electrs_0_10_6 = ["download"]
47-
4839
bitcoind_download = ["bitcoind/download", "download"]
40+
default = ["electrs_0_10_6", "download"]
41+
42+
electrs_0_10_6 = ["electrs_0_9_11"]
43+
electrs_0_9_11 = ["electrs_0_9_1"]
44+
electrs_0_9_1 = ["electrs_0_8_10"]
45+
electrs_0_8_10 = ["esplora_a33e97e1"]
46+
esplora_a33e97e1 = []
4947

5048
bitcoind_30_2 = ["bitcoind/30_2"]
5149
bitcoind_29_0 = ["bitcoind/29_0"]

electrsd/src/ext.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use electrum_client::ElectrumApi;
1010
use crate::ElectrsD;
1111

1212
impl ElectrsD {
13-
#[cfg(not(feature = "electrs_0_8_10"))]
13+
#[cfg(any(feature = "electrs_0_9_1", not(feature = "electrs_0_8_10")))]
1414
/// wait up to a minute the electrum server has indexed up to the given height.
1515
pub fn wait_height(&self, height: usize) {
1616
for _ in 0..600 {
@@ -56,7 +56,7 @@ mod test {
5656

5757
use crate::test::setup_nodes;
5858

59-
#[cfg(not(feature = "electrs_0_8_10"))]
59+
#[cfg(any(feature = "electrs_0_9_1", not(feature = "electrs_0_8_10")))]
6060
#[test]
6161
fn test_wait_height() {
6262
let (_, bitcoind, electrsd) = setup_nodes();
@@ -85,8 +85,7 @@ mod test {
8585
.txid()
8686
.unwrap();
8787

88-
#[cfg(feature = "electrs_0_8_10")]
89-
{
88+
if crate::versions::IS_ELECTRS_0_8_10 {
9089
// the 0.8.10 version doesn't have a mempool, so we need to mine the tx
9190
bitcoind.client.generate_to_address(1, &generate_address).unwrap();
9291
electrsd.trigger().unwrap();

electrsd/src/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,7 @@ pub struct Conf<'a> {
8383

8484
impl Default for Conf<'_> {
8585
fn default() -> Self {
86-
let args = if cfg!(feature = "electrs_0_9_1")
87-
|| cfg!(feature = "electrs_0_8_10")
88-
|| cfg!(feature = "esplora_a33e97e1")
89-
{
90-
vec!["-vvv"]
91-
} else {
92-
vec![]
93-
};
86+
let args = if versions::USE_VERBOSE_ARG { vec!["-vvv"] } else { vec![] };
9487

9588
Conf {
9689
args,
@@ -196,7 +189,7 @@ impl ElectrsD {
196189
args.push(&rpc_socket);
197190

198191
let p2p_socket;
199-
if cfg!(feature = "electrs_0_8_10") || cfg!(feature = "esplora_a33e97e1") {
192+
if versions::USE_JSONRPC_IMPORT {
200193
args.push("--jsonrpc-import");
201194
} else {
202195
args.push("--daemon-p2p-addr");
@@ -436,7 +429,7 @@ mod test {
436429
debug!("electrs: {}", &electrs_exe);
437430
let mut conf = bitcoind::Conf::default();
438431
conf.view_stdout = log_enabled!(Level::Debug);
439-
if !cfg!(feature = "electrs_0_8_10") && !cfg!(feature = "esplora_a33e97e1") {
432+
if !crate::versions::USE_JSONRPC_IMPORT {
440433
conf.p2p = P2P::Yes;
441434
}
442435
let bitcoind = bitcoind::BitcoinD::with_conf(&bitcoind_exe, &conf).unwrap();

electrsd/src/versions.rs

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,34 @@ const OS: &str = "linux";
77
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
88
const OS: &str = "undefined";
99

10-
#[cfg(feature = "electrs_0_8_10")]
11-
const VERSION: &str = "v0.8.10";
10+
// An explicit version of Electrs must be selected by enabling some feature.
11+
// We check this here instead of in `lib.rs` because this file is included in `build.rs`.
12+
#[cfg(all(
13+
not(feature = "electrs_0_8_10"),
14+
not(feature = "electrs_0_9_1"),
15+
not(feature = "electrs_0_9_11"),
16+
not(feature = "electrs_0_10_6"),
17+
not(feature = "esplora_a33e97e1"),
18+
))]
19+
compile_error!("enable a feature in order to select the version of Electrs to use");
1220

13-
#[cfg(feature = "esplora_a33e97e1")]
14-
const VERSION: &str = "esplora_a33e97e1a1fc63fa9c20a116bb92579bbf43b254";
21+
#[cfg(feature = "electrs_0_10_6")]
22+
const VERSION: &str = "v0.10.6";
23+
24+
#[cfg(all(feature = "electrs_0_9_11", not(feature = "electrs_0_10_6")))]
25+
const VERSION: &str = "v0.9.11";
1526

16-
#[cfg(feature = "electrs_0_9_1")]
27+
#[cfg(all(feature = "electrs_0_9_1", not(feature = "electrs_0_9_11")))]
1728
const VERSION: &str = "v0.9.1";
1829

19-
#[cfg(feature = "electrs_0_9_11")]
20-
const VERSION: &str = "v0.9.11";
30+
#[cfg(all(feature = "electrs_0_8_10", not(feature = "electrs_0_9_1")))]
31+
const VERSION: &str = "v0.8.10";
2132

22-
#[cfg(feature = "electrs_0_10_6")]
23-
const VERSION: &str = "v0.10.6";
33+
#[cfg(all(feature = "esplora_a33e97e1", not(feature = "electrs_0_8_10")))]
34+
const VERSION: &str = "esplora_a33e97e1a1fc63fa9c20a116bb92579bbf43b254";
2435

36+
/// This is meaningless but we need it otherwise we can't get far enough into
37+
/// the build process to trigger the `compile_error!` above.
2538
#[cfg(not(any(
2639
feature = "electrs_0_8_10",
2740
feature = "electrs_0_9_1",
@@ -31,10 +44,6 @@ const VERSION: &str = "v0.10.6";
3144
)))]
3245
const VERSION: &str = "NA";
3346

34-
#[allow(unused)] // this is not used in `build.rs`
35-
pub const USE_LEGACY_COOKIE: bool =
36-
cfg!(all(feature = "esplora_a33e97e1", not(feature = "electrs_0_8_10")));
37-
3847
pub const HAS_FEATURE: bool = cfg!(any(
3948
feature = "electrs_0_8_10",
4049
feature = "electrs_0_9_1",
@@ -44,3 +53,20 @@ pub const HAS_FEATURE: bool = cfg!(any(
4453
));
4554

4655
pub fn electrs_name() -> String { format!("electrs_{}_{}", OS, VERSION) }
56+
57+
pub(crate) const IS_ELECTRS_0_8_10: bool =
58+
cfg!(all(feature = "electrs_0_8_10", not(feature = "electrs_0_9_1")));
59+
60+
pub(crate) const IS_ELECTRS_0_9_1: bool =
61+
cfg!(all(feature = "electrs_0_9_1", not(feature = "electrs_0_9_11")));
62+
63+
const IS_ESPLORA: bool = cfg!(all(feature = "esplora_a33e97e1", not(feature = "electrs_0_8_10")));
64+
65+
#[allow(unused)] // this is not used in `build.rs`
66+
pub const USE_LEGACY_COOKIE: bool = IS_ESPLORA;
67+
68+
#[allow(unused)] // this is not used in `build.rs`
69+
pub const USE_JSONRPC_IMPORT: bool = IS_ELECTRS_0_8_10 || IS_ESPLORA;
70+
71+
#[allow(unused)] // this is not used in `build.rs`
72+
pub const USE_VERBOSE_ARG: bool = IS_ELECTRS_0_8_10 || IS_ELECTRS_0_9_1 || IS_ESPLORA;

0 commit comments

Comments
 (0)