Skip to content

Commit

Permalink
Fix compile errors for all feature combinations
Browse files Browse the repository at this point in the history
*Floresta-chain*
- The `bitcoin/bitcoinconsensus` feature was still needed for the `verify_with_flags` method on `Transaction`
- `BlockHeader` is used without the feature

*Floresta-cli*
- Made `jsonrpc` not optional, as it is needed for the main function to actually run a client
- Changed the way we get the florestad path

*Floresta-common*
- Remove `no-std` feature to avoid the mutually exclusive features, as advised in https://doc.rust-lang.org/cargo/reference/features.html#mutually-exclusive-features. If `std` feature is not set, we are in `no_std`

*Floresta-watch-only*
- Update the common dependency accordingly

*Florestad*
- Make `json-rpc` feature use `compact-filters` as the Rpc trait methods require compact filters
- Missing conditional compilation
  • Loading branch information
JoseSK999 committed Nov 9, 2024
1 parent 68c43df commit 35b9119
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 42 deletions.
2 changes: 1 addition & 1 deletion crates/floresta-chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ hex = "0.4.3"

[features]
default = []
bitcoinconsensus = ["dep:bitcoinconsensus"]
bitcoinconsensus = ["bitcoin/bitcoinconsensus", "dep:bitcoinconsensus"]

[[bench]]
name = "chain_state_bench"
Expand Down
1 change: 0 additions & 1 deletion crates/floresta-chain/src/pruned_utreexo/chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use core::cell::UnsafeCell;
#[cfg(feature = "bitcoinconsensus")]
use core::ffi::c_uint;

