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

Upstream #4

Open
wants to merge 48 commits into
base: new-index
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
085872d
Add index-unspendables CLI flag (#28)
daniel-savu Oct 29, 2020
91076cf
http: Implement GET /block/:hash/header
shesek Nov 4, 2020
78adcdb
Add median time past to blocks json
shesek Nov 4, 2020
627b124
Make asset sorting case insensitive
shesek Nov 6, 2020
1e69fa6
Fix get_fee_histogram
shesek Nov 7, 2020
641a99f
Fix ordering by asset ticker
shesek Nov 12, 2020
85e0d9f
Fix get_block_header() in liquid mode
shesek Nov 12, 2020
1cbc86f
Return the total number of available registered assets
shesek Nov 13, 2020
773291f
Can derive Default
shesek Nov 30, 2020
65e20f9
Update crate dependencies
shesek Dec 19, 2020
c484efa
Don't add mempool transaction that already exists
shesek Dec 31, 2020
bae4881
Properly handle negative balanaces in the Electrum RPC
shesek Feb 15, 2021
d1fd717
Confirmed balances have to be positive
shesek Feb 15, 2021
a33e97e
Display warning message with just the number of transactions
shesek Feb 20, 2021
abfbce7
Report the indexed tip height as a Prometheus metric (#37)
shesek Jun 25, 2021
6b7416b
Upgrade to rust-bitcoin v0.25 and elements v0.15
shesek Jan 21, 2021
f905a01
Adjust for rust-elements's new data types
shesek Jan 21, 2021
4422350
Refactor and cleanup network handling
shesek Jan 23, 2021
2784463
Use rust-bitcoin v0.26 when not in liquid mode
shesek Jan 23, 2021
bf7df0a
Add Signet support
shesek Jan 23, 2021
617f16d
Update to rust-elements v0.16
shesek Feb 20, 2021
7bdb00c
Change monitoring port for Signet
shesek Feb 20, 2021
5ff4260
Delegate magic() to bitcoin::Network
shesek Jan 28, 2021
33d81b7
Refactor parse_blocks()
shesek Jan 28, 2021
098f444
Fix address network test for Signet
shesek Mar 3, 2021
22014ac
Patch version bumps for cargo dependencies
shesek Aug 19, 2021
9ec7dbd
Minor/major version bumps for cargo dependencies
shesek Aug 20, 2021
5c408c5
Update rust-electrum-client to v0.8
shesek Aug 20, 2021
df99d5e
Update to rust-bitcoin v0.27 & rust-elements v0.18
shesek Aug 20, 2021
e03e24b
Update rust-rocksdb to v0.17.0
shesek Aug 25, 2021
130d672
Fix electrum-disocvery socket creation
shesek Sep 2, 2021
391c2d2
elements: Don't consider fee outputs as burns
shesek Sep 25, 2021
15e7053
Add the Liquid Testnet network
shesek Apr 22, 2021
ef2434f
Update the liquid testnet network parameters
shesek Sep 21, 2021
0db507d
Serialize the asset's issuance_prevout as an object
shesek Oct 1, 2021
499517c
elements: Parse addresses using the configured network's params
shesek Oct 1, 2021
7220a86
elements: Support networks where the native asset isn't pegged
shesek Oct 3, 2021
e3a819e
Downgrade to rust-elements v0.16.0
shesek Oct 9, 2021
b5b813f
Label P2TR outputs as such
shesek Nov 9, 2021
9484291
Upgrade rust-elements and rust-bitcoin back up
shesek Nov 9, 2021
703c6a2
Fix P2TR labeling in liquid mode
shesek Nov 10, 2021
54dcf49
Detect P2TR scripts in Liquid mode
shesek Nov 21, 2021
253040e
Update rust-elements to current master
shesek Jan 12, 2022
3483d23
Update crates
shesek Apr 22, 2022
93fff34
Update rust-bitcoin to v0.28
shesek Apr 22, 2022
2924567
Update to rust-elements v0.19
shesek Jun 4, 2022
a808b51
Update to rust-elements v0.19.1
shesek Jun 11, 2022
a307f7e
Merge remote-tracking branch 'blockstream/new-index' into upstream
ns212 Jul 30, 2022
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,354 changes: 582 additions & 772 deletions Cargo.lock

Large diffs are not rendered by default.

70 changes: 28 additions & 42 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,51 +20,45 @@ oldcpu = [ "rocksdb-oldcpu" ]
[dependencies]
arraydeque = "0.4"
arrayref = "0.3.6"
base64 = "0.12.3"
base64 = "0.13.0"
bincode = "1.3.1"
clap = "2.31"
crossbeam-channel = "0.4"
dirs = "3.0.1"
error-chain = "0.12.2"
bitcoin = { version = "0.28", features = [ "use-serde" ] }
clap = "2.33.3"
crossbeam-channel = "0.5.0"
dirs = "4.0.0"
elements = { version = "0.19.1", features = [ "serde-feature" ], optional = true }
error-chain = "0.12.4"
glob = "0.3"
hex = "0.4.2"
itertools = "0.9.0"
itertools = "0.10"
lazy_static = "1.3.0"
libc = "0.2.68"
log = "0.4"
socket2 = { version = "0.3.12", features = ["reuseport"] }
libc = "0.2.81"
log = "0.4.11"
socket2 = { version = "0.4", features = ["all"] }
num_cpus = "1.12.0"
page_size = "0.4.2"
prometheus = "0.9"
rayon = "1.3.1"
rocksdb = { version = "0.14.0", optional = true }
prometheus = "0.13"
rayon = "1.5.0"
rocksdb = { version = "0.17.0", optional = true }
rocksdb-oldcpu = { version = "0.12.4", optional = true, package = "rocksdb" }
rust-crypto = "0.2"
serde = "1.0.114"
serde_derive = "1.0.114"
serde_json = "1.0.56"
signal-hook = "0.1"
stderrlog = "0.4.3"
serde = "1.0.118"
serde_derive = "1.0.118"
serde_json = "1.0.60"
signal-hook = "0.3"
stderrlog = "0.5.0"
sysconf = ">=0.3.4"
time = "0.2.16"
tiny_http = "0.7.0"
url = "2.1.1"
hyper = "0.13.6"
hyperlocal = "0.7"
# close to same tokio version as dependent by hyper v0.13.6 and hyperlocal 0.7 -- things can go awry if they mismatch
tokio = { version = "=0.2.6", features = ["sync", "macros"] }
time = { version = "0.3", features = ["formatting"] }
tiny_http = "0.11"
url = "2.2.0"
hyper = "0.14"
hyperlocal = "0.8"
# close to same tokio version as dependent by hyper v0.14 and hyperlocal 0.8 -- things can go awry if they mismatch
tokio = { version = "1", features = ["sync", "macros"] }

# optional dependencies for electrum-discovery
electrum-client = { version = "0.1.0-beta.6", optional = true }
electrum-client = { version = "0.8", optional = true }

[dependencies.bitcoin]
version = "0.23.0"
features = ["use-serde"]

[dependencies.elements]
optional = true
version = "0.12.1"
features = ["serde-feature"]

[dev-dependencies]
tempfile = "3.0"
Expand All @@ -74,14 +68,6 @@ lto = true
panic = 'abort'
codegen-units = 1

[patch.crates-io.bitcoin]
git = "https://github.com/blockstream/rust-bitcoin"
rev = "0.23-electrs"

[patch.crates-io.elements]
git = "https://github.com/elementsproject/rust-elements"
rev = "98e0c4ba1b55cd876d1d8bcff64bcf01c4c370b6"

[patch.crates-io.electrum-client]
git = "https://github.com/Blockstream/rust-electrum-client"
rev = "bd783aa70604fa1a0d8b29a3459326c640001354" # add-peer
rev = "d3792352992a539afffbe11501d1aff9fd5b919d" # add-peer branch
1 change: 0 additions & 1 deletion src/bin/electrs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate bitcoin;
extern crate error_chain;
#[macro_use]
extern crate log;
Expand Down
154 changes: 106 additions & 48 deletions src/chain.rs
Original file line number Diff line number Diff line change
@@ -1,66 +1,75 @@
#[cfg(not(feature = "liquid"))] // use regular Bitcoin data structures
pub use bitcoin::{util::address, Block, BlockHeader, OutPoint, Transaction, TxIn, TxOut};
pub use bitcoin::{
blockdata::script, consensus::deserialize, util::address, Block, BlockHash, BlockHeader,
OutPoint, Script, Transaction, TxIn, TxOut, Txid,
};

#[cfg(feature = "liquid")]
pub use {
crate::elements::asset,
elements::{
address, confidential, Address, AssetId, Block, BlockHeader, OutPoint, Transaction, TxIn,
TxOut,
address, confidential, encode::deserialize, script, Address, AssetId, Block, BlockHash,
BlockHeader, OutPoint, Script, Transaction, TxIn, TxOut, Txid,
},
};

use bitcoin::blockdata::constants::genesis_block;
use bitcoin::network::constants::Network as BNetwork;
use bitcoin::util::hash::BitcoinHash;
use bitcoin::BlockHash;

use std::collections::HashMap;
use std::sync::{Arc, RwLock};
pub use bitcoin::network::constants::Network as BNetwork;

#[cfg(not(feature = "liquid"))]
pub type Value = u64;
#[cfg(feature = "liquid")]
pub use confidential::Value;

lazy_static! {
static ref CACHED_GENESIS: Arc<RwLock<HashMap<Network, BlockHash>>> =
Arc::new(RwLock::new(HashMap::new()));
}

#[derive(Debug, Copy, Clone, PartialEq, Hash, Serialize, Ord, PartialOrd, Eq)]
pub enum Network {
#[cfg(not(feature = "liquid"))]
Bitcoin,
#[cfg(not(feature = "liquid"))]
Testnet,
#[cfg(not(feature = "liquid"))]
Regtest,
#[cfg(not(feature = "liquid"))]
Signet,

#[cfg(feature = "liquid")]
Liquid,
#[cfg(feature = "liquid")]
LiquidTestnet,
#[cfg(feature = "liquid")]
LiquidRegtest,
}

impl Network {
pub fn genesis_hash(self) -> BlockHash {
if let Some(block_hash) = CACHED_GENESIS.read().unwrap().get(&self) {
return *block_hash;
}
#[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",
};

let block_hash = genesis_block(BNetwork::from(self)).bitcoin_hash();
CACHED_GENESIS.write().unwrap().insert(self, block_hash);
block_hash
impl Network {
#[cfg(not(feature = "liquid"))]
pub fn magic(self) -> u32 {
BNetwork::from(self).magic()
}

#[cfg(feature = "liquid")]
pub fn magic(self) -> u32 {
match self {
Network::Bitcoin => 0xD9B4_BEF9,
Network::Testnet => 0x0709_110B,
Network::Regtest => 0xDAB5_BFFA,
Network::Liquid | Network::LiquidRegtest => 0xDAB5_BFFA,
Network::LiquidTestnet => 0x62DD_0E41,
}
}

pub fn is_regtest(self) -> bool {
match self {
#[cfg(not(feature = "liquid"))]
Network::Regtest => true,
#[cfg(feature = "liquid")]
Network::Liquid => 0xDAB5_BFFA,
#[cfg(feature = "liquid")]
Network::LiquidRegtest => 0xDAB5_BFFA,
Network::LiquidRegtest => true,
_ => false,
}
}

Expand All @@ -70,17 +79,24 @@ impl Network {
match self {
Network::Liquid => &address::AddressParams::LIQUID,
Network::LiquidRegtest => &address::AddressParams::ELEMENTS,
_ => panic!("the liquid-only address_params() called with non-liquid network"),
Network::LiquidTestnet => &LIQUID_TESTNET_PARAMS,
}
}

#[cfg(feature = "liquid")]
pub fn native_asset(self) -> &'static AssetId {
match self {
Network::Liquid => &*asset::NATIVE_ASSET_ID,
// same for testnet and regtest
Network::LiquidRegtest => &*asset::NATIVE_ASSET_ID_TESTNET,
_ => panic!("the liquid-only native_asset_id() called with non-liquid network"),
Network::LiquidTestnet => &*asset::NATIVE_ASSET_ID_TESTNET,
Network::LiquidRegtest => &*asset::NATIVE_ASSET_ID_REGTEST,
}
}

#[cfg(feature = "liquid")]
pub fn pegged_asset(self) -> Option<&'static AssetId> {
match self {
Network::Liquid => Some(&*asset::NATIVE_ASSET_ID),
Network::LiquidTestnet | Network::LiquidRegtest => None,
}
}

Expand All @@ -90,64 +106,106 @@ impl Network {
"mainnet".to_string(),
"testnet".to_string(),
"regtest".to_string(),
"signet".to_string(),
];

#[cfg(feature = "liquid")]
return vec![
"mainnet".to_string(),
"testnet".to_string(),
"regtest".to_string(),
"liquid".to_string(),
"liquidtestnet".to_string(),
"liquidregtest".to_string(),
];
}
}

