Skip to content

Commit bc72994

Browse files
committed
Fix hwi, esplora, compact filters
1 parent 8bc4de4 commit bc72994

File tree

8 files changed

+55
-45
lines changed

8 files changed

+55
-45
lines changed

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ rand = "^0.8"
2323
# Optional dependencies
2424
sled = { version = "0.34", optional = true }
2525
electrum-client = { version = "0.12", optional = true }
26-
# esplora-client = { version = "0.1.1", default-features = false, optional = true }
26+
esplora-client = { git = "https://github.com/bitcoindevkit/rust-esplora-client.git", rev = "64471d9d34e6224cc4226227d0c92981c12cd72d", default-features = false, optional = true }
2727
rusqlite = { version = "0.27.0", optional = true }
2828
ahash = { version = "0.7.6", optional = true }
2929
futures = { version = "0.3", optional = true }
3030
async-trait = { version = "0.1", optional = true }
3131
rocksdb = { version = "0.14", default-features = false, features = ["snappy"], optional = true }
3232
cc = { version = ">=1.0.64", optional = true }
3333
socks = { version = "0.3", optional = true }
34-
# hwi = { version = "0.2.3", optional = true }
34+
hwi = { version = "0.3.0", optional = true }
3535

3636
bip39 = { version = "1.0.1", optional = true }
3737
bitcoinconsensus = { version = "0.19.0-3", optional = true }
@@ -59,7 +59,7 @@ key-value-db = ["sled"]
5959
all-keys = ["keys-bip39"]
6060
keys-bip39 = ["bip39"]
6161
rpc = ["bitcoincore-rpc"]
62-
# hardware-signer = ["hwi"]
62+
hardware-signer = ["hwi"]
6363

6464
# We currently provide mulitple implementations of `Blockchain`, all are
6565
# blocking except for the `EsploraBlockchain` which can be either async or
@@ -77,11 +77,11 @@ rpc = ["bitcoincore-rpc"]
7777
async-interface = ["async-trait"]
7878
electrum = ["electrum-client"]
7979
# MUST ALSO USE `--no-default-features`.
80-
# use-esplora-async = ["esplora", "esplora-client/async", "futures"]
81-
# use-esplora-blocking = ["esplora", "esplora-client/blocking"]
80+
use-esplora-async = ["esplora", "esplora-client/async", "futures"]
81+
use-esplora-blocking = ["esplora", "esplora-client/blocking"]
8282
# Deprecated aliases
83-
# use-esplora-reqwest = ["use-esplora-async"]
84-
# use-esplora-ureq = ["use-esplora-blocking"]
83+
use-esplora-reqwest = ["use-esplora-async"]
84+
use-esplora-ureq = ["use-esplora-blocking"]
8585
# Typical configurations will not need to use `esplora` feature directly.
8686
esplora = []
8787

