도커(Docker) 환경에서 오픈 이더리움(Open Ethereum)을 사용한 이더리움 네트워크 자체 구축

2021. 11. 15. 18:12Blockchain/Project - Coin Swap

네트워크 구축

  1. $ docker run -it --name openethereum ubuntu // 이미지 자동 다운로드, 컨테이너 실행
  2. # apt-get update
    # apt-get install -y gcc g++ pkg-config file make cmake git clang curl libssl-dev
    
    ※ 인스톨 완료 후 Timezone 설정 시, [6 -> 69] 선택
  3. # 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 // 버전 하향 조정
  4. # git clone https://github.com/openethereum/openethereum.git
    # cd openethereum
    # cargo build --release --features final // 빌드 시작, 오래 걸림
     
  5. # exit // 빌드 완료 후 컨테이너 빠져나오기
    $ docker start openethereum // 컨테이너 실행
    $ docker attach openethereum // 컨테이너 접근
  6. # /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
  7. 도커 작업은 잠시 멈춘 상태에서 로컬에서 작업 할 폴더 생성 후 아래와 같은 구조로 구성
  8. /keys'N'/ethereum
    [1 - 3], [2 - 4], 'N'의 홀수번과 짝수번 keys끼리 같은 내용을 넣어 줄 예정
  9. /keys'N'/ethereum/address_book.json 내용 작성
    {}
  10. /keys'N'/ethereum/pos'N'.json 내용 작성
    도커로 돌아가서 vi [ls 입력 시 나오는 4개의 파일명] 했을 때 나오는 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/pos1 : ls 입력 시 나오는 1 번째 파일 json 형태의 텍스트
    keys1&keys3/pos2 : ls 입력 시 나오는 2 번째 파일 json 형태의 텍스트
    keys2&keys4/pos1 : ls 입력 시 나오는 3 번째 파일 json 형태의 텍스트
    keys2&keys4/pos2 : ls 입력 시 나오는 4 번째 파일 json 형태의 텍스트
  11. password 내용 작성
    // 도커에서 만들었던 1 번째 계정의 비밀번호
    // 도커에서 만들었던 2 번째 계정의 비밀번호
    // 도커에서 만들었던 3 번째 계정의 비밀번호
    // 도커에서 만들었던 4 번째 계정의 비밀번호​
  12. 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에는 "세 번째 계정 생성 완료 후 출력되는 공개키 값"
  13. genesis.json 내용 작성
    {
        "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"
          }
        }
      }​
    "list", "accounts" 내용 수정
  14. 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​
  15. $ docker-compose up​
    정상 실행 시 터미널 화면 1
    정상 실행 시 터미널 화면 2

테스트

  1. 메타마스크 실행 후 [맞춤형 RPC] 클릭
  2. 네트워크 생성
    RPC URP : http://127.0.0.1:8547, 체인 ID : 아래 진수 변환 작업 후 나오는 10진수, 통화 기호 : ETH
    위 빈칸에 생일 입력(알기 쉽게) 후 [16진수]에서 [10진수]로 선택하고 변환하기 클릭 // 진수 변환기 링크 : http://www.hipenpal.com/tool/binary-octal-decimal-hexadecimal-number-converter-in-korean.php
  3. 계정 가져오기
    총 4개의 계정을 가져와야하며, 첫 번째와 세 번째 계정 생성 시 10000000 ETH가 들어있어야 함
    빈 칸에는 pos'N'.json 파일에 입력했던 각기 다른 json 형태의 text 입력
    계정명 변경 시 1 (선택)
    계정명 변경 시 2 (선택)
  4. 트랜잭션 테스트
    보낼 ETH와 Gas 입력 후 [다음] 클릭, 이후 [확인] 클릭
  5. 테스트 완료
    (전) 9990005 ETH -&amp;amp;amp;gt; (후) 9980010 ETH
    트랜잭션 발생 시 터미널에서도 확인 가능