본문 바로가기

Blockchain/Ethereum

[블록체인][go-ethereum] Private network (clique) 구축하기

GO-ETHEREUM private network (Clique) 구축하기

 

Index

  1. node 구성
  2. ==> (bootnode, miner node1, miner node2, miner node3)
  3. go 설치
  4. go-ethereum 빌드
  5. private network 구축
    1. 노드 디렉터리 생성
    2. account 생성
    3. genesis 파일 생성(puppeth)
    4. 이더리움 노드 초기화
    5. bootnode 생성 및 시작
    6. 각 노드 실행
    7. 노드 확인

 

1. GO 설치하기

go 설치하기는 다른 블로그를 참조하시면 좋을 것 같습니다. 저는 아래 링크로 설치했습니다

http://snowdeer.github.io/go/2018/01/20/how-to-install-golang-on-centos/

 

2. go-ethereum build

https://github.com/ethereum/go-ethereum에서 clone 후 make all로 빌드를 해주면 됩니다. 현재는 마스터 브런치를 바로 빌드하므로 unstable이지만 git checkout을 통해 원하는 버전을 빌드하면 됩니다

 

[app@localhost ~]$ pwd /home/app [app@localhost ~]$ git clone https://github.com/ethereum/go-ethereum.git .. download .. [app@localhost ~]$ cd go-ethereum/ [app@localhost go-ethereum]$ make all .... install ... [app@localhost go-ethereum]$ cd build/bin/ [app@localhost bin]$ pwd /home/app/go-ethereum/build/bin [app@localhost bin]$ ls abigen  bootnode  clef  ethkey  evm  examples  faucet  geth  p2psim  puppeth  rlpdump  simulations  swarm  swarm-smoke  wnode [app@localhost bin]$ vi ~/.bash_profile export GETHPATH="$HOME/go-ethereum/build" PATH=$PATH:$GETHPATH/bin 

 

 

3. private network 구축

3.1 노드 디렉토리 생성

각각 node1, node2, node3 이라는 디렉토리 생성

[app@localhost clique-test]$ mkdir $HOME/clique-test [app@localhost clique-test]$ cd $HOME/clique-test [app@localhost clique-test]$ mkdir node1 node2 node3 [app@localhost clique-test]$ ll 합계 0 drwxrwxr-x. 2 app app 6  8월 25 22:57 node1 drwxrwxr-x. 2 app app 6  8월 25 22:57 node2 drwxrwxr-x. 2 app app 6  8월 25 22:57 node3 

 

3.2 account 생성

geth의 cli를 이용해서 각각 디렉터리/keystore에 마이닝 어카운트를 생성하였고

마이닝 할 때 unlock 할 패스워드를 지정하기 위해 password.txt를 각각 폴더에 생성하였습니다.

 

[app@localhost clique-test]$ geth --datadir node1/ account new INFO [08-25|23:05:48.903] Maximum peer count                       ETH=25 LES=0 total=25 Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat passphrase: Address: {fa01bfd41c4672b531e0dfbce52d1680a87d5fb0} [app@localhost clique-test]$ geth --datadir node2/ account new INFO [08-25|23:05:56.316] Maximum peer count                       ETH=25 LES=0 total=25 Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat passphrase: Address: {2d5fde2bae5ee752eed7b0f1a990760c93bd1b27} [app@localhost clique-test]$ geth --datadir node3/ account new INFO [08-25|23:06:03.797] Maximum peer count                       ETH=25 LES=0 total=25 Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat passphrase: Address: {afda0df71a31f392dae6f07a1b2a911006e05971} [app@localhost clique-test]$ echo 'pass' > node1/password.txt [app@localhost clique-test]$ echo 'pass' > node2/password.txt [app@localhost clique-test]$ echo 'pass' > node3/password.txt

 

3.3 genesis 파일 생성

 

go-ethereum을 빌드하면 puppeth 이라는 모듈이 생기는데 여기서 genesis 파일을 생성하였습니다.

 

