ReasonJun

Bitcoin : P2P Network 본문

Blockchain/Bitcoin

Bitcoin : P2P Network

ReasonJun 2023. 9. 17. 01:53
728x90

The reason why Gossip Protocol (TCP) is used is that when a transaction occurs, it must be able to push even if there is no request.

 

When a transaction occurs in one node, the information must be spread to other nodes as quickly and widely as possible. At this time, whether each transaction is correct is determined by the basic rules and consensus algorithm of the Bitcoin network.

 

 

Join a network

The new node to be newly joined accesses the 6 domains and receives an address request. (version information + random value)

Domains transmit the addresses of trusted nodes to the new node. (version arc information + received random value)

The newly joined node attempts to connect to the received address.

Here, these domains (DNS Nodes) are somewhat centralized. For this reason, the Bitcoin network is set up to automatically access the source code where trusted addresses are stored if any of the above domains dies. (Addresses are continuously updated.)

 

Block Sync

  1. Ping / Pong
  2. Header Download
  3. Block Download
  4. Block Validation

Block Varification

  1. Receive new blocks
  2. Block structure matching 
  3. Recalculation
  4. Block timestamp < now() + 2 hours
  5. Block Size < 1MB
  6. Coinbase Transaction Check
  7. Transaction Check
  8. Mempool Update
  9. LevelDB Insert New Block
  10. Block propagation

Block structure matching 

Verifies whether each block has the data it should have. Verifying that a block in the Bitcoin blockchain is correct.

 

Recalculation

Check if the block is formed through normal operation. By hashing the nonce value of the header (found through proof-of-work) and the header value, it is checked whether the received hash value is correct. (Check block forgery)

 

Block timestamp < now() + 2hours 

Bitcoin has two mechanisms to protect against miners manipulating the timestamp

 

Future Block Time Rule – The timestamp cannot be more than 2 hours in the future based on the MAX_FUTURE_BLOCK_TIME constant, relative to the median time from the node’s peers. The maximum allowed gap between the time provided by the nodes and the local system clock is 90 minutes, another safeguard. It should be noted that unlike the MPT rule above, this is not a full consensus rule. Blocks with a timestamp too far in the future are not invalid, they can become valid as time moves forwards.

Bitcoin’s Block Timestamp Protection Rules | BitMEX Blog

 

Bitcoin’s Block Timestamp Protection Rules | BitMEX Blog

Abstract: We examine two of Bitcoin’s little-known rules, designed to stop nefarious miners from manipulating the block timestamps and achieving unfairly high mining rewards. We discuss why constants such as the two-hour MAX_FUTURE_BLOCK_TIME value may h

blog.bitmex.com

 

Block Size < 1MB 

Check the block size according to the rules. Up to this point, only block headers are used.

 

Coinbase Transaction Check 

Transaction information about how much the miner will receive is included. Check whether the mining has proceeded normally and whether the fee is appropriate.

 

Transaction Check

Verifies the transaction included in the block.

 

Mempool Update / LevelDB Insert New Block

The node does not store the blockchain in the form of a file, but in a DB called level DB.

 

 

Transaction Propagation

  1. Transactions are propagated from other nodes.
  2. Check whether the transaction has already been received.
  3. If there is none, it is propagated to other nodes. => Deliver a new Transaction txid.
  4. If there is no counterpart node, getdata is requested. => MSG_TX and txid are received.
  5. Delivers a new transaction.
  6. Executes until it is delivered to all connected nodes.

Transaction Varification 

  1. New Transaction received
  2. Check Transaction structural match
  3. In, out List check for existence
  4. Transaction Size < 1MB
  5. Output Value < 2100만 BTC
  6. Mempool check for existence
  7. Block check for existence
  8. Input Check(Double Spending)
  9. Input Check(Orphan Tx)
  10. Input Check (Coinbase)
  11. Input Check (Not UTXO)
  12. Input > Output value
  13. Check Input Script
  14. Add Mempool
  15. Transaction Propagation

Mempool

This is where received but not yet processed transactions are stored. In order to prevent multiple transaction processing, the existence of transactions in the mempool is checked.

 

Block check for existence

Avoid double spending. It is to check approved transactions.

 

Input Check (Orphan Tx)

Check if it has been processed and included in a block, but the block itself has ended unacknowledged.

 

Input Check (Coinbase)

In the case of miner reward transaction, it is created and set to be used only after the 100th block. So, if the 100th block has not been formed and it is a transaction to be used, it is deleted.

 

Input Check(Not UTXO)

Check if it is UTXO.

 

Input > Output value

Prevents 1BTC from becoming 2BTC.

 

Check Input Script

Check that the signature was done correctly.

 

Add Mempool

Notifies that it is a normal transaction that has not yet been processed by storing it in the mempool.

 

Block Propagation

  1. Ping
  2. The received Block Header is delivered.
  3. For blocks that have not yet been delivered, both headers and getdata are requested. => In headers, I send the latest Block Header List I have.
  4. The new block and the blocks in between are delivered to the node

ex) 

If A node has only the 99th block according to the network situation, but B node sends information about the 105th block, A node sends getdata with its own 99th block information.

Then, information about blocks 99 to 105 is transmitted.

728x90
Comments