don't stop believing

테스트 네트워크 만들어보기 (by static-nodes.json) 본문

Ethereum

테스트 네트워크 만들어보기 (by static-nodes.json)

Tongchun 2018. 9. 29. 16:09

이번에는 static-nodes.json을 이용해 테스트 네트워크를 만들어 보겠습니다.


bootnode를 이용해 테스트 네트워크를 만들었을 때는 초기화 이후 바로 bootnode에 연결하면 잘 붙는데 geth를 종료하고 다시 bootnode 플래그로 연결하면 연결이 되지 않는 문제가 있었습니다.

http://dejavuqa.tistory.com/260


각 node가 실행 후 admin.addPeer() 명령으로 테스트 네트워크를 만들어 봤는데요. geth를 종료하면 연결도 끊어지고 다시 geth를 실행하면 다시 admin.addPeer() 명령을 사용해 줘야 합니다.

http://dejavuqa.tistory.com/261


geth가 실행될 때 지정된 node로 자동으로 연결하게 하려면 static-nodes.json에 각 enode URL을 적어두면 됩니다.

이제 시작해 봅시다.


admin.addPeer() 명령을 사용할 때 처럼 4개의 PC를 준비했습니다.


첫 번째는 CentOS에 geth 버전은 1.8.17-unstable 입니다.

두 번째도 CentOS에 geth 버전은 1.8.17-unstable 입니다.

세 번째는 Ubuntu에 geth 버전은 1.8.16-stable 입니다.

네 번째는 MacOS에 geth 버전은 1.8.14-stable 입니다.


각 PC에서 geth를 실행시킵니다. 구분을 위해 port는 이전과 같이 지정했습니다.


첫 번째 PC(CentOS)를 초기화 하고 geth를 실행 합니다. 실행 포트는 30331 입니다.

geth --networkid 12 --datadir /home/ngle/data_nglenet --port 30331 console 2>> /home/ngle/data_nglenet/geth.log


두 번째 PC(CentOS)를 초기화 하고 geth를 실행합니다. 실행 포트는 30332 입니다.

geth --networkid 12 --datadir /home/ngle/data_nglenet --port 30332 console 2>> /home/ngle/data_nglenet/geth.log


세 번째 PC(Ubuntu)를 초기화 하고 geth를 실행합니다. 실행 포트는 30333 입니다.

geth --networkid 12 --datadir /home/ngle/data_nglenet --port 30333 console 2>> /home/ngle/data_nglenet/geth.log


네 번재 PC(MacOS)를 초기화 하고 geth를 실행 합니다. 실행 포트는 30334 입니다.

geth --networkid 12 --datadir /Users/tongchunkim/Documents/Test_Ethereum/data_nglenet --port 30334 console 2>> /Users/tongchunkim/Documents/Test_Ethereum/data_nglenet/geth.log


그리고 각 node의 enode URL을 확인합니다.


첫 번째 PC(CentOS)의 enode 입니다.

"enode://efac3e59b5ba6fa5c55a076af7e7b4731376e3242fe431b9a90639e17552c3ad126b22ad1f8eb60a566332eeb7f6e071305fc78cf2e8b793c6f7c431072f2daa@[::]:30331"


두 번째 PC(CentOS)의 enode 입니다.

"enode://49fe51815a561b6f2d706a81e2e4045b63a1cc1fe5dfb2da08307324718258f5c2459d3c3fe6bba4399de136db88e015f98b5b88fe316cc2addbd78160a43be8@[::]:30332"


세 번째 PC(Ubuntu)의 enode 입니다.

"enode://b2a60a589c9a79f8fbf16dfa1a7dfe7841b96675d4d9d9ef26d4a74d7e97416d9267cac468955cc9b0c33d314b9a61463c1cf38655df75868bcf9aaed7509b80@[::]:30333"


네 번째 PC(MacOS)의 enode 입니다.

"enode://d3bcccb52db594c4677550f4d30d2bb5eae5c074e6051034261dca61e0eba0e4c44477b81a181a1b4941e5f94a44178844d3df19a53937e1d77145f1502a6ba8@59.13.214.161:30334"


이번에는 첫 번째 PC의 node에서 static-node.json을 만들어 연결하겠습니다.

static-node.json의 위치는 data 디렉토리 안에 존재해야 합니다. keystore 폴더와 같은 위치 입니다.

<datadir>/static-nodes.json


첫 번째 PC의 data 디렉토리는 /home/ngle/data_nglenet 입니다. 따라서 static-node.json 파일은 /home/ngle/data_nglenet/static-node.json 에 존재해야 합니다.

$ cd /home/ngle/data_nglenet
$ sudo vim static-nodes.json

static-nodes.json 파일 안에 아래와 같이 작성합니다.