[app@localhost clique-test]$ puppeth // 네트워크 이름 설정 Please specify a network name to administer (no spaces or hyphens, please)  private  Sweet, you can set this via --network=private next time!  INFO [08-25|23:09:14.572] Administering Ethereum network           name=private WARN [08-25|23:09:14.572] No previous configurations found         path=/home/app/.puppeth/private  // 2번을 선택하여 genesis 파일 생성 What would you like to do? (default = stats)   1. Show network stats   2. Configure new genesis   3. Track new remote server   4. Deploy network components > 2  // 합의 엔진 선택 Which consensus engine to use? (default = clique)   1. Ethash - proof-of-work   2. Clique - proof-of-authority > 2  // 블록 생성 시간(초) How many seconds should blocks take? (default = 15) > 10  // 블록 생성 허가 계정 Which accounts are allowed to seal? (mandatory at least one) > 0xfa01bfd41c4672b531e0dfbce52d1680a87d5fb0 > 0x2d5fde2bae5ee752eed7b0f1a990760c93bd1b27 > 0xafda0df71a31f392dae6f07a1b2a911006e05971 > 0x  // 초기 이더 할당(원하면 추후 파일에서 "alloc" 필드 변경해주면 됨) Which accounts should be pre-funded? (advisable at least one) > 0xfa01bfd41c4672b531e0dfbce52d1680a87d5fb0 > 0x2d5fde2bae5ee752eed7b0f1a990760c93bd1b27 > 0xafda0df71a31f392dae6f07a1b2a911006e05971 > 0x  Specify your chain/network ID if you want an explicit one (default = random) > 1234 > INFO [08-25|23:10:08.758] Configured new genesis block  // genesis 파일 export 하기 위해 2번 선택 What would you like to do? (default = stats)   1. Show network stats   2. Manage existing genesis   3. Track new remote server   4. Deploy network components > 2  // genesis 파일 export   1. Modify existing fork rules   2. Export genesis configuration   3. Remove genesis configuration > 2  // genesis 파일 이름 Which file to save the genesis into? (default = private.json)  > genesis.json > INFO [08-25|23:10:20.806] Exported existing genesis block  // ctrl + c 로 종료! What would you like to do? (default = stats)   1. Show network stats   2. Manage existing genesis   3. Track new remote server   4. Deploy network components 

아래와 같이 genesis.json 파일을 살펴보면

