Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support testnet4 #144

Open
wants to merge 1 commit into
base: new-index
Choose a base branch
from
Open
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 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ 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"] }
bitcoin-io = "0.1.2"
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
}
}
25 changes: 25 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 @@ -121,8 +124,12 @@ pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
lazy_static! {
static ref BITCOIN_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Bitcoin).block_hash();
// TESTNET_GENESIS is BlockHash of testnet3
static ref TESTNET_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Testnet).block_hash();
// TESTNET4_GENESIS is BlockHash of testnet4
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 +138,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 +173,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 +197,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,9 +210,23 @@ 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),
}
}
}

#[cfg(not(feature = "liquid"))]
impl From<Network> for &'static bitcoin::params::Params {
fn from(network: Network) -> Self {
match network {
Network::Bitcoin => &bitcoin::params::MAINNET,
Network::Testnet => &bitcoin::params::TESTNET3,
Network::Testnet4 => &bitcoin::params::TESTNET4,
Network::Regtest => &bitcoin::params::REGTEST,
Network::Signet => &bitcoin::params::SIGNET,
}
}
}
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 and '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 @@ -512,7 +512,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 @@ -550,9 +555,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