Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(network): deprecate 7777 network #2020

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions mm2src/mm2_main/src/lp_native_dex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use mm2_core::mm_ctx::{MmArc, MmCtx};
use mm2_err_handle::common_errors::InternalError;
use mm2_err_handle::prelude::*;
use mm2_event_stream::behaviour::{EventBehaviour, EventInitStatus};
use mm2_libp2p::behaviours::atomicdex::DEPRECATED_NETID_LIST;
use mm2_libp2p::{spawn_gossipsub, AdexBehaviourError, NodeType, RelayAddress, RelayAddressError, SwarmRuntime,
WssCerts};
use mm2_metrics::mm_gauge;
Expand Down Expand Up @@ -68,7 +69,7 @@ cfg_wasm32! {
pub mod init_metamask;
}

const NETID_8762_SEEDNODES: [&str; 3] = [
const DEFAULT_NETID_SEEDNODES: [&str; 3] = [
"streamseed1.komodo.earth",
"streamseed2.komodo.earth",
"streamseed3.komodo.earth",
Expand Down Expand Up @@ -267,7 +268,7 @@ impl MmInitError {
#[cfg(target_arch = "wasm32")]
fn default_seednodes(netid: u16) -> Vec<RelayAddress> {
if netid == 8762 {
NETID_8762_SEEDNODES
DEFAULT_NETID_SEEDNODES
.iter()
.map(|seed| RelayAddress::Dns(seed.to_string()))
.collect()
Expand All @@ -280,7 +281,7 @@ fn default_seednodes(netid: u16) -> Vec<RelayAddress> {
fn default_seednodes(netid: u16) -> Vec<RelayAddress> {
use crate::mm2::lp_network::addr_to_ipv4_string;
if netid == 8762 {
NETID_8762_SEEDNODES
DEFAULT_NETID_SEEDNODES
.iter()
.filter_map(|seed| addr_to_ipv4_string(seed).ok())
.map(RelayAddress::IPv4)
Expand Down Expand Up @@ -523,6 +524,10 @@ pub async fn init_p2p(ctx: MmArc) -> P2PResult<()> {
let i_am_seed = ctx.conf["i_am_seed"].as_bool().unwrap_or(false);
let netid = ctx.netid();

if DEPRECATED_NETID_LIST.contains(&netid) {
return MmError::err(P2PInitError::InvalidNetId(NetIdError::Deprecated { netid }));
}

let seednodes = seednodes(&ctx)?;

let ctx_on_poll = ctx.clone();
Expand Down
2 changes: 2 additions & 0 deletions mm2src/mm2_main/src/lp_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ pub fn addr_to_ipv4_string(address: &str) -> Result<String, MmError<ParseAddress
pub enum NetIdError {
#[display(fmt = "Netid {} is larger than max {}", netid, max_netid)]
LargerThanMax { netid: u16, max_netid: u16 },
#[display(fmt = "{} netid is deprecated.", netid)]
Deprecated { netid: u16 },
}

pub fn lp_ports(netid: u16) -> Result<(u16, u16, u16), MmError<NetIdError>> {
Expand Down
10 changes: 7 additions & 3 deletions mm2src/mm2_p2p/src/behaviours/atomicdex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use super::peers_exchange::{PeerAddresses, PeersExchange, PeersExchangeRequest,
use super::ping::AdexPing;
use super::request_response::{build_request_response_behaviour, PeerRequest, PeerResponse, RequestResponseBehaviour,
RequestResponseSender};
use crate::network::{get_all_network_seednodes, NETID_8762};
use crate::network::{get_all_network_seednodes, DEFAULT_NETID};
use crate::relay_address::{RelayAddress, RelayAddressError};
use crate::swarm_runtime::SwarmRuntime;
use crate::{NetworkInfo, NetworkPorts, RequestResponseBehaviourEvent};
Expand All @@ -51,6 +51,10 @@ const ANNOUNCE_INTERVAL: Duration = Duration::from_secs(600);
const ANNOUNCE_INITIAL_DELAY: Duration = Duration::from_secs(60);
const CHANNEL_BUF_SIZE: usize = 1024 * 8;

pub const DEPRECATED_NETID_LIST: &[u16] = &[
7777, // TODO: keep it inaccessible until Q2 of 2024.
];

/// The structure is the same as `PeerResponse`,
/// but is used to prevent `PeerResponse` from being used outside the network implementation.
#[derive(Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -641,7 +645,7 @@ fn start_gossipsub(
let mut gossipsub = Gossipsub::new(MessageAuthenticity::Author(local_peer_id), gossipsub_config)
.map_err(|e| AdexBehaviourError::InitializationError(e.to_owned()))?;

let floodsub = Floodsub::new(local_peer_id, netid != NETID_8762);
let floodsub = Floodsub::new(local_peer_id, netid != DEFAULT_NETID);

let mut peers_exchange = PeersExchange::new(network_info);
if !network_info.in_memory() {
Expand Down Expand Up @@ -735,7 +739,7 @@ fn start_gossipsub(
debug!("Swarm event {:?}", event);

if let SwarmEvent::Behaviour(event) = event {
if swarm.behaviour_mut().netid != NETID_8762 {
if swarm.behaviour_mut().netid != DEFAULT_NETID {
if let AdexBehaviourEvent::Floodsub(FloodsubEvent::Message(message)) = &event {
for topic in &message.topics {
if topic == &FloodsubTopic::new(PEERS_TOPIC) {
Expand Down
8 changes: 4 additions & 4 deletions mm2src/mm2_p2p/src/network.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::relay_address::RelayAddress;
use libp2p::PeerId;

pub const NETID_8762: u16 = 8762;
pub const DEFAULT_NETID: u16 = 8762;

#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
const ALL_NETID_8762_SEEDNODES: &[(&str, &str)] = &[
const ALL_DEFAULT_NETID_SEEDNODES: &[(&str, &str)] = &[
(
"12D3KooWHKkHiNhZtKceQehHhPqwU5W1jXpoVBgS1qst899GjvTm",
"168.119.236.251",
Expand Down Expand Up @@ -52,10 +52,10 @@ pub fn get_all_network_seednodes(_netid: u16) -> Vec<(PeerId, RelayAddress)> { V
pub fn get_all_network_seednodes(netid: u16) -> Vec<(PeerId, RelayAddress)> {
use std::str::FromStr;

if netid != NETID_8762 {
if netid != DEFAULT_NETID {
return Vec::new();
}
ALL_NETID_8762_SEEDNODES
ALL_DEFAULT_NETID_SEEDNODES
.iter()
.map(|(peer_id, ipv4)| {
let peer_id = PeerId::from_str(peer_id).expect("valid peer id");
Expand Down
Loading