{   "config": {     "chainId": 1234,     ...         "clique": {       "period": 10,       "epoch": 30000     }   },   ...   "alloc": {     ...     "2d5fde2bae5ee752eed7b0f1a990760c93bd1b27": {      "balance": "0x200000000000000000000000000000000000000000000000000000000000000"    },    "afda0df71a31f392dae6f07a1b2a911006e05971": {      "balance": "0x200000000000000000000000000000000000000000000000000000000000000"    },    "fa01bfd41c4672b531e0dfbce52d1680a87d5fb0": {      "balance": "0x200000000000000000000000000000000000000000000000000000000000000"    }   } 

config에서 설정한 network/chainid 1234가 설정되어 있고 합의 엔진으로 clique, 생성 시간 10초가
설정된 것을 확인할 수 있습니다. 또한 alloc 필드에 premine으로 미리 이더를 할당할 수 있습니다.
다른 일반 계정에 할당하고 싶으면 geth new account를 통해서 계정을 생성하고 이더를 할당해주면 됩니다.

 

3.4 이더리움 노드 초기화

geth와 genesis.json을 이용하여 init 명령어를 실행하면 아래와 같이 각 디렉토리에
geth라는 폴더가 생성됩니다.

[app@localhost clique-test]$ geth --datadir node1/ init genesis.json [app@localhost clique-test]$ geth --datadir node2/ init genesis.json [app@localhost clique-test]$ geth --datadir node3/ init genesis.json [app@localhost clique-test]$ tree -L 2 . ├── genesis.json ├── node1 │   ├── geth │   ├── keystore │   └── password.txt ├── node2 │   ├── geth │   ├── keystore │   └── password.txt └── node3     ├── geth     ├── keystore     └── password.txt 
3.5 Bootnode 생성 및 시작

node1, node2, node3을 각각 연결하지 않고 별도의 boot node를 생성하여
각 노드들이 boot node로 접속하도록 구성하였습니다.

[app@localhost clique-test]$ bootnode -genkey boot.key [app@localhost clique-test]$ ll 합계 28 -rw-------. 1 app app    64  8월 25 23:15 boot.key -rw-r--r--. 1 app app 21931  8월 25 23:10 genesis.json drwxrwxr-x. 4 app app    54  8월 25 23:12 node1 drwxrwxr-x. 4 app app    54  8월 25 23:12 node2 drwxrwxr-x. 4 app app    54  8월 25 23:12 node3   [app@localhost clique-test]$ bootnode -nodekey boot.key -verbosity 9 -addr :30310 INFO [08-25|23:17:38.078] UDP listener up                          self=enode://fc8b830dd799aa0ea409bd6735170fedcb6ad323c2fdf82497636bd7eaf398f37e8610b0b1edd136a756a593a732710940c1fa460140f72ee5475f257c7df207@[::]:30310
3.6 이더리움 노드 시작

첫번째로는 cli 옵션을 설정하여 실행해주면 됩니다.
위에서 설정한 enode를 기반으로 노드를 실행해줍니다.
각각 node 마다 --datadir, --ipcpath, --port, --rpcport, -unlock, --password 값을 다르게하여서
실행하면 각각 실행이 됩니다(예를들어 node1/ => node2/ => node3)

[app@localhost clique-test]$ geth --datadir node1/ --ipcpath node1/node1.ipc --syncmode 'full' --port 30311 --rpc --rpcaddr 'localhost' --rpcport 8501 --rpcapi 'personal,db,eth,net,web3,txpool,miner' --bootnodes 'enode://fc8b830dd799aa0ea409bd6735170fedcb6ad323c2fdf82497636bd7eaf398f37e8610b0b1edd136a756a593a732710940c1fa460140f72ee5475f257c7df207@127.0.0.1:30310' --networkid 1234 --gasprice '1' -unlock '0xfa01bfd41c4672b531e0dfbce52d1680a87d5fb0' --password node1/password.txt --mine

두번째로는 dumpconfig를 이용하여 toml 파일을 생성하여 실행해주며 됩니다.

[app@localhost clique-test]$ geth --datadir node1/ --ipcpath node1/node1.ipc --syncmode 'full' --port 30311 --rpc --rpcaddr 'localhost' --rpcport 8501 --rpcapi 'personal,db,eth,net,web3,txpool,miner' --bootnodes 'enode://fc8b830dd799aa0ea409bd6735170fedcb6ad323c2fdf82497636bd7eaf398f37e8610b0b1edd136a756a593a732710940c1fa460140f72ee5475f257c7df207@127.0.0.1:30310' --networkid 1234 --gasprice '1' -unlock '0xfa01bfd41c4672b531e0dfbce52d1680a87d5fb0' --password node1/password.txt --mine dumpconfig > node1.toml [app@localhost clique-test]$ geth --config node1.toml
3.7 노드 확인

위에서 설정한 ipc경로를 바탕으로 geth attach를 이용하여 피어 정보를 아래와 같이 확인하면 됩니다

[app@localhost clique-test]$ geth attach node1/node1.ipc Welcome to the Geth JavaScript console!

instance: Geth/v1.8.15-unstable-70398d30/linux-amd64/go1.10 coinbase: 0xfa01bfd41c4672b531e0dfbce52d1680a87d5fb0 at block: 16 (Sat, 25 Aug 2018 23:33:26 KST) datadir: /home/app/clique-test/node1 modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

> eth.blockNumber 16 > admin.peers [{ caps: ["eth/62", "eth/63"], id: "7a67f6f4452c0329e5bf97bfae117598ec9532803049aa15da576695480823930cae6d5f9f2a71ea141ca68ca7c89fa4130a01fe6d1977389db046e50e94885b", name: "Geth/v1.8.15-unstable-70398d30/linux-amd64/go1.10", network: { inbound: true, localAddress: "127.0.0.1:30311", remoteAddress: "127.0.0.1:34688", static: false, trusted: false }, protocols: { eth: { difficulty: 29, head: "0xda44d682047766765e93d010ac03bac31994f8cc579eb57b9f58cf537a2b17f5", version: 63 } } }, { caps: ["eth/62", "eth/63"], id: "e4423bf5fdf50b78c800dd9b8a7441e04a4b220d4384b6a1623a3ee2fa2daaf95fc2c43b3ecdf8af80ccaf5c206eceb2e9db218ec68806d4d24b57f529310166", name: "Geth/v1.8.15-unstable-70398d30/linux-amd64/go1.10", network: { inbound: true, localAddress: "127.0.0.1:30311", remoteAddress: "127.0.0.1:34706", static: false, trusted: false }, protocols: { eth: { difficulty: 31, head: "0xd6f2ea96a87e4561fa22c2035d22ca516cfaf1e89aaf802de2a1c30de078551f", version: 63 } } }] > eth.blockNumber 29

 

개발용 이더리움을 구축할 때는 ethash보다는 poa 알고리즘으로 환경을 구축하고 테스트하는게 좋을 것 같습니다
genesis 블록에 대한 설명을 core를 포스팅하면서 올리겠습니다.
다음은 parity aura 설치를 포스팅하겠습니다

참고

'Blockchain > Ethereum' 카테고리의 다른 글

[Ethereum-POA] Parity aura consensus 간단 분석  (0) 2019.11.03