#[cfg(feature = "bitcoinconsensus")]
use bitcoin::block::Header as BlockHeader;
use bitcoin::blockdata::constants::genesis_block;
use bitcoin::consensus::deserialize_partial;
Expand Down
6 changes: 1 addition & 5 deletions crates/floresta-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ bitcoin = { version = "0.32", features = ["serde", "std"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"
jsonrpc = { version = "0.18.0", optional=true, features = ["minreq_http"] }

[features]
default = ["with-jsonrpc"]
with-jsonrpc = ["jsonrpc"]
jsonrpc = { version = "0.18.0", features = ["minreq_http"] }

[dev-dependencies]
rand = "0.8.5"
Expand Down
16 changes: 10 additions & 6 deletions crates/floresta-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! ready-to-use library for interacting with florestad's json-rpc interface in your rust
//! application.

#[cfg(feature = "with-jsonrpc")]
pub mod jsonrpc_client;

pub mod rpc;
Expand Down Expand Up @@ -57,14 +56,17 @@ mod tests {
/// for both RPC and Electrum. The datadir will be in the current dir, under a `tmp` subdir.
/// If you're at $HOME/floresta it will run on $HOME/floresta/tmp/<random_name>/
fn start_florestad() -> (Florestad, Client) {
let here = env!("PWD");
// CARGO_MANIFEST_DIR is always floresta-cli's directory; PWD changes based on where the
// command is executed.
let root = format!("{}/../..", env!("CARGO_MANIFEST_DIR"));
let florestad_path = format!("{root}/target/debug/florestad");

// makes a temporary directory
let test_code = rand::random::<u64>();
let dirname = format!("{here}/tmp/floresta.{test_code}");
let dirname = format!("{root}/tmp/floresta.{test_code}");
fs::DirBuilder::new()
.recursive(true)
.create(dirname.clone())
.create(&dirname)
.unwrap();

// Generate SSL certificate and key using rcgen
Expand All @@ -77,7 +79,7 @@ mod tests {
fs::write(format!("{dirname}/regtest/ssl/key.pem"), key_pem).unwrap();

let port = get_available_port();
let fld = Command::new(format!("{here}/target/debug/florestad"))
let fld = Command::new(&florestad_path)
.args(["-n", "regtest"])
.args(["--data-dir", &dirname])
.args(["--rpc-address", &format!("127.0.0.1:{}", port)])
Expand All @@ -86,7 +88,9 @@ mod tests {
.stdout(Stdio::null())
.stderr(Stdio::inherit())
.spawn()
.unwrap();
.unwrap_or_else(
|e| panic!("Couldn't launch florestad at {}: {}", florestad_path, e)
);

let client = Client::new(format!("http://127.0.0.1:{port}"));

Expand Down
1 change: 0 additions & 1 deletion crates/floresta-cli/src/rpc_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ pub struct GetBlockRes {
pub enum Error {
/// An error while deserializing our response
Serde(serde_json::Error),
#[cfg(feature = "with-jsonrpc")]
/// An internal reqwest error
JsonRpc(jsonrpc::Error),
/// An error internal to our jsonrpc server
Expand Down
10 changes: 5 additions & 5 deletions crates/floresta-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ bitcoin = { version = "0.32", default-features = false, features = ["serde"] }
spin = "0.9.8"

# No-std specific dependencies
hashbrown = { version = "0.14.0", optional = true }
core2 = { version = "0.4.0", default-features = false, optional = true }
hashbrown = { version = "0.14.0" }
core2 = { version = "0.4.0", default-features = false }

# Optional as descriptors feature
miniscript = { version = "12", default-features = false, optional = true }

[features]
default = ["std", "descriptors"]
default = ["std", "descriptors-std"]
std = ["bitcoin/std", "sha2/std"]
no-std = ["hashbrown", "core2"]
descriptors = ["miniscript/std"]
# Both features can be set at the same time, but for `no_std` only the latter should be used
descriptors-std = ["miniscript/std"]
descriptors-no-std = ["miniscript/no-std"]
18 changes: 4 additions & 14 deletions crates/floresta-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
// SPDX-License-Identifier: MIT

#![no_std]
// Ensure that both `std` and `no-std` are not enabled simultaneously
#[cfg(all(feature = "std", feature = "no-std"))]
compile_error!("Features `std` and `no-std` cannot be enabled simultaneously.");

// Ensure that one of `std` or `no-std` is enabled
#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("One of the `std` or `no-std` features must be enabled.");

#[cfg(all(feature = "no-std", feature = "descriptors"))]
compile_error!("For `no-std` enable the `descriptors-no-std` feature instead of `descriptors`.");

use bitcoin::hashes::sha256;
use bitcoin::hashes::Hash;
use bitcoin::ScriptBuf;
#[cfg(any(feature = "descriptors", feature = "descriptors-no-std"))]
#[cfg(any(feature = "descriptors-std", feature = "descriptors-no-std"))]
use miniscript::Descriptor;
#[cfg(any(feature = "descriptors", feature = "descriptors-no-std"))]
#[cfg(any(feature = "descriptors-std", feature = "descriptors-no-std"))]
use miniscript::DescriptorPublicKey;
use sha2::Digest;
pub mod spsc;
Expand Down Expand Up @@ -46,7 +36,7 @@ pub mod service_flags {
pub const UTREEXO_FILTER: u64 = 1 << 25;
}

#[cfg(any(feature = "descriptors", feature = "descriptors-no-std"))]
#[cfg(any(feature = "descriptors-std", feature = "descriptors-no-std"))]
pub fn parse_descriptors(
descriptors: &[String],
) -> Result<Vec<Descriptor<DescriptorPublicKey>>, miniscript::Error> {
Expand All @@ -64,7 +54,7 @@ pub fn parse_descriptors(
Ok(descriptors)
}

#[cfg(feature = "no-std")]
#[cfg(not(feature = "std"))]
pub mod prelude {
extern crate alloc;
pub use alloc::borrow::ToOwned;
Expand Down
8 changes: 4 additions & 4 deletions crates/floresta-watch-only/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ bitcoin = { version = "0.32", features = ["serde"] }
kv = "0.24.0"
log = "0.4"
thiserror = "1.0"
floresta-common = { path = "../floresta-common" }
floresta-common = { path = "../floresta-common", default-features = false, features = ["descriptors-no-std"] }
floresta-chain = { path = "../floresta-chain" }

[dev-dependencies]
rand = "0.8.5"

[features]
default = []
default = ["std"]
memory-database = []
no-std = []
std = ["serde/std"]
# The default features in common are `std` and `descriptors-std` (which is a superset of `descriptors-no-std`)
std = ["floresta-common/default", "serde/std"]
7 changes: 4 additions & 3 deletions florestad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ floresta-common = { path = "../crates/floresta-common" }
floresta-electrum = { path = "../crates/floresta-electrum" }
floresta-watch-only = { path = "../crates/floresta-watch-only" }
floresta-wire = { path = "../crates/floresta-wire" }
floresta-compact-filters = { path = "../crates/floresta-compact-filters", optional=true }
floresta-compact-filters = { path = "../crates/floresta-compact-filters", optional = true }

anyhow = "1.0.40"
jsonrpc-http-server = { version = "18.0.0", optional = true }
Expand All @@ -53,16 +53,17 @@ path = "src/main.rs"
pretty_assertions = "1"

[features]
compact-filters = ["floresta-compact-filters"]
compact-filters = ["dep:floresta-compact-filters"]
zmq-server = ["zmq"]
experimental-p2p = []
json-rpc = [
"jsonrpc-http-server",
"jsonrpc-derive",
"jsonrpc-core",
"jsonrpc-core-client",
"compact-filters"
]
default = ["experimental-p2p", "json-rpc", "compact-filters"]
default = ["experimental-p2p", "json-rpc"]

[build-dependencies]
toml = "0.5.10"
2 changes: 2 additions & 0 deletions florestad/src/florestad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use floresta_chain::AssumeValidArg;
use floresta_chain::BlockchainError;
use floresta_chain::ChainState;
use floresta_chain::KvChainStore;
#[cfg(feature = "compact-filters")]
use floresta_compact_filters::flat_filters_store::FlatFiltersStore;
#[cfg(feature = "compact-filters")]
use floresta_compact_filters::network_filters::NetworkFilters;
use floresta_electrum::electrum_protocol::client_accept_loop;
use floresta_electrum::electrum_protocol::ElectrumServer;
Expand Down
3 changes: 3 additions & 0 deletions florestad/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ fn main() {
log_to_file: params.log_to_file,
assume_valid: params.assume_valid,
log_to_stdout: true,
#[cfg(feature = "zmq-server")]
zmq_address: params.zmq_address,
#[cfg(feature = "json-rpc")]
json_rpc_address: params.rpc_address,
electrum_address: params.electrum_address,
ssl_electrum_address: params.ssl_electrum_address,
Expand Down
4 changes: 2 additions & 2 deletions florestad/src/zmq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use bitcoin::consensus::serialize;
///
/// # Examples
/// Creating a server
/// ```
/// ```ignore
/// use florestad::zmq::ZMQServer;
/// let _ = ZMQServer::new("tcp://127.0.0.1:5150");
/// ```
///
/// Listening for new blocks
///
/// ```!
/// ```ignore
/// use zmq::{Context, Socket};
/// let ctx = Context::new();
/// // The oposite of PUSH is PULL
Expand Down

0 comments on commit 35b9119

Please sign in to comment.