Files
nym/nym-node/src/config/mixnode.rs
T
Jędrzej Stuczyński 51b511b27e Rebased the branch one more time
WIP; rebasing

Another branch squash

Squashing the v3 branch

changing min pledge amounts

logic for adding new nymnode into the contract

converting mixnode/gateway bonding into nym-node bonding

logic for migrating gateways into nymnodes

ibid for mixnodes

further nym-node work + fixed most existing unit tests

forbid nymnode migration with pending cost params changes

preassign nodeid for gateways

changing role assignment and epoch progression

changing role assignment and epoch progression

optional custom http port

logic for unbonding a nym-node

updating Delegation struct

logic for increasing pledge of either mixnode or nymnode

logic for decreasing pledge of either mixnode or a nym node

logic for changing cost params of either mixnode or a nym node

wip

initialise nymnodes storage

fixing transaction tests

fixed naive family tests

reward-compatibility related works

resolving delegation events

introduced rewarded set metadata

another iteration of restoring old tests

updated rewarding part of nym-api

parking the branch

unparking the branch

wip

purged families

added 'ExitGateway' role

passing explicit work factor for rewarding function

remove legacy layers storage

wip: node description queries

added announced ports to self-described api

step1 in gruelling journey of adding node_id to gateways

ensure epoch work never goes above 1.0

changed active set to contain role distribution

[theoretically] sending rewarding messages for the new rewarded set

[theoretically] assigning new rewarded set

reimplementing more nym-api features

remove legacy types

re-implement legacy network monitor

restoring further routes + minor refactor of NodeStatusCache

skimmed routes now return legacy nodes alongside nym-nodes

seemingly restored all functionalities in nym-api

removing more legacy things from the contract

initial contract cleanup

added nym-api endpoints to return generic annotations regardless of type

updated simulator to use new rewarding parameters

more contract cleanup

made existing mixnet contract tests compile

extra validation of nym-node bonding parameters

fixed additional compilation issues

fixed nym-api v3 database migration failure

added additional nym-node contract queries

updated the schema

made additional delegation/rewards queries compatible with both legacy mixnodes and nym-nodes

fixing existing unit tests in mixnet contract

wip

resolved first batch of 500 compiler errors

re-deprecating routes

making wallet's rust backend compile

fixed non-determinism in contract + nym-api build

fixes to the build

populating cotracts-cache with nym-nodes data

more missing nymnodes queries

temp mixnet contract methods + restored result submission in nym-api

allow deprecated routes

submitting correct results for mixnode results

removed deprecated re-export of AxumAppState and removed smurf naming

moved axum modules into support::http

cleaning up nym-api warnings

determine entry gateways before exits

exposed transaction to update nym-node config

missing memo for updating node config

 new routes

added routes to swagger and fixed relative paths

fixed some macro derivations

added nym-node commands to nym-cli
2024-10-10 13:27:05 +01:00

223 lines
7.6 KiB
Rust

// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
// SPDX-License-Identifier: GPL-3.0-only
use crate::config::persistence::MixnodePaths;
use crate::config::Config;
use crate::error::MixnodeError;
use clap::crate_version;
use nym_config::defaults::DEFAULT_VERLOC_LISTENING_PORT;
use nym_config::helpers::inaddr_any;
use nym_config::serde_helpers::de_maybe_port;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use std::time::Duration;
pub const DEFAULT_VERLOC_PORT: u16 = DEFAULT_VERLOC_LISTENING_PORT;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct MixnodeConfig {
pub storage_paths: MixnodePaths,
pub verloc: Verloc,
#[serde(default)]
pub debug: Debug,
}
impl MixnodeConfig {
pub fn new_default() -> Self {
MixnodeConfig {
storage_paths: MixnodePaths {},
verloc: Default::default(),
debug: Default::default(),
}
}
}
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct Verloc {
/// Socket address this node will use for binding its verloc API.
/// default: `0.0.0.0:1790`
pub bind_address: SocketAddr,
/// If applicable, custom port announced in the self-described API that other clients and nodes
/// will use.
/// Useful when the node is behind a proxy.
#[serde(deserialize_with = "de_maybe_port")]
pub announce_port: Option<u16>,
#[serde(default)]
pub debug: VerlocDebug,
}
impl Default for Verloc {
fn default() -> Self {
Verloc {
bind_address: SocketAddr::new(inaddr_any(), DEFAULT_VERLOC_PORT),
announce_port: None,
debug: Default::default(),
}
}
}
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
#[serde(deny_unknown_fields)]
pub struct VerlocDebug {
/// Specifies number of echo packets sent to each node during a measurement run.
pub packets_per_node: usize,
/// Specifies maximum amount of time to wait for the connection to get established.
#[serde(with = "humantime_serde")]
pub connection_timeout: Duration,
/// Specifies maximum amount of time to wait for the reply packet to arrive before abandoning the test.
#[serde(with = "humantime_serde")]
pub packet_timeout: Duration,
/// Specifies delay between subsequent test packets being sent (after receiving a reply).
#[serde(with = "humantime_serde")]
pub delay_between_packets: Duration,
/// Specifies number of nodes being tested at once.
pub tested_nodes_batch_size: usize,
/// Specifies delay between subsequent test runs.
#[serde(with = "humantime_serde")]
pub testing_interval: Duration,
/// Specifies delay between attempting to run the measurement again if the previous run failed
/// due to being unable to get the list of nodes.
#[serde(with = "humantime_serde")]
pub retry_timeout: Duration,
}
impl VerlocDebug {
const DEFAULT_PACKETS_PER_NODE: usize = 100;
const DEFAULT_CONNECTION_TIMEOUT: Duration = Duration::from_millis(5000);
const DEFAULT_PACKET_TIMEOUT: Duration = Duration::from_millis(1500);
const DEFAULT_DELAY_BETWEEN_PACKETS: Duration = Duration::from_millis(50);
const DEFAULT_BATCH_SIZE: usize = 50;
const DEFAULT_TESTING_INTERVAL: Duration = Duration::from_secs(60 * 60 * 12);
const DEFAULT_RETRY_TIMEOUT: Duration = Duration::from_secs(60 * 30);
}
impl Default for VerlocDebug {
fn default() -> Self {
VerlocDebug {
packets_per_node: VerlocDebug::DEFAULT_PACKETS_PER_NODE,
connection_timeout: VerlocDebug::DEFAULT_CONNECTION_TIMEOUT,
packet_timeout: VerlocDebug::DEFAULT_PACKET_TIMEOUT,
delay_between_packets: VerlocDebug::DEFAULT_DELAY_BETWEEN_PACKETS,
tested_nodes_batch_size: VerlocDebug::DEFAULT_BATCH_SIZE,
testing_interval: VerlocDebug::DEFAULT_TESTING_INTERVAL,
retry_timeout: VerlocDebug::DEFAULT_RETRY_TIMEOUT,
}
}
}
impl From<VerlocDebug> for nym_mixnode::config::Verloc {
fn from(value: VerlocDebug) -> Self {
nym_mixnode::config::Verloc {
packets_per_node: value.packets_per_node,
connection_timeout: value.connection_timeout,
packet_timeout: value.packet_timeout,
delay_between_packets: value.delay_between_packets,
tested_nodes_batch_size: value.tested_nodes_batch_size,
testing_interval: value.testing_interval,
retry_timeout: value.retry_timeout,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Debug {
/// Delay between each subsequent node statistics being logged to the console
#[serde(with = "humantime_serde")]
pub node_stats_logging_delay: Duration,
/// Delay between each subsequent node statistics being updated
#[serde(with = "humantime_serde")]
pub node_stats_updating_delay: Duration,
}
impl Debug {
const DEFAULT_NODE_STATS_LOGGING_DELAY: Duration = Duration::from_millis(60_000);
const DEFAULT_NODE_STATS_UPDATING_DELAY: Duration = Duration::from_millis(30_000);
}
impl Default for Debug {
fn default() -> Self {
Debug {
node_stats_logging_delay: Debug::DEFAULT_NODE_STATS_LOGGING_DELAY,
node_stats_updating_delay: Debug::DEFAULT_NODE_STATS_UPDATING_DELAY,
}
}
}
// a temporary solution until all nodes are even more tightly integrated
pub fn ephemeral_mixnode_config(
config: Config,
) -> Result<nym_mixnode::config::Config, MixnodeError> {
let host = nym_mixnode::config::Host {
public_ips: config.host.public_ips,
hostname: config.host.hostname,
};
let http = nym_mixnode::config::Http {
bind_address: config.http.bind_address,
landing_page_assets_path: config.http.landing_page_assets_path,
metrics_key: config.http.access_token,
};
let verloc_bind_ip = config.mixnode.verloc.bind_address.ip();
let mix_bind_ip = config.mixnet.bind_address.ip();
if verloc_bind_ip != mix_bind_ip {
return Err(MixnodeError::UnsupportedAddresses {
verloc_bind_ip,
mix_bind_ip,
});
}
let listening_address = mix_bind_ip;
let mix_port = config.mixnet.bind_address.port();
let verloc_port = config.mixnode.verloc.bind_address.port();
let nym_api_urls = config.mixnet.nym_api_urls;
let mixnode = nym_mixnode::config::MixNode {
// that field is very much irrelevant, but I guess let's keep them for now
version: format!("{}-nym-node", crate_version!()),
id: config.id,
listening_address,
mix_port,
verloc_port,
nym_api_urls,
};
Ok(nym_mixnode::config::Config::externally_loaded(
host,
http,
mixnode,
nym_mixnode::config::MixNodePaths::new_empty(),
config.mixnode.verloc.debug,
config.logging,
nym_mixnode::config::Debug {
node_stats_logging_delay: config.mixnode.debug.node_stats_logging_delay,
node_stats_updating_delay: config.mixnode.debug.node_stats_updating_delay,
packet_forwarding_initial_backoff: config
.mixnet
.debug
.packet_forwarding_initial_backoff,
packet_forwarding_maximum_backoff: config
.mixnet
.debug
.packet_forwarding_maximum_backoff,
initial_connection_timeout: config.mixnet.debug.initial_connection_timeout,
maximum_connection_buffer_size: config.mixnet.debug.maximum_connection_buffer_size,
use_legacy_framed_packet_version: false,
},
))
}