Skip to content

Commit

Permalink
Bump 'bitcoin' dependency to 0.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
romanz committed May 17, 2024
1 parent 74b868c commit d30d826
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 50 deletions.
96 changes: 73 additions & 23 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ spec = "internal/config_specification.toml"

[dependencies]
anyhow = "1.0"
bitcoin = { version = "0.31.2", features = ["serde", "rand-std"] }
bitcoin_slices = { version = "0.7", features = ["bitcoin", "sha2"] }
bitcoincore-rpc = { version = "0.18" }
bitcoin = { version = "0.32.0", features = ["serde", "rand-std"] }
bitcoin_slices = { version = "0.8", features = ["bitcoin", "sha2"] }
bitcoincore-rpc = { version = "0.19.0" }
configure_me = "0.4"
crossbeam-channel = "0.5"
dirs-next = "2.0"
Expand Down
12 changes: 6 additions & 6 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bitcoincore_rpc::{json, jsonrpc, Auth, Client, RpcApi};
use crossbeam_channel::Receiver;
use parking_lot::Mutex;
use serde::Serialize;
use serde_json::{json, Value};
use serde_json::{json, value::RawValue, Value};

use std::fs::File;
use std::io::Read;
Expand Down Expand Up @@ -309,13 +309,13 @@ where
T: Serialize,
{
debug!("calling {} on {} items", name, items.len());
let args: Vec<_> = items
let args: Vec<Box<RawValue>> = items
.iter()
.map(|item| vec![serde_json::value::to_raw_value(item).unwrap()])
.collect();
let reqs: Vec<_> = args
.map(|item| jsonrpc::try_arg([item]).context("failed to serialize into JSON"))
.collect::<Result<Vec<_>>>()?;
let reqs: Vec<jsonrpc::Request> = args
.iter()
.map(|arg| client.build_request(name, arg))
.map(|arg| client.build_request(name, Some(arg)))
.collect();
match client.send_batch(&reqs) {
Ok(values) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fn index_single_block(
fn visit_tx_out(&mut self, _vout: usize, tx_out: &bsl::TxOut) -> ControlFlow<()> {
let script = bitcoin::Script::from_bytes(tx_out.script_pubkey());
// skip indexing unspendable outputs
if !script.is_provably_unspendable() {
if !script.is_op_return() {
let row = ScriptHashRow::row(ScriptHash::new(script), self.height);
self.batch.funding_rows.push(row.to_db_row());
}
Expand Down
28 changes: 15 additions & 13 deletions src/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use bitcoin::{
Decodable,
},
hashes::Hash,
io,
p2p::{
self, address,
message::{self, CommandString, NetworkMessage},
Expand All @@ -19,9 +20,8 @@ use bitcoin::{
use bitcoin_slices::{bsl, Parse};
use crossbeam_channel::{bounded, select, Receiver, Sender};

use std::io::{self, ErrorKind, Write};
use std::io::Write;
use std::net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream};
use std::sync::Arc;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};

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

let (tx_send, tx_recv) = bounded::<NetworkMessage>(1);
let (rx_send, rx_recv) = bounded::<RawNetworkMessage>(1);
Expand Down Expand Up @@ -180,7 +181,6 @@ impl Connection {
default_duration_buckets(),
);

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

let stream = Arc::clone(&conn);
let mut stream_reader = std::io::BufReader::new(recv_conn);
crate::thread::spawn("p2p_recv", move || loop {
let start = Instant::now();
let raw_msg = RawNetworkMessage::consensus_decode(&mut &*stream);
let raw_msg = RawNetworkMessage::consensus_decode(&mut stream_reader);
{
let duration = duration_to_seconds(start.elapsed());
let label = format!(
Expand All @@ -232,7 +232,7 @@ impl Connection {
}
raw_msg
}
Err(encode::Error::Io(e)) if e.kind() == ErrorKind::UnexpectedEof => {
Err(encode::Error::Io(e)) if e.kind() == io::ErrorKind::UnexpectedEof => {
debug!("closing p2p_recv thread: connection closed");
return Ok(());
}
Expand Down Expand Up @@ -390,7 +390,9 @@ enum ParsedNetworkMessage {
}

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

Expand Down
8 changes: 4 additions & 4 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use bitcoin::blockdata::block::Header as BlockHeader;
use bitcoin::{
consensus::encode::{deserialize, Decodable, Encodable},
hashes::{hash_newtype, sha256, Hash},
OutPoint, Script, Txid,
io, OutPoint, Script, Txid,
};
use bitcoin_slices::bsl;

Expand All @@ -16,10 +16,10 @@ macro_rules! impl_consensus_encoding {
($thing:ident, $($field:ident),+) => (
impl Encodable for $thing {
#[inline]
fn consensus_encode<S: ::std::io::Write + ?Sized>(
fn consensus_encode<S: io::Write + ?Sized>(
&self,
s: &mut S,
) -> Result<usize, std::io::Error> {
) -> Result<usize, io::Error> {
let mut len = 0;
$(len += self.$field.consensus_encode(s)?;)+
Ok(len)
Expand All @@ -28,7 +28,7 @@ macro_rules! impl_consensus_encoding {

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

0 comments on commit d30d826

Please sign in to comment.