-
Notifications
You must be signed in to change notification settings - Fork 0
Blockchain Network
jazmin ferreiro edited this page Mar 28, 2020
·
2 revisions
It use the Bitcoin broadcast network to propagate transactions and blocks. All communications are done over TCP (ipv6 and tor is supported). The Header structure is:
name | description | size | data type |
---|---|---|---|
version | Block version information | 4 bits | int32 |
prev_block | The hash value of the previous block this particular block references | 32 bits | char[32] |
merkle_root | The reference to a Merkle tree collection which is a hash of all transactions related to this block | 32 bytes | char[32] |
timestamp | A timestamp recording when this block was created | 4 bits | int32 |
bits | The calculated difficulty target being used for this block | 4 bits | uint32 |
nonce | The nonce used to generate this block… to allow variations of the header and compute different hashes | 4 bits | uint32 |
txn_count | Number of transaction entries, this value is always 0 | 1+ bits | var_int |
Inside the payload there is a message with the following structure
name | description | size | data type |
---|---|---|---|
magic | Magic value indicating message origin network, and used to seek to next message when stream state is unknown | 4 | uint32 |
command | ASCII string identifying the packet content, NULL padded (non-NULL padding results in packet rejected) | 12 | char[12] |
lengt | Length of payload in number of bytes | 4 | uint32 |
checksum | First 4 bytes of sha256(sha256(payload)) | 4 | uint32 |
payload | The actual data | ? | char[] |
The possible commands messages are:
- version - Information about program version and block count. Exchanged when first connecting.
- verack - Sent in response to a version message to acknowledge that we are willing to connect.
- addr - List of one or more IP addresses and ports.
- inv - "I have these blocks/transactions: ..." Normally sent only when a new block or transaction is being relayed. This is only a list, not the actual data.
- getdata - Request a single block or transaction by hash.
- getblocks - Request an inv of all blocks in a range.
- getheaders - Request a headers message containing all block headers in a range.
- tx - Send a transaction. This is sent only in response to a getdata request.
- block - Send a block. This is sent only in response to a getdata request.
- headers - Send up to 2,000 block headers. Non-generators can download the headers of blocks instead of entire blocks.
- getaddr - Request an addr message containing a bunch of known-active peers (for bootstrapping).
- submitorder, checkorder, and reply - Used when performing an IP transaction.
- alert - Send a network alert.
- ping - Does nothing. Used to check that the connection is still online. A TCP error will occur if the connection has died.