diff --git a/cardano-rosetta-server/package.json b/cardano-rosetta-server/package.json index d5b02300..06434b0b 100644 --- a/cardano-rosetta-server/package.json +++ b/cardano-rosetta-server/package.json @@ -89,6 +89,7 @@ "http-status-codes": "1.4.0", "moment": "2.29.2", "pg": "8.3.0", + "systeminformation": "5.11.2", "temp-write": "4.0.0" }, "resolutions": { diff --git a/cardano-rosetta-server/packages-cache/systeminformation-5.11.2.tgz b/cardano-rosetta-server/packages-cache/systeminformation-5.11.2.tgz new file mode 100644 index 00000000..68b060b2 Binary files /dev/null and b/cardano-rosetta-server/packages-cache/systeminformation-5.11.2.tgz differ diff --git a/cardano-rosetta-server/src/server/services/network-service.ts b/cardano-rosetta-server/src/server/services/network-service.ts index 42ec562a..b4e8794a 100644 --- a/cardano-rosetta-server/src/server/services/network-service.ts +++ b/cardano-rosetta-server/src/server/services/network-service.ts @@ -4,6 +4,8 @@ import { MAIN_TESTNET_NETWORK_MAGIC } from '../utils/constants'; import { BlockService } from './block-service'; import fs from 'fs'; import path from 'path'; +import systemInformation from 'systeminformation'; + const filePath = process.env.EXEMPTION_TYPES_PATH; let exemptionsFile: Components.Schemas.BalanceExemption[] = []; @@ -20,10 +22,10 @@ export interface NetworkService { } interface Producer { - addr: string; + port: number; } interface AccessPoint { - address: string; + port: number; } interface PublicRoot { publicRoots: { @@ -40,13 +42,20 @@ export interface Peer { } const getPublicRoots = (publicRoots?: PublicRoot[]) => - publicRoots?.map(pr => pr.publicRoots.accessPoints.map(ap => ({ addr: ap.address }))).flat() || []; + publicRoots?.map(pr => pr.publicRoots.accessPoints.map(ap => ({ port: ap.port }))).flat() || []; -const getPeersFromConfig = (logger: Logger, topologyFile: TopologyConfig): Peer[] => { +const getPeersFromConfig = async (logger: Logger, topologyFile: TopologyConfig): Promise => { logger.info('[getPeersFromConfig] Looking for peers from topologyFile'); - const Producers = topologyFile?.Producers || getPublicRoots(topologyFile.PublicRoots); - logger.debug(`[getPeersFromConfig] Found ${Producers.length} peers`); - return Producers as Peer[]; + const producersPort = (topologyFile?.Producers || getPublicRoots(topologyFile.PublicRoots)) + .filter(i => i !== undefined) + .map(p => p!.port.toString()); + + const peers = (await systemInformation.networkConnections()) + .filter(item => producersPort.includes(item.peerPort)) + .map(i => ({ addr: i.peerAddress })); + + logger.debug(`[getPeersFromConfig] Found ${peers.length} peers`); + return peers; }; const getExemptionFile = (logger: Logger): Components.Schemas.BalanceExemption[] => { @@ -81,11 +90,10 @@ const configure = ( logger.info('[networkStatus] Looking for genesis block'); const genesisBlock = await blockchainService.getGenesisBlock(logger); logger.debug({ genesisBlock }, '[networkStatus] Genesis block found'); - return { latestBlock, genesisBlock, - peers: getPeersFromConfig(logger, topologyFile) + peers: await getPeersFromConfig(logger, topologyFile) }; }, getExemptionTypes(logger: Logger) { diff --git a/cardano-rosetta-server/test/e2e/network/netowork-status-api.test.ts b/cardano-rosetta-server/test/e2e/network/netowork-status-api.test.ts index a2a248f8..7eab771d 100644 --- a/cardano-rosetta-server/test/e2e/network/netowork-status-api.test.ts +++ b/cardano-rosetta-server/test/e2e/network/netowork-status-api.test.ts @@ -8,7 +8,6 @@ import { generateNetworkPayload } from './common'; import { latestBlockIdentifier } from '../fixture-data'; const NETWORK_STATUS_ENDPOINT = '/network/status'; -const peers = [{ peer_id: 'relays-new.cardano-mainnet.iohk.io' }]; const genesis_block_identifier = { hash: '5f20df933584822601f9e3f8c024eb5eb252fe8cefb24d1317dc3d432e940ebb', index: 0 // FIXME this is not ok @@ -36,7 +35,7 @@ describe('/network/status endpoint', () => { expect(response.statusCode).toEqual(StatusCodes.OK); expect(response.json().genesis_block_identifier).toEqual(genesis_block_identifier); expect(response.json().current_block_identifier).toEqual(latestBlockIdentifier); - expect(response.json().peers).toEqual(peers); + expect(response.json().peers).toEqual([]); }); testInvalidNetworkParameters( diff --git a/cardano-rosetta-server/yarn.lock b/cardano-rosetta-server/yarn.lock index ad2d3280..5da65d49 100644 --- a/cardano-rosetta-server/yarn.lock +++ b/cardano-rosetta-server/yarn.lock @@ -7463,6 +7463,11 @@ symbol-tree@^3.2.4: resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2" integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw== +systeminformation@5.11.2: + version "5.11.2" + resolved "https://registry.yarnpkg.com/systeminformation/-/systeminformation-5.11.2.tgz#291280715c91f06d84f8748e78dab97df2f7ac1f" + integrity sha512-/6+p1ze2curwSMZQgQ9Gv4eLgtAaX9ROBEVELddkYy7llpP0SQjpSx4qDFEBscxqm/6yu+Khwi0Pneoy/wTwVg== + table@^5.2.3: version "5.4.6" resolved "https://registry.yarnpkg.com/table/-/table-5.4.6.tgz#1292d19500ce3f86053b05f0e8e7e4a3bb21079e"