์•ˆ๋…•ํ•˜์„ธ์š”?

์ด๋ฒˆ ๊ธ€์—์„œ๋Š” ๊ทธ ๋™์•ˆ ์ง„ํ–‰ํ–ˆ๋˜ ๋ธ”๋ก์ฒด์ธ์˜ ๋Ÿฐํƒ€์ž„ ํ™˜๊ฒฝ์—์„œ ํ•ฉ์˜(Consensus) ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์ ์šฉ์‹œ๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์„ค๋ช…ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.
Fabric์€ ๊ธฐ๋ณธ์œผ๋กœ noops ๋ผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์ ์šฉ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. noops ๋Š” ํ•ฉ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ๋™์ž‘์„ ๋ฌด์‹œํ•˜๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ์œผ๋กœ ์–ด๋– ํ•œ ํ•ฉ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด ๋™์ž‘ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ ํ•ฉ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๊ฐ„๋‹จํ•œ ์„ค์ •์ด ํ•„์š”ํ•œ๋ฐ์š”, Fabric v0.6.1 ๊นŒ์ง€๋Š” ๋Œ€ํ‘œ์ ์ธ ํ•ฉ์˜ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ PBFT(Practical Byzantine Fault Tolerance)๋ฅผ ๊ตฌํ˜„ํ•˜์—ฌ ๋ฐฐํฌํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ค๋Š˜์€ ๋ธ”๋ก์ฒด์ธ ๋„คํŠธ์›Œํฌ์— PBFT ๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค. (์ง€๊ธˆ๊นŒ์ง€์˜ ๊ณผ์ •์„ ์ž˜ ๋”ฐ๋ผ์˜ค์…จ์œผ๋ฉด ์•„์ฃผ ๊ฐ„๋‹จํ•˜๊ฒŒ ์„ค์ •์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.)

Fabric v1.0 ์—์„œ๋Š” ๋งŽ์€ ๋ถ€๋ถ„ ์•„ํ‚คํ…์ฒ˜๊ฐ€ ๋ณ€๊ฒฝ์ด ๋˜๋ฉฐ, ๊ทธ์— ๋”ฐ๋ผ ๊ธฐ์กด์˜ Consensus ์˜ ๋™์ž‘ ๊ตฌ์กฐ๋„ ๋งŽ์ด ๋ณ€๊ฒฝ๋  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

1. PBFT ( Practical Byzantine Fault Tolerance)

PBFT๋Š” 1999๋…„ ๋ฏธ๊ตฌ์—˜ ์นด์ŠคํŠธ๋กœ์™€ ๋ฐ”๋ฐ”๋ผ ๋ฆฌ์Šค์ฝ”ํ”„์— ์˜ํ•ด์„œ ์†Œ๊ฐœ๋œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ๊ณ ์†์˜ ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ๊ณ ์•ˆ๋œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ์ดˆ๋‹น ์ˆ˜์ฒœ๋งŒ๊ฑด์˜ ํŠธ๋žœ์žญ์…˜์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋Š” ํŠน์ง•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์—ฌ๋Ÿฌ ๋ณต์ œ๊ฐ„์˜ state machine์„ ๋™๊ธฐํ™” ํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋กœํ† ์ฝœ
  • (N-1)/3 ์ฐธ๊ฐ€์ž๊ฐ€ ๋™์‹œ์— ์œ„์กฐํ•˜๋ ค๊ณ  ํ•ด๋„ ์œ ์ง€๋˜๋„๋ก ํ•จ
  • ๋ถ€์ •ํ•œ ๋…ธ๋“œ๋“ค์ด ๊ฒฐํƒํ•˜๊ฑฐ๋‚˜ ํ†ต์‹ ์ด ๋‹ค์†Œ ์ง€์—ฐ๋˜์–ด๋„ ๊ดœ์ฐฎ์Œ(์œ ํ•œ์‹œ๊ฐ„ ์ง€์—ฐ ๊ฒฌ๋”œ์ˆ˜ ์žˆ๋„๋ก ์ง€์›)


