/conceal-guardian

Conceal Node Guardian

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

Conceal Node Guardian

1. About

ConcealNodeGuard is a guardian process that monitors over the conceald daemon. It can catch daemon errors and also monitors if the block count is increasing. In case an error is detected or the block count is stale it restarts the daemon and notifies the devs on the Discord over a web hook, or sends a mail to the recipient, or both.

It can also connect to a pool so the node is then listed among available nodes either for infrastrucure monitoring or for remote node with fee listing.

2. Installation

To install and run it you have two options. Install and run it via the node.js virual machine or you can download the precompiled executabled that alreay include node.js and run that. In that case you have 0 dependencies.

If you go with the first options the continue reading, otherwise go to installation page

First need to install dependencies. There are two:

You can see how to install it here.

When you have it installed you can run the guardian by simply doing:

  1. npm install
  2. node index.js

Before doing that however its wise to check the config.json and set the correct settings. For interactive config setup please refer to installation page. Sample of config.json

{
   "node":{
      "args":[
         "--rpc-bind-ip",
         "127.0.0.1",
         "--rpc-bind-port",
         "16000"
      ],
      "path":"C:\\Wallets\\Conceal-CLI\\conceald.exe",
      "port":16000,
      "name":"TestNode",
      "bindAddr":"0.0.0.0",
      "feeAddr":"your fee CCX address"
   },
   "error":{
      "notify":{
         "discord":{
            "url":"put the discord web hook url in here"
         },
         "email":{
            "smtp":{
               "host":"conceal.network",
               "port":25,
               "secure":false
            },
            "auth":{
               "username":"your SMTP username",
               "password":"your SMTP password"
            },
            "message":{
               "from":"no-reply@conceal.network",
               "to":"test.email@gmail.com",
               "subject":"Guardian error occured"
            }
         }
      }
   },
   "restart":{
      "errorForgetTime":600,
      "maxCloseErrors":3,
      "maxBlockTime":1800,
      "maxInitTime":600
   },
   "api":{
      "port":8080
   },
   "pool":{
      "notify":{
         "url":"URL to the guardian pool service if you want to register there",
         "interval":30
      }
   },
   "url": {
      "host": your custom hostname (usually an URL)
      "port": your custom port
   }
}

The explanation of config options:

  • node
    • args: The arguments that get appended to the monitored process.
    • path: The path of the process. If omited it uses the same path where the guardian is located
    • port: The port on which conceald is running
    • name: Name of the node. If omited it uses the hostname.
    • feeAddr: The CCX address on which the transaction fee will be sent in case of remote node.
    • bindAddr: The address on which you listen. 127.0.0.1 for localhost only. 0.0.0.0 for outside accesible node.
  • error
    • notify
      • discord
        • url: the ulr of the Discord web hook, where the error reports are send.
      • email
        • smtp
          • host: SMTP hostname
          • port: SMTP port (default is 25)
          • secure: do you want secure connection (usually false)
        • auth
          • username: SMTP username
          • password: SMTP password
        • message
          • from: From field of the message
          • to: To field of the message
          • subject: Subject of the message
  • restart
    • errorForgetTime: The time in seconds after which the error is forgoten and error count decreased by 1.
    • maxCloseErrors: Maximum number of errors. After that the guardian stops as there is a serious issue with the daemon.
    • maxBlockTime: Maximum time in seconds between block number increase. If afrer this time the block is still the same its considered an error.
    • maxInitTime: Maximum time in secords in which the node should be initialized.
  • api
    • port: port of the api on which to listen. If not specified the guardian will not listen for incoming requests
  • pool
    • notify
      • url: the url of the Conceal Guardian Pool. The Guardian is sending its data to pool for public listing
      • interval: the interval in seconds in which the data is being sent
  • url
    • host: if you want to have a custom hostname, specify it here and it will override the automatically assigned one
    • port: if you want to have a custom port, specify it here and it will override the automatically assigned one

To run as a service you can use the build in service controls described on installation page. Or you can do it the manual way. On linux you can use systemctl

[Unit]
Description=Node Guardian

[Service]
Type=simple
# Another Type option: forking
User=nodeguard
WorkingDirectory=/usr/bin
ExecStart=/usr/bin/node /path/to/guardian/index.js
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

Copy ccx-guardian.service.template to /etc/systemd/system/ccx-guardian.service and edit it approprietly.

Now you can start it or stop it with:

  • start: sudo systemctl start ccx-guardian
  • stop: sudo systemctl stop ccx-guardian
  • status: sudo systemctl status ccx-guardian
  • print log: journalctl -e -u ccx-guardian.service
  • reload conf: systemctl daemon-reload

3. API

The Guardian can have an api that listens for incoming requests and returns some info about the node. The api only has one handler (all other request are considered invalid and return 403):

  • getInfo

The result is for example:

{
   "id":"7b6e8b0c-039c-48a9-959f-2f379f897a78",
   "os":"linux",
   "name":"Solaris",
   "nodeHost":"80.241.210.162",
   "nodePort":16000,
   "status":{
      "errors":0,
      "startTime":"2019-04-08T15:32:03.011Z"
   },
   "blockchain":{
      "alt_blocks_count":4,
      "block_major_version":7,
      "block_minor_version":0,
      "difficulty":411075551,
      "fee_address":"ccx7ZuCP9NA2KmnxbyBn9QgeLSATHXHRAXVpxgiaNxsH4GwMvQ92SeYhEeF2tJHADHbW4bZMFHvFf8GpucLrRyw49q4Gkc3AXM",
      "full_deposit_amount":10158060988835,
      "full_deposit_interest":54938177048,
      "grey_peerlist_size":1120,
      "height":220877,
      "incoming_connections_count":37,
      "last_block_difficulty":442618488,
      "last_block_reward":7500300,
      "last_block_timestamp":1555001815,
      "last_known_block_index":220876,
      "outgoing_connections_count":7,
      "status":"OK",
      "top_block_hash":"bd7ec15e292b293561cd8e153d42a4c6ab83006165faf0e37727cd7f527d4b1b",
      "tx_count":315644,
      "tx_pool_size":0,
      "version":"5.3.0",
      "white_peerlist_size":97
   },
   "location":{
      "ip":"80.241.210.162",
      "data":{
         "country":"DE",
         "countryCode":"DE",
         "region":"Bavaria",
         "regionCode":"",
         "city":"Munich",
         "postal":"81549",
         "ip":"80.241.210.162",
         "latitude":48.1089,
         "longitude":11.6074,
         "timezone":""
      }
   }
}