Move p2p::constants::PROTOCOL_VERSION to p2p module

The `PROTOCOL_VERSION` const is a p2p layer constant. It can live in the
`mod.rs` file of the `p2p` module.

This is a straight code move, the `PROTOCOL_VERSION` replaces the
current re-export.
This commit is contained in:
Tobin C. Harding 2023-05-31 16:31:33 +10:00
parent 1bac1fd518
commit 4330722d62
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
4 changed files with 23 additions and 24 deletions

View File

@ -42,23 +42,6 @@ use crate::error::impl_std_error;
use crate::io; use crate::io;
use crate::prelude::{String, ToOwned}; 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. /// The cryptocurrency network to act on.
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)] #[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]

View File

@ -11,9 +11,8 @@ use hashes::{sha256d, Hash as _};
use crate::consensus::encode::{self, Decodable, Encodable}; use crate::consensus::encode::{self, Decodable, Encodable};
use crate::hash_types::{BlockHash, Txid, Wtxid}; use crate::hash_types::{BlockHash, Txid, Wtxid};
use crate::internal_macros::impl_consensus_encoding; use crate::internal_macros::impl_consensus_encoding;
use crate::io;
use crate::p2p::constants;
use crate::prelude::*; use crate::prelude::*;
use crate::{io, p2p};
/// An inventory item. /// An inventory item.
#[derive(PartialEq, Eq, Clone, Debug, Copy, Hash, PartialOrd, Ord)] #[derive(PartialEq, Eq, Clone, Debug, Copy, Hash, PartialOrd, Ord)]
@ -128,7 +127,7 @@ pub struct GetHeadersMessage {
impl GetBlocksMessage { impl GetBlocksMessage {
/// Construct a new `getblocks` message /// Construct a new `getblocks` message
pub fn new(locator_hashes: Vec<BlockHash>, stop_hash: BlockHash) -> GetBlocksMessage { pub fn new(locator_hashes: Vec<BlockHash>, 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 { impl GetHeadersMessage {
/// Construct a new `getheaders` message /// Construct a new `getheaders` message
pub fn new(locator_hashes: Vec<BlockHash>, stop_hash: BlockHash) -> GetHeadersMessage { pub fn new(locator_hashes: Vec<BlockHash>, stop_hash: BlockHash) -> GetHeadersMessage {
GetHeadersMessage { version: constants::PROTOCOL_VERSION, locator_hashes, stop_hash } GetHeadersMessage { version: p2p::PROTOCOL_VERSION, locator_hashes, stop_hash }
} }
} }

View File

@ -10,10 +10,10 @@ use hashes::sha256d;
use crate::consensus::{encode, Decodable, Encodable, ReadExt}; use crate::consensus::{encode, Decodable, Encodable, ReadExt};
use crate::internal_macros::impl_consensus_encoding; use crate::internal_macros::impl_consensus_encoding;
use crate::io;
use crate::p2p::address::Address; use crate::p2p::address::Address;
use crate::p2p::constants::{self, ServiceFlags}; use crate::p2p::constants::ServiceFlags;
use crate::prelude::*; use crate::prelude::*;
use crate::{io, p2p};
/// Some simple messages /// Some simple messages
@ -54,7 +54,7 @@ impl VersionMessage {
start_height: i32, start_height: i32,
) -> VersionMessage { ) -> VersionMessage {
VersionMessage { VersionMessage {
version: constants::PROTOCOL_VERSION, version: p2p::PROTOCOL_VERSION,
services, services,
timestamp, timestamp,
receiver, receiver,

View File

@ -25,3 +25,20 @@ pub mod message_filter;
pub mod message_network; pub mod message_network;
pub use self::constants::Magic; 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;