Skip to content

Commit 3f192d0

Browse files
Add p2p v7, and make other versions obsolete one day before crescendo (kaspanet#662)
* Add p2p v7, and make other versions obsolete one day before crescendo * Apply only to mainnet * Fix threshold and protocol version for v6 Co-authored-by: Michael Sutton <[email protected]> * Make v7 an alias of v6 Co-authored-by: Michael Sutton <[email protected]> * Change network type to 'not testnet' --------- Co-authored-by: Michael Sutton <[email protected]>
1 parent 47abc36 commit 3f192d0

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

protocol/flows/src/flow_context.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
use crate::flowcontext::{
2-
orphans::{OrphanBlocksPool, OrphanOutput},
3-
process_queue::ProcessQueue,
4-
transactions::TransactionsSpread,
1+
use crate::{
2+
flowcontext::{
3+
orphans::{OrphanBlocksPool, OrphanOutput},
4+
process_queue::ProcessQueue,
5+
transactions::TransactionsSpread,
6+
},
7+
v7,
58
};
69
use crate::{v5, v6};
710
use async_trait::async_trait;
811
use futures::future::join_all;
912
use kaspa_addressmanager::AddressManager;
1013
use kaspa_connectionmanager::ConnectionManager;
11-
use kaspa_consensus_core::api::{BlockValidationFuture, BlockValidationFutures};
1214
use kaspa_consensus_core::block::Block;
1315
use kaspa_consensus_core::config::Config;
1416
use kaspa_consensus_core::errors::block::RuleError;
1517
use kaspa_consensus_core::tx::{Transaction, TransactionId};
18+
use kaspa_consensus_core::{
19+
api::{BlockValidationFuture, BlockValidationFutures},
20+
network::NetworkType,
21+
};
1622
use kaspa_consensus_notify::{
1723
notification::{Notification, PruningPointUtxoSetOverrideNotification},
1824
root::ConsensusNotificationRoot,
@@ -58,8 +64,8 @@ use tokio::sync::{
5864
use tokio_stream::{wrappers::UnboundedReceiverStream, StreamExt};
5965
use uuid::Uuid;
6066

61-
/// The P2P protocol version. Currently the only one supported.
62-
const PROTOCOL_VERSION: u32 = 6;
67+
/// The P2P protocol version.
68+
const PROTOCOL_VERSION: u32 = 7;
6369

6470
/// See `check_orphan_resolution_range`
6571
const BASELINE_ORPHAN_RESOLUTION_RANGE: u32 = 5;
@@ -776,10 +782,24 @@ impl ConnectionInitializer for FlowContext {
776782
debug!("protocol versions - self: {}, peer: {}", PROTOCOL_VERSION, peer_version.protocol_version);
777783

778784
// Register all flows according to version
779-
let (flows, applied_protocol_version) = match peer_version.protocol_version {
780-
v if v >= PROTOCOL_VERSION => (v6::register(self.clone(), router.clone()), PROTOCOL_VERSION),
781-
5 => (v5::register(self.clone(), router.clone()), 5),
782-
v => return Err(ProtocolError::VersionMismatch(PROTOCOL_VERSION, v)),
785+
const CONNECT_ONLY_NEW_VERSIONS_THRESHOLD_MILLIS: u64 = 24 * 3600 * 1000; // one day in milliseconds
786+
let daa_threshold = CONNECT_ONLY_NEW_VERSIONS_THRESHOLD_MILLIS / self.config.target_time_per_block().before();
787+
let sink_daa_score = self.consensus().unguarded_session().async_get_sink_daa_score_timestamp().await.daa_score;
788+
let connect_only_new_versions = self.config.net.network_type() != NetworkType::Testnet
789+
&& self.config.crescendo_activation.is_active(sink_daa_score + daa_threshold); // activate the protocol version constraint daa_threshold blocks ahead of time
790+
791+
let (flows, applied_protocol_version) = if connect_only_new_versions {
792+
match peer_version.protocol_version {
793+
v if v >= PROTOCOL_VERSION => (v7::register(self.clone(), router.clone()), PROTOCOL_VERSION),
794+
v => return Err(ProtocolError::VersionMismatch(PROTOCOL_VERSION, v)),
795+
}
796+
} else {
797+
match peer_version.protocol_version {
798+
v if v >= PROTOCOL_VERSION => (v7::register(self.clone(), router.clone()), PROTOCOL_VERSION),
799+
6 => (v6::register(self.clone(), router.clone()), 6),
800+
5 => (v5::register(self.clone(), router.clone()), 5),
801+
v => return Err(ProtocolError::VersionMismatch(PROTOCOL_VERSION, v)),
802+
}
783803
};
784804

785805
// Build and register the peer properties

protocol/flows/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ pub mod flowcontext;
44
pub mod service;
55
pub mod v5;
66
pub mod v6;
7+
pub use v6 as v7;

0 commit comments

Comments
 (0)