[ ์ด๋ฏธ์ง€ ์ถœ์ฒ˜: Miguel Castro, Barbara Liskov: Practical Byzantine fault tolerance and proactive recovery. ACM Trans. Comput. Syst. 20(4): 398-461 (2002) ]

๊ฐ„๋žตํ•œ ๋™์ž‘๊ตฌ์กฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  1. ์ตœ์ดˆ ํด๋ผ์ด์–ธํŠธ์—์„œ ํŠธ๋žœ์žญ์…˜์ด ๋ฐœ์ƒํ•˜์—ฌ ํ•ฉ์˜๋ฅผ ์š”์ฒญ
  2. Pre-Prepare : primary node๊ฐ€ ์š”์ฒญ์— ์‹œํ€€์Šค ๋ฒˆํ˜ธ๋ฅผ ๋ถ€์—ฌํ•˜๊ณ  ๋‹ค๋ฅธ ๋…ธ๋“œ์— ํ•ฉ์˜ ์š”๊ตฌ๋ฅผ ์œ„ํ•ด ๋ฉ€ํ‹ฐ ์บ์ŠคํŠธ
  3. Prepare : ๊ฐ ๋…ธ๋“œ๊ฐ€ ๊ฒ€์ฆ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ์ž์‹  ์ด์™ธ์˜ ๋…ธ๋“œ์— ๋ฉ€ํ‹ฐ ์บ์ŠคํŠธ
  4. Commit : ๊ฐ ๋…ธ๋“œ๊ฐ€ commit ๋ฉ”์‹œ์ง€๋ฅผ ๋ฉ€ํ‹ฐ ์บ์ŠคํŠธํ•œ๋‹ค. ๊ทธ ํ›„ 1/3 ์ด์ƒ์˜ ๋‹ค๋ฅธ ๋…ธ๋“œ์—์„œ ์ž์‹ ์ด ๋ณด๋‚ธ ๊ฒƒ๊ณผ commit ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ด ์˜ค๋ฉด, commit ์™„๋ฃŒ๋กœ ๊ธฐ๋ก

2. Peer์—์„œ PBFT ์ ์šฉ์„ ์œ„ํ•ด ์„ค์ •ํŒŒ์ผ ๋ณ€๊ฒฝ

PBFT ์ ์šฉ์„ ์œ„ํ•ด์„œ๋Š” ๋จผ์ € Peer ์„œ๋น„์Šค์˜ ์„ค์ •ํŒŒ์ผ์„ ์ˆ˜์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์•ž์„œ TLS ์„ค์ • ์—์„œ ์ž‘์„ฑํ•˜์˜€๋˜ docker-compose.yml ์„ ํ†ตํ•ด์„œ ๋ธ”๋ก์ฒด์ธ ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค. (์‹คํ–‰ํ•œ ์ƒํƒœ์ด๋ฉด ๋‹ค์Œ์œผ๋กœ ๋„˜์–ด๊ฐ‘๋‹ˆ๋‹ค.)
๊ทธ๋Ÿฐ ๋‹ค์Œ, vp0 ์ปจํ…Œ์ด๋„ˆ์— ๋Œ€ํ•ด์„œ ์„ค์ •ํŒŒ์ผ ์ˆ˜์ •์„ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ์˜ ๋ช…๋ น์„ ํ†ตํ•ด์„œ vp0 ์ปจํ…Œ์ด๋„ˆ์— ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

docker exec -it vp0 bash

๋‹ค์Œ์œผ๋กœ ์„ค์ •ํŒŒ์ผ์ธ core.yaml ํŒŒ์ผ์„ ์•„๋ž˜ ๊ทธ๋ฆผ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

cd peer
vi core.yaml

์„ค์ •ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์˜€์œผ๋ฉด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ƒˆ๋กœ์šด ํƒœ๊ทธ๋ช…์œผ๋กœ commit ํ•ฉ๋‹ˆ๋‹ค.

docker commit vp0 hyperledger/peer:1.4

๊ทธ๋ฆฌ๊ณ  docker-compose.yml ํŒŒ์ผ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์žฌ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

