]> git.bitcoin.ninja Git - dnsseed-rust/commitdiff
Update to latest rust-bitcoin
authorMatt Corallo <git@bluematt.me>
Sat, 13 Jun 2020 22:09:04 +0000 (18:09 -0400)
committerMatt Corallo <git@bluematt.me>
Sat, 13 Jun 2020 22:09:04 +0000 (18:09 -0400)
Cargo.toml
src/main.rs
src/peer.rs

index a628f3febb5e5c3b669ea7cce082b05f8519e0ab..9054eeefc7e6c77a083ce1010cb13b74cf6a9dda 100644 (file)
@@ -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"
index ba326f77d65d76b965b433e6a652b4c4116f5e1f..a66b9392269e832d1d6e559378c772c9275c5ec5 100644 (file)
@@ -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<Box<Mutex<Arc<(u64, sha256d::Hash, Block)>>>> = None;
-static mut HIGHEST_HEADER: Option<Box<Mutex<(sha256d::Hash, u64)>>> = None;
-static mut HEADER_MAP: Option<Box<Mutex<HashMap<sha256d::Hash, u64>>>> = None;
-static mut HEIGHT_MAP: Option<Box<Mutex<HashMap<u64, sha256d::Hash>>>> = None;
+static mut REQUEST_BLOCK: Option<Box<Mutex<Arc<(u64, BlockHash, Block)>>>> = None;
+static mut HIGHEST_HEADER: Option<Box<Mutex<(BlockHash, u64)>>> = None;
+static mut HEADER_MAP: Option<Box<Mutex<HashMap<BlockHash, u64>>>> = None;
+static mut HEIGHT_MAP: Option<Box<Mutex<HashMap<u64, BlockHash>>>> = None;
 static mut DATA_STORE: Option<Box<Store>> = None;
 static mut PRINTER: Option<Box<Printer>> = None;
 static mut TOR_PROXY: Option<SocketAddr> = 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<BGPClient>) {
                                                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(());
                                                        }
                                                }
index aeeb2c2c582e7ba9c0546c5a08010468a6ef7fe1..ff0d502191dd5fa3b7eb00f7439b805c2631691a 100644 (file)
@@ -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,