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:
build:
docker:
- image: rust:1.32.0-slim
- image: rust:1.34.0-slim
steps:
- checkout

7
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"

3
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"] }

1
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)

2
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+).

2
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 {

2
src/config.rs

@ -255,7 +255,7 @@ impl Config {
config
}
pub fn cookie_getter(&self) -> Arc<CookieGetter> {
pub fn cookie_getter(&self) -> Arc<dyn CookieGetter> {
if let Some(ref value) = self.cookie {
Arc::new(StaticCookie {
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::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<BufReader<TcpStream>>,
cookie_getter: Arc<CookieGetter>,
cookie_getter: Arc<dyn CookieGetter>,
addr: SocketAddr,
signal: Waiter,
}
@ -172,7 +171,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result<TcpStream> {
impl Connection {
fn new(
addr: SocketAddr,
cookie_getter: Arc<CookieGetter>,
cookie_getter: Arc<dyn CookieGetter>,
signal: Waiter,
) -> Result<Connection> {
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<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 {
daemon_dir: PathBuf,
network: Network,
@ -323,7 +300,7 @@ impl Daemon {
pub fn new(
daemon_dir: &PathBuf,
daemon_rpc_addr: SocketAddr,
cookie_getter: Arc<CookieGetter>,
cookie_getter: Arc<dyn CookieGetter>,
network: Network,
signal: Waiter,
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();
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<Sha256dHash> {
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);
}

2
src/mempool.rs

@ -186,7 +186,7 @@ impl Tracker {
&self.histogram
}
pub fn index(&self) -> &ReadStore {
pub fn index(&self) -> &dyn ReadStore {
&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.
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 value = store.get(&key)?;
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
.scan(&TxRow::filter_prefix(txid_prefix))
.iter()
@ -157,7 +157,7 @@ fn txrows_by_prefix(store: &ReadStore, txid_prefix: HashPrefix) -> Vec<TxRow> {
.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
.scan(&TxOutRow::filter(script_hash))
.iter()
@ -166,7 +166,7 @@ fn txids_by_script_hash(store: &ReadStore, script_hash: &[u8]) -> Vec<HashPrefix
}
fn txids_by_funding_output(
store: &ReadStore,
store: &dyn ReadStore,
txn_id: &Sha256dHash,
output_index: usize,
) -> Vec<HashPrefix> {
@ -225,7 +225,7 @@ impl Query {
fn load_txns_by_prefix(
&self,
store: &ReadStore,
store: &dyn ReadStore,
prefixes: Vec<HashPrefix>,
) -> Result<Vec<TxnHeight>> {
let mut txns = vec![];
@ -244,7 +244,7 @@ impl Query {
fn find_spending_input(
&self,
store: &ReadStore,
store: &dyn ReadStore,
funding: &FundingOutput,
) -> Result<Option<SpendingInput>> {
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
}
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()
}

7
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)]

Loading…
Cancel
Save