Browse Source

Merge branch 'master' into configure_me

master
Martin Habovštiak 5 years ago
committed by GitHub
parent
commit
bbc6fcb21d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .circleci/config.yml
  2. 7
      Cargo.lock
  3. 3
      Cargo.toml
  4. 1
      RELEASE-NOTES.md
  5. 2
      doc/usage.md
  6. 2
      src/app.rs
  7. 2
      src/config.rs
  8. 29
      src/daemon.rs
  9. 8
      src/index.rs
  10. 2
      src/mempool.rs
  11. 12
      src/query.rs
  12. 2
      src/store.rs
  13. 7
      src/util.rs

2
.circleci/config.yml

@ -3,7 +3,7 @@ version: 2
jobs: jobs:
build: build:
docker: docker:
- image: rust:1.32.0-slim - image: rust:1.34.0-slim
steps: steps:
- checkout - checkout

7
Cargo.lock

@ -30,11 +30,6 @@ dependencies = [
"scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.4.11" version = "0.4.11"
@ -351,7 +346,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
name = "electrs" name = "electrs"
version = "0.7.1" version = "0.7.1"
dependencies = [ 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)", "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)", "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)", "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 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 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 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 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 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" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"

3
Cargo.toml

@ -16,10 +16,9 @@ build = "build.rs"
lto = true lto = true
[features] [features]
latest_rust = [] # use latest Rust features (otherwise, support Rust 1.32) latest_rust = [] # use latest Rust features (otherwise, support Rust 1.34)
[dependencies] [dependencies]
arrayref = "0.3"
base64 = "0.10" base64 = "0.10"
bincode = "1.0" bincode = "1.0"
bitcoin = { version = "0.18", features = ["use-serde"] } bitcoin = { version = "0.18", features = ["use-serde"] }

1
RELEASE-NOTES.md

@ -2,6 +2,7 @@
* Use `configure_me` instead of `clap` to support config files, environment variables and man pages (@Kixunil) * Use `configure_me` instead of `clap` to support config files, environment variables and man pages (@Kixunil)
* Don't accept `--cookie` via CLI arguments (@Kixunil) * Don't accept `--cookie` via CLI arguments (@Kixunil)
* Support Rust >=1.34 (for Debian)
# 0.7.1 (27 July 2019) # 0.7.1 (27 July 2019)

2
doc/usage.md

