Skip to content

Commit

Permalink
Merge pull request #1 from ZencashOfficial/dev
Browse files Browse the repository at this point in the history
Beta testnet
  • Loading branch information
ADumaine authored Oct 25, 2017
2 parents e2a7e58 + 71c1ffa commit f082bab
Show file tree
Hide file tree
Showing 6 changed files with 346 additions and 180 deletions.
77 changes: 52 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,99 @@
# secnodetracker
#### ZenCash Secure Node tracking app

This is installed on a Secure Node to allow it to communicate with the zensystem.io tracking server. It provides data to the server about the node and performs compliance challenges. It is very lightweight as it only needs to act as a connector between the node and server.
This is installed on a Secure Node to allow it to communicate with the zensystem.io tracking server. It provides data to the server about the Secure Node and performs compliance challenges. Nodes that are in compliance receive a percentage of the block rewards. This runs completely separate from the zen node network.

## UPDATE 0.0.6
- Added collection of peers info for verifying TLS connections
- Added error checking if zen is loading when tracker restarts
- Added check for ipv6 in setup (thanks to @num81)
## UPDATE 0.0.8 - BETA-Testnet
- Added region selection in the setup
- Added failover to other servers
- Repository moved to zencashofficial

### About This Phase of the Beta
This part of the beta involves switching all the testnet nodes over to the new sets of regional servers. Some of the priority items to test in this phase are: Node setup process, node failover, moving nodes between servers (changing home server), consistent info across servers, and. The next phase will be migration of existing nodes to mainnet. Instructions will be published later for that phase.

There are now three sets of regional servers. A node should select the closest region as a default.

### IMPORTANT UPDATE STEPS -- Changing to a new repository and new servers:
These are upgrade and migration instructions. If you are doing a new install see the New Installation instructions further down.

RUN SETUP: not needed for this update unless you are running ipv6 only and would like to test.
This version connects to new zensystem.io servers (NOT devtracksys.secnodes.com).
Setup has to be run.

Update from github:
1. Delete the following files in the secnodetracker/config folder(unless you want to re-enter):
- nodeid, serverurl, lastChalBlock, lastExecSec

2. Change to the secnodetracker folder. The repository has to be changed then checked to ensure it matches.
* git remote set-url origin https://github.com/ZencashOfficial/secnodetracker.git
* git remote -v

3. Update the files from github
* git fetch origin
* git checkout master
* git pull

3. Run the tracker setup and pay attention to the region. Enter another region code if it is not correct.
* node setup

Restart secnodetracker app.
4. Stop the tracker and restart it. The tracker should connect to the new server and register.
* Ctrl-c
* node app


## Version Notes
This software is still under development and active alpha testing.
This is Beta-Testnet and remains on the testnet. It will not work on the devtracksys.secnodes.com server.


## New Installation
If you have followed Part 1, Part 2, and Part 2.5 of guides for creating a Secure Node, you should be ready to install this on your node. More complete instructions will be added to Part 3 in the future.

## Installation
If you have followed Part 1, Part 2, and Part 2.5 of creating a Secure Node, you should be ready to install this on your secure node. More complete instructions will be added to Part 3 in the future.
You will need about 1 zen in the node wallet in a private address. Send multiple small amounts (0.2 each) to work around an issue with 0 balances due to waiting for change to return after a challenge.

You will need at least 1 zen in the node wallet in a private address. The balance is checked when the app starts and will show the address on the console.
The private z-address needs to be created manually if not present (zen-cli z_getnewaddress). If already present the balance is checked when the app starts and the address is displayed on the tracker console.