pub fn genesis_hash(network: Network) -> BlockHash {
#[cfg(not(feature = "liquid"))]
return bitcoin_genesis_hash(network.into());
#[cfg(feature = "liquid")]
return liquid_genesis_hash(network);
}

pub fn bitcoin_genesis_hash(network: BNetwork) -> bitcoin::BlockHash {
lazy_static! {
static ref BITCOIN_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Bitcoin).block_hash();
static ref TESTNET_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Testnet).block_hash();
static ref REGTEST_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Regtest).block_hash();
static ref SIGNET_GENESIS: bitcoin::BlockHash =
genesis_block(BNetwork::Signet).block_hash();
}
match network {
BNetwork::Bitcoin => *BITCOIN_GENESIS,
BNetwork::Testnet => *TESTNET_GENESIS,
BNetwork::Regtest => *REGTEST_GENESIS,
BNetwork::Signet => *SIGNET_GENESIS,
}
}

#[cfg(feature = "liquid")]
pub fn liquid_genesis_hash(network: Network) -> elements::BlockHash {
lazy_static! {
static ref LIQUID_GENESIS: BlockHash =
"1466275836220db2944ca059a3a10ef6fd2ea684b0688d2c379296888a206003"
.parse()
.unwrap();
}

match network {
Network::Liquid => *LIQUID_GENESIS,
// The genesis block for liquid regtest chains varies based on the chain configuration.
// This instead uses an all zeroed-out hash, which doesn't matter in practice because its
// only used for Electrum server discovery, which isn't active on regtest.
_ => Default::default(),
}
}

