티스토리 뷰

반응형

공식 문서

내용 번역

https://hyperledger-fabric.readthedocs.io/en/release-1.4/commands/peerchannel.html#peer-channel-fetch

 

지정된 블록을 가져 와서 파일에 씁니다.

사용법:
  peer channel fetch <newest|oldest|config|(number)> [출력파일] [플래그]

플래그:
      --bestEffort         fetch 요청이 최선의 노력으로 오류를 무시하고 블록을 리턴해야하는지 여부
  -c, --channelID string   newChain 명령의 경우 생성할 채널 ID. 250자 미만의 소문자 및 다음 정규식과 일치해야함: [a-z][a-z0-9.-]*
  -h, --help               fetch 명령에 대한 도움말

Global 플래그:
      --cafile string                       오더링 엔드포인트(ordering endpoint)에 대해 PEM으로 인코딩된 신뢰할 수 있는 인증서가 포함된 파일의 경로
      --certfile string                     오더러 엔드포인트(orderer endpoint)와의 상호 TLS 통신에 사용할 PEM으로 인코딩된 X509 공개 키를 포함하는 파일의 경로
      --clientauth                          오더러 엔드포인트(orderer endpoint)와 통신할 때 상호 TLS 사용
      --connTimeout duration                클라이언트 연결 timeout 시간 (default 3초)
      --keyfile string                      오더러 엔드포인트(orderer endpoint)와의 상호 TLS 통신에 사용할 PEM으로 인코딩된 개인 키가 포함된 파일의 경로
  -o, --orderer string                      오더링 서비스 엔드포인트(Ordering service endpoint)
      --ordererTLSHostnameOverride string   오더러(orderer)에 대한 TLS 연결의 유효성을 검증할 때 사용할 호스트 이름 오버라이드
      --tls                                 오더러 엔드포인트(orderer endpoint)와 통신할 때 TLS 사용

사용 예시

byfn 네트워크를 기준으로 peer channel fetch 명령을 실행해봅시다.

 

기본 설정

peer channel fetch 명령을 실행하기 위해서는 cli 또는 peer 컨테이너에 접속해야 합니다.
여기에서는 cli 컨테이너에서 실행하도록 합니다.

# cli 컨테이너 접속
docker exec -it cli bash

cli 컨테이너 접속

블록을 fetch할 채널을 지정하기 위해 CHANNEL 변수를 사용합니다. CHANNEL 변수에 자신의 채널ID를 설정하고 해당 변수를 호출했을 때 자신의 채널ID가 출력되는지 확인합니다.

# CHANNEL 환경변수에 블록을 fetch할 채널 지정
export CHANNEL=mychannel
echo $CHANNEL
mychannel

CHANNEL 환경변수에 블록을 fetch할 채널 지정

newest: 가장 최신 블록 fetch

가장 최신 블록을 fetch하기 위해 newest 옵션으로 실행합니다. 
따로 출력파일을 지정하지 않으면 <채널ID>_newest.block이라는 파일명으로 블록 파일이 생성됩니다. 여기에서는 mychannel_newest.block 블록 파일이 생성된 것을 확인할 수 있습니다.

# 가장 최신 블록 fetch
peer channel fetch newest -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -c $CHANNEL
2019-12-12 05:07:53.875 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-12 05:07:53.937 UTC [cli.common] readBlock -> INFO 002 Received block: 4

# mychannel_newest.block 블록 파일 생성 확인
ls -al
total 48
drwxr-xr-x 5 root root  4096 Dec 12 05:07 .
drwxr-xr-x 3 root root  4096 Dec 12 01:51 ..
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:51 channel-artifacts
drwxr-xr-x 4 1000 1000  4096 Dec 12 01:50 crypto
-rw-r--r-- 1 root root     3 Dec 12 01:53 log.txt
-rw-r--r-- 1 root root 15989 Dec 12 01:51 mychannel.block
-rw-r--r-- 1 root root  4854 Dec 12 05:07 mychannel_newest.block
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:50 scripts

