getumbrel / umbrel-middleware

RESTful Bitcoin and Lightning API for Umbrel
MIT License
21 stars 11 forks source link

Bitcoin Stats Endpoint #9

Closed mayankchhabra closed 4 years ago

mayankchhabra commented 4 years ago

@nolim1t can you do a bitcoind stats endpoint?

GET /api/v1/bitcoind/info/stats

Returns:

{
    peers: <number of connected peers>
    mempool: <size of amempool in bytes>
    hashrate: <network hashes per second>
    blockchainSize: <the estimated size of the block and undo files on disk>
}

We require it to display these stats on the dashboard:

image

nolim1t commented 4 years ago

@mayankchhabra - can you combine multiple calls together?

If so, this is already mostly implemented in master branch right now.

So all it would need is adding a few more endpoints

mayankchhabra commented 4 years ago

That's possible, but I would recommend against it... there's simply too much of polling happening already 🤢

nolim1t commented 4 years ago

This should be available soon (mempool info)

{"loaded":true,"size":2654,"bytes":920559,"usage":4068320,"maxmempool":512000000,"mempoolminfee":0.00001,"minrelaytxfee":0.00001}
mayankchhabra commented 4 years ago

Great, we just need the "usage":4068320 key-value pair

nolim1t commented 4 years ago

Im adding stuff to the sync endpoint because stuff exists. Maybe I should add mempool info there too?

mayankchhabra commented 4 years ago

To the sync endpoint? I don't think it's a good idea. Sync should only have the % sync value, tip, and the block header to ensure separation of concerns.

Either a separate endpoint /mempool or a combined, like /stats, should do.

nolim1t commented 4 years ago

the sync endpoint is calling the same RPC calls so that get the same information so they will get called anyway

nolim1t commented 4 years ago

block size and sync percentage are in the same call

nolim1t commented 4 years ago

However I will keep mempool separate because thats a different call

nolim1t commented 4 years ago

/v1/bitcoind/info/sync as of developmental branch

{
  "percent": "1.0000",
  "currentBlock": 627729,
  "headerCount": 627729,
  "difficulty": 15958652328578.42,
  "size": 311144972067
}
nolim1t commented 4 years ago

/v1/bitcoind/info/connections already exposes peers but I can expose the entire raw amount too

mayankchhabra commented 4 years ago

/v1/bitcoind/info/connections is ok as is

nolim1t commented 4 years ago

Also have a /stats endpoint for everything if you prefer one call.. wasn't so bad to add in

{
  "blockchain_info": {
    "chain": "main",
    "blocks": 627732,
    "headers": 627732,
    "bestblockhash": "0000000000000000000dbc52d94673ab45b8271c38ec3245f82eb1a55bf10da3",
    "difficulty": 15958652328578.42,
    "mediantime": 1587917440,
    "verificationprogress": 0.9999987748965766,
    "initialblockdownload": false,
    "chainwork": "00000000000000000000000000000000000000000ee0e63b21634097f85357a4",
    "sizeOnDisk": 311149168631,
    "pruned": false,
    "softforks": {
      "bip34": {
        "type": "buried",
        "active": true,
        "height": 227931
      },
      "bip66": {
        "type": "buried",
        "active": true,
        "height": 363725
      },
      "bip65": {
        "type": "buried",
        "active": true,
        "height": 388381
      },
      "csv": {
        "type": "buried",
        "active": true,
        "height": 419328
      },
      "segwit": {
        "type": "buried",
        "active": true,
        "height": 481824
      }
    },
    "warnings": ""
  },
  "network_info": {
    "version": 190100,
    "subversion": "/Satoshi:0.19.1/",
    "protocolversion": 70015,
    "localservices": "0000000000000409",
    "localservicesnames": [
      "NETWORK",
      "WITNESS",
      "NETWORK_LIMITED"
    ],
    "localrelay": true,
    "timeoffset": -2,
    "networkactive": true,
    "connections": 10,
    "networks": [
      {
        "name": "ipv4",
        "limited": false,
        "reachable": true,
        "proxy": "",
        "proxyRandomizeCredentials": false
      },
      {
        "name": "ipv6",
        "limited": false,
        "reachable": true,
        "proxy": "",
        "proxyRandomizeCredentials": false
      },
      {
        "name": "onion",
        "limited": false,
        "reachable": true,
        "proxy": "127.0.0.1:9150",
        "proxyRandomizeCredentials": true
      }
    ],
    "relayfee": 1e-05,
    "incrementalfee": 1e-05,
    "localaddresses": [
      {
        "address": "3svpjvkmpftz2gny.onion",
        "port": 8333,
        "score": 7
      }
    ],
    "warnings": ""
  },
  "mempool": {
    "loaded": true,
    "size": 728,
    "bytes": 250136,
    "usage": 1135312,
    "maxmempool": 512000000,
    "mempoolminfee": 1e-05,
    "minrelaytxfee": 1e-05
  }
}