From fa551b6d9d090e18d6cc52fc0ea2583da3fd4926 Mon Sep 17 00:00:00 2001 From: Fouad Date: Tue, 5 Nov 2024 13:01:22 +0000 Subject: [PATCH 1/4] Nym node - Fix claim delegator rewards (#5090) * update function param from mixId to nodeId * fix claim operator rewards --- explorer/src/utils/index.ts | 1 - .../components/Bonding/modals/RedeemRewardsModal.tsx | 12 +++--------- nym-wallet/src/pages/bonding/Bonding.tsx | 2 +- nym-wallet/src/requests/actions.ts | 2 +- nym-wallet/src/requests/rewards.ts | 2 +- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/explorer/src/utils/index.ts b/explorer/src/utils/index.ts index 5375377b5a..91b082c5ca 100644 --- a/explorer/src/utils/index.ts +++ b/explorer/src/utils/index.ts @@ -102,7 +102,6 @@ export const isLessThan = (a: number, b: number) => a < b; */ export const isBalanceEnough = (fee: string, tx: string = '0', balance: string = '0') => { - console.log('balance', balance, fee, tx); try { return Big(balance).gte(Big(fee).plus(Big(tx))); } catch (e) { diff --git a/nym-wallet/src/components/Bonding/modals/RedeemRewardsModal.tsx b/nym-wallet/src/components/Bonding/modals/RedeemRewardsModal.tsx index 8e00ddbfa5..0243e765f3 100644 --- a/nym-wallet/src/components/Bonding/modals/RedeemRewardsModal.tsx +++ b/nym-wallet/src/components/Bonding/modals/RedeemRewardsModal.tsx @@ -4,11 +4,10 @@ import { ModalListItem } from 'src/components/Modals/ModalListItem'; import { SimpleModal } from 'src/components/Modals/SimpleModal'; import { ModalFee } from 'src/components/Modals/ModalFee'; import { useGetFee } from 'src/hooks/useGetFee'; -import { simulateClaimOperatorReward, simulateVestingClaimOperatorReward } from 'src/requests'; import { AppContext } from 'src/context'; import { BalanceWarning } from 'src/components/FeeWarning'; import { Box } from '@mui/material'; -import { TBondedMixnode } from 'src/requests/mixnodeDetails'; +import { TBondedNymNode } from 'src/requests/nymNodeDetails'; export const RedeemRewardsModal = ({ node, @@ -16,23 +15,18 @@ export const RedeemRewardsModal = ({ onError, onClose, }: { - node: TBondedMixnode; + node: TBondedNymNode; onConfirm: (fee?: FeeDetails) => Promise; onError: (err: string) => void; onClose: () => void; }) => { - const { fee, getFee, isFeeLoading, feeError } = useGetFee(); + const { fee, isFeeLoading, feeError } = useGetFee(); const { userBalance } = useContext(AppContext); useEffect(() => { if (feeError) onError(feeError); }, [feeError]); - useEffect(() => { - if (node.proxy) getFee(simulateVestingClaimOperatorReward, {}); - else getFee(simulateClaimOperatorReward, {}); - }, []); - const handleOnOK = async () => onConfirm(fee); return ( diff --git a/nym-wallet/src/pages/bonding/Bonding.tsx b/nym-wallet/src/pages/bonding/Bonding.tsx index b66ffbe58e..d618775e05 100644 --- a/nym-wallet/src/pages/bonding/Bonding.tsx +++ b/nym-wallet/src/pages/bonding/Bonding.tsx @@ -292,7 +292,7 @@ export const Bonding = () => { /> )} - {showModal === 'redeem' && bondedNode && isMixnode(bondedNode) && ( + {showModal === 'redeem' && bondedNode && isNymNode(bondedNode) && ( setShowModal(undefined)} diff --git a/nym-wallet/src/requests/actions.ts b/nym-wallet/src/requests/actions.ts index 6907cf054a..835fcb465b 100644 --- a/nym-wallet/src/requests/actions.ts +++ b/nym-wallet/src/requests/actions.ts @@ -7,7 +7,7 @@ import { NodeConfigUpdate, GatewayConfigUpdate, } from '@nymproject/types'; -import { TBondGatewayArgs, TBondGatewaySignatureArgs, TNodeConfigUpdateArgs } from '../types'; +import { TBondGatewayArgs, TBondGatewaySignatureArgs } from '../types'; import { invokeWrapper } from './wrapper'; export const bondGateway = async (args: TBondGatewayArgs) => diff --git a/nym-wallet/src/requests/rewards.ts b/nym-wallet/src/requests/rewards.ts index 36b90838e7..ed5dcb797a 100644 --- a/nym-wallet/src/requests/rewards.ts +++ b/nym-wallet/src/requests/rewards.ts @@ -6,7 +6,7 @@ export const claimOperatorReward = async (fee?: Fee) => export const claimDelegatorRewards = async (mixId: number, fee?: FeeDetails) => invokeWrapper('claim_locked_and_unlocked_delegator_reward', { - mixId, + nodeId: mixId, fee: fee?.fee, }); From 15ca24b848f1e0714e5e347c518496fd4ba55039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan-=C8=98tefan=20Neac=C5=9Fu?= Date: Tue, 5 Nov 2024 15:30:00 +0200 Subject: [PATCH 2/4] Add more translations from v2 to v3 authenticator (#5091) --- .../src/v3/conversion.rs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/common/authenticator-requests/src/v3/conversion.rs b/common/authenticator-requests/src/v3/conversion.rs index 15659271b2..2ceaeb0301 100644 --- a/common/authenticator-requests/src/v3/conversion.rs +++ b/common/authenticator-requests/src/v3/conversion.rs @@ -98,6 +98,16 @@ impl TryFrom for v2::response::Authenticato } } +impl From for v3::response::AuthenticatorResponse { + fn from(value: v2::response::AuthenticatorResponse) -> Self { + Self { + protocol: value.protocol, + data: value.data.into(), + reply_to: value.reply_to, + } + } +} + impl TryFrom for v2::response::AuthenticatorResponseData { type Error = crate::Error; @@ -129,6 +139,22 @@ impl TryFrom for v2::response::Authenti } } +impl From for v3::response::AuthenticatorResponseData { + fn from(value: v2::response::AuthenticatorResponseData) -> Self { + match value { + v2::response::AuthenticatorResponseData::PendingRegistration( + pending_registration_response, + ) => Self::PendingRegistration(pending_registration_response.into()), + v2::response::AuthenticatorResponseData::Registered(registered_response) => { + Self::Registered(registered_response.into()) + } + v2::response::AuthenticatorResponseData::RemainingBandwidth( + remaining_bandwidth_response, + ) => Self::RemainingBandwidth(remaining_bandwidth_response.into()), + } + } +} + impl From for v2::response::PendingRegistrationResponse { fn from(value: v3::response::PendingRegistrationResponse) -> Self { Self { @@ -139,6 +165,16 @@ impl From for v2::response::PendingRe } } +impl From for v3::response::PendingRegistrationResponse { + fn from(value: v2::response::PendingRegistrationResponse) -> Self { + Self { + request_id: value.request_id, + reply_to: value.reply_to, + reply: value.reply.into(), + } + } +} + impl From for v2::response::RegisteredResponse { fn from(value: v3::response::RegisteredResponse) -> Self { Self { @@ -149,6 +185,16 @@ impl From for v2::response::RegisteredResponse } } +impl From for v3::response::RegisteredResponse { + fn from(value: v2::response::RegisteredResponse) -> Self { + Self { + request_id: value.request_id, + reply_to: value.reply_to, + reply: value.reply.into(), + } + } +} + impl From for v2::response::RemainingBandwidthResponse { fn from(value: v3::response::RemainingBandwidthResponse) -> Self { Self { @@ -159,6 +205,16 @@ impl From for v2::response::RemainingB } } +impl From for v3::response::RemainingBandwidthResponse { + fn from(value: v2::response::RemainingBandwidthResponse) -> Self { + Self { + request_id: value.request_id, + reply_to: value.reply_to, + reply: value.reply.map(Into::into), + } + } +} + impl From for v2::registration::RegistrationData { fn from(value: v3::registration::RegistrationData) -> Self { Self { @@ -169,6 +225,16 @@ impl From for v2::registration::Registration } } +impl From for v3::registration::RegistrationData { + fn from(value: v2::registration::RegistrationData) -> Self { + Self { + nonce: value.nonce, + gateway_data: value.gateway_data.into(), + wg_port: value.wg_port, + } + } +} + impl From for v2::registration::RegistredData { fn from(value: v3::registration::RegistredData) -> Self { Self { @@ -179,6 +245,16 @@ impl From for v2::registration::RegistredData { } } +impl From for v3::registration::RegistredData { + fn from(value: v2::registration::RegistredData) -> Self { + Self { + pub_key: value.pub_key, + private_ip: value.private_ip, + wg_port: value.wg_port, + } + } +} + impl From for v2::registration::RemainingBandwidthData { fn from(value: v3::registration::RemainingBandwidthData) -> Self { Self { @@ -186,3 +262,11 @@ impl From for v2::registration::Remain } } } + +impl From for v3::registration::RemainingBandwidthData { + fn from(value: v2::registration::RemainingBandwidthData) -> Self { + Self { + available_bandwidth: value.available_bandwidth, + } + } +} From 69e97b3bbc4e9ef2cf58586d4deddb91a7ddbb7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogdan-=C8=98tefan=20Neac=C5=9Fu?= Date: Tue, 5 Nov 2024 16:16:59 +0200 Subject: [PATCH 3/4] Remove old use of 1GB constant (#5096) * Remove old use of 1GB constant * Fix clippy --- common/wireguard/src/peer_controller.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/wireguard/src/peer_controller.rs b/common/wireguard/src/peer_controller.rs index 0c77bcf010..bc143745c4 100644 --- a/common/wireguard/src/peer_controller.rs +++ b/common/wireguard/src/peer_controller.rs @@ -7,8 +7,8 @@ use defguard_wireguard_rs::{ WireguardInterfaceApi, }; use futures::channel::oneshot; -use nym_authenticator_requests::{ - latest::registration::RemainingBandwidthData, v1::registration::BANDWIDTH_CAP_PER_DAY, +use nym_authenticator_requests::latest::registration::{ + RemainingBandwidthData, BANDWIDTH_CAP_PER_DAY, }; use nym_credential_verification::{ bandwidth_storage_manager::BandwidthStorageManager, BandwidthFlushingBehaviourConfig, @@ -230,7 +230,7 @@ impl PeerController { // host information not updated yet return Ok(None); }; - BANDWIDTH_CAP_PER_DAY.saturating_sub((peer.rx_bytes + peer.tx_bytes) as i64) + BANDWIDTH_CAP_PER_DAY.saturating_sub(peer.rx_bytes + peer.tx_bytes) as i64 }; Ok(Some(RemainingBandwidthData { From d03c5b365013ae595e6fed8d407c6440eac0110a Mon Sep 17 00:00:00 2001 From: Dinko Zdravac <173912580+dynco-nym@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:36:16 +0100 Subject: [PATCH 4/4] Graceful agent 1.1.5 (#5093) * Bump NS agent to 0.1.5 * API improvements - agent exits gracefully when no testrun available - API doesn't log every error * Bump NSAPI to 0.1.6 --- Cargo.lock | 4 +-- nym-node-status-agent/Cargo.toml | 2 +- nym-node-status-agent/src/cli.rs | 37 +++++++++++++------- nym-node-status-api/Cargo.toml | 2 +- nym-node-status-api/src/http/api/mod.rs | 10 ++---- nym-node-status-api/src/http/api/testruns.rs | 3 +- nym-node-status-api/src/http/error.rs | 4 +-- 7 files changed, 35 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65bf102040..fc972ebc8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5980,7 +5980,7 @@ dependencies = [ [[package]] name = "nym-node-status-agent" -version = "0.1.4" +version = "0.1.5" dependencies = [ "anyhow", "clap 4.5.18", @@ -5996,7 +5996,7 @@ dependencies = [ [[package]] name = "nym-node-status-api" -version = "0.1.5" +version = "0.1.6" dependencies = [ "anyhow", "axum 0.7.7", diff --git a/nym-node-status-agent/Cargo.toml b/nym-node-status-agent/Cargo.toml index f89065b5b3..45363a8cb6 100644 --- a/nym-node-status-agent/Cargo.toml +++ b/nym-node-status-agent/Cargo.toml @@ -4,7 +4,7 @@ [package] name = "nym-node-status-agent" -version = "0.1.4" +version = "0.1.5" authors.workspace = true repository.workspace = true homepage.workspace = true diff --git a/nym-node-status-agent/src/cli.rs b/nym-node-status-agent/src/cli.rs index 81e70e2da9..a7bbef5ebe 100644 --- a/nym-node-status-agent/src/cli.rs +++ b/nym-node-status-agent/src/cli.rs @@ -1,3 +1,4 @@ +use anyhow::bail; use clap::{Parser, Subcommand}; use nym_bin_common::bin_info; use nym_common_models::ns_api::TestrunAssignment; @@ -51,11 +52,13 @@ impl Args { let version = probe.version().await; tracing::info!("Probe version:\n{}", version); - let testrun = request_testrun(&server_address).await?; + if let Some(testrun) = request_testrun(&server_address).await? { + let log = probe.run_and_get_log(&Some(testrun.gateway_identity_key)); - let log = probe.run_and_get_log(&Some(testrun.gateway_identity_key)); - - submit_results(&server_address, testrun.testrun_id, log).await?; + submit_results(&server_address, testrun.testrun_id, log).await?; + } else { + tracing::info!("No testruns available, exiting") + } Ok(()) } @@ -64,16 +67,26 @@ impl Args { const URL_BASE: &str = "internal/testruns"; #[instrument(level = "debug", skip_all)] -async fn request_testrun(server_addr: &str) -> anyhow::Result { +async fn request_testrun(server_addr: &str) -> anyhow::Result> { let target_url = format!("{}/{}", server_addr, URL_BASE); let client = reqwest::Client::new(); - let res = client - .get(target_url) - .send() - .await - .and_then(|response| response.error_for_status())?; - res.json() - .await + let res = client.get(target_url).send().await?; + let status = res.status(); + let response_text = res.text().await?; + + if status.is_client_error() { + bail!("{}: {}", status, response_text); + } else if status.is_server_error() { + if matches!(status, reqwest::StatusCode::SERVICE_UNAVAILABLE) + && response_text.contains("No testruns available") + { + return Ok(None); + } else { + bail!("{}: {}", status, response_text); + } + } + + serde_json::from_str(&response_text) .map(|testrun| { tracing::info!("Received testrun assignment: {:?}", testrun); testrun diff --git a/nym-node-status-api/Cargo.toml b/nym-node-status-api/Cargo.toml index 0969d31045..511ab91b59 100644 --- a/nym-node-status-api/Cargo.toml +++ b/nym-node-status-api/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-node-status-api" -version = "0.1.5" +version = "0.1.6" authors.workspace = true repository.workspace = true homepage.workspace = true diff --git a/nym-node-status-api/src/http/api/mod.rs b/nym-node-status-api/src/http/api/mod.rs index 4e4693ac1f..ed24fa80f5 100644 --- a/nym-node-status-api/src/http/api/mod.rs +++ b/nym-node-status-api/src/http/api/mod.rs @@ -1,10 +1,7 @@ use anyhow::anyhow; use axum::{response::Redirect, Router}; use tokio::net::ToSocketAddrs; -use tower_http::{ - cors::CorsLayer, - trace::{DefaultOnResponse, TraceLayer}, -}; +use tower_http::{cors::CorsLayer, trace::TraceLayer}; use utoipa::OpenApi; use utoipa_swagger_ui::SwaggerUi; @@ -61,10 +58,7 @@ impl RouterBuilder { // CORS layer needs to wrap other API layers .layer(setup_cors()) // logger should be outermost layer - .layer( - TraceLayer::new_for_http() - .on_response(DefaultOnResponse::new().level(tracing::Level::DEBUG)), - ) + .layer(TraceLayer::new_for_http()) } } diff --git a/nym-node-status-api/src/http/api/testruns.rs b/nym-node-status-api/src/http/api/testruns.rs index e55e462110..b13d62ba88 100644 --- a/nym-node-status-api/src/http/api/testruns.rs +++ b/nym-node-status-api/src/http/api/testruns.rs @@ -49,7 +49,8 @@ async fn request_testrun(State(state): State) -> HttpResult Err(HttpError::internal_with_logging(err)), diff --git a/nym-node-status-api/src/http/error.rs b/nym-node-status-api/src/http/error.rs index 808ace9cec..a7fe9d98ab 100644 --- a/nym-node-status-api/src/http/error.rs +++ b/nym-node-status-api/src/http/error.rs @@ -27,9 +27,9 @@ impl HttpError { } } - pub(crate) fn no_available_testruns() -> Self { + pub(crate) fn no_testruns_available() -> Self { Self { - message: serde_json::json!({"message": "No available testruns"}).to_string(), + message: serde_json::json!({"message": "No testruns available"}).to_string(), status: axum::http::StatusCode::SERVICE_UNAVAILABLE, } }