Skip to content

Commit

Permalink
Merge branch 'refactor/general-fixes' into feature/p2p-10334
Browse files Browse the repository at this point in the history
  • Loading branch information
i25959341 committed Jul 2, 2018
2 parents 41d54ad + 54b445b commit 80cad8f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 34 deletions.
12 changes: 6 additions & 6 deletions create_table_queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -143,8 +143,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;
Expand Down
33 changes: 21 additions & 12 deletions neo-back/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ 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)
})

types.setTypeParser(1700, 'text', parseFloat);

let cache = apicache.middleware

const pool = new Pool({
Expand All @@ -15,6 +22,7 @@ router.get('/', function(req, res, next) {
res.json({ title: 'Express' });
});

// Took 154ms
// SELECT max(blockheight)
// FROM blockheight_history
// WHERE blockheight IS NOT NULL
Expand All @@ -39,6 +47,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)
Expand Down Expand Up @@ -532,8 +541,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
Expand Down Expand Up @@ -699,17 +708,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,
Expand All @@ -719,7 +728,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
)
Expand All @@ -730,17 +739,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,
Expand All @@ -750,7 +759,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
)
Expand Down
20 changes: 10 additions & 10 deletions neo-collector/insert/insertData.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions neo-interface/src/components/NodesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ class NodesTable extends Component {
<td>{node.blockheight}</td>
<td>{node.mempool_size}</td>
<td>{node.latency}</td>
{node.rcp_http_status === true &&
{node.rpc_http_status === true &&
<td>Okay</td>
}
{node.rcp_http_status === false &&
{node.rpc_http_status === false &&
<td>N/A</td>
}
{node.rcp_http_status === true &&
{node.rpc_http_status === true &&
<td>Okay</td>
}
{node.rcp_http_status === false &&
{node.rpc_http_status === false &&
<td>N/A</td>
}
{node.online === true &&
Expand All @@ -58,8 +58,8 @@ class NodesTable extends Component {
{node.online === false &&
<td>Offline</td>
}
<td>{node.rcp_http_status}</td>
<td>{node.rcp_https_status}</td>
<td>{node.rpc_http_status}</td>
<td>{node.rpc_https_status}</td>
<td>{node.connection_counts}</td>
<td>{node.count} pct</td>
<td>{node.version}</td>
Expand Down

0 comments on commit 80cad8f

Please sign in to comment.