Title: REGTEST communication over the network protocol Post by: bababubu on August 12, 2020, 03:10:48 PM Hello
Bitcoin Client Software and Version Number: Bitcoin core 0.20.0 (regtest) Operating System: Linux Mint 19.1 Description of Problem: I wrote a program which is communication over the network protocol (specified in https://en.bitcoin.it/wiki/Protocol_documentation (https://en.bitcoin.it/wiki/Protocol_documentation)) with a bitcoin node. More in detail sending getaddr messages. For the handshake at the beginning I have to send a version (and verack) message. When I run my own node on the main network everything works fine. But now I wanted to play around an use a regtest network instead. Doing my research i only found out, that i have to change the magic number. Doing this when sending a version message I get nothing back as response. Is there something else I have to consider when communication with a regtest node?. Title: Re: REGTEST communication over the network protocol Post by: Paperweight on August 12, 2020, 03:42:18 PM Remember it's port 18444, and only works with nodes that are running regtest themselves. I think regtest has a higher minimum version requirement, e.g. always SegWit?
Title: Re: REGTEST communication over the network protocol Post by: Coding Enthusiast on August 12, 2020, 07:46:31 PM You can find all the "chain parameters" in chainparams.cpp (https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp) file. The magic is called pchMessageStart and is found on lines 286-289
Is there something else I have to consider when communication with a regtest node?. I'm curious about this too. I believe you have to use each node on a different port if they are on the same machine (eg. one on 18444 another on 18445).Title: Re: REGTEST communication over the network protocol Post by: bababubu on August 13, 2020, 09:13:48 AM Remember it's port 18444, and only works with nodes that are running regtest themselves. I think regtest has a higher minimum version requirement, e.g. always SegWit? What exactly do you mean with " always SegWit"? I manged it to run a regtest network with 3 nodes. With my program I connect to one of the nodes via tcp. The problem is that when I send the version message there is no reply (should be version and verack). My version messages content is the same as in the protocol documentation. (https://en.bitcoin.it/wiki/Protocol_documentation#version) plus the header. My specific question was if there is a difference in the fields e.g. user_agent from the real network to the regtest. I already changed the magic value field (in the header). The content of the fields I sent are the following (before packing them): Header magic_number: 0xfabfb5da command: "\x00" * (12 - len('version'))) length: len(payload) checksum: e.g b'\x13+\x07\xf2' payload: version payload from below Version payload version: 70015 services: 0 timestamp: number like 1596794043 addr_recv: 127.0.0.1:18444 addr_from: 0.0.0.0:0 nonce: number like 615169444417225228 user_agent: b'\x0F/Satoshi:0.7.2/' start_height: 478000 relay: 0 And the one regtest node I want to speak to is running on 127.0.0.1:18444 Title: Re: REGTEST communication over the network protocol Post by: Paperweight on August 13, 2020, 06:01:55 PM Is there info in the debug logs? (Using -debug=1 -logips)
Title: Re: REGTEST communication over the network protocol Post by: bababubu on August 14, 2020, 08:06:38 AM Thanks that was a good tip for me.
It says: 2020-08-14T07:53:14Z Added connection to 127.0.0.1:50698 peer=10 2020-08-14T07:53:14Z connection from 127.0.0.1:50698 accepted 2020-08-14T07:53:14Z PROCESSMESSAGE: INVALID MESSAGESTART version peer=10 2020-08-14T07:53:14Z disconnecting peer=10 2020-08-14T07:53:14Z Cleared nodestate for peer=10 Getting that output I assume the protocol version is wrong. But checking with getnetworkinfo: { "version": 200000, "subversion": "/Satoshi:0.20.0/", "protocolversion": 70015, "localservices": "0000000000000409", "localservicesnames": [ "NETWORK", "WITNESS", "NETWORK_LIMITED" ], "localrelay": true, "timeoffset": 0, "networkactive": true, "connections": 0, "networks": [ { "name": "ipv4", "limited": false, "reachable": true, "proxy": "", "proxy_randomize_credentials": false }, { "name": "ipv6", "limited": false, "reachable": true, "proxy": "", "proxy_randomize_credentials": false }, { "name": "onion", "limited": true, "reachable": false, "proxy": "", "proxy_randomize_credentials": false } ], "relayfee": 0.00001000, "incrementalfee": 0.00001000, "localaddresses": [ ], "warnings": "" } The protocolversion seems the same. Title: Re: REGTEST communication over the network protocol Post by: Coding Enthusiast on August 14, 2020, 09:29:49 AM 2020-08-14T07:53:14Z PROCESSMESSAGE: INVALID MESSAGESTART version peer=10 You get this error message when the message magic (the starting 4 bytes) are not as expected. https://github.com/bitcoin/bitcoin/blob/b4d0366b47dd9b8fe29cc9a100dcdf6ca1d3cabf/src/net_processing.cpp#L3861-L3862 |