bitpay / bitcore

A full stack for bitcoin and blockchain-based applications
https://bitcore.io/
MIT License
4.83k stars 2.08k forks source link

(Not) Connected to peer #3534

Open ASHKARAN opened 1 year ago

ASHKARAN commented 1 year ago

When i run bitcore-node i see this logs in the output

{"message":"2023-02-07 12:50:57.840 GMT+3 | Not connected to peer: 127.0.0.1:8333  | Chain: BTC | Network: testnet","level":"warn"}
{"message":"2023-02-07 12:51:27.840 GMT+3 | Not connected to peer: 127.0.0.1:8343  | Chain: BTC | Network: mainnet","level":"warn"}
{"message":"2023-02-07 12:51:32.810 GMT+3 | Connected to peer: 127.0.0.1:8333  | Chain: BTC | Network: testnet","level":"info"}
{"message":"2023-02-07 12:52:02.810 GMT+3 | Connected to peer: 127.0.0.1:8343  | Chain: BTC | Network: mainnet","level":"info"}
{"message":"2023-02-07 12:52:02.840 GMT+3 | Not connected to peer: 127.0.0.1:8333  | Chain: BTC | Network: testnet","level":"warn"}
{"message":"2023-02-07 12:52:32.840 GMT+3 | Not connected to peer: 127.0.0.1:8343  | Chain: BTC | Network: mainnet","level":"warn"}
{"message":"2023-02-07 12:52:37.811 GMT+3 | Connected to peer: 127.0.0.1:8333  | Chain: BTC | Network: testnet","level":"info"}
{"message":"2023-02-07 12:53:07.811 GMT+3 | Connected to peer: 127.0.0.1:8343  | Chain: BTC | Network: mainnet","level":"info"}
{"message":"2023-02-07 12:53:07.840 GMT+3 | Not connected to peer: 127.0.0.1:8333  | Chain: BTC | Network: testnet","level":"warn"}
{"message":"2023-02-07 12:53:37.840 GMT+3 | Not connected to peer: 127.0.0.1:8343  | Chain: BTC | Network: mainnet","level":"warn"}
{"message":"2023-02-07 12:53:42.813 GMT+3 | Connected to peer: 127.0.0.1:8333  | Chain: BTC | Network: testnet","level":"info"}
{"message":"2023-02-07 12:54:12.812 GMT+3 | Connected to peer: 127.0.0.1:8343  | Chain: BTC | Network: mainnet","level":"info"}
{"message":"2023-02-07 12:54:12.824 GMT+3 | Not connected to peer: 127.0.0.1:8333  | Chain: BTC | Network: testnet","level":"warn"}

what does it mean and why is this happening?

ASHKARAN commented 1 year ago

after some googling, i found out this behavior looks normal

escottalexander commented 1 year ago

This not normal behavior. It indicates that Bitcore-Node isn't properly connected to your Bitcoin nodes. I think your ports are wrong. As an example, if your Bitcoin configuration file (bitcoin.conf located in the --datadir you specify when you run the Bitcoin node) looks like this:

...
port=20000
rpcport=20001
rpcallowip=127.0.0.1
...

Then your bitcore.config.json should look like this:

...
"BTC": {
        "mainnet": {
          "chainSource": "p2p",
          "trustedPeers": [
            {
              "host": "localhost",
              "port": 20000
            }
          ],
          "rpc": {
            "protocol": "http",
            "host": "localhost",
            "port": 20001,
            "username": "XXXXXX",
            "password": "XXXXXX"
          }
        }
      },
...

Hope that is helpful.

ASHKARAN commented 1 year ago

i changed my configurations to your example for now i see this log in console