가장 최신 블록 fetch

파일명을 지정하고 싶은 경우에는 newest 옵션 바로 뒤에 지정할 파일명을 입력합니다.


여기에서는 newest_<채널ID>로 설정해보겠습니다.

# 블록 파일명을 지정해 가장 최신 블록 fetch - 파일명: newest_$CHANNEL.block
peer channel fetch newest newest_$CHANNEL.block -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -c $CHANNEL
2019-12-12 05:07:53.875 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-12 05:07:53.937 UTC [cli.common] readBlock -> INFO 002 Received block: 4

# newest_mychannel.block 블록 파일 생성 확인
ls -al
total 112
drwxr-xr-x 5 root root  4096 Dec 18 02:30 .
drwxr-xr-x 3 root root  4096 Dec 12 01:51 ..
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:51 channel-artifacts
drwxr-xr-x 4 1000 1000  4096 Dec 12 01:50 crypto
-rw-r--r-- 1 root root     3 Dec 12 01:53 log.txt
-rw-r--r-- 1 root root 16988 Dec 12 09:12 mychannel_2.block
-rw-r--r-- 1 root root 15989 Dec 12 01:51 mychannel.block
-rw-r--r-- 1 root root 16988 Dec 12 08:45 mychannel_config.block
-rw-r--r-- 1 root root  4854 Dec 12 05:07 mychannel_newest.block
-rw-r--r-- 1 root root 15989 Dec 12 08:35 mychannel_oldest.block
-rw-r--r-- 1 root root  4854 Dec 18 02:30 newest_mychannel.block
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:50 scripts

블록 파일명을 지정해 가장 최신 블록 fetch

oldest: 가장 오래된 블록 fetch

가장 오래된 블록을 fetch하기 위해 oldest 옵션으로 실행합니다.
따로 출력파일을 지정하지 않으면 <채널ID>_oldest.block이라는 파일명으로 블록 파일이 생성됩니다. 여기에서는 mychannel_oldest.block 블록 파일이 생성된 것을 확인할 수 있습니다.

# 가장 오래된 블록 fetch
peer channel fetch oldest -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -c $CHANNEL
2019-12-12 08:35:21.426 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-12 08:35:21.436 UTC [cli.common] readBlock -> INFO 002 Received block: 0

# mychannel_oldest.block 블록 파일 생성 확인
ls -al
total 64
drwxr-xr-x 5 root root  4096 Dec 12 08:35 .
drwxr-xr-x 3 root root  4096 Dec 12 01:51 ..
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:51 channel-artifacts
drwxr-xr-x 4 1000 1000  4096 Dec 12 01:50 crypto
-rw-r--r-- 1 root root     3 Dec 12 01:53 log.txt
-rw-r--r-- 1 root root 15989 Dec 12 01:51 mychannel.block
-rw-r--r-- 1 root root  4854 Dec 12 05:07 mychannel_newest.block
-rw-r--r-- 1 root root 15989 Dec 12 08:35 mychannel_oldest.block
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:50 scripts

가장 오래된 블록 fetch

파일명을 지정하고 싶은 경우에는 oldest 옵션 바로 뒤에 지정할 파일명을 입력합니다.

config: 채널 구성 블록 fetch

채널 구성 블록을 fetch하기 위해 config 옵션으로 실행합니다.
따로 출력파일을 지정하지 않으면 <채널ID>_config.block이라는 파일명으로 블록 파일이 생성됩니다. 여기에서는 mychannel_config.block 블록 파일이 생성된 것을 확인할 수 있습니다.

