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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ arraydeque = "0.5.1"
arrayref = "0.3.6"
base64 = "0.22"
bincode = "1.3.1"
bitcoin = { version = "0.32", features = ["serde"] }
bitcoin = { version = "0.32.4", features = ["serde"] }
clap = "2.33.3"
crossbeam-channel = "0.5.0"
dirs = "5.0.1"
Expand Down
3 changes: 1 addition & 2 deletions electrs_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use proc_macro::TokenStream;


#[proc_macro_attribute]
#[cfg(feature = "otlp-tracing")]
pub fn trace(attr: TokenStream, item: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -32,4 +31,4 @@ pub fn trace(attr: TokenStream, item: TokenStream) -> TokenStream {
#[cfg(not(feature = "otlp-tracing"))]
pub fn trace(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}
}
10 changes: 10 additions & 0 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum Network {
#[cfg(not(feature = "liquid"))]
Testnet,
#[cfg(not(feature = "liquid"))]
Testnet4,
#[cfg(not(feature = "liquid"))]
Regtest,
#[cfg(not(feature = "liquid"))]
Signet,
Expand Down Expand Up @@ -97,6 +99,7 @@ impl Network {
return vec![
"mainnet".to_string(),
"testnet".to_string(),
"testnet4".to_string(),
"regtest".to_string(),
"signet".to_string(),
];
Expand All @@ -123,6 +126,8 @@ pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
genesis_block(BNetwork::Bitcoin).block_hash();
static ref TESTNET_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Testnet).block_hash();
static ref TESTNET4_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Testnet4).block_hash();
static ref REGTEST_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Regtest).block_hash();
static ref SIGNET_GENESIS: bitcoin::BlockHash =
Expand All @@ -131,6 +136,7 @@ pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
match network {
BNetwork::Bitcoin => *BITCOIN_GENESIS,
BNetwork::Testnet => *TESTNET_GENESIS,
BNetwork::Testnet4 => *TESTNET4_GENESIS,
BNetwork::Regtest => *REGTEST_GENESIS,
BNetwork::Signet => *SIGNET_GENESIS,
_ => panic!("unknown network {:?}", network),
Expand Down Expand Up @@ -165,6 +171,8 @@ impl From<&str> for Network {
#[cfg(not(feature = "liquid"))]
"testnet" => Network::Testnet,
#[cfg(not(feature = "liquid"))]
"testnet4" => Network::Testnet4,
#[cfg(not(feature = "liquid"))]
"regtest" => Network::Regtest,
#[cfg(not(feature = "liquid"))]
"signet" => Network::Signet,
Expand All @@ -187,6 +195,7 @@ impl From<Network> for BNetwork {
match network {
Network::Bitcoin => BNetwork::Bitcoin,
Network::Testnet => BNetwork::Testnet,
Network::Testnet4 => BNetwork::Testnet4,
Network::Regtest => BNetwork::Regtest,
Network::Signet => BNetwork::Signet,
}
Expand All @@ -199,6 +208,7 @@ impl From<BNetwork> for Network {
match network {
BNetwork::Bitcoin => Network::Bitcoin,
BNetwork::Testnet => Network::Testnet,
BNetwork::Testnet4 => Network::Testnet4,
BNetwork::Regtest => Network::Regtest,
BNetwork::Signet => Network::Signet,
_ => panic!("unknown network {:?}", network),
Expand Down
18 changes: 14 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,19 @@ impl Config {
.arg(
Arg::with_name("electrum_rpc_addr")
.long("electrum-rpc-addr")
.help("Electrum server JSONRPC 'addr:port' to listen on (default: '127.0.0.1:50001' for mainnet, '127.0.0.1:60001' for testnet and '127.0.0.1:60401' for regtest)")
.help("Electrum server JSONRPC 'addr:port' to listen on (default: '127.0.0.1:50001' for mainnet, '127.0.0.1:60001' for testnet3, '127.0.0.1:40001' for testnet4 and '127.0.0.1:60401' for regtest)")
.takes_value(true),
)
.arg(
Arg::with_name("http_addr")
.long("http-addr")
.help("HTTP server 'addr:port' to listen on (default: '127.0.0.1:3000' for mainnet, '127.0.0.1:3001' for testnet and '127.0.0.1:3002' for regtest)")
.help("HTTP server 'addr:port' to listen on (default: '127.0.0.1:3000' for mainnet, '127.0.0.1:3001' for testnet3 and '127.0.0.1:3004' for testnet4 and '127.0.0.1:3002' for regtest)")
.takes_value(true),
)
.arg(
Arg::with_name("daemon_rpc_addr")
.long("daemon-rpc-addr")
.help("Bitcoin daemon JSONRPC 'addr:port' to connect (default: 127.0.0.1:8332 for mainnet, 127.0.0.1:18332 for testnet and 127.0.0.1:18443 for regtest)")
.help("Bitcoin daemon JSONRPC 'addr:port' to connect (default: 127.0.0.1:8332 for mainnet, 127.0.0.1:18332 for testnet3 and 127.0.0.1:48332 for testnet4 and 127.0.0.1:18443 for regtest)")
.takes_value(true),
)
.arg(
Expand All @@ -149,7 +149,7 @@ impl Config {
.arg(
Arg::with_name("monitoring_addr")
.long("monitoring-addr")
.help("Prometheus monitoring 'addr:port' to listen on (default: 127.0.0.1:4224 for mainnet, 127.0.0.1:14224 for testnet and 127.0.0.1:24224 for regtest)")
.help("Prometheus monitoring 'addr:port' to listen on (default: 127.0.0.1:4224 for mainnet, 127.0.0.1:14224 for testnet3 and 127.0.0.1:44224 for testnet4 and 127.0.0.1:24224 for regtest)")
.takes_value(true),
)
.arg(
Expand Down Expand Up @@ -282,6 +282,8 @@ impl Config {
#[cfg(not(feature = "liquid"))]
Network::Testnet => 18332,
#[cfg(not(feature = "liquid"))]
Network::Testnet4 => 48332,
#[cfg(not(feature = "liquid"))]
Network::Regtest => 18443,
#[cfg(not(feature = "liquid"))]
Network::Signet => 38332,
Expand All @@ -297,6 +299,8 @@ impl Config {
#[cfg(not(feature = "liquid"))]
Network::Testnet => 60001,
#[cfg(not(feature = "liquid"))]
Network::Testnet4 => 40001,
#[cfg(not(feature = "liquid"))]
Network::Regtest => 60401,
#[cfg(not(feature = "liquid"))]
Network::Signet => 60601,
Expand All @@ -314,6 +318,8 @@ impl Config {
#[cfg(not(feature = "liquid"))]
Network::Testnet => 3001,
#[cfg(not(feature = "liquid"))]
Network::Testnet4 => 3004,
#[cfg(not(feature = "liquid"))]
Network::Regtest => 3002,
#[cfg(not(feature = "liquid"))]
Network::Signet => 3003,
Expand All @@ -331,6 +337,8 @@ impl Config {
#[cfg(not(feature = "liquid"))]
Network::Testnet => 14224,
#[cfg(not(feature = "liquid"))]
Network::Testnet4 => 44224,
#[cfg(not(feature = "liquid"))]
Network::Regtest => 24224,
#[cfg(not(feature = "liquid"))]
Network::Signet => 54224,
Expand Down Expand Up @@ -493,6 +501,8 @@ pub fn get_network_subdir(network: Network) -> Option<&'static str> {
#[cfg(not(feature = "liquid"))]
Network::Testnet => Some("testnet3"),
#[cfg(not(feature = "liquid"))]
Network::Testnet4 => Some("testnet4"),
#[cfg(not(feature = "liquid"))]
Network::Regtest => Some("regtest"),
#[cfg(not(feature = "liquid"))]
Network::Signet => Some("signet"),
Expand Down
24 changes: 19 additions & 5 deletions src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use itertools::{Either, Itertools};

#[cfg(not(feature = "liquid"))]
use bitcoin::consensus::encode::serialize;
use electrs_macros::trace;
#[cfg(feature = "liquid")]
use elements::{encode::serialize, AssetId};

Expand All @@ -11,7 +12,6 @@ use std::iter::FromIterator;
use std::sync::{Arc, RwLock};
use std::time::{Duration, Instant};

use electrs_macros::trace;
use crate::chain::{deserialize, BlockHash, Network, OutPoint, Transaction, TxOut, Txid};
use crate::config::Config;
use crate::daemon::Daemon;
Expand Down Expand Up @@ -516,7 +516,12 @@ impl Mempool {
daemon: &Daemon,
tip: &BlockHash,
) -> Result<bool> {
let _timer = mempool.read().unwrap().latency.with_label_values(&["update"]).start_timer();
let _timer = mempool
.read()
.unwrap()
.latency
.with_label_values(&["update"])
.start_timer();

// Continuously attempt to fetch mempool transactions until we're able to get them in full
let mut fetched_txs = HashMap::<Txid, Transaction>::new();
Expand Down Expand Up @@ -554,9 +559,18 @@ impl Mempool {
{
let mempool = mempool.read().unwrap();

mempool.count.with_label_values(&["all_txs"]).set(all_txids.len() as f64);
mempool.count.with_label_values(&["fetched_txs"]).set((indexed_txids.len() + fetched_txs.len()) as f64);
mempool.count.with_label_values(&["missing_txs"]).set(new_txids.len() as f64);
mempool
.count
.with_label_values(&["all_txs"])
.set(all_txids.len() as f64);
mempool
.count
.with_label_values(&["fetched_txs"])
.set((indexed_txids.len() + fetched_txs.len()) as f64);
mempool
.count
.with_label_values(&["missing_txs"])
.set(new_txids.len() as f64);
}

let new_txs = daemon.gettransactions_available(&new_txids)?;
Expand Down
21 changes: 12 additions & 9 deletions src/rest.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@

use crate::chain::{
address, BlockHash, Network, OutPoint, Script, Sequence, Transaction, TxIn, TxMerkleNode,
TxOut, Txid,
};
use crate::config::Config;
use crate::errors;
use crate::new_index::{compute_script_hash, Query, SpendingInput, Utxo};
#[cfg(feature = "liquid")]
use crate::util::optional_value_for_newer_blocks;
use crate::util::{
create_socket, electrum_merkle, extract_tx_prevouts, get_innerscripts, get_tx_fee, has_prevout,
is_coinbase, BlockHeaderMeta, BlockId, FullHash, ScriptToAddr, ScriptToAsm, TransactionStatus,
DEFAULT_BLOCKHASH,
};
#[cfg(feature = "liquid")]
use crate::util::optional_value_for_newer_blocks;
#[cfg(not(feature = "liquid"))]
use bitcoin::consensus::encode;

Expand Down Expand Up @@ -186,14 +185,18 @@ impl TransactionValue {
status: Some(TransactionStatus::from(blockid)),

#[cfg(feature = "liquid")]
discount_vsize: optional_value_for_newer_blocks(blockid,
START_OF_LIQUID_DISCOUNT_CT_POLICY,
tx.discount_vsize()),
discount_vsize: optional_value_for_newer_blocks(
blockid,
START_OF_LIQUID_DISCOUNT_CT_POLICY,
tx.discount_vsize(),
),

#[cfg(feature = "liquid")]
discount_weight: optional_value_for_newer_blocks(blockid,
START_OF_LIQUID_DISCOUNT_CT_POLICY,
tx.discount_weight()),
discount_weight: optional_value_for_newer_blocks(
blockid,
START_OF_LIQUID_DISCOUNT_CT_POLICY,
tx.discount_weight(),
),
}
}
}
Expand Down
74 changes: 56 additions & 18 deletions src/util/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ impl From<Option<BlockId>> for TransactionStatus {
}
}


#[cfg(feature = "liquid")]
pub fn optional_value_for_newer_blocks(block_id: Option<BlockId>,
check_time: u32,
value: usize) -> Option<usize> {
pub fn optional_value_for_newer_blocks(
block_id: Option<BlockId>,
check_time: u32,
value: usize,
) -> Option<usize> {
match block_id {
// use the provided value only if it was after the "activation" time
Some(b) if b.time >= check_time => Some(value),
Expand Down Expand Up @@ -132,13 +133,12 @@ where
s.end()
}


#[cfg(all(test, feature = "liquid"))]
mod test {
use super::optional_value_for_newer_blocks;
use crate::util::BlockId;
use bitcoin::hashes::Hash;
use elements::BlockHash;
use crate::util::BlockId;
use super::optional_value_for_newer_blocks;

#[test]
fn opt_value_newer_block() {
Expand All @@ -149,20 +149,58 @@ mod test {

// unconfirmed block should include the value
let block_id = None;
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
assert_eq!(
optional_value_for_newer_blocks(block_id, check_time, value),
Some(value)
);

// block time before check_time should NOT include the value
let block_id = Some(BlockId{ height, hash, time: 0 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), None);
let block_id = Some(BlockId{ height, hash, time: 31 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), None);
let block_id = Some(BlockId {
height,
hash,
time: 0,
});
assert_eq!(
optional_value_for_newer_blocks(block_id, check_time, value),
None
);
let block_id = Some(BlockId {
height,
hash,
time: 31,
});
assert_eq!(
optional_value_for_newer_blocks(block_id, check_time, value),
None
);

// block time on or after check_time should include the value
let block_id = Some(BlockId{ height, hash, time: 32 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
let block_id = Some(BlockId{ height, hash, time: 33 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
let block_id = Some(BlockId{ height, hash, time: 333 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
let block_id = Some(BlockId {
height,
hash,
time: 32,
});
assert_eq!(
optional_value_for_newer_blocks(block_id, check_time, value),
Some(value)
);
let block_id = Some(BlockId {
height,
hash,
time: 33,
});
assert_eq!(
optional_value_for_newer_blocks(block_id, check_time, value),
Some(value)
);
let block_id = Some(BlockId {
height,
hash,
time: 333,
});
assert_eq!(
optional_value_for_newer_blocks(block_id, check_time, value),
Some(value)
);
}
}