From: Matt Corallo Date: Sat, 13 Jun 2020 22:09:04 +0000 (-0400) Subject: Update to latest rust-bitcoin X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=dbd60f299ee413b64e5e2a09286bf8ca2ffde8de;p=dnsseed-rust Update to latest rust-bitcoin --- diff --git a/Cargo.toml b/Cargo.toml index a628f3f..9054eee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,8 +5,7 @@ authors = ["matt"] edition = "2018" [dependencies] -bitcoin = "0.19" -bitcoin_hashes = "0.7" +bitcoin = "0.23" bgp-rs = { git = "https://github.com/TheBlueMatt/bgp-rs", rev = "96bd15e67789b91f679f835fc62ff3beb16685bf" } tokio = "0.1" bytes = "0.4" diff --git a/src/main.rs b/src/main.rs index ba326f7..a66b939 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,13 +12,12 @@ use std::sync::atomic::{Ordering, AtomicBool}; use std::time::{Duration, Instant}; use std::net::{SocketAddr, ToSocketAddrs}; -use bitcoin_hashes::sha256d; - use bitcoin::blockdata::block::Block; use bitcoin::blockdata::constants::genesis_block; -use bitcoin::network::constants::Network; +use bitcoin::hash_types::{BlockHash}; +use bitcoin::network::constants::{Network, ServiceFlags}; use bitcoin::network::message::NetworkMessage; -use bitcoin::network::message_blockdata::{GetHeadersMessage, Inventory, InvType}; +use bitcoin::network::message_blockdata::{GetHeadersMessage, Inventory}; use bitcoin::util::hash::BitcoinHash; use printer::{Printer, Stat}; @@ -31,10 +30,10 @@ use bgp_client::BGPClient; use tokio::prelude::*; use tokio::timer::Delay; -static mut REQUEST_BLOCK: Option>>> = None; -static mut HIGHEST_HEADER: Option>> = None; -static mut HEADER_MAP: Option>>> = None; -static mut HEIGHT_MAP: Option>>> = None; +static mut REQUEST_BLOCK: Option>>> = None; +static mut HIGHEST_HEADER: Option>> = None; +static mut HEADER_MAP: Option>>> = None; +static mut HEIGHT_MAP: Option>>> = None; static mut DATA_STORE: Option> = None; static mut PRINTER: Option> = None; static mut TOR_PROXY: Option = None; @@ -42,7 +41,7 @@ pub static START_SHUTDOWN: AtomicBool = AtomicBool::new(false); static SCANNING: AtomicBool = AtomicBool::new(false); struct PeerState { - request: Arc<(u64, sha256d::Hash, Block)>, + request: Arc<(u64, BlockHash, Block)>, node_services: u64, msg: (String, bool), fail_reason: AddressState, @@ -125,7 +124,7 @@ pub fn scan_node(scan_time: Instant, node: SocketAddr, manual: bool) { state_lock.fail_reason = AddressState::LowVersion; return future::err(()); } - if ver.services & (1 | (1 << 10)) == 0 { + if !ver.services.has(ServiceFlags::NETWORK) && !ver.services.has(ServiceFlags::NETWORK_LIMITED) { state_lock.msg = (format!("({}: services {:x})", safe_ua, ver.services), true); state_lock.fail_reason = AddressState::NotFullNode; return future::err(()); @@ -136,7 +135,7 @@ pub fn scan_node(scan_time: Instant, node: SocketAddr, manual: bool) { return future::err(()); } check_set_flag!(recvd_version, "version"); - state_lock.node_services = ver.services; + state_lock.node_services = ver.services.as_u64(); state_lock.msg = (format!("(subver: {})", safe_ua), false); if let Err(_) = write.try_send(NetworkMessage::Verack) { return future::err(()); @@ -173,10 +172,7 @@ pub fn scan_node(scan_time: Instant, node: SocketAddr, manual: bool) { } if addrs.len() > 10 { if !state_lock.recvd_addrs { - if let Err(_) = write.try_send(NetworkMessage::GetData(vec![Inventory { - inv_type: InvType::WitnessBlock, - hash: state_lock.request.1, - }])) { + if let Err(_) = write.try_send(NetworkMessage::GetData(vec![Inventory::WitnessBlock(state_lock.request.1)])) { return future::err(()); } } @@ -195,10 +191,13 @@ pub fn scan_node(scan_time: Instant, node: SocketAddr, manual: bool) { }, Some(NetworkMessage::Inv(invs)) => { for inv in invs { - if inv.inv_type == InvType::Transaction { - state_lock.fail_reason = AddressState::EvilNode; - state_lock.msg = ("due to unrequested inv tx".to_string(), true); - return future::err(()); + match inv { + Inventory::Transaction(_) | Inventory::WitnessTransaction(_) => { + state_lock.fail_reason = AddressState::EvilNode; + state_lock.msg = ("due to unrequested inv tx".to_string(), true); + return future::err(()); + } + _ => {}, } } }, @@ -359,10 +358,9 @@ fn make_trusted_conn(trusted_sockaddr: SocketAddr, bgp_client: Arc) { printer.set_stat(printer::Stat::HeaderCount(top_height)); if top_height >= starting_height as u64 { - if let Err(_) = trusted_write.try_send(NetworkMessage::GetData(vec![Inventory { - inv_type: InvType::WitnessBlock, - hash: height_map.get(&(top_height - 216)).unwrap().clone(), - }])) { + if let Err(_) = trusted_write.try_send(NetworkMessage::GetData(vec![ + Inventory::WitnessBlock(height_map.get(&(top_height - 216)).unwrap().clone()) + ])) { return future::err(()); } } diff --git a/src/peer.rs b/src/peer.rs index aeeb2c2..ff0d502 100644 --- a/src/peer.rs +++ b/src/peer.rs @@ -5,7 +5,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; use bitcoin::consensus::encode; use bitcoin::consensus::encode::{Decodable, Encodable}; use bitcoin::network::address::Address; -use bitcoin::network::constants::Network; +use bitcoin::network::constants::{Network, ServiceFlags}; use bitcoin::network::message::{RawNetworkMessage, NetworkMessage}; use bitcoin::network::message_network::VersionMessage; @@ -198,10 +198,10 @@ impl Peer { })); let _ = sender.try_send(NetworkMessage::Version(VersionMessage { version: 70015, - services: (1 << 3), // NODE_WITNESS + services: ServiceFlags::WITNESS, timestamp: SystemTime::now().duration_since(UNIX_EPOCH).expect("time > 1970").as_secs() as i64, - receiver: Address::new(&addr, 0), - sender: Address::new(&"0.0.0.0:0".parse().unwrap(), 0), + receiver: Address::new(&addr, ServiceFlags::NONE), + sender: Address::new(&"0.0.0.0:0".parse().unwrap(), ServiceFlags::WITNESS), nonce: 0xdeadbeef, user_agent: "/rust-bitcoin:0.18/bluematt-tokio-client:0.1/".to_string(), start_height: 0,