Bitcoin Forum
March 31, 2023, 09:44:00 AM *
News: Latest Bitcoin Core release: 24.0.1 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: REGTEST communication over the network protocol  (Read 128 times)
bababubu (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 5


View Profile
August 12, 2020, 03:10:48 PM
 #1

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) 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?.


1680255840
Hero Member
*
Offline Offline

Posts: 1680255840

View Profile Personal Message (Offline)

Ignore
1680255840
Reply with quote  #2

1680255840
Report to moderator
1680255840
Hero Member
*
Offline Offline

Posts: 1680255840

View Profile Personal Message (Offline)

Ignore
1680255840
Reply with quote  #2

1680255840
Report to moderator
If you see garbage posts (off-topic, trolling, spam, no point, etc.), use the "report to moderator" links. All reports are investigated, though you will rarely be contacted about your reports.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
Paperweight
Jr. Member
*
Offline Offline

Activity: 41
Merit: 37



View Profile
August 12, 2020, 03:42:18 PM
 #2

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?
Coding Enthusiast
Legendary
*
Offline Offline

Activity: 1025
Merit: 2659


Bitcoin and C♯ Enthusiast


View Profile WWW
August 12, 2020, 07:46:31 PM
 #3

You can find all the "chain parameters" in 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).

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.17.0)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.24.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
bababubu (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 5


View Profile
August 13, 2020, 09:13:48 AM
 #4

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
Paperweight
Jr. Member
*
Offline Offline

Activity: 41
Merit: 37



View Profile
August 13, 2020, 06:01:55 PM
 #5

Is there info in the debug logs? (Using -debug=1 -logips)
bababubu (OP)
Newbie
*
Offline Offline

Activity: 3
Merit: 5


View Profile
August 14, 2020, 08:06:38 AM
Merited by Paperweight (2)
 #6

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.
Coding Enthusiast
Legendary
*
Offline Offline

Activity: 1025
Merit: 2659


Bitcoin and C♯ Enthusiast


View Profile WWW
August 14, 2020, 09:29:49 AM
 #7

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

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.17.0)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.24.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!