You will also need an address with at least 42 zen so the node will register on the server. This stake address does not have to be on the node.
You will also need a transparent address in a wallet (not on the node) with at least 42 zen so the node will register on the server. This is not the address shown on the console (the t-address on the console is used as the node's identity). The stake address is the payout address.

If you need some testnet zen (znt) please ask in the channel and post your transparent address (starts with 'zt' in testnet): someone will send some to you.

### Install npm and Node.js
Login to your secure node. This will install NPM and 8.5.0 or above of Node.js.
Log into your secure node. The following installs the NPM and Node.js (a javascript virtual machine).

* sudo apt-get install npm
* sudo npm install -g n
* sudo n latest

### Clone this repository
If you followed the Guide you should have a ~/zencash folder with zen folder in it.
If you followed the Guides you should have a ~/zencash folder with the zen folder in it.
Put this repository in the zencash folder too.

* cd ~/zencash
* git clone https://github.com/ADumaine/secnodetracker.git
* git clone https://github.com/ZencashOfficial/secnodetracker.git

### Install the node modules
### Install the nodejs modules

* cd secnodetracker
* npm install

### Run setup
You will need your staking address (with at least 42zen) and an email address for alerts (not implemented yet).
The setup prompts for the address and email and allows you to override the default address of the tracking server.
You will need your staking address (with at least 42zen - znt for testnet) and an email address for alerts (if you do not want alerts enter 'none' for the email address). During setup press Enter to accept the default or enter the information.

* node setup

* node setup.js

### Start the tracking app
* node app.js

* node app

Follow any instructions shown on the console. Rerun setup if needed: it will remember your previous values.
Use Ctrl-C to break out of the app.
Use Ctrl-c to break out of the app.

**NOTE:** There should only be 1 instance of the tracking app running at a time.

Check your node at http://devtracksys.secnodes.com
Check your node on the tracking server: https://securenodes.zensystem.io

Report any issues to @devman in the zencash slack #securenodes channel.
Report any critical issues to @devman or ask for help in the zencash slack #securenodes channel.


Instructions on installing a monitoring tool like nodemon or pm2 will be included later so the app can run within a daemon wrapper (in the background).
Instructions on installing a monitoring tool like nodemon or PM2 will be included later so the app can run in the background and start on reboot. If you want to install something now checkout PM2.



Expand Down
62 changes: 27 additions & 35 deletions SecNodeTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Client = require('bitcoin-core');
const Zcash = require('zcash');

let host = local.getItem('rpcallowip') || local.getItem('rpcbind');
if (!host) host = '127.0.0.1';
if (!host || local.getItem('ipv') == 6) host = 'localhost';

const cfg = {
host: host,
Expand Down Expand Up @@ -60,10 +60,6 @@ class SecNode {
this.statsTimer = setInterval(this.statsLoop, this.statsInterval);
}

loop() {
this.getStats()
}

getPrimaryAddress(cb) {
const self = this;
this.corerpc.getAddressesByAccount("", (err, data) => {
Expand Down Expand Up @@ -92,7 +88,6 @@ class SecNode {

if (result.length == 0) {
console.log("No private address found. Please create one and send at least 1 ZEN for challenges");

return cb(null)
}

Expand All @@ -102,7 +97,6 @@ class SecNode {

self.zenrpc.z_getbalance(addr)
.then((balance) => {

self.corerpc.getInfo()
.then((data) => {
let valid = true;
Expand Down Expand Up @@ -147,15 +141,22 @@ class SecNode {
self.crid = chal.crid
self.corerpc.getBlockHash(chal.blocknum, (err, hash) => {

if (err) return console.log(err)
if (err) {
let resp = { "crid": chal.crid, "status": "failed", "error": "unable to get blockhash from zen" }
self.chalRunning = false;
resp.ident = self.ident;
self.socket.emit("chalresp", resp);
console.log(logtime(), `Challenge Error: unable to get blockhash for challenge id${chal.crid} block ${chal.blocnum}`);
console.log(err);
return
}

self.corerpc.getBlock(hash, (err, block) => {

let msgBuff = new Buffer.from(block.merkleroot);
let amts = [{ "address": chal.sendto, "amount": self.amt, "memo": msgBuff.toString('hex') }];

self.getAddrWithBal((err, result) => {

if (err) return console.log(err);

let zaddr = result.addr;
Expand Down Expand Up @@ -214,10 +215,8 @@ class SecNode {

self.zenrpc.z_getoperationstatus([opid])
.then(operation => {

let elapsed = (((new Date()) - self.chalStart) / 1000).toFixed(0);


if (operation.length == 0) {
if (elapsed < 12) return

Expand All @@ -238,7 +237,6 @@ class SecNode {
console.log(logtime(), "Elapsed challenge time=" + elapsed + " status=" + op.status);

if (op.status == "success") {

console.log(logtime(), "Challenge submit: " + op.status);

let resp = {
Expand All @@ -252,37 +250,27 @@ class SecNode {
resp.memNearEnd = self.memNearEnd
}

console.log(op);
console.log("txid= " + op.result.txid);
console.log(logtime(), `Challenge result:${op.status} seconds:${op.execution_secs}`);

resp.ident = self.ident;

self.chalRunning = false;
self.socket.emit("chalresp", resp);

local.setItem('lastExecSec', (op.execution_secs).toFixed(2));

self.getBlockHeight(true);


//clear the operation from queue
self.zenrpc.z_getoperationresult([opid]);


} else if (op.status == "failed") {

console.log(logtime(), "Challenge result: " + op.status)
console.log(logtime(), `Challenge result:${op.status}`)
console.log(op.error.message);

let resp = { "crid": chal.crid, "status": op.status, "error": op.error.message }
self.chalRunning = false;

resp.ident = self.ident;
self.socket.emit("chalresp", resp);

//clear the operation from queue
self.zenrpc.z_getoperationresult([opid]);

} else if (os == 'linux' && op.status == "executing") {

let last = local.getItem('lastExecSec') || self.defaultMemTime;
Expand All @@ -304,8 +292,8 @@ class SecNode {
});
}

getConfig(req, poolver, hw) {
// node version, poolver, and hw
getConfig(req, trkver, hw) {
// node version, trkver, and hw
const self = this;
this.corerpc.getInfo()
.then((data) => {
Expand All @@ -318,7 +306,7 @@ class SecNode {

if (!self.ident.nid && req.nid) self.ident.nid = req.nid;

let config = { node: node, poolver: poolver, hw: hw }
let config = { node: node, trkver: trkver, hw: hw }
self.socket.emit("node", { type: "config", ident: self.ident, config: config });

})
Expand All @@ -328,7 +316,7 @@ class SecNode {
);
}

collectStats(){
collectStats() {
const self = this;

if (!self.socket.connected) return;
Expand All @@ -341,9 +329,13 @@ class SecNode {
}
} else {
self.getTLSPeers(null, (err, tlsPeers) => {
stats.tlsPeers = tlsPeers;
self.socket.emit("node", { type: "stats", stats: stats, ident: self.ident });
console.log(logtime(), "stat check");
stats.tlsPeers = tlsPeers;
self.socket.emit("node", { type: "stats", stats: stats, ident: self.ident });
let display = "";
for (let s in stats) {
if (s !== 'tlsPeers') display += `${s}:${stats[s]} `;
}
console.log(logtime(), `Stat check: connected to:${self.ident.con.cur} ${display}`);
});
}
})
Expand Down Expand Up @@ -376,8 +368,8 @@ class SecNode {
"lastChalBlock": addrBal.lastChalBlock,
"lastExecSec": local.getItem('lastExecSec')
}
console.log(stats)
// console.log("lastchalblock=" + local.getItem('lastChalBlock'))
// console.log(stats)
// console.log("lastchalblock=" + local.getItem('lastChalBlock'))
if (addrBal.bal < self.minChalBal && addrBal.valid) console.log(logtime(), "Low challenge balance. " + addrBal.bal)

if (self.ident) {
Expand Down Expand Up @@ -425,7 +417,7 @@ class SecNode {
for (let i = 0; i < data.length; i++) {
let p = data[i];
if (p.inbound == false) {
let ip = p.addr.indexOf(']') != -1 ? p.addr.substr(1, p.addr.indexOf(']')-1) : p.addr.substr(0, p.addr.indexOf(":"));
let ip = p.addr.indexOf(']') != -1 ? p.addr.substr(1, p.addr.indexOf(']') - 1) : p.addr.substr(0, p.addr.indexOf(":"));
let peer = { ip, tls: p.tls_verified };
peers.push(peer);
}
Expand All @@ -447,7 +439,7 @@ class SecNode {
const self = this;
this.corerpc.getInfo()
.then((data) => {
// console.log("GETBLOCK set last", setLast)
// console.log("GETBLOCK set last", setLast)
if (setLast) local.setItem('lastChalBlock', data.blocks);
return data.blocks;
})
Expand Down
Loading

0 comments on commit f082bab

Please sign in to comment.