Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,192 changes: 759 additions & 433 deletions Cargo.lock

Large diffs are not rendered by default.

33 changes: 15 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,41 @@ readme = "README.md"
edition = "2018"

[features]
default = [ "rocksdb" ]
liquid = [ "elements" ]
electrum-discovery = [ "electrum-client"]
oldcpu = [ "rocksdb-oldcpu" ]

[dependencies]
arraydeque = "0.4"
arraydeque = "0.5.1"
arrayref = "0.3.6"
base64 = "0.13.0"
base64 = "0.21.3"
bincode = "1.3.1"
bitcoin = { version = "0.30.1", features = [ "serde" ] }
bitcoin = { version = "0.31", features = [ "serde" ] }
clap = "2.33.3"
crossbeam-channel = "0.5.0"
dirs = "4.0.0"
elements = { version = "0.23.0", features = [ "serde" ], optional = true }
dirs = "5.0.1"
elements = { version = "0.24", features = [ "serde" ], optional = true }
error-chain = "0.12.4"
glob = "0.3"
hex = { package = "hex-conservative", version = "0.1.1" }
itertools = "0.10"
itertools = "0.12"
lazy_static = "1.3.0"
libc = "0.2.81"
log = "0.4.11"
socket2 = { version = "0.4", features = ["all"] }
socket2 = { version = "0.5.3", features = ["all"] }
num_cpus = "1.12.0"
page_size = "0.4.2"
page_size = "0.6.0"
prometheus = "0.13"
rayon = "1.5.0"
rocksdb = { version = "0.17.0", optional = true }
rocksdb-oldcpu = { version = "0.12.4", optional = true, package = "rocksdb" }
rocksdb = "0.21"
rust-crypto = "0.2"
serde = "1.0.118"
serde_derive = "1.0.118"
serde_json = "1.0.60"
signal-hook = "0.3"
stderrlog = "0.5.0"
stderrlog = "0.6"
sysconf = ">=0.3.4"
time = { version = "0.3", features = ["formatting"] }
tiny_http = "0.11"
tiny_http = "0.12.0"
url = "2.2.0"
hyper = "0.14"
hyperlocal = "0.8"
Expand All @@ -61,11 +58,11 @@ electrum-client = { version = "0.8", optional = true }


[dev-dependencies]
bitcoind = { version = "0.32.0", features = [ "25_0" ] }
elementsd = { version = "0.8.0", features = [ "22_1_1" ] }
bitcoind = { version = "0.34", features = [ "25_0" ] }
elementsd = { version = "0.9", features = [ "22_1_1" ] }
electrumd = { version = "0.1.0", features = [ "4_1_5" ] }
ureq = { version = "2.4", default-features = false, features = [ "json" ] }
tempfile = "3.0"
ureq = { version = "2.9", default-features = false, features = [ "json" ] }
tempfile = "3.10"

