From d1b10500052c4dc380b44a89557bdc84813d440d Mon Sep 17 00:00:00 2001 From: i25959341 Date: Mon, 2 Jul 2018 09:38:02 +0100 Subject: [PATCH 1/3] add fixes --- create_table_queries.md | 12 +++++----- neo-back/routes/index.js | 26 ++++++++++++---------- neo-collector/insert/insertData.py | 20 ++++++++--------- neo-interface/src/components/NodesTable.js | 12 +++++----- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/create_table_queries.md b/create_table_queries.md index 0b195a58..d7e78bc4 100644 --- a/create_table_queries.md +++ b/create_table_queries.md @@ -59,17 +59,17 @@ CREATE TABLE IF NOT EXISTS online_history ( online boolean ); -CREATE TABLE IF NOT EXISTS rcp_http_status_history ( +CREATE TABLE IF NOT EXISTS rpc_http_status_history ( id serial PRIMARY KEY, ts TIMESTAMP WITHOUT TIME zone, address_id INTEGER REFERENCES address(id) , - rcp_http_status boolean); + rpc_http_status boolean); -CREATE TABLE IF NOT EXISTS rcp_https_status_history ( +CREATE TABLE IF NOT EXISTS rpc_https_status_history ( id serial PRIMARY KEY, ts TIMESTAMP WITHOUT TIME zone, address_id INTEGER REFERENCES address(id) , - rcp_https_status boolean); + rpc_https_status boolean); CREATE TABLE IF NOT EXISTS locale ( id bigserial PRIMARY key, @@ -136,8 +136,8 @@ DROP TABLE latency_history; DROP TABLE mempool_size_history; DROP TABLE connection_counts_history; DROP TABLE online_history; -DROP TABLE rcp_http_status_history; -DROP TABLE rcp_https_status_history; +DROP TABLE rpc_http_status_history; +DROP TABLE rpc_https_status_history; DROP TABLE edges; DROP TABLE ip; DROP TABLE locale; diff --git a/neo-back/routes/index.js b/neo-back/routes/index.js index 92925e16..2f1c3b5c 100644 --- a/neo-back/routes/index.js +++ b/neo-back/routes/index.js @@ -15,6 +15,7 @@ router.get('/', function(req, res, next) { res.json({ title: 'Express' }); }); +// Took 154ms // SELECT max(blockheight) // FROM blockheight_history // WHERE blockheight IS NOT NULL @@ -39,6 +40,7 @@ router.get('/bestblock',cache('1 seconds'), function(req, res, next) { }) }); +// Took 143ms // SELECT Min(ts) // FROM blockheight_history // WHERE blockheight IN ( SELECT MAX(blockheight) @@ -532,8 +534,8 @@ router.get('/nodes/:node_id', cache('2 seconds'), function(req, res, next) { lat.latency, 200 ) AS latency, - b.rcp_https_status, - c.rcp_http_status, + b.rpc_https_status as rpc_https_status, + c.rpc_http_status as rpc_http_status, coalesce( d.mempool_size, 0 @@ -699,17 +701,17 @@ router.get('/nodes/:node_id', cache('2 seconds'), function(req, res, next) { SELECT address_id, coalesce( - rcp_https_status, + rpc_https_status, FALSE - ) AS rcp_https_status + ) AS rpc_https_status FROM ( SELECT address_id, ts, - rcp_https_status + rpc_https_status FROM - rcp_https_status_history + rpc_https_status_history WHERE ( address_id, @@ -719,7 +721,7 @@ router.get('/nodes/:node_id', cache('2 seconds'), function(req, res, next) { address_id, max(ts) AS ts FROM - rcp_https_status_history + rpc_https_status_history GROUP BY address_id ) @@ -730,17 +732,17 @@ router.get('/nodes/:node_id', cache('2 seconds'), function(req, res, next) { SELECT address_id, coalesce( - rcp_http_status, + rpc_http_status, FALSE - ) AS rcp_http_status + ) AS rpc_http_status FROM ( SELECT address_id, ts, - rcp_http_status + rpc_http_status FROM - rcp_http_status_history + rpc_http_status_history WHERE ( address_id, @@ -750,7 +752,7 @@ router.get('/nodes/:node_id', cache('2 seconds'), function(req, res, next) { address_id, max(ts) AS ts FROM - rcp_http_status_history + rpc_http_status_history GROUP BY address_id ) diff --git a/neo-collector/insert/insertData.py b/neo-collector/insert/insertData.py index a7ea2e19..66ff9305 100644 --- a/neo-collector/insert/insertData.py +++ b/neo-collector/insert/insertData.py @@ -71,7 +71,7 @@ def getProtocol(cursor): protocol_dict[addressId] = protocol return protocol_dict -def get_lantency(addr): +def get_latency(addr): start = time.time() response = requests.post(addr, json={'jsonrpc': '2.0', 'method': 'getblockcount', 'params': [], 'id': 1}, ) end = time.time() @@ -159,7 +159,7 @@ def update(endpoints, client, dict_address_port): print("{} Blockheight: {}".format(address, height)) cursor.execute("INSERT INTO blockheight_history (ts, address_id, blockheight) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, height]) - latency = get_lantency(endpoint.addr) + latency = get_latency(endpoint.addr) print("Latency: {}".format(latency)) cursor.execute("INSERT INTO latency_history (ts, address_id, latency_history) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, latency]) try: @@ -189,22 +189,22 @@ def update(endpoints, client, dict_address_port): for tx in raw_mempool: cursor.execute("INSERT INTO unconfirmed_tx (last_blockheight, address_id, tx) VALUES (%s, %s, %s)", [height, addressId, tx]) - rcp_https_service = test_port(address,JSON_RPC_HTTPS_PORT) - rcp_http_service = test_port(address,JSON_RPC_HTTP_PORT) + rpc_https_service = test_port(address,JSON_RPC_HTTPS_PORT) + rpc_http_service = test_port(address,JSON_RPC_HTTP_PORT) - if rcp_https_service: + if rpc_https_service: print("JSON_RPC_HTTPS_PORT okay") - cursor.execute("INSERT INTO rcp_http_status_history (ts, address_id, rcp_http_status) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, True]) + cursor.execute("INSERT INTO rpc_http_status_history (ts, address_id, rpc_http_status) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, True]) else: print("JSON_RPC_HTTPS_PORT not avaliable") - cursor.execute("INSERT INTO rcp_http_status_history (ts, address_id, rcp_http_status) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, False]) + cursor.execute("INSERT INTO rpc_http_status_history (ts, address_id, rpc_http_status) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, False]) - if rcp_http_service: + if rpc_http_service: print("JSON_RPC_HTTP_PORT okay") - cursor.execute("INSERT INTO rcp_https_status_history (ts, address_id, rcp_https_status) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, True]) + cursor.execute("INSERT INTO rpc_https_status_history (ts, address_id, rpc_https_status) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, True]) else: print("JSON_RPC_HTTP_PORT not avaliable") - cursor.execute("INSERT INTO rcp_https_status_history (ts, address_id, rcp_https_status) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, False]) + cursor.execute("INSERT INTO rpc_https_status_history (ts, address_id, rpc_https_status) VALUES (%s, %s, %s)", [getSqlDateTime(time.time()), addressId, False]) try: peers = client.get_peers(endpoint=endpoint) diff --git a/neo-interface/src/components/NodesTable.js b/neo-interface/src/components/NodesTable.js index 1ecf7b89..55744069 100644 --- a/neo-interface/src/components/NodesTable.js +++ b/neo-interface/src/components/NodesTable.js @@ -40,16 +40,16 @@ class NodesTable extends Component { {node.blockheight} {node.mempool_size} {node.latency} - {node.rcp_http_status === true && + {node.rpc_http_status === true && Okay } - {node.rcp_http_status === false && + {node.rpc_http_status === false && N/A } - {node.rcp_http_status === true && + {node.rpc_http_status === true && Okay } - {node.rcp_http_status === false && + {node.rpc_http_status === false && N/A } {node.online === true && @@ -58,8 +58,8 @@ class NodesTable extends Component { {node.online === false && Offline } - {node.rcp_http_status} - {node.rcp_https_status} + {node.rpc_http_status} + {node.rpc_https_status} {node.connection_counts} {node.count} pct {node.version} From e44b9c260428a4222a79b372f9667e035ae723a0 Mon Sep 17 00:00:00 2001 From: i25959341 Date: Mon, 2 Jul 2018 10:09:58 +0100 Subject: [PATCH 2/3] add general fixes --- neo-back/routes/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/neo-back/routes/index.js b/neo-back/routes/index.js index 2f1c3b5c..e5f0a4ad 100644 --- a/neo-back/routes/index.js +++ b/neo-back/routes/index.js @@ -3,6 +3,11 @@ var router = express.Router(); var apicache = require('apicache'); const { Pool } = require('pg') +var types = require('pg').types +types.setTypeParser(20, function(val) { + return parseInt(val) +}) + let cache = apicache.middleware const pool = new Pool({ From 54b445b383a7dd6fce75bd371a0140c31ccf565a Mon Sep 17 00:00:00 2001 From: i25959341 Date: Mon, 2 Jul 2018 11:43:14 +0100 Subject: [PATCH 3/3] add float parser --- neo-back/routes/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neo-back/routes/index.js b/neo-back/routes/index.js index e5f0a4ad..2196ccd9 100644 --- a/neo-back/routes/index.js +++ b/neo-back/routes/index.js @@ -8,6 +8,8 @@ types.setTypeParser(20, function(val) { return parseInt(val) }) +types.setTypeParser(1700, 'text', parseFloat); + let cache = apicache.middleware const pool = new Pool({