Initial connection management #5299

issue ghost openend this issue on November 18, 2014
  1. ghost commented at 6:40 am on November 18, 2014: none
    Pointing two peers at each other via the “addnode” / “connect” args in bitcoin.conf on init results in multiple (3 as observed in getpeerinfo on regtest) connections (on different ports) and, hence, chatty traffic (say inventory exchange) when running off of the current master. Connecting via the “addnode” RPC call after a successful initialization of both peers corrects this.
  2. laanwj added the label Bug on Dec 5, 2014
  3. laanwj added the label Priority Low on Dec 5, 2014
  4. gmaxwell commented at 10:23 am on April 1, 2015: contributor
    I’m not clear on what problem is being described here. How is connecting via addnode different?
  5. ghost commented at 0:14 am on April 2, 2015: none

    Scenario 1:

    Set the appropriate “addnode” / “connect” args in bitcoin.conf for both nodes, pointing them at each other as described above. Fire them up. Observe the number of peers. Result incongruous (3).

    Scenario 2:

    Fire both nodes up, without setting the “addnode” / “connect” args in bitcoin.conf. Connect Node A to Node B, or vice versā, via the addnode CLI command. Observe the number of peers. Result as expected (1).

  6. gmaxwell commented at 2:27 am on April 2, 2015: contributor
    Thanks. How can there be a non-even number of connections with two nodes? Can you give me the (anonymized) getpeerinfo from each?
  7. ghost commented at 3:17 am on April 2, 2015: none

    That is the question of course. Haven’t stepped through GDB yet.

    Summary: Regtest. NODEB fired up first, NODEC follows. Common IP, separate ports (PORTB, PORTC). Connections 3 on both. If one experiments with the settings, and the startup sequenece, a wide range of peer counts is observed (1,2,3).

    Requested (pseudo-cleaned up & running off of the latest master 4/1/2015, leaving the timestamps untouched) info: NODE B bitcoin.conf addnode=IP1:PORTC connect=IP1:PORTC

    $ ./bitcoin-cli getinfo { “version” : 109900, “protocolversion” : 70002, “walletversion” : 60000, “balance” : 1000.00000000, “blocks” : 937, “timeoffset” : 0, “connections” : 3, “proxy” : “”, “difficulty” : 0.00000000, “testnet” : false, “keypoololdest” : 1416286280, “keypoolsize” : 101, “paytxfee” : 0.00000000, “relayfee” : 0.00001000, “errors” : “This is a pre-release test build - use at your own risk - do not use for mining or merchant applications” } $ ./bitcoin-cli getpeerinfo [ { “id” : 1, “addr” : “IP1:PORT1”, “services” : “0000000000000001”, “lastsend” : 1427943077, “lastrecv” : 1427943077, “bytessent” : 1022, “bytesrecv” : 1046, “conntime” : 1427943077, “timeoffset” : 0, “pingtime” : 0.05142700, “version” : 70002, “subver” : “/Satoshi:0.10.99/”, “inbound” : true, “startingheight” : 937, “banscore” : 0, “synced_headers” : 937, “synced_blocks” : 937, “inflight” : [ ], “whitelisted” : false }, { “id” : 2, “addr” : “IP1:PORT1+1”, “services” : “0000000000000001”, “lastsend” : 1427943077, “lastrecv” : 1427943077, “bytessent” : 215, “bytesrecv” : 239, “conntime” : 1427943077, “timeoffset” : 0, “pingtime” : 0.05049700, “version” : 70002, “subver” : “/Satoshi:0.10.99/”, “inbound” : true, “startingheight” : 937, “banscore” : 0, “synced_headers” : -1, “synced_blocks” : -1, “inflight” : [ ], “whitelisted” : false }, { “id” : 3, “addr” : “IP1:PORTC”, “services” : “0000000000000001”, “lastsend” : 1427943077, “lastrecv” : 1427943077, “bytessent” : 239, “bytesrecv” : 215, “conntime” : 1427943077, “timeoffset” : 0, “pingtime” : 0.05015800, “version” : 70002, “subver” : “/Satoshi:0.10.99/”, “inbound” : false, “startingheight” : 937, “banscore” : 0, “synced_headers” : -1, “synced_blocks” : -1, “inflight” : [ ], “whitelisted” : false } ]


    NODE C bitcoin.conf: addnode=IP1:PORTB connect=IP1:PORTB

    $ ./bitcoin-cli getinfo { “version” : 109900, “protocolversion” : 70002, “walletversion” : 60000, “balance” : 2000.00000000, “blocks” : 937, “timeoffset” : 0, “connections” : 3, “proxy” : “”, “difficulty” : 0.00000000, “testnet” : false, “keypoololdest” : 1416201679, “keypoolsize” : 101, “paytxfee” : 0.00000000, “relayfee” : 0.00001000, “errors” : “This is a pre-release test build - use at your own risk - do not use for mining or merchant applications” } $ ./bitcoin-cli getpeerinfo [ { “id” : 1, “addr” : “IP1:PORTB”, “services” : “0000000000000001”, “lastsend” : 1427943077, “lastrecv” : 1427943077, “bytessent” : 1046, “bytesrecv” : 1022, “conntime” : 1427943077, “timeoffset” : 0, “pingtime” : 0.05212700, “version” : 70002, “subver” : “/Satoshi:0.10.99/”, “inbound” : false, “startingheight” : 937, “banscore” : 0, “synced_headers” : 937, “synced_blocks” : 937, “inflight” : [ ], “whitelisted” : false }, { “id” : 2, “addr” : “IP1:PORTB”, “services” : “0000000000000001”, “lastsend” : 1427943077, “lastrecv” : 1427943077, “bytessent” : 239, “bytesrecv” : 215, “conntime” : 1427943077, “timeoffset” : 0, “pingtime” : 0.05145200, “version” : 70002, “subver” : “/Satoshi:0.10.99/”, “inbound” : false, “startingheight” : 937, “banscore” : 0, “synced_headers” : -1, “synced_blocks” : -1, “inflight” : [ ], “whitelisted” : false }, { “id” : 3, “addr” : “IP1:PORT2”, “services” : “0000000000000001”, “lastsend” : 1427943077, “lastrecv” : 1427943077, “bytessent” : 215, “bytesrecv” : 239, “conntime” : 1427943077, “timeoffset” : 0, “pingtime” : 0.05165500, “version” : 70002, “subver” : “/Satoshi:0.10.99/”, “inbound” : true, “startingheight” : 937, “banscore” : 0, “synced_headers” : -1, “synced_blocks” : -1, “inflight” : [ ], “whitelisted” : false } ]

  8. laanwj removed the label Priority Low on Dec 6, 2017
  9. MarcoFalke added the label P2P on Apr 24, 2020
  10. kouloumos commented at 3:10 pm on July 28, 2022: member

    The initial reporting of this issue makes it seem like the use of addnode or connect as args in bitcoin.conf results to this behaviour. What’s shown later is that this multiple-connections from/to the same peer behavior occurs when addnode and connect are used together in the configuration.

    I’ve tried different scenarios of options (combinations of addnode/connect in bitcoin.conf and connecting via the “addnode” RPC call) on regtest and I was only able to reproduce this behavior with 2 peers having their peer’s address in both addnode and connectargs. (on current master branch)

    The observed behavior (using getpeerinfo RPC) is 3 connections on each node. The startup sequence defines the type of connections. The node that will start second will create 2 outbound connections to the first node.

    ➤ How to reproduce with 2 peers on regtest:

    • Create directories and bitcoin.conf files

      0mkdir -p /tmp/node1-datadir
      1mkdir -p /tmp/node2-datadir
      
       0# node1 bitcoin.conf
       1regtest=1
       2listen=1 # default is 0 when using `connect`
       3[regtest]
       4connect=127.0.0.1:18400
       5addnode=127.0.0.1:18400
       6
       7# node2 bitcoin.conf
       8regtest=1
       9listen=1 
      10[regtest]
      11connect=127.0.0.1:18445
      12addnode=127.0.0.1:18445
      
    • Start nodes

      0# terminal1
      1src/bitcoind -datadir=/tmp/node1-datadir
      2
      3# terminal2 (non-default ports)
      4src/bitcoind -datadir=/tmp/node2-datadir -rpcport=18300 -port=18400
      
    • Observe connections using bitcoin-cli.

      0src/bitcoin-cli -datadir=/tmp/node1-datadir getpeerinfo
      
        0[
        1  {
        2    "id": 0,
        3    "addr": "127.0.0.1:50176",
        4    "addrbind": "127.0.0.1:18445",
        5    "network": "onion",
        6    "services": "0000000000000409",
        7    "servicesnames": [
        8      "NETWORK",
        9      "WITNESS",
       10      "NETWORK_LIMITED"
       11    ],
       12    "lastsend": 1659017341,
       13    "lastrecv": 1659017341,
       14    "last_transaction": 0,
       15    "last_block": 0,
       16    "bytessent": 470,
       17    "bytesrecv": 494,
       18    "conntime": 1659017341,
       19    "timeoffset": 0,
       20    "pingtime": 0.001835,
       21    "minping": 0.001835,
       22    "version": 70016,
       23    "subver": "/Satoshi:23.99.0/",
       24    "inbound": true,
       25    "bip152_hb_to": false,
       26    "bip152_hb_from": false,
       27    "startingheight": 0,
       28    "synced_headers": -1,
       29    "synced_blocks": -1,
       30    "inflight": [
       31    ],
       32    "relaytxes": true,
       33    "minfeefilter": 0.09170997,
       34    "addr_relay_enabled": true,
       35    "addr_processed": 0,
       36    "addr_rate_limited": 0,
       37    "permissions": [
       38    ],
       39    "bytessent_per_msg": {
       40      "feefilter": 32,
       41      "getheaders": 93,
       42      "headers": 25,
       43      "ping": 32,
       44      "pong": 32,
       45      "sendaddrv2": 24,
       46      "sendcmpct": 33,
       47      "sendheaders": 24,
       48      "verack": 24,
       49      "version": 127,
       50      "wtxidrelay": 24
       51    },
       52    "bytesrecv_per_msg": {
       53      "feefilter": 32,
       54      "getaddr": 24,
       55      "getheaders": 93,
       56      "headers": 25,
       57      "ping": 32,
       58      "pong": 32,
       59      "sendaddrv2": 24,
       60      "sendcmpct": 33,
       61      "sendheaders": 24,
       62      "verack": 24,
       63      "version": 127,
       64      "wtxidrelay": 24
       65    },
       66    "connection_type": "inbound"
       67  },
       68  {
       69    "id": 1,
       70    "addr": "127.0.0.1:50177",
       71    "addrbind": "127.0.0.1:18445",
       72    "network": "onion",
       73    "services": "0000000000000409",
       74    "servicesnames": [
       75      "NETWORK",
       76      "WITNESS",
       77      "NETWORK_LIMITED"
       78    ],
       79    "lastsend": 1659017341,
       80    "lastrecv": 1659017341,
       81    "last_transaction": 0,
       82    "last_block": 0,
       83    "bytessent": 352,
       84    "bytesrecv": 376,
       85    "conntime": 1659017341,
       86    "timeoffset": 0,
       87    "pingtime": 0.000515,
       88    "minping": 0.000515,
       89    "version": 70016,
       90    "subver": "/Satoshi:23.99.0/",
       91    "inbound": true,
       92    "bip152_hb_to": false,
       93    "bip152_hb_from": false,
       94    "startingheight": 0,
       95    "synced_headers": -1,
       96    "synced_blocks": -1,
       97    "inflight": [
       98    ],
       99    "relaytxes": true,
      100    "minfeefilter": 0.09170997,
      101    "addr_relay_enabled": true,
      102    "addr_processed": 0,
      103    "addr_rate_limited": 0,
      104    "permissions": [
      105    ],
      106    "bytessent_per_msg": {
      107      "feefilter": 32,
      108      "ping": 32,
      109      "pong": 32,
      110      "sendaddrv2": 24,
      111      "sendcmpct": 33,
      112      "sendheaders": 24,
      113      "verack": 24,
      114      "version": 127,
      115      "wtxidrelay": 24
      116    },
      117    "bytesrecv_per_msg": {
      118      "feefilter": 32,
      119      "getaddr": 24,
      120      "ping": 32,
      121      "pong": 32,
      122      "sendaddrv2": 24,
      123      "sendcmpct": 33,
      124      "sendheaders": 24,
      125      "verack": 24,
      126      "version": 127,
      127      "wtxidrelay": 24
      128    },
      129    "connection_type": "inbound"
      130  },
      131  {
      132    "id": 2,
      133    "addr": "127.0.0.1:18400",
      134    "addrbind": "127.0.0.1:50182",
      135    "network": "not_publicly_routable",
      136    "services": "0000000000000409",
      137    "servicesnames": [
      138      "NETWORK",
      139      "WITNESS",
      140      "NETWORK_LIMITED"
      141    ],
      142    "lastsend": 1659017346,
      143    "lastrecv": 1659017346,
      144    "last_transaction": 0,
      145    "last_block": 0,
      146    "bytessent": 376,
      147    "bytesrecv": 352,
      148    "conntime": 1659017346,
      149    "timeoffset": 0,
      150    "pingtime": 0.00078,
      151    "minping": 0.00078,
      152    "version": 70016,
      153    "subver": "/Satoshi:23.99.0/",
      154    "inbound": false,
      155    "bip152_hb_to": false,
      156    "bip152_hb_from": false,
      157    "startingheight": 0,
      158    "synced_headers": -1,
      159    "synced_blocks": -1,
      160    "inflight": [
      161    ],
      162    "relaytxes": true,
      163    "minfeefilter": 0.09170997,
      164    "addr_relay_enabled": true,
      165    "addr_processed": 0,
      166    "addr_rate_limited": 0,
      167    "permissions": [
      168    ],
      169    "bytessent_per_msg": {
      170      "feefilter": 32,
      171      "getaddr": 24,
      172      "ping": 32,
      173      "pong": 32,
      174      "sendaddrv2": 24,
      175      "sendcmpct": 33,
      176      "sendheaders": 24,
      177      "verack": 24,
      178      "version": 127,
      179      "wtxidrelay": 24
      180    },
      181    "bytesrecv_per_msg": {
      182      "feefilter": 32,
      183      "ping": 32,
      184      "pong": 32,
      185      "sendaddrv2": 24,
      186      "sendcmpct": 33,
      187      "sendheaders": 24,
      188      "verack": 24,
      189      "version": 127,
      190      "wtxidrelay": 24
      191    },
      192    "connection_type": "manual"
      193  }
      194]
      
      0src/bitcoin-cli -rpcport=18300 -datadir=/tmp/node2-datadir getpeerinfo
      
        0[
        1  {
        2    "id": 0,
        3    "addr": "127.0.0.1:18445",
        4    "addrbind": "127.0.0.1:50176",
        5    "network": "not_publicly_routable",
        6    "services": "0000000000000409",
        7    "servicesnames": [
        8      "NETWORK",
        9      "WITNESS",
       10      "NETWORK_LIMITED"
       11    ],
       12    "lastsend": 1659018421,
       13    "lastrecv": 1659018421,
       14    "last_transaction": 0,
       15    "last_block": 0,
       16    "bytessent": 1070,
       17    "bytesrecv": 1046,
       18    "conntime": 1659017341,
       19    "timeoffset": 0,
       20    "pingtime": 0.000634,
       21    "minping": 0.000252,
       22    "version": 70016,
       23    "subver": "/Satoshi:23.99.0/",
       24    "inbound": false,
       25    "bip152_hb_to": false,
       26    "bip152_hb_from": false,
       27    "startingheight": 0,
       28    "synced_headers": -1,
       29    "synced_blocks": -1,
       30    "inflight": [
       31    ],
       32    "relaytxes": true,
       33    "minfeefilter": 0.09170997,
       34    "addr_relay_enabled": true,
       35    "addr_processed": 0,
       36    "addr_rate_limited": 0,
       37    "permissions": [
       38    ],
       39    "bytessent_per_msg": {
       40      "feefilter": 32,
       41      "getaddr": 24,
       42      "getheaders": 93,
       43      "headers": 25,
       44      "ping": 320,
       45      "pong": 320,
       46      "sendaddrv2": 24,
       47      "sendcmpct": 33,
       48      "sendheaders": 24,
       49      "verack": 24,
       50      "version": 127,
       51      "wtxidrelay": 24
       52    },
       53    "bytesrecv_per_msg": {
       54      "feefilter": 32,
       55      "getheaders": 93,
       56      "headers": 25,
       57      "ping": 320,
       58      "pong": 320,
       59      "sendaddrv2": 24,
       60      "sendcmpct": 33,
       61      "sendheaders": 24,
       62      "verack": 24,
       63      "version": 127,
       64      "wtxidrelay": 24
       65    },
       66    "connection_type": "manual"
       67  },
       68  {
       69    "id": 1,
       70    "addr": "127.0.0.1:18445",
       71    "addrbind": "127.0.0.1:50177",
       72    "network": "not_publicly_routable",
       73    "services": "0000000000000409",
       74    "servicesnames": [
       75      "NETWORK",
       76      "WITNESS",
       77      "NETWORK_LIMITED"
       78    ],
       79    "lastsend": 1659018421,
       80    "lastrecv": 1659018421,
       81    "last_transaction": 0,
       82    "last_block": 0,
       83    "bytessent": 952,
       84    "bytesrecv": 928,
       85    "conntime": 1659017341,
       86    "timeoffset": 0,
       87    "pingtime": 0.000401,
       88    "minping": 0.000222,
       89    "version": 70016,
       90    "subver": "/Satoshi:23.99.0/",
       91    "inbound": false,
       92    "bip152_hb_to": false,
       93    "bip152_hb_from": false,
       94    "startingheight": 0,
       95    "synced_headers": -1,
       96    "synced_blocks": -1,
       97    "inflight": [
       98    ],
       99    "relaytxes": true,
      100    "minfeefilter": 0.09170997,
      101    "addr_relay_enabled": true,
      102    "addr_processed": 0,
      103    "addr_rate_limited": 0,
      104    "permissions": [
      105    ],
      106    "bytessent_per_msg": {
      107      "feefilter": 32,
      108      "getaddr": 24,
      109      "ping": 320,
      110      "pong": 320,
      111      "sendaddrv2": 24,
      112      "sendcmpct": 33,
      113      "sendheaders": 24,
      114      "verack": 24,
      115      "version": 127,
      116      "wtxidrelay": 24
      117    },
      118    "bytesrecv_per_msg": {
      119      "feefilter": 32,
      120      "ping": 320,
      121      "pong": 320,
      122      "sendaddrv2": 24,
      123      "sendcmpct": 33,
      124      "sendheaders": 24,
      125      "verack": 24,
      126      "version": 127,
      127      "wtxidrelay": 24
      128    },
      129    "connection_type": "manual"
      130  },
      131  {
      132    "id": 2,
      133    "addr": "127.0.0.1:50182",
      134    "addrbind": "127.0.0.1:18400",
      135    "network": "not_publicly_routable",
      136    "services": "0000000000000409",
      137    "servicesnames": [
      138      "NETWORK",
      139      "WITNESS",
      140      "NETWORK_LIMITED"
      141    ],
      142    "lastsend": 1659018427,
      143    "lastrecv": 1659018427,
      144    "last_transaction": 0,
      145    "last_block": 0,
      146    "bytessent": 928,
      147    "bytesrecv": 952,
      148    "conntime": 1659017346,
      149    "timeoffset": 0,
      150    "pingtime": 0.000166,
      151    "minping": 0.000166,
      152    "version": 70016,
      153    "subver": "/Satoshi:23.99.0/",
      154    "inbound": true,
      155    "bip152_hb_to": false,
      156    "bip152_hb_from": false,
      157    "startingheight": 0,
      158    "synced_headers": -1,
      159    "synced_blocks": -1,
      160    "inflight": [
      161    ],
      162    "relaytxes": true,
      163    "minfeefilter": 0.09170997,
      164    "addr_relay_enabled": true,
      165    "addr_processed": 0,
      166    "addr_rate_limited": 0,
      167    "permissions": [
      168    ],
      169    "bytessent_per_msg": {
      170      "feefilter": 32,
      171      "ping": 320,
      172      "pong": 320,
      173      "sendaddrv2": 24,
      174      "sendcmpct": 33,
      175      "sendheaders": 24,
      176      "verack": 24,
      177      "version": 127,
      178      "wtxidrelay": 24
      179    },
      180    "bytesrecv_per_msg": {
      181      "feefilter": 32,
      182      "getaddr": 24,
      183      "ping": 320,
      184      "pong": 320,
      185      "sendaddrv2": 24,
      186      "sendcmpct": 33,
      187      "sendheaders": 24,
      188      "verack": 24,
      189      "version": 127,
      190      "wtxidrelay": 24
      191    },
      192    "connection_type": "inbound"
      193  }
      194]
      

    I think that this mgiht be some kind of concurrency issue, as this is happening during startup initialization and a manual connection to the same peer is not allowed under any other circumstances.

  11. willcl-ark commented at 1:15 pm on November 3, 2022: member

    I wonder if it’s being added twice here:

    https://github.com/bitcoin/bitcoin/blob/c540f07ec3846b43f3af8a74820fd055ada5dfe5/src/net.cpp#L1876-L1902

    Once via m_added_nodes and once from the existing (incoming) connection in m_nodes. This might cause ThreadOpenAddedConnections() to outbound connect to it twice?

    Posting here now so I (or someone else) can investigate later…

  12. willcl-ark referenced this in commit 01cd9316f3 on Jun 2, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 18:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me