도커(Docker) 환경에서 오픈 이더리움(Open Ethereum)을 사용한 이더리움 네트워크 자체 구축
2021. 11. 15. 18:12ㆍBlockchain/Project - Coin Swap
네트워크 구축
-
$ docker run -it --name openethereum ubuntu // 이미지 자동 다운로드, 컨테이너 실행
-
# apt-get update # apt-get install -y gcc g++ pkg-config file make cmake git clang curl libssl-dev ※ 인스톨 완료 후 Timezone 설정 시, [6 -> 69] 선택
-
# curl https://sh.rustup.rs -sSf | sh # apt-get install -y yasm # apt-get install cargo # source $HOME/.cargo/env # rustc --version // Rust 설치 확인 # rustup override set 1.51.0 // 버전 하향 조정
-
# git clone https://github.com/openethereum/openethereum.git # cd openethereum # cargo build --release --features final // 빌드 시작, 오래 걸림
-
# exit // 빌드 완료 후 컨테이너 빠져나오기 $ docker start openethereum // 컨테이너 실행 $ docker attach openethereum // 컨테이너 접근
-
# /openethereum/target/release/openethereum account new // 계정 생성, 4번 반복하여 4개의 계정 생성 ※ 생성 된 계정은 '~/.local/share/openethereum/keys/ethereum' 경로에 저장 됨 ※ 입력했던 비밀번호와 계정 생성 완료 후 출력되는 공개키 값은 따로 보관 # cd ~/.local/share/openethereum/keys/ethereum # ls # apt-get install vim // 파일의 내용 확인을 위해 패키지 설치 # vi [ls 입력 시 나오는 4개의 파일명] // json 형태의 텍스트 확인 가능 # vi UTC--2021-11-15T06-03-52Z--8a2eec67-4f02-c481-55d6-ab0bddff32c7
- 도커 작업은 잠시 멈춘 상태에서 로컬에서 작업 할 폴더 생성 후 아래와 같은 구조로 구성
- /keys'N'/ethereum
[1 - 3], [2 - 4], 'N'의 홀수번과 짝수번 keys끼리 같은 내용을 넣어 줄 예정 - /keys'N'/ethereum/address_book.json 내용 작성
{}
- /keys'N'/ethereum/pos'N'.json 내용 작성
도커로 돌아가서 vi [ls 입력 시 나오는 4개의 파일명] 했을 때 나오는 json 형태의 텍스트를 복사 붙여넣기
keys1&keys3/pos1 : ls 입력 시 나오는 1 번째 파일 json 형태의 텍스트{"id":"3d94b60a-545a-d8f8-460a-5cceb96ba574","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"58157795f26f1a3f9d282b7f3086e562"},"ciphertext":"017e9b109443dc7d5752251b0b4b8793df7a5168c627358edc6c65b6ca12a07f","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"0cdfdd2138459add2e4dacba82564c38fc4c3a7204805d09b0864468445b2393"},"mac":"fba821edeaf48771d806c3df1c6109725564156da9a480a2dc759b9ba69ca62d"},"address":"ca0759bc3b2dbdbf1c587e95ec120345fbdcce68","name":"","meta":"{}"}
keys1&keys3/pos2 : ls 입력 시 나오는 2 번째 파일 json 형태의 텍스트
keys2&keys4/pos1 : ls 입력 시 나오는 3 번째 파일 json 형태의 텍스트
keys2&keys4/pos2 : ls 입력 시 나오는 4 번째 파일 json 형태의 텍스트 - password 내용 작성
// 도커에서 만들었던 1 번째 계정의 비밀번호 // 도커에서 만들었던 2 번째 계정의 비밀번호 // 도커에서 만들었던 3 번째 계정의 비밀번호 // 도커에서 만들었던 4 번째 계정의 비밀번호
- config'N'.json 내용 작성
각 파일 별 변하는 내용# 작동에 관한 기본 매개변수 [parity] chain = "/openethereum/genesis.json" base_path = "/openethereum/" # 네트워크 및 피어 관련 설정 # 오프라인 모드인 경우 네트워크 사용 불가 [network] port = 30305 reserved_peers= "/openethereum/nodes" # HTTP를 통해 JSON-RPC API를 노출 [rpc] # HTTP를 통한 JSON-RPC는 포트 8547에서 액세스할 수 있습니다. port = 8547 apis = ["web3", "eth", "net", "personal", "parity", "parity_set", "traces" ,"rpc", "parity_accounts"] # JSON-RPC는 모든 로컬에서 연결을 수신 대기합니다. interface = "all" # 모든 도메인의 교차 출처 요청을 허용합니다. cors = ["all"] [account] password = ["/openethereum/password"] # 마이닝 노드에 대한 옵션 [mining] # 블록 채굴 시 보상을 받을 계정 주소입니다. engine_signer = "계정 생성 완료 후 출력되는 공개키 값" # 새 블록을 밀봉할 때 블록당 4000000 가스를 목표로 합니다. gas_floor_target = "40000000" # Miscellaneous, 기타 분류되지 않은 옵션 [misc] # 로깅 패턴(`<module>=<level>`, 예: `own_tx=trace`) logging = "own_tx=trace" # 로그는 이곳에 저장됩니다. log_file = "/openethereum/log.log"
* [network] -> port = config1부터 30305++
* [rpc] -> port = config1부터 8547++
* engine_signer = config1과 3에는 "첫 번째 계정 생성 완료 후 출력되는 공개키 값", config2와 4에는 "세 번째 계정 생성 완료 후 출력되는 공개키 값" - genesis.json 내용 작성
"list", "accounts" 내용 수정{ "name": "ethereum", "engine": { "authorityRound": { "params": { "blockReward": "0x4563918244F40000", "stepDuration": "1", "validators": { "list": [ "1 번째 계정 생성 완료 후 출력되는 공개키 값", "2 번째 계정 생성 완료 후 출력되는 공개키 값", "3 번째 계정 생성 완료 후 출력되는 공개키 값", "4 번째 계정 생성 완료 후 출력되는 공개키 값" ] } } } }, "params": { "gasLimitBoundDivisor": "0x400", "maximumExtraDataSize": "0x20", "minGasLimit": "0x1388", "networkID": "0x4c4", "eip155Transition": 0, "validateChainIdTransition": 0, "eip140Transition": 0, "eip211Transition": 0, "eip214Transition": 0, "eip658Transition": 0 }, "genesis": { "seal": { "authorityRound": { "step": "0x0", "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" } }, "difficulty": "0x10", "gasLimit": "0x2625A00" }, "accounts": { "1 번째 계정 생성 완료 후 출력되는 공개키 값": { "balance": "10000000000000000000000000" }, "3 번째 계정 생성 완료 후 출력되는 공개키 값": { "balance": "10000000000000000000000000" } } }
- docker-compose.yaml 내용 작성
※ [Enter]키와 [Tab]키 사용 시 주의, 다르게 입력 시 작동에 오류 발생 가능
version: "3" services: pos1: image: "hwan/openethereum:version1" tty: true ports: - 8547:8547 - 30305:30305 environment: ENV: ETHERNODE1 RPCPORT: 8547 PORT: 30305 volumes: - ./config1.toml:/openethereum/config.toml - ./genesis.json:/openethereum/genesis.json - ./password:/openethereum/password - ./nodes:/openethereum/nodes - ./keys1:/openethereum/keys container_name: pos1 command: > sh -c "cd ~/ /openethereum/target/release/openethereum --config /openethereum/config.toml" working_dir: /openethereum pos2: image: "hwan/openethereum:version1" tty: true ports: - 8548:8548 - 30306:30306 environment: ENV: ETHERNODE1 RPCPORT: 8548 PORT: 30306 volumes: - ./config2.toml:/openethereum/config.toml - ./genesis.json:/openethereum/genesis.json - ./password:/openethereum/password - ./nodes:/openethereum/nodes - ./keys2:/openethereum/keys container_name: pos2 command: > sh -c "cd ~/ /openethereum/target/release/openethereum --config /openethereum/config.toml" working_dir: /openethereum pos3: image: "hwan/openethereum:version1" tty: true ports: - 8549:8549 - 30307:30307 environment: ENV: ETHERNODE1 RPCPORT: 8549 PORT: 30307 volumes: - ./config3.toml:/openethereum/config.toml - ./genesis.json:/openethereum/genesis.json - ./password:/openethereum/password - ./nodes:/openethereum/nodes - ./keys3:/openethereum/keys container_name: pos3 command: > sh -c "cd ~/ /openethereum/target/release/openethereum --config /openethereum/config.toml" working_dir: /openethereum pos4: image: "hwan/openethereum:version1" tty: true ports: - 8550:8550 - 30308:30308 environment: ENV: ETHERNODE1 RPCPORT: 8550 PORT: 30308 volumes: - ./config4.toml:/openethereum/config.toml - ./genesis.json:/openethereum/genesis.json - ./password:/openethereum/password - ./nodes:/openethereum/nodes - ./keys4:/openethereum/keys container_name: pos4 command: > sh -c "cd ~/ /openethereum/target/release/openethereum --config /openethereum/config.toml" working_dir: /openethereum poscli: image: "hwan/openethereum:version1" tty: true container_name: pos-cli working_dir: /openethereum command: /bin/bash links: - pos1:pos1 - pos2:pos2 - pos3:pos3 - pos4:pos4 depends_on: - pos1 - pos2 - pos3 - pos4
-
$ docker-compose up
테스트
- 메타마스크 실행 후 [맞춤형 RPC] 클릭
- 네트워크 생성
- 계정 가져오기
총 4개의 계정을 가져와야하며, 첫 번째와 세 번째 계정 생성 시 10000000 ETH가 들어있어야 함
- 트랜잭션 테스트
- 테스트 완료
'Blockchain > Project - Coin Swap' 카테고리의 다른 글
리액트(React) CRA로 프로젝트 생성 후 스토리북(Storybook) 환경 구축 (0) | 2021.11.22 |
---|---|
211109 미팅 내용 정리 (0) | 2021.11.09 |
자료조사 : 탈중앙 금융에서의 유동성 풀(Pools)과 농사(Farms) (0) | 2021.11.07 |
Uniswap_interface 코드 분석 (0) | 2021.11.07 |
Truffle, Solidity, Node.js, Web3.js 버전 변경 방법 (0) | 2021.11.03 |