[
	"enode://49fe51815a561b6f2d706a81e2e4045b63a1cc1fe5dfb2da08307324718258f5c2459d3c3fe6bba4399de136db88e015f98b5b88fe316cc2addbd78160a43be8@10.10.1.167:30332",
	"enode://b2a60a589c9a79f8fbf16dfa1a7dfe7841b96675d4d9d9ef26d4a74d7e97416d9267cac468955cc9b0c33d314b9a61463c1cf38655df75868bcf9aaed7509b80@10.10.1.39:30333",
	"enode://d3bcccb52db594c4677550f4d30d2bb5eae5c074e6051034261dca61e0eba0e4c44477b81a181a1b4941e5f94a44178844d3df19a53937e1d77145f1502a6ba8@10.10.0.145:30334"
]

json 파일 데이터는 문자의 배열 형식입니다.

각 node의 enode url에 @<node의 ip>:<node의 port> 형식으로 작성하면 됩니다. 첫 번째 PC의 node를 제외한 나머지 node의 enode url로 작성합니다.

네 번째 PC(MacOS)에서는 enode 정보를 확인했을때 공인 IP로 나오고 있습니다. 이걸 같은 네트워크 대역인 사설 IP로 변경해서 적용했습니다.


static-nodes.json 파일을 생성했다면 첫 번째 PC에 geth를 다시 실행하고 net.peerCount와 amdin.peers를 확인해 봅니다.

> net.peerCount
3
> admin.peers
[{
    caps: ["eth/62", "eth/63"],
    id: "3fb6758302063e456fdf5fa27d24069199c6823bd2dc42cb418a60183cc029eb",
    name: "Geth/v1.8.17-unstable-e39a9b34/linux-amd64/go1.9.4",
    network: {
      inbound: false,
      localAddress: "10.10.1.168:44976",
      remoteAddress: "10.10.1.167:30332",
      static: true,
      trusted: false
    },
    protocols: {
      eth: {
        difficulty: 20141354,
        head: "0x2aa83c6111c7fddce8553dee6adda0b61901306ec2656452337510c29c5d03e4",
        version: 63
      }
    }
}, {
    caps: ["eth/62", "eth/63"],
    id: "567503d1eaabdf4c68f7abfdbf4b93f83d3ebba2b50b229050f5e6ac6c48fc60",
    name: "Geth/v1.8.14-stable/darwin-amd64/go1.10.3",
    network: {
      inbound: false,
      localAddress: "10.10.1.168:51234",
      remoteAddress: "10.10.0.145:30334",
      static: true,
      trusted: false
    },
    protocols: {
      eth: {
        difficulty: 20141354,
        head: "0x2aa83c6111c7fddce8553dee6adda0b61901306ec2656452337510c29c5d03e4",
        version: 63
      }
    }
}, {
    caps: ["eth/62", "eth/63"],
    id: "90ae1ff9ebe62f99054a70ef8a98480ab5631e6609d1e63909f87e63f5c00fae",
    name: "Geth/v1.8.16-stable-477eb093/linux-amd64/go1.10",
    network: {
      inbound: false,
      localAddress: "10.10.1.168:33700",
      remoteAddress: "10.10.1.39:30333",
      static: true,
      trusted: false
    },
    protocols: {
      eth: {
        difficulty: 20141354,
        head: "0x2aa83c6111c7fddce8553dee6adda0b61901306ec2656452337510c29c5d03e4",
        version: 63
      }
    }
}]
> 

첫 번째 PC에서는 static-nodes.json에 지정한데로 3개의 peer가 잘 보이고 있습니다.

다른 PC에서는 연결된 node 하나만 보이며 정상입니다.

> net.peerCount
1
> admin.peers
[{
    caps: ["eth/62", "eth/63"],
    id: "efac3e59b5ba6fa5c55a076af7e7b4731376e3242fe431b9a90639e17552c3ad126b22ad1f8eb60a566332eeb7f6e071305fc78cf2e8b793c6f7c431072f2daa",
    name: "Geth/v1.8.17-unstable-d3441ebb/linux-amd64/go1.9.4",
    network: {
      inbound: true,
      localAddress: "10.10.0.145:30334",
      remoteAddress: "10.10.1.168:51234",
      static: false,
      trusted: false
    },
    protocols: {
      eth: {
        difficulty: 20141354,
        head: "0x2aa83c6111c7fddce8553dee6adda0b61901306ec2656452337510c29c5d03e4",
        version: 63
      }
    }
}]
> 

세 번째 PC에서 mining을 하고 다른 node들도 잘 전파되는지도 확인해 보겠습니다.


세 번째 PC에서 mining 합니다.

> miner.start(1)
null
> eth.mining
true
> eth.blockNumber
149
> 

다른 PC에서 blockNumber를 확인했을 때 잘 전파되는 것을 확인 할 수 있습니다.


여기까지 static-nodes.json을 사용한 테스트 네트워크 만들기였습니다.


Comments