bcoin-org / bcoin

Javascript bitcoin library for node.js and browsers
https://bcoin.io
Other
3.01k stars 811 forks source link

Uncaught exceptions on SPV node #139

Closed ghost closed 7 years ago

ghost commented 7 years ago

I'm getting uncaught exceptions when creating a spv node and connecting to other peers on testnet like Error: Peer does not support BIP37.

It happens at every restart, how should it be handled?

chjj commented 7 years ago

@jmliz, you need to listen for the error event on the Pool or Node object.

If you're running bin/spvnode, could you post the exact config options you were running with?

ghost commented 7 years ago

@chjj I've already tried with the error event but still the same:

Code:


const
    config = require('./config'),
    log = require('./log'),
    bcoin = require('bcoin').set('testnet');

// SPV chains only store the chain headers.
var chain = new bcoin.chain({
    db: 'leveldb',
    location: config.btc_node_location + '/spvchain',
    spv: true
});

var pool = new bcoin.pool({
    chain: chain,
    spv: true,
    maxPeers: 8
});

var walletdb = new bcoin.walletdb({
    db: 'leveldb',
    location: config.btc_node_location + '/wallet',
});

pool.open().then(function() {
    return walletdb.open();
}).then(function() {
    return walletdb.create();
}).then(function(wallet) {
    log.info('Created wallet with address %s', wallet.getAddress('base58'));

    // Add our address to the spv filter.
    pool.watchAddress(wallet.getAddress());

    // Connect, start retrieving txs
    pool.connect();

    // Start the blockchain sync.
    pool.startSync();

    pool.on('tx', function(tx) {
        wallet.addTX(tx);
    });

    pool.on('error', function(err) {
        log.error(err);
    });

    wallet.on('balance', function(balance) {
        log.info('Balance updated.');
        log.info(bcoin.amount.btc(balance));
    });
});

Result:


ubuntu:~/baseapp (master) $ node config/spv.js 
2017-02-23T11:06:29.035Z - info: Created wallet with address mqsoCxsC1JLYwMF6y4sFFjscYcKpdsosAb
{
  "date": "Thu Feb 23 2017 11:06:29 GMT+0000 (UTC)",
  "process": {
    "pid": 4479,
    "uid": 1000,
    "gid": 1000,
    "cwd": "/home/ubuntu/workspace/baseapp",
    "execPath": "/home/ubuntu/.nvm/versions/node/v4.6.1/bin/node",
    "version": "v4.6.1",
    "argv": [
      "/home/ubuntu/.nvm/versions/node/v4.6.1/bin/node",
      "/home/ubuntu/workspace/baseapp/config/spv.js"
    ],
    "memoryUsage": {
      "rss": 45608960,
      "heapTotal": 21831776,
      "heapUsed": 15122328
    }
  },
  "os": {
    "loadavg": [
      1.6552734375,
      2.4658203125,
      2.826171875
    ],
    "uptime": 629501
  },
  "trace": [
    {
      "column": 3,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/pool.js",
      "function": "Pool.startSync",
      "line": 521,
      "method": "startSync",
      "native": false
    },
    {
      "column": 10,
      "file": "/home/ubuntu/workspace/baseapp/config/spv.js",
      "function": null,
      "line": 46,
      "method": null,
      "native": false
    }
  ],
  "stack": [
    "AssertionError: Pool is not connected!",
    "    at Pool.startSync (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/pool.js:521:3)",
    "    at /home/ubuntu/workspace/baseapp/config/spv.js:46:10"
  ],
  "level": "error",
  "message": "uncaughtException: Pool is not connected!",
  "timestamp": "2017-02-23T11:06:29.075Z"
}
{
  "date": "Thu Feb 23 2017 11:06:31 GMT+0000 (UTC)",
  "process": {
    "pid": 4479,
    "uid": 1000,
    "gid": 1000,
    "cwd": "/home/ubuntu/workspace/baseapp",
    "execPath": "/home/ubuntu/.nvm/versions/node/v4.6.1/bin/node",
    "version": "v4.6.1",
    "argv": [
      "/home/ubuntu/.nvm/versions/node/v4.6.1/bin/node",
      "/home/ubuntu/workspace/baseapp/config/spv.js"
    ],
    "memoryUsage": {
      "rss": 50618368,
      "heapTotal": 22851680,
      "heapUsed": 17304488
    }
  },
  "os": {
    "loadavg": [
      1.68310546875,
      2.4580078125,
      2.8212890625
    ],
    "uptime": 629503
  },
  "trace": [
    {
      "column": 15,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/peer.js",
      "function": "Peer.handleVersion",
      "line": 1660,
      "method": "handleVersion",
      "native": false
    },
    {
      "column": null,
      "file": null,
      "function": "next",
      "line": null,
      "method": null,
      "native": true
    },
    {
      "column": 22,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": "step",
      "line": 32,
      "method": null,
      "native": false
    },
    {
      "column": 5,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": null,
      "line": 59,
      "method": null,
      "native": false
    },
    {
      "column": 10,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": "exec",
      "line": 24,
      "method": null,
      "native": false
    },
    {
      "column": 12,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": "Peer.handleVersion",
      "line": 87,
      "method": "handleVersion",
      "native": false
    },
    {
      "column": 18,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/peer.js",
      "function": "Peer.handlePacket",
      "line": 1569,
      "method": "handlePacket",
      "native": false
    },
    {
      "column": null,
      "file": null,
      "function": "next",
      "line": null,
      "method": null,
      "native": true
    },
    {
      "column": 22,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": "step",
      "line": 32,
      "method": null,
      "native": false
    },
    {
      "column": 5,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": null,
      "line": 59,
      "method": null,
      "native": false
    }
  ],
  "stack": [
    "Error: Peer does not support BIP37. (46.29.20.209:18333)",
    "    at Peer.handleVersion (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/peer.js:1660:15)",
    "    at next (native)",
    "    at step (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:32:22)",
    "    at /home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:59:5",
    "    at exec (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:24:10)",
    "    at Peer.handleVersion (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:87:12)",
    "    at Peer.handlePacket (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/peer.js:1569:18)",
    "    at next (native)",
    "    at step (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:32:22)",
    "    at /home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:59:5"
  ],
  "level": "error",
  "message": "uncaughtException: Peer does not support BIP37. (46.29.20.209:18333)",
  "timestamp": "2017-02-23T11:06:31.492Z"
}
{
  "date": "Thu Feb 23 2017 11:06:31 GMT+0000 (UTC)",
  "process": {
    "pid": 4479,
    "uid": 1000,
    "gid": 1000,
    "cwd": "/home/ubuntu/workspace/baseapp",
    "execPath": "/home/ubuntu/.nvm/versions/node/v4.6.1/bin/node",
    "version": "v4.6.1",
    "argv": [
      "/home/ubuntu/.nvm/versions/node/v4.6.1/bin/node",
      "/home/ubuntu/workspace/baseapp/config/spv.js"
    ],
    "memoryUsage": {
      "rss": 52060160,
      "heapTotal": 32139104,
      "heapUsed": 15341104
    }
  },
  "os": {
    "loadavg": [
      1.68310546875,
      2.4580078125,
      2.8212890625
    ],
    "uptime": 629503
  },
  "trace": [
    {
      "column": 15,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/peer.js",
      "function": "Peer.handleVersion",
      "line": 1660,
      "method": "handleVersion",
      "native": false
    },
    {
      "column": null,
      "file": null,
      "function": "next",
      "line": null,
      "method": null,
      "native": true
    },
    {
      "column": 22,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": "step",
      "line": 32,
      "method": null,
      "native": false
    },
    {
      "column": 5,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": null,
      "line": 59,
      "method": null,
      "native": false
    },
    {
      "column": 10,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": "exec",
      "line": 24,
      "method": null,
      "native": false
    },
    {
      "column": 12,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": "Peer.handleVersion",
      "line": 87,
      "method": "handleVersion",
      "native": false
    },
    {
      "column": 18,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/peer.js",
      "function": "Peer.handlePacket",
      "line": 1569,
      "method": "handlePacket",
      "native": false
    },
    {
      "column": null,
      "file": null,
      "function": "next",
      "line": null,
      "method": null,
      "native": true
    },
    {
      "column": 22,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": "step",
      "line": 32,
      "method": null,
      "native": false
    },
    {
      "column": 5,
      "file": "/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js",
      "function": null,
      "line": 59,
      "method": null,
      "native": false
    }
  ],
  "stack": [
    "Error: Peer does not support BIP37. (104.236.132.224:18333)",
    "    at Peer.handleVersion (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/peer.js:1660:15)",
    "    at next (native)",
    "    at step (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:32:22)",
    "    at /home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:59:5",
    "    at exec (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:24:10)",
    "    at Peer.handleVersion (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:87:12)",
    "    at Peer.handlePacket (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/net/peer.js:1569:18)",
    "    at next (native)",
    "    at step (/home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:32:22)",
    "    at /home/ubuntu/workspace/baseapp/node_modules/bcoin/lib/utils/co.js:59:5"
  ],
  "level": "error",
  "message": "uncaughtException: Peer does not support BIP37. (104.236.132.224:18333)",
  "timestamp": "2017-02-23T11:06:31.709Z"
ghost commented 7 years ago

solved with spv.pool.on('error', function() {});, sorry for the noob question.