diff --git a/bitcoin/src/p2p/constants.rs b/bitcoin/src/p2p/constants.rs index 7e86ebaa..90c0e591 100644 --- a/bitcoin/src/p2p/constants.rs +++ b/bitcoin/src/p2p/constants.rs @@ -42,23 +42,6 @@ use crate::error::impl_std_error; use crate::io; use crate::prelude::{String, ToOwned}; -/// Version of the protocol as appearing in network message headers -/// This constant is used to signal to other peers which features you support. -/// Increasing it implies that your software also supports every feature prior to this version. -/// Doing so without support may lead to you incorrectly banning other peers or other peers banning you. -/// These are the features required for each version: -/// 70016 - Support receiving `wtxidrelay` message between `version` and `verack` message -/// 70015 - Support receiving invalid compact blocks from a peer without banning them -/// 70014 - Support compact block messages `sendcmpct`, `cmpctblock`, `getblocktxn` and `blocktxn` -/// 70013 - Support `feefilter` message -/// 70012 - Support `sendheaders` message and announce new blocks via headers rather than inv -/// 70011 - Support NODE_BLOOM service flag and don't support bloom filter messages if it is not set -/// 70002 - Support `reject` message -/// 70001 - Support bloom filter messages `filterload`, `filterclear` `filteradd`, `merkleblock` and FILTERED_BLOCK inventory type -/// 60002 - Support `mempool` message -/// 60001 - Support `pong` message and nonce in `ping` message -pub const PROTOCOL_VERSION: u32 = 70001; - /// The cryptocurrency network to act on. #[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] diff --git a/bitcoin/src/p2p/message_blockdata.rs b/bitcoin/src/p2p/message_blockdata.rs index 2a69f1e8..3a563097 100644 --- a/bitcoin/src/p2p/message_blockdata.rs +++ b/bitcoin/src/p2p/message_blockdata.rs @@ -11,9 +11,8 @@ use hashes::{sha256d, Hash as _}; use crate::consensus::encode::{self, Decodable, Encodable}; use crate::hash_types::{BlockHash, Txid, Wtxid}; use crate::internal_macros::impl_consensus_encoding; -use crate::io; -use crate::p2p::constants; use crate::prelude::*; +use crate::{io, p2p}; /// An inventory item. #[derive(PartialEq, Eq, Clone, Debug, Copy, Hash, PartialOrd, Ord)] @@ -128,7 +127,7 @@ pub struct GetHeadersMessage { impl GetBlocksMessage { /// Construct a new `getblocks` message pub fn new(locator_hashes: Vec, stop_hash: BlockHash) -> GetBlocksMessage { - GetBlocksMessage { version: constants::PROTOCOL_VERSION, locator_hashes, stop_hash } + GetBlocksMessage { version: p2p::PROTOCOL_VERSION, locator_hashes, stop_hash } } } @@ -137,7 +136,7 @@ impl_consensus_encoding!(GetBlocksMessage, version, locator_hashes, stop_hash); impl GetHeadersMessage { /// Construct a new `getheaders` message pub fn new(locator_hashes: Vec, stop_hash: BlockHash) -> GetHeadersMessage { - GetHeadersMessage { version: constants::PROTOCOL_VERSION, locator_hashes, stop_hash } + GetHeadersMessage { version: p2p::PROTOCOL_VERSION, locator_hashes, stop_hash } } } diff --git a/bitcoin/src/p2p/message_network.rs b/bitcoin/src/p2p/message_network.rs index 996aad66..a0ab6cb4 100644 --- a/bitcoin/src/p2p/message_network.rs +++ b/bitcoin/src/p2p/message_network.rs @@ -10,10 +10,10 @@ use hashes::sha256d; use crate::consensus::{encode, Decodable, Encodable, ReadExt}; use crate::internal_macros::impl_consensus_encoding; -use crate::io; use crate::p2p::address::Address; -use crate::p2p::constants::{self, ServiceFlags}; +use crate::p2p::constants::ServiceFlags; use crate::prelude::*; +use crate::{io, p2p}; /// Some simple messages @@ -54,7 +54,7 @@ impl VersionMessage { start_height: i32, ) -> VersionMessage { VersionMessage { - version: constants::PROTOCOL_VERSION, + version: p2p::PROTOCOL_VERSION, services, timestamp, receiver, diff --git a/bitcoin/src/p2p/mod.rs b/bitcoin/src/p2p/mod.rs index afe4eff9..9e2a1c1a 100644 --- a/bitcoin/src/p2p/mod.rs +++ b/bitcoin/src/p2p/mod.rs @@ -25,3 +25,20 @@ pub mod message_filter; pub mod message_network; pub use self::constants::Magic; + +/// Version of the protocol as appearing in network message headers +/// This constant is used to signal to other peers which features you support. +/// Increasing it implies that your software also supports every feature prior to this version. +/// Doing so without support may lead to you incorrectly banning other peers or other peers banning you. +/// These are the features required for each version: +/// 70016 - Support receiving `wtxidrelay` message between `version` and `verack` message +/// 70015 - Support receiving invalid compact blocks from a peer without banning them +/// 70014 - Support compact block messages `sendcmpct`, `cmpctblock`, `getblocktxn` and `blocktxn` +/// 70013 - Support `feefilter` message +/// 70012 - Support `sendheaders` message and announce new blocks via headers rather than inv +/// 70011 - Support NODE_BLOOM service flag and don't support bloom filter messages if it is not set +/// 70002 - Support `reject` message +/// 70001 - Support bloom filter messages `filterload`, `filterclear` `filteradd`, `merkleblock` and FILTERED_BLOCK inventory type +/// 60002 - Support `mempool` message +/// 60001 - Support `pong` message and nonce in `ping` message +pub const PROTOCOL_VERSION: u32 = 70001;