{"message":"Another node is the primary syncing node","level":"info"}
{"message":"Another node is the primary syncing node","level":"info"}
{"message":"Another node is the primary syncing node","level":"info"}
{"message":"Another node is the primary syncing node","level":"info"}
{"message":"This worker is now the syncing node for BTC mainnet","level":"info"}
peerheaders HeadersMessage {
  command: 'headers',
  network: Network {
    name: 'livenet',
    alias: 'mainnet',
    pubkeyhash: 0,
    privatekey: 128,
    scripthash: 5,
    bech32prefix: 'bc',
    xpubkey: *******,,
    xprivkey: *******,
    networkMagic: <Buffer f9 be b4 d9>,
    port: 8333,
    dnsSeeds: [
      'seed.bitcoin.sipa.be',
      'dnsseed.bluematt.me',
      'dnsseed.bitcoin.dashjr.org',
      'seed.bitcoinstats.com',
      'seed.bitnodes.io',
      'bitseed.xf2.org'
    ]
  },
  BlockHeader: [Function: BlockHeader] {
    _from: [Function: _from],
    _fromObject: [Function: _fromObject],
    fromObject: [Function: fromObject],
    fromRawBlock: [Function: fromRawBlock],
    fromBuffer: [Function: fromBuffer],
    fromString: [Function: fromString],
    _fromBufferReader: [Function: _fromBufferReader],
    fromBufferReader: [Function: fromBufferReader],
    Constants: { START_OF_HEADER: 8, MAX_TIME_OFFSET: 7200, LARGEST_HASH: [BN] }
  },
  headers: []
}
{"peer":"127.0.0.1:8342","chain":"BTC","network":"mainnet","count":0,"level":"warn","message":"peerheaders message received"}
{"message":"2023-02-08 11:53:15.288 GMT+3 | Sync completed | Chain: BTC | Network: mainnet","level":"info"}
{"message":"2023-02-08 11:53:34.824 GMT+3 | Connected to peer: 127.0.0.1:8332  | Chain: BTC | Network: testnet","level":"info"}
{"message":"2023-02-08 11:54:04.852 GMT+3 | Not connected to peer: 127.0.0.1:8332  | Chain: BTC | Network: testnet","level":"warn"}
{"message":"2023-02-08 11:54:39.826 GMT+3 | Connected to peer: 127.0.0.1:8332  | Chain: BTC | Network: testnet","level":"info"}

is there any resource or complete documentation which explains the whole system and how it works?

kajoseph commented 1 year ago

You are connected to 8342 (congrats!) but you still have a configuration in bitcore.config.json for 8332. Remove that config object (or set disabled: true) and it'll remove the "connected"..."not connected"..."connected" messages.

The "another node is the primary syncing node" message means either you have multiple instances of bitcore running and the other one is the syncing node that's writing to the db, OR most likely you didn't shut down bitcore cleanly. If the later, it'll fix itself eventually (which it did in your log above) or you can manually clear the syncing node field in the state mongo collection.

ASHKARAN commented 1 year ago

thanks for your helps I removed the object from state collection and the another node is the primary syncing node error is gone after that i tried to remove BTC mainnet 8342 from my bitcore-config.json

Here is my bitcore-config.json

{
  "bitcoreNode": {
    "modules": ["./bitcoin", "./bitcoin-cash", "./ethereum", "./matic", "./ripple"],
    "services": {
      "api": {
        "wallets": {
          "allowCreationBeforeCompleteSync": true
        }
      }
    },
    "chains": {
      "BTC": {
        "testnet": {
          "chainSource": "p2p",
          "trustedPeers": [
            {
              "host": "localhost",
              "port": 8332
            }
          ],
          "rpc": {
            "host": "localhost",
            "port": 8333,
            "username": "xxxxx",
            "password": "xxxxx"
          }
        }
      }
    }
  }
}

but still i see connected not connected logs

{"message":"Started Socket Service","level":"info"}
{"message":"2023-02-09 10:44:35.194 GMT+3 | Not connected to peer: 127.0.0.1:8332  | Chain: BTC | Network: testnet","level":"warn"}
{"message":"2023-02-09 10:45:09.970 GMT+3 | Connected to peer: 127.0.0.1:8332  | Chain: BTC | Network: testnet","level":"info"}
{"message":"2023-02-09 10:45:40.000 GMT+3 | Not connected to peer: 127.0.0.1:8332  | Chain: BTC | Network: testnet","level":"warn"}
{"message":"2023-02-09 10:46:14.972 GMT+3 | Connected to peer: 127.0.0.1:8332  | Chain: BTC | Network: testnet","level":"info"}

Of course I'm missing something but unfortunately i couldn't find it yet