@ -1,6 +1,6 @@
## Installation ## 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+) [latest Bitcoin Core](https://bitcoincore.org/en/download/) (0.16+)
and [latest Electrum wallet](https://electrum.org/#download) (3.3+). and [latest Electrum wallet](https://electrum.org/#download) (3.3+).

2
src/app.rs

@ -31,7 +31,7 @@ impl App {
&self.store &self.store
} }
// TODO: use index for queries. // TODO: use index for queries.
pub fn read_store(&self) -> &store::ReadStore { pub fn read_store(&self) -> &dyn store::ReadStore {
&self.store &self.store
} }
pub fn index(&self) -> &index::Index { pub fn index(&self) -> &index::Index {

2
src/config.rs

@ -255,7 +255,7 @@ impl Config {
config config
} }
pub fn cookie_getter(&self) -> Arc<CookieGetter> { pub fn cookie_getter(&self) -> Arc<dyn CookieGetter> {
if let Some(ref value) = self.cookie { if let Some(ref value) = self.cookie {
Arc::new(StaticCookie { Arc::new(StaticCookie {
value: value.as_bytes().to_vec(), value: value.as_bytes().to_vec(),

29
src/daemon.rs

@ -13,7 +13,6 @@ use std::collections::{HashMap, HashSet};
use std::io::{BufRead, BufReader, Lines, Write}; use std::io::{BufRead, BufReader, Lines, Write};
use std::net::{SocketAddr, TcpStream}; use std::net::{SocketAddr, TcpStream};
use std::path::PathBuf; use std::path::PathBuf;
#[cfg(feature = "latest_rust")]
use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::Duration; use std::time::Duration;
@ -151,7 +150,7 @@ pub trait CookieGetter: Send + Sync {
struct Connection { struct Connection {
tx: TcpStream, tx: TcpStream,
rx: Lines<BufReader<TcpStream>>, rx: Lines<BufReader<TcpStream>>,
cookie_getter: Arc<CookieGetter>, cookie_getter: Arc<dyn CookieGetter>,
addr: SocketAddr, addr: SocketAddr,
signal: Waiter, signal: Waiter,
} }
@ -172,7 +171,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result<TcpStream> {
impl Connection { impl Connection {
fn new( fn new(
addr: SocketAddr, addr: SocketAddr,
cookie_getter: Arc<CookieGetter>, cookie_getter: Arc<dyn CookieGetter>,
signal: Waiter, signal: Waiter,
) -> Result<Connection> { ) -> Result<Connection> {
let conn = tcp_connect(addr, &signal)?; let conn = tcp_connect(addr, &signal)?;
@ -269,12 +268,10 @@ impl Connection {
} }
} }
#[cfg(feature = "latest_rust")]
struct Counter { struct Counter {
value: AtomicU64, value: AtomicU64,
} }
#[cfg(feature = "latest_rust")]
impl Counter { impl Counter {
fn new() -> Self { fn new() -> Self {
Counter { value: 0.into() } Counter { value: 0.into() }
@ -286,26 +283,6 @@ impl Counter {
} }
} }
#[cfg(not(feature = "latest_rust"))]
struct Counter {
value: Mutex<u64>,
}
#[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 { pub struct Daemon {
daemon_dir: PathBuf, daemon_dir: PathBuf,
network: Network, network: Network,
@ -323,7 +300,7 @@ impl Daemon {
pub fn new( pub fn new(
daemon_dir: &PathBuf, daemon_dir: &PathBuf,
daemon_rpc_addr: SocketAddr, daemon_rpc_addr: SocketAddr,
cookie_getter: Arc<CookieGetter>, cookie_getter: Arc<dyn CookieGetter>,
network: Network, network: Network,
signal: Waiter, signal: Waiter,
blocktxids_cache: Arc<BlockTxIDsCache>, blocktxids_cache: Arc<BlockTxIDsCache>,

8
src/index.rs

@ -221,7 +221,7 @@ pub fn last_indexed_block(blockhash: &Sha256dHash) -> Row {
} }
} }
pub fn read_indexed_blockhashes(store: &ReadStore) -> HashSet<Sha256dHash> { pub fn read_indexed_blockhashes(store: &dyn ReadStore) -> HashSet<Sha256dHash> {
let mut result = HashSet::new(); let mut result = HashSet::new();
for row in store.scan(b"B") { for row in store.scan(b"B") {
let key: BlockKey = bincode::deserialize(&row.key).unwrap(); let key: BlockKey = bincode::deserialize(&row.key).unwrap();
@ -230,7 +230,7 @@ pub fn read_indexed_blockhashes(store: &ReadStore) -> HashSet<Sha256dHash> {
result 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") { let latest_blockhash: Sha256dHash = match store.get(b"L") {
// latest blockheader persisted in the DB. // latest blockheader persisted in the DB.
Some(row) => deserialize(&row).unwrap(), Some(row) => deserialize(&row).unwrap(),
@ -336,7 +336,7 @@ pub struct Index {
impl Index { impl Index {
pub fn load( pub fn load(
store: &ReadStore, store: &dyn ReadStore,
daemon: &Daemon, daemon: &Daemon,
metrics: &Metrics, metrics: &Metrics,
batch_size: usize, 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(); let mut headers = self.headers.write().unwrap();
*headers = read_indexed_headers(store); *headers = read_indexed_headers(store);
} }

2
src/mempool.rs

@ -186,7 +186,7 @@ impl Tracker {
&self.histogram &self.histogram
} }
pub fn index(&self) -> &ReadStore { pub fn index(&self) -> &dyn ReadStore {
&self.index &self.index
} }

12
src/query.rs

@ -143,13 +143,13 @@ fn create_merkle_branch_and_root(
} }
// TODO: the functions below can be part of ReadStore. // TODO: the functions below can be part of ReadStore.
fn txrow_by_txid(store: &ReadStore, txid: &Sha256dHash) -> Option<TxRow> { fn txrow_by_txid(store: &dyn ReadStore, txid: &Sha256dHash) -> Option<TxRow> {
let key = TxRow::filter_full(&txid); let key = TxRow::filter_full(&txid);
let value = store.get(&key)?; let value = store.get(&key)?;
Some(TxRow::from_row(&Row { key, value })) Some(TxRow::from_row(&Row { key, value }))
} }
fn txrows_by_prefix(store: &ReadStore, txid_prefix: HashPrefix) -> Vec<TxRow> { fn txrows_by_prefix(store: &dyn ReadStore, txid_prefix: HashPrefix) -> Vec<TxRow> {
store store
.scan(&TxRow::filter_prefix(txid_prefix)) .scan(&TxRow::filter_prefix(txid_prefix))
.iter() .iter()
@ -157,7 +157,7 @@ fn txrows_by_prefix(store: &ReadStore, txid_prefix: HashPrefix) -> Vec<TxRow> {
.collect() .collect()
} }
fn txids_by_script_hash(store: &ReadStore, script_hash: &[u8]) -> Vec<HashPrefix> { fn txids_by_script_hash(store: &dyn ReadStore, script_hash: &[u8]) -> Vec<HashPrefix> {
store store
.scan(&TxOutRow::filter(script_hash)) .scan(&TxOutRow::filter(script_hash))
.iter() .iter()
@ -166,7 +166,7 @@ fn txids_by_script_hash(store: &ReadStore, script_hash: &[u8]) -> Vec<HashPrefix
} }
fn txids_by_funding_output( fn txids_by_funding_output(
store: &ReadStore, store: &dyn ReadStore,
txn_id: &Sha256dHash, txn_id: &Sha256dHash,
output_index: usize, output_index: usize,
) -> Vec<HashPrefix> { ) -> Vec<HashPrefix> {
@ -225,7 +225,7 @@ impl Query {
fn load_txns_by_prefix( fn load_txns_by_prefix(
&self, &self,
store: &ReadStore, store: &dyn ReadStore,
prefixes: Vec<HashPrefix>, prefixes: Vec<HashPrefix>,
) -> Result<Vec<TxnHeight>> { ) -> Result<Vec<TxnHeight>> {
let mut txns = vec![]; let mut txns = vec![];
@ -244,7 +244,7 @@ impl Query {
fn find_spending_input( fn find_spending_input(
&self, &self,
store: &ReadStore, store: &dyn ReadStore,
funding: &FundingOutput, funding: &FundingOutput,
) -> Result<Option<SpendingInput>> { ) -> Result<Option<SpendingInput>> {
let spending_txns: Vec<TxnHeight> = self.load_txns_by_prefix( let spending_txns: Vec<TxnHeight> = self.load_txns_by_prefix(

2
src/store.rs

@ -188,7 +188,7 @@ pub fn full_compaction(store: DBStore) -> DBStore {
store 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); let marker = store.get(&full_compaction_marker().key);
marker.is_some() marker.is_some()
} }

7
src/util.rs

@ -2,6 +2,7 @@ use bitcoin::blockdata::block::BlockHeader;
use bitcoin::util::hash::BitcoinHash; use bitcoin::util::hash::BitcoinHash;
use bitcoin_hashes::sha256d::Hash as Sha256dHash; use bitcoin_hashes::sha256d::Hash as Sha256dHash;
use std::collections::HashMap; use std::collections::HashMap;
use std::convert::TryInto;
use std::fmt; use std::fmt;
use std::iter::FromIterator; use std::iter::FromIterator;
use std::slice; use std::slice;
@ -20,11 +21,13 @@ pub type FullHash = [u8; HASH_LEN];
pub type HashPrefix = [u8; HASH_PREFIX_LEN]; pub type HashPrefix = [u8; HASH_PREFIX_LEN];
pub fn hash_prefix(hash: &[u8]) -> HashPrefix { 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 { 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)] #[derive(Eq, PartialEq, Clone)]

Loading…
Cancel
Save