정보보안/Blockchain

Bitcoin Network

yeseong9769 2024. 8. 19. 18:32

Bitcoin Communication Methods

  • Client-Bitcoin Network (Wallet 등): HTTP 기반의 JSON RPC 방식으로 통신, Client-Server 구조
  • Node-Node: 네트워크 노드들이 정보를 효율적으로 전파하도록 TCP 기반의 Gossip Protocol을 사용, 양방향 통신

 

Client Communication Example

1. Bitcoind와 원격 연결(Port 8223)
2. 블록체인 데이터 조회 ex) getblock, gettransaction
3. Wallet 관리 ex) ImportPrivKey, GetBalance
4. Transaction 생성 ex) sendtoaddress, signrawtransactionwitwallet

 

Bitcoin Node Commuication

Initial Node Connection

Peer Discovery

  1. Bitcoin Core Client에 포함 되어 있는 dns seeds로 부터 랜덤으로 선택된 노드들의 주소를 찾음
  2. 해당 주소로 연결 시도 (version/verack)
  3. 실패 시 Bitcoin Source Code내에 하드 코딩된 IP와 Port로 연결

 

Connecting to Peers

  1. 위 과정을 통해 알아낸 노드로 연결하기 위해 "version" message를 상대 노드에게 보냄. "version" message는 버전 정보, 블록, 현재시간이 담겨있음.
  2. "version" message를 받은 노드는 자신의 "version" message를 전달함
  3. 서로 message를 받은 경우 두 개의 노드는 서로에게 "verack" message를 전송하고 연결이 성립되었음을 알림
  4. 연결이 성립한 경우, 추가적인 다른 노드들을 알아내기 위해 "addr" message를 전송함

 

Initial Block Download

  1. Ping/Pong: Network에 Blockchain 다운 받기 위해 연결된 다른 노드들에게 Ping 전송
  2. Header Download: 80bytes의 작은 Block Header 들을 먼저 받음 (getheaders / headers)
  3. Block Download: Genesis Block + 1 부터 시작하여 최근 Block까지 Transaction을 포함한 전체 데이터를 다운로드 (getdata)
  4. Block Validation: Genesis Block부터 Block을 받을 때마나다 Rule에 따라 검증 진행

※ Lightweight Node는 2번까지 진행, Full Node는 4번까지 진행

※ Bitcoin Core (<= 0.9.3)은 Blocks-First 방식을 통해 Initial Block Download(IBD)를 진행