Skip to content

Commit

Permalink
Query local block number using JSON RPC..
Browse files Browse the repository at this point in the history
so the healthcheck works for both geth and parity
  • Loading branch information
troggy committed Dec 4, 2017
1 parent d82a63e commit 1ab406a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# geth-healthcheck

Little http node.js server to run along the geth node. Returns **503 Service Unavailable** if the last block number on the local node is off by 4 or more blocks from the last block nubmer from Etherscan. Otherwise returns **200 OK**
Little http node.js server to run along the ethereum node. Node needs to have JSONRPC enabled. Returns **503 Service Unavailable** if the last block number on the local node is off by 4 or more blocks from the last block nubmer from Etherscan. Otherwise returns **200 OK**

## Installation
1. Install node.js if needed:
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const MAX_BLOCK_DIFFERENCE = 3;

const getLocalBlockNum = () => {
return new Promise((resolve, reject) => {
exec('geth --exec eth.blockNumber attach', (error, stdout, stderr) => {
exec('curl --data \'{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}\' -H "Content-Type: application/json" -X POST localhost:8545', (error, stdout, stderr) => {
if (error) {
return reject(`${error}`);
}
resolve(parseInt(stdout.trim()));
resolve(parseInt(JSON.parse(stdout.trim()).result));
});
});
};
Expand Down

0 comments on commit 1ab406a

Please sign in to comment.