PBFT๋ฅผ ์ ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์ตœ์†Œ 4๊ฐœ์˜ Peer๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
๊ทธ๋ฆฌ๊ณ  Peer์˜ index๊ฐ€ 0์œผ๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, peer.id ๊ฐ€ vp0,vp1, …. vpN ์ด ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ์˜ ๊ฒฝ๋กœ์—์„œ ์ˆ˜์ •๋œ docker-compose ํŒŒ์ผ์„ ๋‹ค์šด ๋ฐ›์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. https://github.com/mjkong/blockchain_hyperledger/blob/master/docs/Setup/prodmode/4_peers/docker-compose.yml

membersrvc:
  image: hyperledger/membersrvc:1.0
  ports:
    - "7054:7054"
  hostname: membersrvc
  container_name: membersrvc
  command: membersrvc
vp0:
  image: hyperledger/peer:1.4
  ports:
    - "7050:7050"
    - "7051:7051"
    - "7053:7053"
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=https://192.168.99.100:2476
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp0
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_SECURITY_ENROLLID=test_vp0
    - CORE_SECURITY_ENROLLSECRET=MwYpmSRjupbT
  hostname: vp0
  container_name: vp0
  links:
    - membersrvc
  command: sh -c "sleep 5; peer node start"
vp1:
  image: hyperledger/peer:1.4
  ports:
    - "7061:7061"
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=https://192.168.99.100:2476
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp1
    - CORE_PEER_ADDRESS=0.0.0.0:7061
    - CORE_PEER_LISTENADDRESS=0.0.0.0:7061
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_SECURITY_ENROLLID=test_vp1
    - CORE_SECURITY_ENROLLSECRET=5wgHK9qqYaPy
    - CORE_PEER_DISCOVERY_ROOTNODE=192.168.99.100:7051
  hostname: vp1
  container_name: vp1
  links:
    - membersrvc
    - vp0
  command: sh -c "sleep 5; peer node start"
vp2:
  image: hyperledger/peer:1.4
  ports:
    - "7071:7071"
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=https://192.168.99.100:2476
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp2
    - CORE_PEER_ADDRESS=0.0.0.0:7071
    - CORE_PEER_LISTENADDRESS=0.0.0.0:7071
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_SECURITY_ENROLLID=test_vp2
    - CORE_SECURITY_ENROLLSECRET=vQelbRvja7cJ
    - CORE_PEER_DISCOVERY_ROOTNODE=192.168.99.100:7051
  hostname: vp2
  container_name: vp2
  links:
    - membersrvc
    - vp0
  command: sh -c "sleep 5; peer node start"
vp3:
  image: hyperledger/peer:1.4
  ports:
    - "7081:7081"
  environment:
    - CORE_PEER_ADDRESSAUTODETECT=true
    - CORE_VM_ENDPOINT=https://192.168.99.100:2476
    - CORE_LOGGING_LEVEL=DEBUG
    - CORE_PEER_ID=vp3
    - CORE_PEER_ADDRESS=0.0.0.0:7081
    - CORE_PEER_LISTENADDRESS=0.0.0.0:7081
    - CORE_PEER_PKI_ECA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TCA_PADDR=membersrvc:7054
    - CORE_PEER_PKI_TLSCA_PADDR=membersrvc:7054
    - CORE_SECURITY_ENABLED=true
    - CORE_SECURITY_ENROLLID=test_vp3
    - CORE_SECURITY_ENROLLSECRET=9LKqKH5peurL
    - CORE_PEER_DISCOVERY_ROOTNODE=192.168.99.100:7051
  hostname: vp3
  container_name: vp3
  links:
    - membersrvc
    - vp0
  command: sh -c "sleep 5; peer node start"

์ปจํ…Œ์ด๋„ˆ ์žฌ์‹œ์ž‘ ํ›„ ๋กœ๊ทธ์— ์—๋Ÿฌ์—†์ด ์ •์ƒ ์‹œ์ž‘๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ์ •์ƒ ์‹œ์ž‘๋˜์—ˆ์œผ๋ฉด REST API๋ฅผ ํ†ตํ•ด ํŠธ๋žœ์žญ์…˜ ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.