搭建开源BitCoin节点,完成实验内容。
Requirements
In this lab we are going to get an old block from the BitCoin block chain and demonstrate how any changes would be caught by the BitCoin network.
- Connect to a peer in the P2P BitCoin network and get the block number that corresponds to your SU
- ID number (your number modulo 650000).
- Display the transactions in the block.
- Have your program manipulate one of the transactions in the block to change its output account, then fix up the block to correctly represent this modified data (fix the merkle-tree hashes, etc.).
- Then show with a program-generated report how the hash of the block has changed and the ways in which this block would be rejected by peers in the network.
Program written in Python 3 with no use of publicly available BitCoin libraries (except as shown below). - Use TCP/IP to communicate with a full node in the network.
- Submit the program in the usual way on cs1 , all in one file,
Start by reading about blockchains in general, the original paper the developer documentation (https://bitcoin.org/bitcoin.pdf) , and (https://bitcoin.org/en/developer-reference) .
Getting Connected
To get a list of bitcoin nodes, use makeseeds (https://github.com/bitcoin/bitcoin/tree/master/contrib/seeds) . You may need to install dnspython for this to work (
pip3 curl -s HTTP://BITCOIN.SIPA.BE/SEEDS.TXT.GZ | gzip -dc > SEEDS_MAIN.TXT
python3 -W IGNORE::DEPRECATIONWARNING MAKESEEDS.PY < SEEDS_MAIN.TXT > NODES_MAIN.TXT
[NOTE: On Windows, the command is usually python and on a Mac python3 . The -W directive is to get around their use of a deprecated method in the DNS resolver library. The process can take 5 minutes or more.]
Pick nodes from that are not onion nodes (https://en.wikipedia.org/wiki/Onion_routing) and just choose one at random that is currently working. You may have to try several before you get a working node. You can leave the host you are using hard-coded in your submitted program.
Guidance
Here is the beginning dialog I recorded with one of the BitCoin peers:
sending MESSAGE
(110) f9beb4d976657273696f6e0000000000560000003b9840b27f11010000000000000000007833d25d0000000001000000000000000000000000000000...
HEADER
------------------------------------------------------
f9beb4d9 MAGIC
76657273696f6e0000000000 COMMAND: version
56000000 PAYLOAD size: 86
3b9840b2 checksum (verified)
VERSION
------------------------------------------------------
7f110100 version 70015
0000000000000000 my services
7833d25d00000000 epoch time Mon, 18 Nov 2019 06:00:24 GMT
0100000000000000 your services
00000000000000000000ffff5c3fc0d1 your host 92.63.192.209
8d20 your port 8333
0000000000000000 my services (AGAIN)
00000000000000000000FFFF0A000048 my host 10.0.0.72
9ee8 my port 59550
0000000000000000 nonce
00 user AGENT size 0
user AGENT ''
00000000 START height 0
00 RELAY FALSE
received MESSAGE
(126) f9beb4d976657273696f6e000000000066000000c6d922107f1101000d040000000000007833d25d0000000000000000000000000000000000000000...
HEADER
------------------------------------------------------
f9beb4d9 MAGIC
76657273696f6e0000000000 COMMAND: version
66000000 PAYLOAD size: 102
c6d92210 checksum (verified)
VERSION
------------------------------------------------------
7f110100 version 70015
0d04000000000000 my services
7833d25d00000000 epoch time Mon, 18 Nov 2019 06:00:24 GMT
0000000000000000 your services
00000000000000000000ffff4961e4ed your host 73.97.228.237
e89e your port 40680
0d04000000000000 my services (AGAIN)
00000000000000000000000000000000 my host 0.0.0.0
0000 my port 0
C1F685008A419236 nonce
10 user AGENT size 16
2F5361746F7368693A302E31382E302F user AGENT '/SATOSHI:0.18.0/'
A4380900 START height 604324
01 RELAY True