[profile.release]
lto = true
Expand Down
28 changes: 21 additions & 7 deletions src/bin/tx-fingerprint-stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn main() {
continue;
}
// skip coinbase txs
if tx.is_coin_base() {
if tx.is_coinbase() {
continue;
}

Expand All @@ -90,12 +90,26 @@ fn main() {
.collect(),
);

let total_out: u64 = tx.output.iter().map(|out| out.value).sum();
let small_out = tx.output.iter().map(|out| out.value).min().unwrap();
let large_out = tx.output.iter().map(|out| out.value).max().unwrap();

let total_in: u64 = prevouts.values().map(|out| out.value).sum();
let smallest_in = prevouts.values().map(|out| out.value).min().unwrap();
let total_out: u64 = tx.output.iter().map(|out| out.value.to_sat()).sum();
let small_out = tx
.output
.iter()
.map(|out| out.value.to_sat())
.min()
.unwrap();
let large_out = tx
.output
.iter()
.map(|out| out.value.to_sat())
.max()
.unwrap();

let total_in: u64 = prevouts.values().map(|out| out.value.to_sat()).sum();
let smallest_in = prevouts
.values()
.map(|out| out.value.to_sat())
.min()
.unwrap();

let fee = total_in - total_out;

Expand Down
13 changes: 2 additions & 11 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub use {
};

use bitcoin::blockdata::constants::genesis_block;
pub use bitcoin::network::constants::Network as BNetwork;
pub use bitcoin::network::Network as BNetwork;

#[cfg(not(feature = "liquid"))]
pub type Value = u64;
Expand All @@ -41,15 +41,6 @@ pub enum Network {
LiquidRegtest,
}

#[cfg(feature = "liquid")]
pub const LIQUID_TESTNET_PARAMS: address::AddressParams = address::AddressParams {
p2pkh_prefix: 36,
p2sh_prefix: 19,
blinded_prefix: 23,
bech_hrp: "tex",
blech_hrp: "tlq",
};

impl Network {
#[cfg(not(feature = "liquid"))]
pub fn magic(self) -> u32 {
Expand Down Expand Up @@ -80,7 +71,7 @@ impl Network {
match self {
Network::Liquid => &address::AddressParams::LIQUID,
Network::LiquidRegtest => &address::AddressParams::ELEMENTS,
Network::LiquidTestnet => &LIQUID_TESTNET_PARAMS,
Network::LiquidTestnet => &address::AddressParams::LIQUID_TESTNET,
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::time::Duration;

use base64;
use glob;
use base64::prelude::{Engine, BASE64_STANDARD};
use hex::FromHex;
use itertools::Itertools;
use serde_json::{from_str, from_value, Value};
Expand Down Expand Up @@ -169,7 +168,7 @@ impl Connection {
let cookie = &self.cookie_getter.get()?;
let msg = format!(
"POST / HTTP/1.1\nAuthorization: Basic {}\nContent-Length: {}\n\n{}",
base64::encode(cookie),
BASE64_STANDARD.encode(cookie),
request.len(),
request,
);
Expand Down
35 changes: 35 additions & 0 deletions src/elements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,38 @@ impl From<&TxIn> for IssuanceValue {
}
}
}

// Traits to make rust-elements' types compatible with the changes made in rust-bitcoin v0.31
// Should hopefully eventually make its way into rust-elements itself.
pub mod ebcompact {
pub trait SizeMethod {
fn total_size(&self) -> usize;
}
impl SizeMethod for elements::Block {
fn total_size(&self) -> usize {
self.size()
}
}
impl SizeMethod for elements::Transaction {
fn total_size(&self) -> usize {
self.size()
}
}

pub trait ScriptMethods {
fn is_p2wpkh(&self) -> bool;
fn is_p2wsh(&self) -> bool;
fn is_p2tr(&self) -> bool;
}
impl ScriptMethods for elements::Script {
fn is_p2wpkh(&self) -> bool {
self.is_v0_p2wpkh()
}
fn is_p2wsh(&self) -> bool {
self.is_v0_p2wsh()
}
fn is_p2tr(&self) -> bool {
self.is_v1_p2tr()
}
}
}
1 change: 0 additions & 1 deletion src/elements/peg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ impl PegoutValue {
pub fn from_txout(txout: &TxOut, network: Network, parent_network: BNetwork) -> Option<Self> {
let pegoutdata = get_pegout_data(txout, network, parent_network)?;

// pending https://github.com/ElementsProject/rust-elements/pull/69 is merged
let scriptpubkey = pegoutdata.script_pubkey;
let address = bitcoin::Address::from_script(&scriptpubkey, parent_network).ok();

Expand Down
2 changes: 1 addition & 1 deletion src/new_index/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a> Iterator for ScanIterator<'a> {
if self.done {
return None;
}
let (key, value) = self.iter.next()?;
let (key, value) = self.iter.next()?.expect("valid iterator");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rust-rocksdb was changed to iterate over a Result that may contain an error if the iteration fails.

Previously the iterator was terminated with a None and it was expected that users of the library manually check iter.status() for errors after calling next(), which we did not do -- meaning that errors were ignored.

mempool/electrs#16 updated rust-rocksdb while keeping the old behavior, but it seems more correct to panic on errors as I implemented here.

if !key.starts_with(&self.prefix) {
self.done = true;
return None;
Expand Down
4 changes: 3 additions & 1 deletion src/new_index/fetch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use rayon::prelude::*;

#[cfg(feature = "liquid")]
use crate::elements::ebcompact::*;
#[cfg(not(feature = "liquid"))]
use bitcoin::consensus::encode::{deserialize, Decodable};
#[cfg(feature = "liquid")]
Expand Down Expand Up @@ -88,7 +90,7 @@ fn bitcoind_fetcher(
.zip(entries)
.map(|(block, entry)| BlockEntry {
entry: entry.clone(), // TODO: remove this clone()
size: block.size() as u32,
size: block.total_size() as u32,
block,
})
.collect();
Expand Down
15 changes: 9 additions & 6 deletions src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use crate::daemon::Daemon;
use crate::errors::*;
use crate::metrics::{GaugeVec, HistogramOpts, HistogramVec, MetricOpts, Metrics};
use crate::new_index::{
compute_script_hash, schema::FullHash, ChainQuery, FundingInfo, ScriptStats, SpendingInfo,
SpendingInput, TxHistoryInfo, Utxo,
compute_script_hash, schema::FullHash, ChainQuery, FundingInfo, GetAmountVal, ScriptStats,
SpendingInfo, SpendingInput, TxHistoryInfo, Utxo,
};
use crate::util::fees::{make_fee_histogram, TxFeeInfo};
use crate::util::{extract_tx_prevouts, full_hash, has_prevout, is_spendable, Bytes};
Expand All @@ -36,7 +36,7 @@ pub struct Mempool {
feeinfo: HashMap<Txid, TxFeeInfo>,
history: HashMap<FullHash, Vec<TxHistoryInfo>>, // ScriptHash -> {history_entries}
edges: HashMap<OutPoint, (Txid, u32)>, // OutPoint -> (spending_txid, spending_vin)
recent: ArrayDeque<[TxOverview; RECENT_TXS_SIZE], Wrapping>, // The N most recent txs to enter the mempool
recent: ArrayDeque<TxOverview, RECENT_TXS_SIZE, Wrapping>, // The N most recent txs to enter the mempool
backlog_stats: (BacklogStats, Instant),

// monitoring
Expand Down Expand Up @@ -362,7 +362,10 @@ impl Mempool {
fee: feeinfo.fee,
vsize: feeinfo.vsize,
#[cfg(not(feature = "liquid"))]
value: prevouts.values().map(|prevout| prevout.value).sum(),
value: prevouts
.values()
.map(|prevout| prevout.value.to_sat())
.sum(),
});

self.feeinfo.insert(txid, feeinfo);
Expand All @@ -377,7 +380,7 @@ impl Mempool {
vin: input_index as u16,
prev_txid: full_hash(&txi.previous_output.txid[..]),
prev_vout: txi.previous_output.vout as u16,
value: prevout.value,
value: prevout.value.amount_value(),
}),
)
});
Expand All @@ -396,7 +399,7 @@ impl Mempool {
TxHistoryInfo::Funding(FundingInfo {
txid: txid_bytes,
vout: index as u16,
value: txo.value,
value: txo.value.amount_value(),
}),
)
});
Expand Down
4 changes: 2 additions & 2 deletions src/new_index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ pub use self::fetch::{BlockEntry, FetchFrom};
pub use self::mempool::Mempool;
pub use self::query::Query;
pub use self::schema::{
compute_script_hash, parse_hash, ChainQuery, FundingInfo, Indexer, ScriptStats, SpendingInfo,
SpendingInput, Store, TxHistoryInfo, TxHistoryKey, TxHistoryRow, Utxo,
compute_script_hash, parse_hash, ChainQuery, FundingInfo, GetAmountVal, Indexer, ScriptStats,
SpendingInfo, SpendingInput, Store, TxHistoryInfo, TxHistoryKey, TxHistoryRow, Utxo,
};
31 changes: 27 additions & 4 deletions src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rayon::prelude::*;
use bitcoin::consensus::encode::{deserialize, serialize};
#[cfg(feature = "liquid")]
use elements::{
confidential,
encode::{deserialize, serialize},
AssetId,
};
Expand Down Expand Up @@ -112,9 +113,9 @@ pub struct Utxo {
pub value: Value,

#[cfg(feature = "liquid")]
pub asset: elements::confidential::Asset,
pub asset: confidential::Asset,
#[cfg(feature = "liquid")]
pub nonce: elements::confidential::Nonce,
pub nonce: confidential::Nonce,
#[cfg(feature = "liquid")]
pub witness: elements::TxOutWitness,
}
Expand Down Expand Up @@ -1104,7 +1105,7 @@ fn index_transaction(
TxHistoryInfo::Funding(FundingInfo {
txid,
vout: txo_index as u16,
value: txo.value,
value: txo.value.amount_value(),
}),
);
rows.push(history.into_row());
Expand Down Expand Up @@ -1132,7 +1133,7 @@ fn index_transaction(
vin: txi_index as u16,
prev_txid: full_hash(&txi.previous_output.txid[..]),
prev_vout: txi.previous_output.vout as u16,
value: prev_txo.value,
value: prev_txo.value.amount_value(),
}),
);
rows.push(history.into_row());
Expand Down Expand Up @@ -1642,3 +1643,25 @@ fn from_utxo_cache(utxos_cache: CachedUtxoMap, chain: &ChainQuery) -> UtxoMap {
})
.collect()
}

// Get the amount value as gets stored in the DB and mempool tracker.
// For bitcoin it is the Amount's inner u64, for elements it is the confidential::Value itself.
pub trait GetAmountVal {
#[cfg(not(feature = "liquid"))]
fn amount_value(self) -> u64;
#[cfg(feature = "liquid")]
fn amount_value(self) -> confidential::Value;
}

#[cfg(not(feature = "liquid"))]
impl GetAmountVal for bitcoin::Amount {
fn amount_value(self) -> u64 {
self.to_sat()
}
}
#[cfg(feature = "liquid")]
impl GetAmountVal for confidential::Value {
fn amount_value(self) -> confidential::Value {
self
}
}
Loading