From b635279cbb95fe05f1bb6a0323b2639640eba5ca Mon Sep 17 00:00:00 2001 From: Evan Kaloudis Date: Mon, 10 Jun 2024 10:02:10 -0400 Subject: [PATCH] Neutrino: increase ping threshold, 200->1000ms --- components/Modals/AlertModal.tsx | 5 +++-- locales/en.json | 2 +- stores/AlertStore.ts | 10 +++++++-- utils/LndMobileUtils.ts | 21 ++++++++++++++----- .../EmbeddedNode/Peers/NeutrinoPeers.tsx | 20 +++++++++++------- 5 files changed, 41 insertions(+), 17 deletions(-) diff --git a/components/Modals/AlertModal.tsx b/components/Modals/AlertModal.tsx index 5e915e8d25..5452a7dd40 100644 --- a/components/Modals/AlertModal.tsx +++ b/components/Modals/AlertModal.tsx @@ -15,6 +15,7 @@ import { restartNeeded } from '../../utils/RestartUtils'; import { themeColor } from '../../utils/ThemeUtils'; import NavigationService from '../../NavigationService'; +import { NEUTRINO_PING_THRESHOLD_MS } from 'utils/LndMobileUtils'; interface AlertModalProps { AlertStore: AlertStore; @@ -153,9 +154,9 @@ export default class AlertModal extends React.Component { color: themeColor('text') }} > - {localeString( + {`${localeString( 'components.AlertModal.neutrinoExplainer' - )} + )} (>${NEUTRINO_PING_THRESHOLD_MS}ms)`} { try { const ms = await Ping.start(peer, { - timeout: 1000 + timeout: NEUTRINO_PING_TIMEOUT_MS }); console.log(`# ${peer} - ${ms}`); results.push({ @@ -87,7 +92,8 @@ export default class AlertStore { localeString( 'views.Settings.EmbeddedNode.NeutrinoPeers.timedOut' ) || - (Number.isInteger(result.ms) && result.ms > 200) + (Number.isInteger(result.ms) && + result.ms > NEUTRINO_PING_THRESHOLD_MS) ); }); diff --git a/utils/LndMobileUtils.ts b/utils/LndMobileUtils.ts index 98bc6068c3..19dfa176f2 100644 --- a/utils/LndMobileUtils.ts +++ b/utils/LndMobileUtils.ts @@ -70,6 +70,9 @@ export function checkLndStreamErrorResponse( return null; } +export const NEUTRINO_PING_TIMEOUT_MS = 1500; +export const NEUTRINO_PING_THRESHOLD_MS = 1000; + const writeLndConfig = async ( isTestnet?: boolean, rescan?: boolean, @@ -287,7 +290,9 @@ export async function startLnd( } export async function chooseNeutrinoPeers(isTestnet?: boolean) { - console.log('Selecting Neutrino peers with ping times <200ms'); + console.log( + `Selecting Neutrino peers with ping times <${NEUTRINO_PING_THRESHOLD_MS}ms` + ); let peers = isTestnet ? DEFAULT_NEUTRINO_PEERS_TESTNET : DEFAULT_NEUTRINO_PEERS_MAINNET; @@ -298,7 +303,7 @@ export async function chooseNeutrinoPeers(isTestnet?: boolean) { await new Promise(async (resolve) => { try { const ms = await Ping.start(peer, { - timeout: 1000 + timeout: NEUTRINO_PING_TIMEOUT_MS }); console.log(`# ${peer} - ${ms}`); results.push({ @@ -318,7 +323,10 @@ export async function chooseNeutrinoPeers(isTestnet?: boolean) { } let filteredResults = results.filter((result: any) => { - return Number.isInteger(result.ms) && result.ms < 200; + return ( + Number.isInteger(result.ms) && + result.ms < NEUTRINO_PING_THRESHOLD_MS + ); }); if (filteredResults.length < 3 && !isTestnet) { @@ -328,7 +336,7 @@ export async function chooseNeutrinoPeers(isTestnet?: boolean) { await new Promise(async (resolve) => { try { const ms = await Ping.start(peer, { - timeout: 1000 + timeout: NEUTRINO_PING_TIMEOUT_MS }); console.log(`# ${peer} - ${ms}`); results.push({ @@ -349,7 +357,10 @@ export async function chooseNeutrinoPeers(isTestnet?: boolean) { } filteredResults = results.filter((result: any) => { - return Number.isInteger(result.ms) && result.ms < 200; + return ( + Number.isInteger(result.ms) && + result.ms < NEUTRINO_PING_THRESHOLD_MS + ); }); const selectedPeers: string[] = []; diff --git a/views/Settings/EmbeddedNode/Peers/NeutrinoPeers.tsx b/views/Settings/EmbeddedNode/Peers/NeutrinoPeers.tsx index fbeec6d6fc..f35fb5cb40 100644 --- a/views/Settings/EmbeddedNode/Peers/NeutrinoPeers.tsx +++ b/views/Settings/EmbeddedNode/Peers/NeutrinoPeers.tsx @@ -17,6 +17,7 @@ import { WarningMessage, ErrorMessage } from '../../../../components/SuccessErrorMessage'; +import LoadingIndicator from '../../../../components/LoadingIndicator'; import SettingsStore, { DEFAULT_NEUTRINO_PEERS_MAINNET, @@ -26,7 +27,10 @@ import SettingsStore, { import { localeString } from '../../../../utils/LocaleUtils'; import { restartNeeded } from '../../../../utils/RestartUtils'; import { themeColor } from '../../../../utils/ThemeUtils'; -import LoadingIndicator from '../../../../components/LoadingIndicator'; +import { + NEUTRINO_PING_THRESHOLD_MS, + NEUTRINO_PING_TIMEOUT_MS +} from '../../../../utils/LndMobileUtils'; import Stopwatch from '../../../../assets/images/SVG/Stopwatch.svg'; @@ -128,7 +132,7 @@ export default class NeutrinoPeers extends React.Component< {!pingTimeout && !pinging && pingHost && - pingTime <= 100 && ( + pingTime <= 200 && ( 100 && ( + pingTime < NEUTRINO_PING_THRESHOLD_MS && + pingTime > 200 && ( = 200 && ( + pingTime >= NEUTRINO_PING_THRESHOLD_MS && (