@@ -95,7 +95,7 @@ test-rpc = ["rpc", "electrsd/electrs_0_8_10", "electrsd/bitcoind_22_0", "test-bl
9595
test-rpc-legacy = ["rpc", "electrsd/electrs_0_8_10", "electrsd/bitcoind_0_20_0", "test-blockchains"]
9696
test-esplora = ["electrsd/legacy", "electrsd/esplora_a33e97e1", "electrsd/bitcoind_22_0", "test-blockchains"]
9797
test-md-docs = ["electrum"]
98-
# test-hardware-signer = ["hardware-signer"]
98+
test-hardware-signer = ["hardware-signer"]
9999

100100
[dev-dependencies]
101101
lazy_static = "1.4"

src/blockchain/compact_filters/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl WalletSync for CompactFiltersBlockchain {
479479
}
480480

481481
/// Data to connect to a Bitcoin P2P peer
482-
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]
482+
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq)]
483483
pub struct BitcoinPeerConfig {
484484
/// Peer address such as 127.0.0.1:18333
485485
pub address: String,
@@ -490,7 +490,7 @@ pub struct BitcoinPeerConfig {
490490
}
491491

492492
/// Configuration for a [`CompactFiltersBlockchain`]
493-
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]
493+
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq)]
494494
pub struct CompactFiltersBlockchainConfig {
495495
/// List of peers to try to connect to for asking headers and filters
496496
pub peers: Vec<BitcoinPeerConfig>,

src/blockchain/compact_filters/peer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ impl Mempool {
7575
/// Look-up a transaction in the mempool given an [`Inventory`] request
7676
pub fn get_tx(&self, inventory: &Inventory) -> Option<Transaction> {
7777
let identifer = match inventory {
78-
Inventory::Error | Inventory::Block(_) | Inventory::WitnessBlock(_) => return None,
78+
Inventory::Error
79+
| Inventory::Block(_)
80+
| Inventory::WitnessBlock(_)
81+
| Inventory::CompactBlock(_) => return None,
7982
Inventory::Transaction(txid) => TxIdentifier::Txid(*txid),
8083
Inventory::WitnessTransaction(txid) => TxIdentifier::Txid(*txid),
8184
Inventory::WTx(wtxid) => TxIdentifier::Wtxid(*wtxid),

src/blockchain/compact_filters/store.rs

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -103,42 +103,42 @@ where
103103
}
104104

105105
impl Encodable for BundleStatus {
106-
fn consensus_encode<W: Write>(&self, mut e: W) -> Result<usize, std::io::Error> {
106+
fn consensus_encode<W: Write + ?Sized>(&self, e: &mut W) -> Result<usize, std::io::Error> {
107107
let mut written = 0;
108108

109109
match self {
110110
BundleStatus::Init => {
111-
written += 0x00u8.consensus_encode(&mut e)?;
111+
written += 0x00u8.consensus_encode(e)?;
112112
}
113113
BundleStatus::CfHeaders { cf_headers } => {
114-
written += 0x01u8.consensus_encode(&mut e)?;
115-
written += VarInt(cf_headers.len() as u64).consensus_encode(&mut e)?;
114+
written += 0x01u8.consensus_encode(e)?;
115+
written += VarInt(cf_headers.len() as u64).consensus_encode(e)?;
116116
for header in cf_headers {
117-
written += header.consensus_encode(&mut e)?;
117+
written += header.consensus_encode(e)?;
118118
}
119119
}
120120
BundleStatus::CFilters { cf_filters } => {
121-
written += 0x02u8.consensus_encode(&mut e)?;
122-
written += VarInt(cf_filters.len() as u64).consensus_encode(&mut e)?;
121+
written += 0x02u8.consensus_encode(e)?;
122+
written += VarInt(cf_filters.len() as u64).consensus_encode(e)?;
123123
for filter in cf_filters {
124-
written += filter.consensus_encode(&mut e)?;
124+
written += filter.consensus_encode(e)?;
125125
}
126126
}
127127
BundleStatus::Processed { cf_filters } => {
128-
written += 0x03u8.consensus_encode(&mut e)?;
129-
written += VarInt(cf_filters.len() as u64).consensus_encode(&mut e)?;
128+
written += 0x03u8.consensus_encode(e)?;
129+
written += VarInt(cf_filters.len() as u64).consensus_encode(e)?;
130130
for filter in cf_filters {
131-
written += filter.consensus_encode(&mut e)?;
131+
written += filter.consensus_encode(e)?;
132132
}
133133
}
134134
BundleStatus::Pruned => {
135-
written += 0x04u8.consensus_encode(&mut e)?;
135+
written += 0x04u8.consensus_encode(e)?;
136136
}
137137
BundleStatus::Tip { cf_filters } => {
138-
written += 0x05u8.consensus_encode(&mut e)?;
139-
written += VarInt(cf_filters.len() as u64).consensus_encode(&mut e)?;
138+
written += 0x05u8.consensus_encode(e)?;
139+
written += VarInt(cf_filters.len() as u64).consensus_encode(e)?;
140140
for filter in cf_filters {
141-
written += filter.consensus_encode(&mut e)?;
141+
written += filter.consensus_encode(e)?;
142142
}
143143
}
144144
}
@@ -148,51 +148,53 @@ impl Encodable for BundleStatus {
148148
}
149149

150150
impl Decodable for BundleStatus {
151-
fn consensus_decode<D: Read>(mut d: D) -> Result<Self, bitcoin::consensus::encode::Error> {
152-
let byte_type = u8::consensus_decode(&mut d)?;
151+
fn consensus_decode<D: Read + ?Sized>(
152+
d: &mut D,
153+
) -> Result<Self, bitcoin::consensus::encode::Error> {
154+
let byte_type = u8::consensus_decode(d)?;
153155
match byte_type {
154156
0x00 => Ok(BundleStatus::Init),
155157
0x01 => {
156-
let num = VarInt::consensus_decode(&mut d)?;
158+
let num = VarInt::consensus_decode(d)?;
157159
let num = num.0 as usize;
158160

159161
let mut cf_headers = Vec::with_capacity(num);
160162
for _ in 0..num {
161-
cf_headers.push(FilterHeader::consensus_decode(&mut d)?);
163+
cf_headers.push(FilterHeader::consensus_decode(d)?);
162164
}
163165

164166
Ok(BundleStatus::CfHeaders { cf_headers })
165167
}
166168
0x02 => {
167-
let num = VarInt::consensus_decode(&mut d)?;
169+
let num = VarInt::consensus_decode(d)?;
168170
let num = num.0 as usize;
169171

170172
let mut cf_filters = Vec::with_capacity(num);
171173
for _ in 0..num {
172-
cf_filters.push(Vec::<u8>::consensus_decode(&mut d)?);
174+
cf_filters.push(Vec::<u8>::consensus_decode(d)?);
173175
}
174176

175177
Ok(BundleStatus::CFilters { cf_filters })
176178
}
177179
0x03 => {
178-
let num = VarInt::consensus_decode(&mut d)?;
180+
let num = VarInt::consensus_decode(d)?;
179181
let num = num.0 as usize;
180182

181183
let mut cf_filters = Vec::with_capacity(num);
182184
for _ in 0..num {
183-
cf_filters.push(Vec::<u8>::consensus_decode(&mut d)?);
185+
cf_filters.push(Vec::<u8>::consensus_decode(d)?);
184186
}
185187

186188
Ok(BundleStatus::Processed { cf_filters })
187189
}
188190
0x04 => Ok(BundleStatus::Pruned),
189191
0x05 => {
190-
let num = VarInt::consensus_decode(&mut d)?;
192+
let num = VarInt::consensus_decode(d)?;
191193
let num = num.0 as usize;
192194

193195
let mut cf_filters = Vec::with_capacity(num);
194196
for _ in 0..num {
195-
cf_filters.push(Vec::<u8>::consensus_decode(&mut d)?);
197+
cf_filters.push(Vec::<u8>::consensus_decode(d)?);
196198
}
197199

198200
Ok(BundleStatus::Tip { cf_filters })
@@ -276,7 +278,11 @@ impl ChainStore<Full> {
276278
}
277279

278280
pub fn start_snapshot(&self, from: usize) -> Result<ChainStore<Snapshot>, CompactFiltersError> {
279-
let new_cf_name: String = thread_rng().sample_iter(&Alphanumeric).take(16).collect();
281+
let new_cf_name: String = thread_rng()
282+
.sample_iter(&Alphanumeric)
283+
.map(|byte| byte as char)
284+
.take(16)
285+
.collect();
280286
let new_cf_name = format!("_headers:{}", new_cf_name);
281287

282288
let mut write_store = self.store.write().unwrap();
@@ -647,7 +653,7 @@ impl CfStore {
647653
&first_key,
648654
(
649655
BundleStatus::Init,
650-
filter.filter_header(&FilterHeader::from_hash(Default::default())),
656+
filter.filter_header(&FilterHeader::from_hash(Hash::all_zeros())),
651657
)
652658
.serialize(),
653659
)?;

src/blockchain/compact_filters/sync.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::sync::{Arc, Mutex};
1414
use std::time::Duration;
1515

1616
use bitcoin::hash_types::{BlockHash, FilterHeader};
17+
use bitcoin::hashes::Hash;
1718
use bitcoin::network::message::NetworkMessage;
1819
use bitcoin::network::message_blockdata::GetHeadersMessage;
1920
use bitcoin::util::bip158::BlockFilter;
@@ -254,7 +255,7 @@ where
254255

255256
peer.send(NetworkMessage::GetHeaders(GetHeadersMessage::new(
256257
locators_vec,
257-
Default::default(),
258+
Hash::all_zeros(),
258259
)))?;
259260
let (mut snapshot, mut last_hash) = if let NetworkMessage::Headers(headers) = peer
260261
.recv("headers", Some(Duration::from_secs(TIMEOUT_SECS)))?
@@ -276,7 +277,7 @@ where
276277
while sync_height < peer.get_version().start_height as usize {
277278
peer.send(NetworkMessage::GetHeaders(GetHeadersMessage::new(
278279
vec![last_hash],
279-
Default::default(),
280+
Hash::all_zeros(),
280281
)))?;
281282
if let NetworkMessage::Headers(headers) = peer
282283
.recv("headers", Some(Duration::from_secs(TIMEOUT_SECS)))?

src/blockchain/esplora/async.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ impl GetTx for EsploraBlockchain {
125125
#[maybe_async]
126126
impl GetBlockHash for EsploraBlockchain {
127127
fn get_block_hash(&self, height: u64) -> Result<BlockHash, Error> {
128-
let block_header = await_or_block!(self.url_client.get_header(height as u32))?;
129-
Ok(block_header.block_hash())
128+
Ok(await_or_block!(self
129+
.url_client
130+
.get_block_hash(height as u32))?)
130131
}
131132
}
132133

src/blockchain/esplora/blocking.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ impl GetTx for EsploraBlockchain {
110110

111111
impl GetBlockHash for EsploraBlockchain {
112112
fn get_block_hash(&self, height: u64) -> Result<BlockHash, Error> {
113-
let block_header = self.url_client.get_header(height as u32)?;
114-
Ok(block_header.block_hash())
113+
Ok(self.url_client.get_block_hash(height as u32)?)
115114
}
116115
}
117116

src/blockchain/esplora/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod blocking;
3333
pub use self::blocking::*;
3434

3535
/// Configuration for an [`EsploraBlockchain`]
36-
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq)]
36+
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone, PartialEq, Eq)]
3737
pub struct EsploraBlockchainConfig {
3838
/// Base URL of the esplora service
3939
///

0 commit comments

Comments
 (0)