Skip to content

Dynamic node list - #474

Open
curupo wants to merge 3 commits into
NemProject:devfrom
curupo:feat/dynamic-node-list
Open

Dynamic node list#474
curupo wants to merge 3 commits into
NemProject:devfrom
curupo:feat/dynamic-node-list

Conversation

@curupo

@curupo curupo commented Jul 29, 2026

Copy link
Copy Markdown

No description provided.

@AnthonyLaw

AnthonyLaw commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Thanks for the update 🙏🏼 .
Fetching the node list from NodeWatch and caching the result looks good.

To make the implementation easier for the team to maintain in the future, I suggest moving this logic into the existing services:

  • Implement a loadNetworkNodes(network) method in nodes.service.js. This service should remain the single place responsible for loading, validating, caching, and providing node lists.

  • Call and await loadNetworkNodes(Wallet.network) inside the connect() method in dataBridge.service.js, since this is where the wallet begins selecting a node and establishing its connection.

  • If the NodeWatch request fails or times out, use the cached node list and then fall back to the bundled static nodes.

Keeping the logic inside the existing service structure should make the behavior clearer and easier to test and maintain. This is the suggested direction rather than a required implementation. Please feel free to propose another approach that keeps node-loading responsibility within nodes.service.js.

Comment thread nanowallet/src/vendors/dynamic-nodes.js Outdated
}
}

function loadNetworkNodes(key, url) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this logic into nodes.service.js.

Comment thread nanowallet/src/vendors/dynamic-nodes.js Outdated
}

Promise.all([
loadNetworkNodes('mainnet', NODEWATCH_URLS.mainnet).then(function (n) { freshByNetwork.mainnet = n; }),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method can be used in the connect() method in dataBridge.service.js, since this is where the wallet begins selecting a node and establishing its connection.

Comment thread nanowallet/src/start.html Outdated
Comment on lines +29 to +31
<!-- Dynamic node list (nodewatch.symbol.tools; falls back to bundled defaults on any failure) -->
<script src="vendors/dynamic-nodes.js"></script>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once it moves into existing services, we no longer need it here.

curupo pushed a commit to curupo/miscellaneous that referenced this pull request Jul 30, 2026
curupo pushed a commit to curupo/miscellaneous that referenced this pull request Jul 30, 2026
@curupo
curupo force-pushed the feat/dynamic-node-list branch from e409edf to 5a2776e Compare July 30, 2026 01:37
@curupo

curupo commented Jul 30, 2026

Copy link
Copy Markdown
Author

Thanks for the review.
I've addressed the points you raised.
What do you think?

import nem from 'nem-sdk';
import UrlParser from 'url-parse';

var NODEWATCH_URLS = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since both the URL and cache key are network-specific, could we centralize them in a network configuration map? For example:

const NODEWATCH_BASE_URL = 'https://nodewatch.symbol.tools';

const NETWORK_NODE_CONFIG = {
    [nem.model.network.data.mainnet.id]: {
        url: `${NODEWATCH_BASE_URL}/api/nem/nodes`,
        cacheKey: 'nodeWatchNodes_mainnet'
    },
    [nem.model.network.data.testnet.id]: {
        url: `${NODEWATCH_BASE_URL}/testnet/api/nem/nodes`,
        cacheKey: 'nodeWatchNodes_testnet'
    }
};

This keeps the related configuration together and removes the need to derive the network name and cache key separately.

What do you think?

mainnet: 'https://nodewatch.symbol.tools/api/nem/nodes',
testnet: 'https://nodewatch.symbol.tools/testnet/api/nem/nodes'
};
var DYNAMIC_NODES_DEFAULT_PORT = 7890;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of defining another default-port constant, could we reuse the value already provided by nem-sdk?

nem.model.nodes.defaultPort contains the same port (7890) and is already used elsewhere in the wallet, so reusing it would avoid duplicating this value.

Comment on lines +9 to +13
var DYNAMIC_NODES_HEIGHT_TOLERANCE = 20;
var DYNAMIC_NODES_MIN_NODES = 3;
var DYNAMIC_NODES_FETCH_TIMEOUT_MS = 8000;
var DYNAMIC_NODES_CACHE_TTL_MS = 6 * 60 * 60 * 1000;
var DYNAMIC_NODES_PRIVATE_HOST_RE = /^(127\.|10\.|172\.(1[6-9]|2\d|3[01])\.|192\.168\.|169\.254\.|0\.0\.0\.0$)|^localhost$|^\[?::1\]?$/i;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we replace the generic DYNAMIC_NODES_* prefix with NODEWATCH_NODES_* or simply NODEWATCH_*? This makes it clearer that these constants specifically configure the node list retrieved from NodeWatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants