diff --git a/.circleci/config.yml b/.circleci/config.yml index 8d2c9e5..39ce4e0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ version: 2 jobs: build: docker: - - image: rust:1.32.0-slim + - image: rust:1.34.0-slim steps: - checkout diff --git a/Cargo.lock b/Cargo.lock index a6e391e..149fd56 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -30,11 +30,6 @@ dependencies = [ "scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "arrayref" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "arrayvec" version = "0.4.11" @@ -351,7 +346,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" name = "electrs" version = "0.7.1" dependencies = [ - "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "bitcoin 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1207,7 +1201,6 @@ dependencies = [ "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arc-swap 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "bc4662175ead9cd84451d5c35070517777949a2ed84551764129cedb88384841" "checksum argon2rs 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f67b0b6a86dae6e67ff4ca2b6201396074996379fba2b92ff649126f37cb392" -"checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" "checksum ascii 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "97be891acc47ca214468e09425d02cef3af2c94d0d82081cd02061f996802f14" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" diff --git a/Cargo.toml b/Cargo.toml index 7a4dede..cedd290 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,10 +16,9 @@ build = "build.rs" lto = true [features] -latest_rust = [] # use latest Rust features (otherwise, support Rust 1.32) +latest_rust = [] # use latest Rust features (otherwise, support Rust 1.34) [dependencies] -arrayref = "0.3" base64 = "0.10" bincode = "1.0" bitcoin = { version = "0.18", features = ["use-serde"] } diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 42ce6ff..80119bf 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -2,6 +2,7 @@ * Use `configure_me` instead of `clap` to support config files, environment variables and man pages (@Kixunil) * Don't accept `--cookie` via CLI arguments (@Kixunil) +* Support Rust >=1.34 (for Debian) # 0.7.1 (27 July 2019) diff --git a/doc/usage.md b/doc/usage.md index fdbd9e3..77eca16 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -1,6 +1,6 @@ ## Installation -Install [latest Rust](https://rustup.rs/) (1.32+), +Install [latest Rust](https://rustup.rs/) (1.34+), [latest Bitcoin Core](https://bitcoincore.org/en/download/) (0.16+) and [latest Electrum wallet](https://electrum.org/#download) (3.3+). diff --git a/src/app.rs b/src/app.rs index 7336fc2..54d46e2 100644 --- a/src/app.rs +++ b/src/app.rs @@ -31,7 +31,7 @@ impl App { &self.store } // TODO: use index for queries. - pub fn read_store(&self) -> &store::ReadStore { + pub fn read_store(&self) -> &dyn store::ReadStore { &self.store } pub fn index(&self) -> &index::Index { diff --git a/src/config.rs b/src/config.rs index 028c2e2..820f139 100644 --- a/src/config.rs +++ b/src/config.rs @@ -255,7 +255,7 @@ impl Config { config } - pub fn cookie_getter(&self) -> Arc { + pub fn cookie_getter(&self) -> Arc { if let Some(ref value) = self.cookie { Arc::new(StaticCookie { value: value.as_bytes().to_vec(), diff --git a/src/daemon.rs b/src/daemon.rs index 1dcc564..a01c000 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -13,7 +13,6 @@ use std::collections::{HashMap, HashSet}; use std::io::{BufRead, BufReader, Lines, Write}; use std::net::{SocketAddr, TcpStream}; use std::path::PathBuf; -#[cfg(feature = "latest_rust")] use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::{Arc, Mutex}; use std::time::Duration; @@ -151,7 +150,7 @@ pub trait CookieGetter: Send + Sync { struct Connection { tx: TcpStream, rx: Lines>, - cookie_getter: Arc, + cookie_getter: Arc, addr: SocketAddr, signal: Waiter, } @@ -172,7 +171,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result { impl Connection { fn new( addr: SocketAddr, - cookie_getter: Arc, + cookie_getter: Arc, signal: Waiter, ) -> Result { let conn = tcp_connect(addr, &signal)?; @@ -269,12 +268,10 @@ impl Connection { } } -#[cfg(feature = "latest_rust")] struct Counter { value: AtomicU64, } -#[cfg(feature = "latest_rust")] impl Counter { fn new() -> Self { Counter { value: 0.into() } @@ -286,26 +283,6 @@ impl Counter { } } -#[cfg(not(feature = "latest_rust"))] -struct Counter { - value: Mutex, -} - -#[cfg(not(feature = "latest_rust"))] -impl Counter { - fn new() -> Self { - Counter { - value: Mutex::new(0), - } - } - - fn next(&self) -> u64 { - let mut value = self.value.lock().unwrap(); - *value += 1; - *value - } -} - pub struct Daemon { daemon_dir: PathBuf, network: Network, @@ -323,7 +300,7 @@ impl Daemon { pub fn new( daemon_dir: &PathBuf, daemon_rpc_addr: SocketAddr, - cookie_getter: Arc, + cookie_getter: Arc, network: Network, signal: Waiter, blocktxids_cache: Arc, diff --git a/src/index.rs b/src/index.rs index f36142f..6fd1c45 100644 --- a/src/index.rs +++ b/src/index.rs @@ -221,7 +221,7 @@ pub fn last_indexed_block(blockhash: &Sha256dHash) -> Row { } } -pub fn read_indexed_blockhashes(store: &ReadStore) -> HashSet { +pub fn read_indexed_blockhashes(store: &dyn ReadStore) -> HashSet { let mut result = HashSet::new(); for row in store.scan(b"B") { let key: BlockKey = bincode::deserialize(&row.key).unwrap(); @@ -230,7 +230,7 @@ pub fn read_indexed_blockhashes(store: &ReadStore) -> HashSet { result } -fn read_indexed_headers(store: &ReadStore) -> HeaderList { +fn read_indexed_headers(store: &dyn ReadStore) -> HeaderList { let latest_blockhash: Sha256dHash = match store.get(b"L") { // latest blockheader persisted in the DB. Some(row) => deserialize(&row).unwrap(), @@ -336,7 +336,7 @@ pub struct Index { impl Index { pub fn load( - store: &ReadStore, + store: &dyn ReadStore, daemon: &Daemon, metrics: &Metrics, batch_size: usize, @@ -352,7 +352,7 @@ impl Index { }) } - pub fn reload(&self, store: &ReadStore) { + pub fn reload(&self, store: &dyn ReadStore) { let mut headers = self.headers.write().unwrap(); *headers = read_indexed_headers(store); } diff --git a/src/mempool.rs b/src/mempool.rs index a3ea329..5ac88c6 100644 --- a/src/mempool.rs +++ b/src/mempool.rs @@ -186,7 +186,7 @@ impl Tracker { &self.histogram } - pub fn index(&self) -> &ReadStore { + pub fn index(&self) -> &dyn ReadStore { &self.index } diff --git a/src/query.rs b/src/query.rs index d11575a..063a502 100644 --- a/src/query.rs +++ b/src/query.rs @@ -143,13 +143,13 @@ fn create_merkle_branch_and_root( } // TODO: the functions below can be part of ReadStore. -fn txrow_by_txid(store: &ReadStore, txid: &Sha256dHash) -> Option { +fn txrow_by_txid(store: &dyn ReadStore, txid: &Sha256dHash) -> Option { let key = TxRow::filter_full(&txid); let value = store.get(&key)?; Some(TxRow::from_row(&Row { key, value })) } -fn txrows_by_prefix(store: &ReadStore, txid_prefix: HashPrefix) -> Vec { +fn txrows_by_prefix(store: &dyn ReadStore, txid_prefix: HashPrefix) -> Vec { store .scan(&TxRow::filter_prefix(txid_prefix)) .iter() @@ -157,7 +157,7 @@ fn txrows_by_prefix(store: &ReadStore, txid_prefix: HashPrefix) -> Vec { .collect() } -fn txids_by_script_hash(store: &ReadStore, script_hash: &[u8]) -> Vec { +fn txids_by_script_hash(store: &dyn ReadStore, script_hash: &[u8]) -> Vec { store .scan(&TxOutRow::filter(script_hash)) .iter() @@ -166,7 +166,7 @@ fn txids_by_script_hash(store: &ReadStore, script_hash: &[u8]) -> Vec Vec { @@ -225,7 +225,7 @@ impl Query { fn load_txns_by_prefix( &self, - store: &ReadStore, + store: &dyn ReadStore, prefixes: Vec, ) -> Result> { let mut txns = vec![]; @@ -244,7 +244,7 @@ impl Query { fn find_spending_input( &self, - store: &ReadStore, + store: &dyn ReadStore, funding: &FundingOutput, ) -> Result> { let spending_txns: Vec = self.load_txns_by_prefix( diff --git a/src/store.rs b/src/store.rs index 7e4fd80..e5b483d 100644 --- a/src/store.rs +++ b/src/store.rs @@ -188,7 +188,7 @@ pub fn full_compaction(store: DBStore) -> DBStore { store } -pub fn is_fully_compacted(store: &ReadStore) -> bool { +pub fn is_fully_compacted(store: &dyn ReadStore) -> bool { let marker = store.get(&full_compaction_marker().key); marker.is_some() } diff --git a/src/util.rs b/src/util.rs index b805710..bdc9d0a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -2,6 +2,7 @@ use bitcoin::blockdata::block::BlockHeader; use bitcoin::util::hash::BitcoinHash; use bitcoin_hashes::sha256d::Hash as Sha256dHash; use std::collections::HashMap; +use std::convert::TryInto; use std::fmt; use std::iter::FromIterator; use std::slice; @@ -20,11 +21,13 @@ pub type FullHash = [u8; HASH_LEN]; pub type HashPrefix = [u8; HASH_PREFIX_LEN]; pub fn hash_prefix(hash: &[u8]) -> HashPrefix { - *array_ref![hash, 0, HASH_PREFIX_LEN] + hash[..HASH_PREFIX_LEN] + .try_into() + .expect("failed to convert into HashPrefix") } pub fn full_hash(hash: &[u8]) -> FullHash { - *array_ref![hash, 0, HASH_LEN] + hash.try_into().expect("failed to convert into FullHash") } #[derive(Eq, PartialEq, Clone)]