51b511b27e
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
130 lines
3.5 KiB
Rust
130 lines
3.5 KiB
Rust
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
use crate::error::NetworkTestingError;
|
|
use crate::node::TestableNode;
|
|
use crate::NodeId;
|
|
use nym_sphinx::message::NymMessage;
|
|
use nym_topology::{gateway, mix};
|
|
use serde::de::DeserializeOwned;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy)]
|
|
pub struct Empty;
|
|
|
|
#[derive(Serialize, Deserialize, Clone)]
|
|
pub struct TestMessage<T = Empty> {
|
|
pub tested_node: TestableNode,
|
|
|
|
pub msg_id: u32,
|
|
pub total_msgs: u32,
|
|
|
|
// any additional fields that might be required by a specific tester.
|
|
// For example nym-api might want to attach route ids
|
|
#[serde(flatten)]
|
|
pub ext: T,
|
|
}
|
|
|
|
impl<T> TestMessage<T> {
|
|
pub fn new<N: Into<TestableNode>>(node: N, msg_id: u32, total_msgs: u32, ext: T) -> Self {
|
|
TestMessage {
|
|
tested_node: node.into(),
|
|
msg_id,
|
|
total_msgs,
|
|
ext,
|
|
}
|
|
}
|
|
|
|
pub fn new_mix(node: &mix::LegacyNode, msg_id: u32, total_msgs: u32, ext: T) -> Self {
|
|
Self::new(node, msg_id, total_msgs, ext)
|
|
}
|
|
|
|
// pub fn new_gateway(node: &gateway::Node, msg_id: u32, total_msgs: u32, ext: T) -> Self {
|
|
// Self::new(node, msg_id, total_msgs, ext)
|
|
// }
|
|
|
|
pub fn new_serialized<N>(
|
|
node: N,
|
|
msg_id: u32,
|
|
total_msgs: u32,
|
|
ext: T,
|
|
) -> Result<Vec<u8>, NetworkTestingError>
|
|
where
|
|
N: Into<TestableNode>,
|
|
T: Serialize,
|
|
{
|
|
Self::new(node, msg_id, total_msgs, ext).as_bytes()
|
|
}
|
|
|
|
pub fn new_plaintexts<N>(
|
|
node: &N,
|
|
total_msgs: u32,
|
|
ext: T,
|
|
) -> Result<Vec<Vec<u8>>, NetworkTestingError>
|
|
where
|
|
for<'a> &'a N: Into<TestableNode>,
|
|
T: Serialize + Clone,
|
|
{
|
|
let mut msgs = Vec::with_capacity(total_msgs as usize);
|
|
for msg_id in 1..=total_msgs {
|
|
msgs.push(Self::new(node, msg_id, total_msgs, ext.clone()).as_bytes()?)
|
|
}
|
|
Ok(msgs)
|
|
}
|
|
|
|
pub fn mix_plaintexts(
|
|
node: &mix::LegacyNode,
|
|
total_msgs: u32,
|
|
ext: T,
|
|
) -> Result<Vec<Vec<u8>>, NetworkTestingError>
|
|
where
|
|
T: Serialize + Clone,
|
|
{
|
|
Self::new_plaintexts(node, total_msgs, ext)
|
|
}
|
|
|
|
pub fn legacy_gateway_plaintexts(
|
|
node: &gateway::LegacyNode,
|
|
node_id: NodeId,
|
|
total_msgs: u32,
|
|
ext: T,
|
|
) -> Result<Vec<Vec<u8>>, NetworkTestingError>
|
|
where
|
|
T: Serialize + Clone,
|
|
{
|
|
Self::new_plaintexts(&(node, node_id), total_msgs, ext)
|
|
}
|
|
|
|
pub fn as_json_string(&self) -> Result<String, NetworkTestingError>
|
|
where
|
|
T: Serialize,
|
|
{
|
|
serde_json::to_string(self).map_err(Into::into)
|
|
}
|
|
|
|
pub fn as_bytes(&self) -> Result<Vec<u8>, NetworkTestingError>
|
|
where
|
|
T: Serialize,
|
|
{
|
|
// the test messages are supposed to be rather small so we can use the good old serde_json
|
|
// (the performance penalty over bincode or custom serialization should be minimal)
|
|
serde_json::to_vec(self).map_err(Into::into)
|
|
}
|
|
|
|
pub fn try_recover(msg: NymMessage) -> Result<Self, NetworkTestingError>
|
|
where
|
|
T: DeserializeOwned,
|
|
{
|
|
let inner = msg.into_inner_data();
|
|
Self::try_recover_from_bytes(&inner)
|
|
}
|
|
|
|
pub fn try_recover_from_bytes(raw: &[u8]) -> Result<Self, NetworkTestingError>
|
|
where
|
|
T: DeserializeOwned,
|
|
{
|
|
serde_json::from_slice(raw)
|
|
.map_err(|source| NetworkTestingError::MalformedTestMessageReceived { source })
|
|
}
|
|
}
|