impl From<&str> for Network {
fn from(network_name: &str) -> Self {
match network_name {
#[cfg(not(feature = "liquid"))]
"mainnet" => Network::Bitcoin,
#[cfg(not(feature = "liquid"))]
"testnet" => Network::Testnet,
#[cfg(not(feature = "liquid"))]
"regtest" => Network::Regtest,
#[cfg(not(feature = "liquid"))]
"signet" => Network::Signet,

#[cfg(feature = "liquid")]
"liquid" => Network::Liquid,
#[cfg(feature = "liquid")]
"liquidtestnet" => Network::LiquidTestnet,
#[cfg(feature = "liquid")]
"liquidregtest" => Network::LiquidRegtest,

_ => panic!("unsupported Bitcoin network: {:?}", network_name),
}
}
}

#[cfg(not(feature = "liquid"))]
impl From<Network> for BNetwork {
fn from(network: Network) -> Self {
match network {
Network::Bitcoin => BNetwork::Bitcoin,
Network::Testnet => BNetwork::Testnet,
Network::Regtest => BNetwork::Regtest,

#[cfg(feature = "liquid")]
Network::Liquid => BNetwork::Bitcoin, // @FIXME
#[cfg(feature = "liquid")]
Network::LiquidRegtest => BNetwork::Regtest, // @FIXME
Network::Signet => BNetwork::Signet,
}
}
}

#[cfg(not(feature = "liquid"))]
impl From<BNetwork> for Network {
fn from(network: BNetwork) -> Self {
match network {
#[cfg(not(feature = "liquid"))]
BNetwork::Bitcoin => Network::Bitcoin,
#[cfg(not(feature = "liquid"))]
BNetwork::Testnet => Network::Testnet,
BNetwork::Regtest => Network::Regtest,

#[cfg(feature = "liquid")]
BNetwork::Bitcoin => Network::Liquid, // @FIXME
#[cfg(feature = "liquid")]
BNetwork::Regtest => Network::LiquidRegtest, // @FIXME
BNetwork::Testnet => Network::Testnet, // @FIXME
BNetwork::Signet => Network::Signet,
}
}
}
Loading