Hey SN!
Yesterday, I experimented a bit with the bitcoin protocol and thought it would be cool to speak the bitcoin protocol with my node.
A node immediately advertises it's version when it creates an outgoing connection.
See:
When a node creates an outgoing connection, it will immediately advertise its version. The remote node will respond with its version. No further communication is possible until both peers have exchanged their version.
Therefore, I used the version payload provided in the wiki
0000 f9 be b4 d9 76 65 72 73 69 6f 6e 00 00 00 00 00 ....version..... 0010 64 00 00 00 35 8d 49 32 62 ea 00 00 01 00 00 00 d...5.I2b....... 0020 00 00 00 00 11 b2 d0 50 00 00 00 00 01 00 00 00 .......P........ 0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ................ 0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 0050 00 00 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 ................ 0060 3b 2e b3 5d 8c e6 17 65 0f 2f 53 61 74 6f 73 68 ;..]...e./Satosh 0070 69 3a 30 2e 37 2e 32 2f c0 3e 03 00 i:0.7.2/.>..
and sent it to my node using
$ xxd -r version_001.txt | nc 192.168.178.55 8333 -o version_001_recv.txt > /dev/null
(you can test this out yourself by copying the above message into a file version_001.txt and using the command with the IP and port replaced)
Response:
"version" message:
0000: f9be b4d9 7665 7273 696f 6e00 0000 0000 ....version..... 0010: 6600 0000 bdca d498 8011 0100 0d04 0000 f............... 0020: 0000 0000 5083 5063 0000 0000 0000 0000 ....P.Pc........ 0030: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0040: 0000 0000 0000 0d04 0000 0000 0000 0000 ................ 0050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0060: ff0a e912 84bd d3e2 102f 5361 746f 7368 ........./Satosh 0070: 693a 3233 2e30 2e30 2f8e 960b 0001 i:23.0.0/.....
"verack" message:
0000: f9be b4d9 7665 7261 636b 0000 0000 0000 ....verack...... 0010: 0000 0000 5df6 e0e2 ....]...
"alert" message:
0000: f9be b4d9 616c 6572 7400 0000 0000 0000 ....alert....... 0010: a800 0000 1bf9 aaea 6001 0000 0000 0000 ........`....... 0020: 0000 0000 00ff ffff 7f00 0000 00ff ffff ................ 0030: 7ffe ffff 7f01 ffff ff7f 0000 0000 ffff ................ 0040: ff7f 00ff ffff 7f00 2f55 5247 454e 543a ......../URGENT: 0050: 2041 6c65 7274 206b 6579 2063 6f6d 7072 Alert key compr 0060: 6f6d 6973 6564 2c20 7570 6772 6164 6520 omised, upgrade 0070: 7265 7175 6972 6564 0046 3044 0220 653f required.F0D. e? 0080: ebd6 410f 470f 6bae 11ca d19c 4841 3bec ..A.G.k.....HA;. 0090: b1ac 2c17 f908 fd0f d53b dc3a bd52 0220 ..,......;.:.R. 00a0: 6d0e 9c96 fe88 d4a0 f01e d9de dae2 b6f9 m............... 00b0: e00d a94c ad0f ecaa e66e cf68 9bf7 1b50 ...L.....n.h...P
Now I was wondering if there already exists a tool where sending such manual messages to your node is possible; similar to Swagger which is limited to REST APIs.
The tool could visualize the response data (similar to the JWT debugger) to help people learn about the bitcoin protocol who are interested in it.
If there is none, would you be interested in one?
May not be of interest, but I remember being shocked to see that there was actually a Wireshark parser of Bitcoin network traffic even as early as like 2014-15.
So: there's the network level traffic in bitcoin (think like the VER, VERACK, TX messages and whatnot that are gossiped between peers), and then there's the RPC-API that a bitcoind node offers, which would be more analogous/a better fit for what is usually done with Swagger.
Anyway, I think I get what you're asking; the wireshark parser doesn't quite fit since it's not designed for education, nor is it interactively participating. I'm not sure if any such thing exists, like 'a toy node that can just talk the protocol but isn't a real node' (or more exactly: I bet it does exist but not sure if anyone's published such a thing).
reply
Thanks for replying.
but I remember being shocked to see that there was actually a Wireshark parser of Bitcoin network traffic even as early as like 2014-15.
Haha, yeah, me too even though I noticed it just a few months ago. Shows that the bitcoin protocol is indeed very relevant even though most people don't care about bitcoin (yet) :)
then there's the RPC-API that a bitcoind node offers, which would be more analogous/a better fit for what is usually done with Swagger.
Yes, but I am not interested in the RPC-API. I want to see the raw bytes and not some frontend showing me already parsed JSON. I want to see the data resulting in this JSON to get a deep understanding.
Anyway, I think I get what you're asking; the wireshark parser doesn't quite fit since it's not designed for education, nor is it interactively participating.
Yeah, that was also my experience.
I will see if I can get a quick PoC of this going in the next days :)
reply
I will see if I can get a quick PoC of this going in the next days :)
I think it would be a valuable learning tool to be able to communicate directly with a node like this in a human-readable way. Great idea!
It is almost as if what you want is a REPL, in some programming language that behaves somewhat like telnet. When it first loads up you will be "greeted" with a version message, and your job now is to reply with a message of your own.
Because this whole thing is happening in a REPL, you should be able to define functions to make your life easier when constructing/parsing messages, but initially there would be only a small library of simple functions and datatypes available to you.
You can then build up your own library of functions and datatypes.
The whole thing could be turned into a game (or contest?). An initial goal of the game is to not be banned by the node. The next goal might be to ask for data, and eventually more complex goals could be achieved including constructing and broadcasting a transaction.
It is fun to think about. Though I wonder how many people would actually play such a game?
Maybe if the node paid you some sats as you progress, people would be interested?
reply
I would play such a game!
The comparison with a REPL sounds very interesting, thank you!
However, I think making a game or contest with sats involved would lead to bad incentives. Preventing that someone just pipes the output of the other node to a node of their own (MITM) sounds hard.
So I think this would only be useful for education. But should be enough :)
Thanks for your reply! Very inspiring :)
reply