오늘은 blockchain 이라는 새 유저를 s1에 새로 만들어보겠다.
우선, root 계정으로 가서 adduser을 해주자.
root@s1:~# adduser blockchain
Adding user `blockchain' ...
Adding new group `blockchain' (1001) ...
Adding new user `blockchain' (1001) with group `blockchain' ...
Creating home directory `/home/blockchain' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for blockchain
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
root@s1:~# ls /home
blockchain han
이제 우리는 s1의 root에 han과 blockchain 유저가 있음을 알 수 있다.
Blockchain@s1 유저에서 본격적으로 genesisblock을 해보자.
blockchain@s1:~$ vi genesis.json
{
"config": {
"chainId": 15,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"difficulty": "10",
"gasLimit": "2100000",
"alloc": {}
}
이제 geth를 초기화해주자.
geth --datadir ~/private_net init genesis.json
명령을 이용한다. Geth를 이용해 지갑을 만들어보자.
blockchain@s1:~$ geth --networkid "15" --datadir "~/private_net" --rpc --rpcaddr 192.168.56.70 --rpcport 8545 --rpcapi "web3, eth, net, personal" --rpccorsdomain "*" console
WARN [08-30|00:22:00.668] Sanitizing cache to Go's GC limits provided=1024 updated=664
INFO [08-30|00:22:00.670] Maximum peer count ETH=25 LES=0 total=25
INFO [08-30|00:22:00.670] Starting peer-to-peer node instance=Geth/v1.8.15-unstable-1acefafe/linux-amd64/go1.9.7
INFO [08-30|00:22:00.671] Allocated cache and file handles database=/home/blockchain/private_net/geth/chaindata cache=498 handles=512
INFO [08-30|00:22:00.690] Initialised chain configuration config="{ChainID: 15 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Constantinople: <nil> Engine: unknown}"
INFO [08-30|00:22:00.691] Disk storage enabled for ethash caches dir=/home/blockchain/private_net/geth/ethash count=3
INFO [08-30|00:22:00.691] Disk storage enabled for ethash DAGs dir=/home/blockchain/.ethash count=2
INFO [08-30|00:22:00.691] Initialising Ethereum protocol versions="[63 62]" network=15
INFO [08-30|00:22:00.692] Loaded most recent local header number=0 hash=357b5e…1b20b9 td=10
INFO [08-30|00:22:00.692] Loaded most recent local full block number=0 hash=357b5e…1b20b9 td=10
INFO [08-30|00:22:00.693] Loaded most recent local fast block number=0 hash=357b5e…1b20b9 td=10
INFO [08-30|00:22:00.693] Regenerated local transaction journal transactions=0 accounts=0
INFO [08-30|00:22:00.693] Starting P2P networking
INFO [08-30|00:22:02.807] IPC endpoint opened url=/home/blockchain/private_net/geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.15-unstable-1acefafe/linux-amd64/go1.9.7
modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
//새로운 지갑을 만들어주자.
> personal.newAccount("비밀번호")
"0xcdfab951fca557449f64cf57092ea106e4cd96a1"
> eth.accounts
["0xcdfab951fca557449f64cf57092ea106e4cd96a1"]
> eth.accounts[0]
"0xcdfab951fca557449f64cf57092ea106e4cd96a1"
> eth.accounts[1]
undefined
> eth.coinbase
INFO [08-30|00:23:57.262] Etherbase automatically configured address=0xcdFab951FCA557449F64cF57092ea106e4CD96a1
"0xcdfab951fca557449f64cf57092ea106e4cd96a1"
> eth.getBlock(0)
{
difficulty: 10,
extraData: "0x",
gasLimit: 2100000,
gasUsed: 0,
hash: "0x357b5eb0b98079e70bdd6cc479ac0b2a749320b2f1dc09b8fcd691db331b20b9",
logsBloom:"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
miner: "0x0000000000000000000000000000000000000000",
mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
nonce: "0x0000000000000000",
number: 0,
parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
receiptsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
sha3Uncles: "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
size: 504,
stateRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
timestamp: 0,
totalDifficulty: 10,
transactions: [],
transactionsRoot: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
uncles: [] //언클(전에 있었던 블럭에서 다른 방향으로 분화된 놈) 블록들의 해쉬값
}
state와 reciept, body 안의 transaction 정보가 Hash 안에 들어있다. logsBloom은 하나의 필터이다.
이제 s1에 blockchain 유저를 만들고 지갑을 생성했다.
s2에도 blockchain 유저를 만들고, 혹시 모를 권한 문제를 해결하기 위해 go와 go-ethereum, geth를 다시 설치하고 실행 시켜주자.
root@s2:~# adduser blockchain
Adding user `blockchain' ...
Adding new group `blockchain' (1001) ...
Adding new user `blockchain' (1001) with group `blockchain' ...
Creating home directory `/home/blockchain' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for blockchain
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
root@s2:~# rm -rf /usr/local/go
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 1 112M 1 1328k 0 0 1747k 0 0:01:06 --:--:-- 0:01:06 17 12 112M 12 13.7M 0 0 3714k 0 0:00:31 0:00:03 0:00:28 37 39 112M 39 44.9M 0 0 9674k 0 0:00:11 0:00:04 0:00:07 96 68 112M 68 77.4M 0 0 13.4M 0 0:00:08 0:00:05 0:00:03 13 88 112M 88 99.2M 0 0 14.2M 0 0:00:07 0:00:06 0:00:01 14100 112M 100 112M 0 0 15.2M 0 0:00:07 0:00:07 --:--:-- 16.8M
root@s2:~# tar -xzf go1.9.7.linux-amd64.tar.gz
root@s2:~# mv go /usr/local
root@s2:~# echo GOPATH="/usr/local/go" >> /home/blockchain/.profile
root@s2:~# echo PATH=\$PATH:\$GOPATH/bin >> /home/blockchain/.profile
Cloning into 'go-ethereum'...
remote: Counting objects: 72871, done.
remote: Total 72871 (delta 0), reused 0 (delta 0), pack-reused 72870
Receiving objects: 100% (72871/72871), 91.89 MiB | 6.59 MiB/s, done.
Resolving deltas: 100% (48522/48522), done.
Checking connectivity... done.
root@s2:~# mv go-ethereum/ /home/blockchain/
root@s2:~# chown -R blockchain:blockchain /home/blockchain/go-ethereum
root@s2:~# su blockchain
blockchain@s2:/root$ cd
blockchain@s2:~$ source .profile
blockchain@s2:~$ go
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
build compile packages and dependencies
clean remove object files
doc show documentation for package or symbol
env print Go environment information
bug start a bug report
fix run go tool fix on packages
fmt run gofmt on package sources
generate generate Go files by processing source
get download and install packages and dependencies
install compile and install packages and dependencies
list list packages
run compile and run Go program
test test packages
tool run specified go tool
version print Go version
vet run go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
c calling between Go and C
buildmode description of build modes
filetype file types
gopath GOPATH environment variable
environment environment variables
importpath import path syntax
packages description of package lists
testflag description of testing flags
testfunc description of testing functions
Use "go help [topic]" for more information about that topic.
blockchain@s2:~$ su
Password:
root@s2:/home/blockchain# chown blockchain:blockchain /usr/bin/geth
root@s2:/home/blockchain# geth version
WARN [08-30|00:56:12.733] Sanitizing cache to Go's GC limits provided=1024 updated=664
Geth
Version: 1.8.15-unstable
Git Commit: 1acefafe2201ba061a58b51afd7a7edf4aa0f120
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.9.7
Operating System: linux
GOPATH=
GOROOT=/usr/local/go
잘 실행된다.
## 여기서 깜빡한 부분이 있다. go-ethereum 폴더로 들어가 make geth를 해주고, go-ethereum/build/bin 안으로 들어가 geth 파일을 /usr/bin 밑으로 옮겨주어야
blockchain@s1에서 geth 명령어가 먹힌다.
이제 하나의 터미널은 blockchain@s1 에 접속하여 mining을 켜놓고, 터미널을 하나 더 켜서 blockchain@s2에 접속하자.
원래의 터미널은 투명 바탕, 새로 킨 터미널은 노란색 바탕으로 기록하겠다.
> miner.start(2) <- 2는 스레드 수
INFO [08-30|01:47:12.469] Updated mining threads threads=1
INFO [08-30|01:47:12.469] Transaction pool price threshold updated price=18000000000
null
> INFO [08-30|01:47:12.470] Commit new mining work number=145 sealhash=62fe84…b993d4 uncles=0 txs=0 gas=0 fees=0 elapsed=222.748µs
INFO [08-30|01:47:17.564] Generating DAG in progress epoch=0 percentage=0 elapsed=4.527s
INFO [08-30|01:47:21.911] Generating DAG in progress epoch=0 percentage=1 elapsed=8.874s
INFO [08-30|01:47:26.289] Generating DAG in progress epoch=0 percentage=2 elapsed=13.251s
.
.
.
채굴이 시작되었다.
이제 또 다른 터미널에 blockchain@s1에 연결하고, 채굴이 되고 있는 지갑을 공개지갑으로 바꾸어주자. 그래야 전송, 수금이 가능하다.
(노란 배경은 채굴이 되는 터미널이 아닌 새로 킨 터미널이다.
hanyeoul@ip-70-12-110-167:~$ ssh blockchain@192.168.56.70
blockchain@192.168.56.70's password:
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.15.0-33-generic x86_64)
3 packages can be updated.
0 updates are security updates.
New release '18.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
// 새로운 터미널이므로 원래 터미널의 geth 정보에 attach 시켜주자.
blockchain@s1:~$ geth attach ~/private_net/geth.ipc
WARN [08-30|01:10:56.575] Sanitizing cache to Go's GC limits provided=1024 updated=664
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.15-unstable-1acefafe/linux-amd64/go1.9.7
coinbase: 0xcdfab951fca557449f64cf57092ea106e4cd96a1
at block: 0 (Thu, 01 Jan 1970 09:00:00 KST)
datadir: /home/blockchain/private_net
modules: admin:1.0 debug:1.0 eth:1.0 ethash:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
> personal.unlockAccount(eth.accounts[2])
Unlock account 0x02c06dd554e2c59e96fbb604c0edee58f6a8d143
Passphrase:
true
> eth.coinbase
"0x02c06dd554e2c59e96fbb604c0edee58f6a8d143"
> eth.getBalance("0x02c06dd554e2c59e96fbb604c0edee58f6a8d143")
90000000000000000000
> web3.fromWei(eth.getBalance(eth.accounts[2]),"ether")
90
현재 채굴이 되고 있는 accounts[2] 지갑의 주소는 “0x02c06dd554e2c59e96fbb604c0edee58f6a8d143” 이다.
그냥 밸런스를 조회하면 wei 단위로 나오고, 이를 web3.~~ 명령으로 환산시켜주면 몇 이더가 캐졌는지 나온다.
마이닝 메시지를 보면, mining을 다시 시작하면 기존 블록들과의 동기화를 시작한다.
이 작업이 끝이 나야 새로운 채굴이 시작된다.
동기화가 되고 있는 메시지는 아래와 같다.
INFO [08-30|01:59:06.818] Generating DAG in progress epoch=0 percentage=83 elapsed=6m20.576s
동기화가 끝나고 나면, 채굴이 시작되고 아래와 같은 메시지를 계속해서 확인할 수 있다.
INFO [08-30|01:41:55.931] Successfully sealed new block number=140 sealhash=7a36ab…661ddd hash=8ff0f0…cac771 elapsed=2.210s
INFO [08-30|01:41:55.932] 🔗 block reached canonical chain number=133 hash=811a85…cca896
INFO [08-30|01:41:55.932] 🔨 mined potential block number=140 hash=8ff0f0…cac771
INFO [08-30|01:41:55.953] Commit new mining work number=141 sealhash=678fa4…b5a90e uncles=0 txs=0 gas=0 fees=0 elapsed=148.233µs
다른 터미널에서 확인해보면, 점점 이더리움이 늘어나는 것을 볼 수 있다.
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
300
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
310
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
450
> web3.fromWei(eth.getBalance(eth.accounts[0]),"ether")
705
다음 포스트에서는 Python을 통해 로그를 확인하는 logsbloom을 만들어볼 것이다.