Skip to content

Commit c5f57dc

Browse files
committed
[WIP] Bump 'bitcoin' dependency to 0.32.0
1 parent 74b868c commit c5f57dc

File tree

5 files changed

+80
-42
lines changed

5 files changed

+80
-42
lines changed

Cargo.lock

Lines changed: 57 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ spec = "internal/config_specification.toml"
2222

2323
[dependencies]
2424
anyhow = "1.0"
25-
bitcoin = { version = "0.31.2", features = ["serde", "rand-std"] }
26-
bitcoin_slices = { version = "0.7", features = ["bitcoin", "sha2"] }
27-
bitcoincore-rpc = { version = "0.18" }
25+
bitcoin = { version = "0.32.0", features = ["serde", "rand-std"] }
26+
bitcoin_slices = { version = "0.8", features = ["bitcoin", "sha2"] }
27+
bitcoincore-rpc = { git = "https://github.com/romanz/rust-bitcoincore-rpc", rev = "904a21c996fd3fe56931cc757d5b3e3249b314c9" }
2828
configure_me = "0.4"
2929
crossbeam-channel = "0.5"
3030
dirs-next = "2.0"

src/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ fn index_single_block(
263263
fn visit_tx_out(&mut self, _vout: usize, tx_out: &bsl::TxOut) -> ControlFlow<()> {
264264
let script = bitcoin::Script::from_bytes(tx_out.script_pubkey());
265265
// skip indexing unspendable outputs
266-
if !script.is_provably_unspendable() {
266+
if !script.is_op_return() {
267267
let row = ScriptHashRow::row(ScriptHash::new(script), self.height);
268268
self.batch.funding_rows.push(row.to_db_row());
269269
}

src/p2p.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use bitcoin::{
77
Decodable,
88
},
99
hashes::Hash,
10+
io,
1011
p2p::{
1112
self, address,
1213
message::{self, CommandString, NetworkMessage},
@@ -19,9 +20,8 @@ use bitcoin::{
1920
use bitcoin_slices::{bsl, Parse};
2021
use crossbeam_channel::{bounded, select, Receiver, Sender};
2122

22-
use std::io::{self, ErrorKind, Write};
23+
use std::io::Write;
2324
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
24-
use std::sync::Arc;
2525
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
2626

2727
use crate::types::SerBlock;
@@ -141,10 +141,11 @@ impl Connection {
141141
metrics: &Metrics,
142142
magic: Magic,
143143
) -> Result<Self> {
144-
let conn = Arc::new(
145-
TcpStream::connect(address)
146-
.with_context(|| format!("{} p2p failed to connect: {:?}", network, address))?,
147-
);
144+
let recv_conn = TcpStream::connect(address)
145+
.with_context(|| format!("{} p2p failed to connect: {:?}", network, address))?;
146+
let mut send_conn = recv_conn
147+
.try_clone()
148+
.context("failed to clone connection")?;
148149

149150
let (tx_send, tx_recv) = bounded::<NetworkMessage>(1);
150151
let (rx_send, rx_recv) = bounded::<RawNetworkMessage>(1);
@@ -180,7 +181,6 @@ impl Connection {
180181
default_duration_buckets(),
181182
);
182183

183-
let stream = Arc::clone(&conn);
184184
let mut buffer = vec![];
185185
crate::thread::spawn("p2p_send", move || loop {
186186
use std::net::Shutdown;
@@ -190,7 +190,7 @@ impl Connection {
190190
// p2p_loop is closed, so tx_send is disconnected
191191
debug!("closing p2p_send thread: no more messages to send");
192192
// close the stream reader (p2p_recv thread may block on it)
193-
if let Err(e) = stream.shutdown(Shutdown::Read) {
193+
if let Err(e) = send_conn.shutdown(Shutdown::Read) {
194194
warn!("failed to shutdown p2p connection: {}", e)
195195
}
196196
return Ok(());
@@ -203,16 +203,16 @@ impl Connection {
203203
raw_msg
204204
.consensus_encode(&mut buffer)
205205
.expect("in-memory writers don't error");
206-
(&*stream)
206+
send_conn
207207
.write_all(buffer.as_slice())
208208
.context("p2p failed to send")
209209
})?;
210210
});
211211

212-
let stream = Arc::clone(&conn);
212+
let mut stream_reader = std::io::BufReader::new(recv_conn);
213213
crate::thread::spawn("p2p_recv", move || loop {
214214
let start = Instant::now();
215-
let raw_msg = RawNetworkMessage::consensus_decode(&mut &*stream);
215+
let raw_msg = RawNetworkMessage::consensus_decode(&mut stream_reader);
216216
{
217217
let duration = duration_to_seconds(start.elapsed());
218218
let label = format!(
@@ -232,7 +232,7 @@ impl Connection {
232232
}
233233
raw_msg
234234
}
235-
Err(encode::Error::Io(e)) if e.kind() == ErrorKind::UnexpectedEof => {
235+
Err(encode::Error::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => {
236236
debug!("closing p2p_recv thread: connection closed");
237237
return Ok(());
238238
}
@@ -390,7 +390,9 @@ enum ParsedNetworkMessage {
390390
}
391391

392392
impl Decodable for RawNetworkMessage {
393-
fn consensus_decode<D: io::Read + ?Sized>(d: &mut D) -> Result<Self, encode::Error> {
393+
fn consensus_decode<D: bitcoin::io::BufRead + ?Sized>(
394+
d: &mut D,
395+
) -> Result<Self, encode::Error> {
394396
let magic = Decodable::consensus_decode(d)?;
395397
let cmd = Decodable::consensus_decode(d)?;
396398

src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use bitcoin::blockdata::block::Header as BlockHeader;
66
use bitcoin::{
77
consensus::encode::{deserialize, Decodable, Encodable},
88
hashes::{hash_newtype, sha256, Hash},
9-
OutPoint, Script, Txid,
9+
io, OutPoint, Script, Txid,
1010
};
1111
use bitcoin_slices::bsl;
1212

@@ -16,10 +16,10 @@ macro_rules! impl_consensus_encoding {
1616
($thing:ident, $($field:ident),+) => (
1717
impl Encodable for $thing {
1818
#[inline]
19-
fn consensus_encode<S: ::std::io::Write + ?Sized>(
19+
fn consensus_encode<S: io::Write + ?Sized>(
2020
&self,
2121
s: &mut S,
22-
) -> Result<usize, std::io::Error> {
22+
) -> Result<usize, io::Error> {
2323
let mut len = 0;
2424
$(len += self.$field.consensus_encode(s)?;)+
2525
Ok(len)
@@ -28,7 +28,7 @@ macro_rules! impl_consensus_encoding {
2828

2929
impl Decodable for $thing {
3030
#[inline]
31-
fn consensus_decode<D: ::std::io::Read + ?Sized>(
31+
fn consensus_decode<D: io::BufRead + ?Sized>(
3232
d: &mut D,
3333
) -> Result<$thing, bitcoin::consensus::encode::Error> {
3434
Ok($thing {

0 commit comments

Comments
 (0)