diff --git a/dumper.ts b/dumper.ts index a161796a48b2a3ac98ba90c9a0a94bf17b54a567..f6ac4e97a059600fee629fb54dea9760a069c64c 100644 --- a/dumper.ts +++ b/dumper.ts @@ -1,4 +1,4 @@ -import { createHiveChain, HealthChecker, IHiveEndpoint } from "@hiveio/wax"; +import { createHiveChain, HealthChecker, IHiveEndpoint, TScoredEndpoint } from "@hiveio/wax"; import { defaultCalcScores } from './src/utils/math'; import fs from 'node:fs'; import endpoints from './src/data/hive-endpoints'; @@ -6,40 +6,53 @@ import endpoints from './src/data/hive-endpoints'; const outputFile = "dump.csv"; const showErrors = false; -const GATHER_STATS_FROM_PREVIOUS_CALLS_AMOUNT=10; +let dataCollectionSize: number = 0; const gatheredData: Map = new Map(); -if (!fs.existsSync(outputFile)) - fs.writeFileSync(outputFile, "endpoint,apicall,latency0,latency1,latency2,latency3,latency4,latency5,latency6,latency7,latency8,latency9\n"); +let writtenHeader = false; const hc = new HealthChecker(undefined, defaultCalcScores); const chain = await createHiveChain(); -const processEndpointData = (endpoint: IHiveEndpoint): void => { - const collectedUrlData = endpoint.list(); - for(const urlData of collectedUrlData) { - const gatheredLatency = urlData.up ? urlData.latency : -1; +const processEndpointData = (endpoint: TScoredEndpoint): void => { + const gatheredLatency = endpoint.up ? endpoint.latencies.at(-1)! : -1; + const gatheredScore = endpoint.score; - const apiCall = endpoint.paths.join('.'); - const key = apiCall + '@' + urlData.endpointUrl; - let data = gatheredData.get(key); - if(data === undefined) { - data = new Array(GATHER_STATS_FROM_PREVIOUS_CALLS_AMOUNT).fill(0, 0, GATHER_STATS_FROM_PREVIOUS_CALLS_AMOUNT); - gatheredData.set(key, data); - } + const key = endpoint.endpointUrl; + let data = gatheredData.get(key); + if(data === undefined) { + data = new Array(dataCollectionSize).fill(0, 0, dataCollectionSize); + gatheredData.set(key, data); + } - data.shift(); - data.push(gatheredLatency); + data.shift(); + data.push(gatheredLatency); - fs.appendFileSync(outputFile, `${urlData.endpointUrl},${apiCall},${data.join(',')}\n`); - } + fs.appendFileSync(outputFile, `${endpoint.endpointUrl},${data.join(',')},${gatheredScore.toFixed(3)}\n`); } -hc.on("data", () => { - for(const endpoint of hc) - processEndpointData(endpoint); +hc.on("data", (data: Array) => { + if(writtenHeader === false) { + if (!fs.existsSync(outputFile)) + fs.writeFileSync(outputFile, "endpoint"); + + /// small hack, but this dumper is rather for internal use. Also size estimation can be done directly + /// by evaluating size of latencies array (but it grows up to this limit) + dataCollectionSize = (hc as object)['cachedScoredListLimit']; + + console.log(`Data collection size is: ${dataCollectionSize}`); + + for(let i = 0;i= 21.2} - '@hiveio/wax@1.27.6-rc7-250206163256': - resolution: {integrity: sha1-bJzNl3fxfPqfU15A8/Sa2Yp01EY=, tarball: https://gitlab.syncad.com/api/v4/projects/419/packages/npm/@hiveio/wax/-/@hiveio/wax-1.27.6-rc7-250206163256.tgz} + '@hiveio/wax@1.27.6-rc7-250211090741': + resolution: {integrity: sha1-oyOfDdiYO1YjTGt9Jm8qKR6vo2g=, tarball: https://gitlab.syncad.com/api/v4/projects/419/packages/npm/@hiveio/wax/-/@hiveio/wax-1.27.6-rc7-250211090741.tgz} engines: {node: ^20.11 || >= 21.2} '@jridgewell/sourcemap-codec@1.4.15': @@ -681,8 +681,8 @@ packages: resolution: {integrity: sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==} engines: {node: '>=14'} - long@5.2.3: - resolution: {integrity: sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==} + long@5.3.0: + resolution: {integrity: sha512-5vvY5yF1zF/kXk+L94FRiTDa1Znom46UjPCH6/XbSvS8zBKMFBHTJk8KDMqJ+2J6QezQFi7k1k8v21ClJYHPaw==} magic-string@0.30.10: resolution: {integrity: sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==} @@ -1075,11 +1075,11 @@ snapshots: '@hiveio/beekeeper@1.27.8-stable.250131103618': {} - '@hiveio/wax@1.27.6-rc7-250206163256': + '@hiveio/wax@1.27.6-rc7-250211090741': dependencies: '@hiveio/beekeeper': 1.27.8-stable.250131103618 events: 3.3.0 - long: 5.2.3 + long: 5.3.0 '@jridgewell/sourcemap-codec@1.4.15': {} @@ -1244,7 +1244,7 @@ snapshots: '@vue/shared@3.4.27': {} - '@vuetify/loader-shared@2.0.3(vue@3.4.27(typescript@5.4.5))(vuetify@3.6.7(typescript@5.4.5)(vite-plugin-vuetify@2.0.3)(vue@3.4.27(typescript@5.4.5)))': + '@vuetify/loader-shared@2.0.3(vue@3.4.27(typescript@5.4.5))(vuetify@3.6.7)': dependencies: upath: 2.0.1 vue: 3.4.27(typescript@5.4.5) @@ -1409,7 +1409,7 @@ snapshots: local-pkg@0.4.3: {} - long@5.2.3: {} + long@5.3.0: {} magic-string@0.30.10: dependencies: @@ -1557,7 +1557,7 @@ snapshots: vite-plugin-vuetify@2.0.3(vite@5.2.11(@types/node@20.12.12)(sass@1.77.2))(vue@3.4.27(typescript@5.4.5))(vuetify@3.6.7): dependencies: - '@vuetify/loader-shared': 2.0.3(vue@3.4.27(typescript@5.4.5))(vuetify@3.6.7(typescript@5.4.5)(vite-plugin-vuetify@2.0.3)(vue@3.4.27(typescript@5.4.5))) + '@vuetify/loader-shared': 2.0.3(vue@3.4.27(typescript@5.4.5))(vuetify@3.6.7) debug: 4.3.4 upath: 2.0.1 vite: 5.2.11(@types/node@20.12.12)(sass@1.77.2) diff --git a/src/components/HealthBar.vue b/src/components/HealthBar.vue index c2759fc75c3e37a86f7421c64bcf815e7ebf1131..986a3133631cf37e28f31fe2d25d128fb853a75a 100644 --- a/src/components/HealthBar.vue +++ b/src/components/HealthBar.vue @@ -87,6 +87,13 @@ onMounted(async () => { hc.on("data", updateData); hc.on("error", console.error); + console.log("Attempting to register endpoints..."); + + //hc.register(chain.api.block_api.get_block, { block_num: 1 }, data => data.block?.previous === "0000000000000000000000000000000000000000" ? true : "Invalid response from block_api", endpoints); hc.register(chain.api.block_api.get_block, { block_num: 1 }, data => data.block?.previous === "0000000000000000000000000000000000000000" ? true : "Invalid response from block_api", endpoints); + hc.register(chain.api.database_api.get_dynamic_global_properties, {}, data => data.head_block_number > 10000000 ? true : "Invalid response from database_api.get_dynamic_global_properties", endpoints); + hc.register(chain.api.rc_api.find_rc_accounts, { accounts: ["hiveio", "gtg"] }, data => data.rc_accounts.length > 0 ? true : "Invalid response from rc_api.find_rc_accounts", endpoints); + hc.register(chain.api.database_api.find_accounts, { accounts: ['gtg', 'blocktrades'] }, data => data.accounts.length > 0 ? true : "Invalid response from database_api.find_accounts", endpoints); + hc.register(chain.api.account_by_key_api.get_key_references, { keys: ['STM6JswFatSixhR9AMUP38rtpMVAagTvxGYu7d8i2JUK1QZDkPbH3', 'STM8GC13uCZbP44HzMLV6zPZGwVQ8Nt4Kji8PapsPiNq1BK153XTX'] }, data => !!data.accounts ? true : "Invalid response from account_by_key.get_key_references", endpoints); });