# 채널 구성 블록 fetch
peer channel fetch config -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -c $CHANNEL
2019-12-12 08:45:20.605 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-12 08:45:20.611 UTC [cli.common] readBlock -> INFO 002 Received block: 4
2019-12-12 08:45:20.621 UTC [cli.common] readBlock -> INFO 003 Received block: 2
2019-12-12 08:45:20.621 UTC [channelCmd] fetch -> INFO 004 Retrieving last config block: 2

# mychannel_config.block 블록 파일 생성 확인
ls -al
total 84
drwxr-xr-x 5 root root  4096 Dec 12 08:45 .
drwxr-xr-x 3 root root  4096 Dec 12 01:51 ..
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:51 channel-artifacts
drwxr-xr-x 4 1000 1000  4096 Dec 12 01:50 crypto
-rw-r--r-- 1 root root     3 Dec 12 01:53 log.txt
-rw-r--r-- 1 root root 15989 Dec 12 01:51 mychannel.block
-rw-r--r-- 1 root root 16988 Dec 12 08:45 mychannel_config.block
-rw-r--r-- 1 root root  4854 Dec 12 05:07 mychannel_newest.block
-rw-r--r-- 1 root root 15989 Dec 12 08:35 mychannel_oldest.block
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:50 scripts

채널 구성 블록 fetch

파일명을 지정하고 싶은 경우에는 config 옵션 바로 뒤에 지정할 파일명을 입력합니다.

 

(number): 특정 번호의 블록 fetch

특정 번호의 블록을 fetch하기 위해 (number) 옵션으로 실행합니다. (number) 부분에 fetch를 원하는 블록 번호를 입력하면 됩니다.
따로 출력파일을 지정하지 않으면 <채널ID>_.block이라는 파일명으로 블록 파일이 생성됩니다. 여기에서는 블록 번호를 2로 설정했기 때문에 mychannel_2.block 블록 파일이 생성된 것을 확인할 수 있습니다.

# 특정 번호의 블록 fetch
peer channel fetch 2 -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -c $CHANNEL
2019-12-18 05:00:01.573 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2019-12-18 05:00:01.605 UTC [cli.common] readBlock -> INFO 002 Received block: 2

# mychannel_2.block 블록 파일 생성 확인
ls -al
total 104
drwxr-xr-x 5 root root  4096 Dec 18 05:00 .
drwxr-xr-x 3 root root  4096 Dec 12 01:51 ..
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:51 channel-artifacts
drwxr-xr-x 4 1000 1000  4096 Dec 12 01:50 crypto
-rw-r--r-- 1 root root     3 Dec 12 01:53 log.txt
-rw-r--r-- 1 root root 16988 Dec 18 05:00 mychannel_2.block
-rw-r--r-- 1 root root 15989 Dec 12 01:51 mychannel.block
-rw-r--r-- 1 root root 16988 Dec 12 08:45 mychannel_config.block
-rw-r--r-- 1 root root  4854 Dec 12 05:07 mychannel_newest.block
-rw-r--r-- 1 root root 15989 Dec 12 08:35 mychannel_oldest.block
drwxrwxr-x 2 1000 1000  4096 Dec 12 01:50 scripts

특정 번호의 블록 fetch

파일명을 지정하고 싶은 경우에는 (number) 옵션 바로 뒤에 지정할 파일명을 입력합니다.

 

블록 번호는 0번부터 시작하기 때문에 (block_height - 1)까지 설정할 수 있습니다.
현재 block_height 값을 알고 싶으면 peer channel getinfo 명령을 사용하면 됩니다.

# 현재 block_height 확인
# peer channel getinfo -c <채널ID>
peer channel getinfo -c $CHANNEL
2019-12-18 01:09:44.120 UTC [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Blockchain info: {"height":5,"currentBlockHash":"PNR4rQEkMutRupbD+RnsL0UmZ+s0heoxl4lMJZFw7To=","previousBlockHash":"piotYkUTIg5JPf4+AKk5conUUs6QPNvA2atNu68ogDE="}

현재 block_height 확인

 

 

 

 

 

반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함