❯ mkdir -p ~/Blockchain
❯ cd Blockchain
❯ puppeth
+-----------------------------------------------------------+
| Welcome to puppeth, your Ethereum private network manager |
| |
| This tool lets you create a new Ethereum network down to |
| the genesis block, bootnodes, miners and ethstats servers |
| without the hassle that it would normally entail. |
| |
| Puppeth uses SSH to dial in to remote servers, and builds |
| its network components out of Docker containers using the |
| docker-compose toolset. |
+-----------------------------------------------------------+
Please specify a network name to administer (no spaces, hyphens or capital letters please)
> choyeah_network
Sweet, you can set this via --network=choyeah_network next time!
INFO [02-03|19:49:47.017] Administering Ethereum network name=choyeah_network
WARN [02-03|19:49:47.017] No previous configurations found path=/Users/choyeah/.puppeth/choyeah_network
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
What would you like to do? (default = create)
1. Create new genesis from scratch
2. Import already existing genesis
> 1
Which consensus engine to use? (default = clique)
1. Ethash - proof-of-work
2. Clique - proof-of-authority
> 1
Which accounts should be pre-funded? (advisable at least one)
> 0x
Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes)
>
ERROR[02-03|19:51:51.218] Invalid input, expected 'y', 'yes', 'n', 'no' or empty
> y
Specify your chain/network ID if you want an explicit one (default = random)
> 4386
INFO [02-03|19:52:23.014] Configured new genesis block
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
1. Modify existing configurations
2. Export genesis configurations
3. Remove genesis configuration
> 2
Which folder to save the genesis specs into? (default = current)
Will create choyeah_network.json, choyeah_network-aleth.json, choyeah_network-harmony.json, choyeah_network-parity.json
>
INFO [02-03|19:53:42.130] Saved native genesis chain spec path=choyeah_network.json
INFO [02-03|19:53:42.133] Saved genesis chain spec client=aleth path=choyeah_network-aleth.json
INFO [02-03|19:53:42.135] Saved genesis chain spec client=parity path=choyeah_network-parity.json
INFO [02-03|19:53:42.136] Saved genesis chain spec client=harmony path=choyeah_network-harmony.json
chain/network ID는 아래 이미지와 같이 이미 사용되는 아이디와 중복될 수 없기 때문에 4386을 사용한다. (마지막 아이디인가?)
위와 같은 과정으로 제네시스 블록 파일을 추출할 수 있다. 추출된 파일은 제네시스 블록의 초기화 정보이다.
이더리움 노드에서 제네시스 블록의 내용을 json 파일을 통해 읽고 체인의 첫 시작을 어떻게 해야하는지 초기화 한다.
// choyeah_network.json
{
// config는 체인의 파라메터를 정의하는데 쓰인다
"config": {
"chainId": 4386,
"homesteadBlock": 0,
"eip150Block": 0,
"eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"ethash": {} // 합의 알고리즘, ethash는 작업증명
},
"nonce": "0x0",
// 타임스탬프는 evm에서 블록생성의 난위도 조절시 사용, 두 개의 블록의 타임스탬프의 차이가 적으면 난이도가 올라가고 크면 난이도가 내려간다.
// 블록들이 올바른 순서대로 진행되는지 확인하는데에도 사용된다.
"timestamp": "0x61fbb38e",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"gasLimit": "0x47b760", // 블록내의 트랜잭션이 소비할 수 있는 최대 가스 값, 각 블록마다 트랜잭션을 몇개나 처리할것인가 제한을 시켜서 블록의 사이즈를 조절
"difficulty": "0x80000", // 블록의 유효성을 검사할때 쓰이는 난이도, 연산을 몇번이나 해야하는지 디피컬티 값과 직접적인 연관이 있다. 디피컬티 값이 높으면 블록 채굴시간이 길어진다.
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
"alloc": { // 지갑 주소에 자금을 미리 할당하는 내용
"0000000000000000000000000000000000000000": {
"balance": "0x1"
},
"0000000000000000000000000000000000000001": {
"balance": "0x1"
},
"0000000000000000000000000000000000000002": {
"balance": "0x1"
},
생략...
},
"number": "0x0", // 블록넘버, 제네시스 블록이기때문에 넘버가 0x0임
"gasUsed": "0x0", // 이 블록내에서 여러가지 트랜잭션을 처리하면서 사용된 모든 가스의 합계, 마찬가지로 제네시스 블록이기 때문에 값이 0x0임
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", // 부모 블록의 해시 정보를 담는다. 제네시스 블록은 부모 블록이 없으므로 0
"baseFeePerGas": null
}
❯ geth --datadir . init choyeah_network.json
INFO [02-03|20:17:34.029] Maximum peer count ETH=50 LES=0 total=50
INFO [02-03|20:17:34.031] Set global gas cap cap=50,000,000
INFO [02-03|20:17:34.031] Allocated cache and file handles database=/Users/choyeah/Blockchain/geth/chaindata cache=16.00MiB handles=16
INFO [02-03|20:17:34.120] Writing custom genesis block
INFO [02-03|20:17:34.127] Persisted trie from memory database nodes=354 size=50.23KiB time=2.315827ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [02-03|20:17:34.129] Successfully wrote genesis state database=chaindata hash=35769a..18544c
INFO [02-03|20:17:34.130] Allocated cache and file handles database=/Users/choyeah/Blockchain/geth/lightchaindata cache=16.00MiB handles=16
INFO [02-03|20:17:34.237] Writing custom genesis block
INFO [02-03|20:17:34.242] Persisted trie from memory database nodes=354 size=50.23KiB time=1.394844ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [02-03|20:17:34.243] Successfully wrote genesis state database=lightchaindata hash=35769a..18544c
geth --datadir . init choyeah_network.json: geth 커맨드를 사용해서 현재 디렉터리에 프라이빗 노드 데이터를 저장
geth, keystore폴더가 새로 추가됨을 볼 수 있음, keystore는 앞으로 만들 계정들을 저장하는 공간이다.
geth --datadir . account new
를 입력하여 keysotre 폴더안에 새로운 이더리움 계정을 무작위로 생성한다.
❯ geth --datadir . account new
INFO [02-03|20:21:42.985] Maximum peer count ETH=50 LES=0 total=50
Your new account is locked with a password. Please give a password. Do not forget this password.
Password:
Repeat password:
Your new key was generated
Public address of the key: 0x3227B17049ce43ebC5b5885089d002D35E55F06b
Path of the secret key file: keystore/UTC--2022-02-03T11-21-57.329883000Z--3227b17049ce43ebc5b5885089d002d35e55f06b
- You can share your public address with anyone. Others need it to interact with you.
- You must NEVER share the secret key with anyone! The key controls access to your funds!
- You must BACKUP your key file! Without the key, it's impossible to access account funds!
- You must REMEMBER your password! Without the password, it's impossible to decrypt the key!
아래와 같이 만든 계정들의 리스트를 볼 수 도 있다. (생성순으로 번호를 매겨 출력된다.)
❯ geth --datadir . account list
INFO [02-03|20:25:34.433] Maximum peer count ETH=50 LES=0 total=50
INFO [02-03|20:25:34.437] Set global gas cap cap=50,000,000
Account #0: {3227b17049ce43ebc5b5885089d002d35e55f06b} keystore:///Users/choyeah/Blockchain/keystore/UTC--2022-02-03T11-21-57.329883000Z--3227b17049ce43ebc5b5885089d002d35e55f06b
Account #1: {c3884118ecacd04c460a149ec59bbf8b67cf5bbe} keystore:///Users/choyeah/Blockchain/keystore/UTC--2022-02-03T11-24-47.594264000Z--c3884118ecacd04c460a149ec59bbf8b67cf5bbe
Account #2: {9cc55b777acb90a0722c2cbb7d95ef2d16551aa1} keystore:///Users/choyeah/Blockchain/keystore/UTC--2022-02-03T11-24-55.908795000Z--9cc55b777acb90a0722c2cbb7d95ef2d16551aa1
모든 채굴 보상금은 첫 번째 계정으로 들어간다.
노드실행을위해 nodestart.cmd 파일을 만들어 아래와 같이 geth와 옵션 파라메터를 지정하여 저장한다.
꼭 한 줄로 작성해야 한다.
geth --networkid 4386 --mine --miner.threads 2 --datadir "./" --nodiscover --allow-insecure-unlock --http --http.port "8545" --http.corsdomain "*" --nat "any" --http.api "eth,web3,personal,net,miner" --unlock 0 --password ./password.sec
각 옵션의 의미는 다음과 같다.
NAT port mapping mechanism (any|none|upnp|pmp|extip:<IP>) (default: "any")
자세한 옵션의 정보는 아래 링크에서 확인
password.sec 파일을 생성하여 앞서 설정한 계정의 비밀번호를 저장한다.
❯ ./nodestart.cmd
INFO [02-04|08:55:03.392] Maximum peer count ETH=50 LES=0 total=50
INFO [02-04|08:55:03.396] Set global gas cap cap=50,000,000
INFO [02-04|08:55:03.396] Allocated trie memory caches clean=154.00MiB dirty=256.00MiB
INFO [02-04|08:55:03.398] Allocated cache and file handles database=/Users/choyeah/Blockchain/geth/chaindata cache=512.00MiB handles=5120
INFO [02-04|08:55:03.679] Opened ancient database database=/Users/choyeah/Blockchain/geth/chaindata/ancient readonly=false
INFO [02-04|08:55:03.681] Initialised chain configuration config="{ChainID: 4386 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: 0, Muir Glacier: <nil>, Berlin: <nil>, London: <nil>, Arrow Glacier: <nil>, MergeFork: <nil>, Engine: ethash}"
INFO [02-04|08:55:03.681] Disk storage enabled for ethash caches dir=/Users/choyeah/Blockchain/geth/ethash count=3
INFO [02-04|08:55:03.682] Disk storage enabled for ethash DAGs dir=/Users/choyeah/Library/Ethash count=2
INFO [02-04|08:55:03.682] Initialising Ethereum protocol network=4386 dbversion=<nil>
INFO [02-04|08:55:03.692] Loaded most recent local header number=0 hash=35769a..18544c td=524,288 age=13h4m9s
INFO [02-04|08:55:03.693] Loaded most recent local full block number=0 hash=35769a..18544c td=524,288 age=13h4m9s
INFO [02-04|08:55:03.693] Loaded most recent local fast block number=0 hash=35769a..18544c td=524,288 age=13h4m9s
WARN [02-04|08:55:03.693] Failed to load snapshot, regenerating err="missing or corrupted snapshot"
INFO [02-04|08:55:03.694] Rebuilding state snapshot
INFO [02-04|08:55:03.696] Resuming state snapshot generation root=b84523..07823f accounts=0 slots=0 storage=0.00B elapsed="463.011µs"
INFO [02-04|08:55:03.697] Regenerated local transaction journal transactions=0 accounts=0
INFO [02-04|08:55:03.698] Gasprice oracle is ignoring threshold set threshold=2
WARN [02-04|08:55:03.700] Error reading unclean shutdown markers error="leveldb: not found"
INFO [02-04|08:55:03.700] Starting peer-to-peer node instance=Geth/v1.10.15-stable-8be800ff/darwin-amd64/go1.17.5
INFO [02-04|08:55:03.732] Generated state snapshot accounts=256 slots=0 storage=9.50KiB elapsed=36.902ms
INFO [02-04|08:55:03.798] New local node record seq=1,643,932,503,797 id=f931b661785e9200 ip=127.0.0.1 udp=0 tcp=30303
INFO [02-04|08:55:03.799] Started P2P networking self="enode://ef0c01f85afe6909f884df2f9b94a2792573bc0bfec37d897b3afd8f6d859faf701f721f2609cea90b6b9741b152a8bb060f66ab024feb51dbe32a835f0b7c1d@127.0.0.1:30303?discport=0"
INFO [02-04|08:55:03.801] IPC endpoint opened url=/Users/choyeah/Blockchain/geth.ipc
INFO [02-04|08:55:03.802] HTTP server started endpoint=127.0.0.1:8545 prefix= cors=* vhosts=localhost
Fatal: Account unlock with HTTP access is forbidden!
❯ ./nodestart.cmd
INFO [02-04|08:56:30.483] Maximum peer count ETH=50 LES=0 total=50
INFO [02-04|08:56:30.487] Set global gas cap cap=50,000,000
INFO [02-04|08:56:30.487] Allocated trie memory caches clean=154.00MiB dirty=256.00MiB
INFO [02-04|08:56:30.489] Allocated cache and file handles database=/Users/choyeah/Blockchain/geth/chaindata cache=512.00MiB handles=5120
INFO [02-04|08:56:30.601] Opened ancient database database=/Users/choyeah/Blockchain/geth/chaindata/ancient readonly=false
INFO [02-04|08:56:30.605] Initialised chain configuration config="{ChainID: 4386 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: 0 EIP155: 0 EIP158: 0 Byzantium: 0 Constantinople: 0 Petersburg: 0 Istanbul: 0, Muir Glacier: <nil>, Berlin: <nil>, London: <nil>, Arrow Glacier: <nil>, MergeFork: <nil>, Engine: ethash}"
INFO [02-04|08:56:30.606] Disk storage enabled for ethash caches dir=/Users/choyeah/Blockchain/geth/ethash count=3
INFO [02-04|08:56:30.606] Disk storage enabled for ethash DAGs dir=/Users/choyeah/Library/Ethash count=2
INFO [02-04|08:56:30.607] Initialising Ethereum protocol network=4386 dbversion=8
INFO [02-04|08:56:30.608] Loaded most recent local header number=0 hash=35769a..18544c td=524,288 age=13h5m36s
INFO [02-04|08:56:30.608] Loaded most recent local full block number=0 hash=35769a..18544c td=524,288 age=13h5m36s
INFO [02-04|08:56:30.608] Loaded most recent local fast block number=0 hash=35769a..18544c td=524,288 age=13h5m36s
WARN [02-04|08:56:30.608] Loaded snapshot journal diskroot=b84523..07823f diffs=missing
INFO [02-04|08:56:30.609] Loaded local transaction journal transactions=0 dropped=0
INFO [02-04|08:56:30.610] Regenerated local transaction journal transactions=0 accounts=0
INFO [02-04|08:56:30.611] Gasprice oracle is ignoring threshold set threshold=2
WARN [02-04|08:56:30.612] Unclean shutdown detected booted=2022-02-04T08:55:03+0900 age=1m27s
INFO [02-04|08:56:30.612] Starting peer-to-peer node instance=Geth/v1.10.15-stable-8be800ff/darwin-amd64/go1.17.5
INFO [02-04|08:56:30.670] New local node record seq=1,643,932,503,798 id=f931b661785e9200 ip=127.0.0.1 udp=0 tcp=30303
INFO [02-04|08:56:30.670] Started P2P networking self="enode://ef0c01f85afe6909f884df2f9b94a2792573bc0bfec37d897b3afd8f6d859faf701f721f2609cea90b6b9741b152a8bb060f66ab024feb51dbe32a835f0b7c1d@127.0.0.1:30303?discport=0"
INFO [02-04|08:56:30.673] IPC endpoint opened url=/Users/choyeah/Blockchain/geth.ipc
INFO [02-04|08:56:30.673] HTTP server started endpoint=127.0.0.1:8545 prefix= cors=* vhosts=localhost
WARN [02-04|08:56:30.674] -------------------------------------------------------------------
WARN [02-04|08:56:30.674] Referring to accounts by order in the keystore folder is dangerous!
WARN [02-04|08:56:30.674] This functionality is deprecated and will be removed in the future!
WARN [02-04|08:56:30.674] Please use explicit addresses! (can search via `geth account list`)
WARN [02-04|08:56:30.674] -------------------------------------------------------------------
INFO [02-04|08:56:31.505] Unlocked account address=0x3227B17049ce43ebC5b5885089d002D35E55F06b
INFO [02-04|08:56:31.505] Transaction pool price threshold updated price=1,000,000,000
INFO [02-04|08:56:31.505] Updated mining threads threads=2
INFO [02-04|08:56:31.505] Transaction pool price threshold updated price=1,000,000,000
INFO [02-04|08:56:31.505] Etherbase automatically configured address=0x3227B17049ce43ebC5b5885089d002D35E55F06b
INFO [02-04|08:56:31.506] Commit new mining work number=1 sealhash=30b827..e32e52 uncles=0 txs=0 gas=0 fees=0 elapsed="994.819µs"
INFO [02-04|08:56:33.480] Generating DAG in progress epoch=0 percentage=0 elapsed=1.199s
INFO [02-04|08:56:34.836] Generating DAG in progress epoch=0 percentage=1 elapsed=2.555s
.
.
.
INFO [02-04|08:59:03.764] Generating DAG in progress epoch=0 percentage=97 elapsed=2m31.482s
INFO [02-04|08:59:05.566] Generating DAG in progress epoch=0 percentage=98 elapsed=2m33.284s
INFO [02-04|08:59:07.118] Generating DAG in progress epoch=0 percentage=99 elapsed=2m34.836s
INFO [02-04|08:59:07.120] Generated ethash verification cache epoch=0 elapsed=2m34.838s
INFO [02-04|08:59:11.528] Generating DAG in progress epoch=1 percentage=0 elapsed=3.085s
INFO [02-04|08:59:14.172] Generating DAG in progress epoch=1 percentage=1 elapsed=5.729s
INFO [02-04|08:59:16.828] Generating DAG in progress epoch=1 percentage=2 elapsed=8.384s
INFO [02-04|08:59:19.414] Generating DAG in progress epoch=1 percentage=3 elapsed=10.971s
INFO [02-04|08:59:21.912] Generating DAG in progress epoch=1 percentage=4 elapsed=13.469s
INFO [02-04|08:59:24.127] Generating DAG in progress epoch=1 percentage=5 elapsed=15.683s
INFO [02-04|08:59:26.912] Generating DAG in progress epoch=1 percentage=6 elapsed=18.469s
INFO [02-04|08:59:29.481] Generating DAG in progress epoch=1 percentage=7 elapsed=21.037s
INFO [02-04|08:59:31.233] Successfully sealed new block number=1 sealhash=30b827..e32e52 hash=032229..ae19c1 elapsed=2m59.726s
INFO [02-04|08:59:31.270] 🔨 mined potential block number=1 hash=032229..ae19c1
INFO [02-04|08:59:31.240] Commit new mining work number=2 sealhash=f42189..b65544 uncles=0 txs=0 gas=0 fees=0 elapsed="230.275µs"
INFO [02-04|08:59:32.177] Generating DAG in progress epoch=1 percentage=8 elapsed=23.733s
INFO [02-04|08:59:34.492] Successfully sealed new block number=2 sealhash=f42189..b65544 hash=87fc75..d22881 elapsed=3.251s
INFO [02-04|08:59:34.492] 🔨 mined potential block number=2 hash=87fc75..d22881
INFO [02-04|08:59:34.492] Commit new mining work number=3 sealhash=9f5f07..537fff uncles=0 txs=0 gas=0 fees=0 elapsed="181.499µs"
INFO [02-04|08:59:34.886] Generating DAG in progress epoch=1 percentage=9 elapsed=26.443s
INFO [02-04|08:59:37.797] Generating DAG in progress epoch=1 percentage=10 elapsed=29.354s
INFO [02-04|08:59:40.534] Generating DAG in progress epoch=1 percentage=11 elapsed=32.090s
INFO [02-04|08:59:42.992] Generating DAG in progress epoch=1 percentage=12 elapsed=34.548s
INFO [02-04|08:59:44.704] Successfully sealed new block number=3 sealhash=9f5f07..537fff hash=3bc389..f914a7 elapsed=10.211s
INFO [02-04|08:59:44.710] 🔨 mined potential block number=3 hash=3bc389..f914a7
INFO [02-04|08:59:44.728] Commit new mining work number=4 sealhash=c57c43..b49088 uncles=0 txs=0 gas=0 fees=0 elapsed="144.959µs"
.
.
.
INFO [02-04|09:00:51.160] Commit new mining work number=14 sealhash=5db876..9abc28 uncles=0 txs=0 gas=0 fees=0 elapsed="181.928µs"
INFO [02-04|09:00:51.377] Generating DAG in progress epoch=1 percentage=40 elapsed=1m42.933s
INFO [02-04|09:00:53.642] Generating DAG in progress epoch=1 percentage=41 elapsed=1m45.197s
INFO [02-04|09:00:56.215] Generating DAG in progress epoch=1 percentage=42 elapsed=1m47.771s
INFO [02-04|09:00:58.430] Successfully sealed new block number=14 sealhash=5db876..9abc28 hash=aedb21..6d71f5 elapsed=7.270s
INFO [02-04|09:00:58.430] 🔗 block reached canonical chain number=7 hash=59666d..111fa0
INFO [02-04|09:00:58.430] 🔨 mined potential block number=14 hash=aedb21..6d71f5
INFO [02-04|09:00:58.431] Commit new mining work number=15 sealhash=1d74e2..96be90 uncles=0 txs=0 gas=0 fees=0 elapsed="249.028µs"
INFO [02-04|09:00:58.685] Generating DAG in progress epoch=1 percentage=43 elapsed=1m50.241s
INFO [02-04|09:01:01.511] Generating DAG in progress epoch=1 percentage=44 elapsed=1m53.067s
INFO [02-04|09:01:02.140] Successfully sealed new block number=15 sealhash=1d74e2..96be90 hash=3be95d..92907d elapsed=3.709s
INFO [02-04|09:01:02.141] 🔗 block reached canonical chain number=8 hash=e0f986..541d3a
INFO [02-04|09:01:02.141] 🔨 mined potential block number=15 hash=3be95d..92907d
INFO [02-04|09:01:02.158] Commit new mining work number=16 sealhash=8529e6..003530 uncles=0 txs=0 gas=0 fees=0 elapsed="145.5µs"
INFO [02-04|09:01:03.764] Generating DAG in progress epoch=1 percentage=45 elapsed=1m55.320s
INFO [02-04|09:01:06.373] Generating DAG in progress epoch=1 percentage=46 elapsed=1m57.928s
INFO [02-04|09:01:08.563] Generating DAG in progress epoch=1 percentage=47 elapsed=2m0.119s
INFO [02-04|09:01:08.824] Successfully sealed new block number=16 sealhash=8529e6..003530 hash=b28e8f..7237cb elapsed=6.666s
INFO [02-04|09:01:08.824] 🔗 block reached canonical chain number=9 hash=0ac261..bb8696
INFO [02-04|09:01:08.824] 🔨 mined potential block number=16 hash=b28e8f..7237cb
INFO [02-04|09:01:08.846] Commit new mining work number=17 sealhash=585908..b37384 uncles=0 txs=0 gas=0 fees=0 elapsed="182.457µs"
INFO [02-04|09:01:11.095] Generating DAG in progress epoch=1 percentage=48 elapsed=2m2.651s
INFO [02-04|09:01:13.295] Generating DAG in progress epoch=1 percentage=49 elapsed=2m4.851s
생략...
Generating DAG in progress 라고 나오는데 이 DAG는 directed acyclic graph(방향성 비순환 그래프)의 약자로 Ethash 채굴 알고리즘에서 필요로하는 데이터 구조이다.
노드를 맨 처음에 실행할때 DAG 파일이 생성된다.
노드가 채굴을 하기 위해서는 이 DAG파일이 먼저 존재해야 한다.
매 30000개의 블록이 생성될때마다 DAG 파일이 새롭게 생성이 된다.
참고로 30000블록을 명칭하는것이 Epoch이다.
처음 DAG 파일이 생성되는 시간은 조금 소요되는 편인데 컴퓨터 사양마다 다르지만 몇분에서 몇십분 수준이다.
epoch=0 percentage=0 elapsed=1.199s
epoch=0 percentage=1 elapsed=2.555s
epoch=0 percentage=2 elapsed=3.804s
epoch=0 percentage=3 elapsed=5.073s
...
epoch=0 percentage=93 elapsed=2m24.448s
epoch=0 percentage=94 elapsed=2m25.669s
epoch=0 percentage=95 elapsed=2m27.634s
epoch=0 percentage=96 elapsed=2m29.355s
첫 번째 epoch은 0으로 시작되고 percentage를 통해 진행상황을 알 수 있다.
epoch 0이 끝나면 epoch 1이 진행되고 epoch 1이 100%가 되면 DAG 파일 생성이 완료된다.
DAG 파일은 아래와 같이 .etash 하위에 저장된다.
각각 1기가가 조금 넘는 사이즈이다.
❯ pwd
/Users/choyeah/.ethash
❯ ls -al
total 4210688
drwxr-xr-x 4 choyeah staff 128 Feb 16 2018 .
drwxr-xr-x+ 143 choyeah staff 4576 Feb 4 09:45 ..
-rw-r--r-- 1 choyeah staff 1073739912 Feb 16 2018 full-R23-0000000000000000
-rw-r--r-- 1 choyeah staff 1082130312 Feb 16 2018 full-R23-290decd9548b62a8
INFO [02-04|09:34:40.253] Successfully sealed new block number=369 sealhash=088eb9..545150 hash=817d76..968280 elapsed=2.712s
INFO [02-04|09:34:40.253] 🔗 block reached canonical chain number=362 hash=fb0d56..7b3d00
INFO [02-04|09:34:40.253] 🔨 mined potential block number=369 hash=817d76..968280
INFO [02-04|09:34:40.254] Commit new mining work number=370 sealhash=3bef48..242531 uncles=0 txs=0 gas=0 fees=0 elapsed="130.898µs"
INFO [02-04|09:34:44.551] Successfully sealed new block number=370 sealhash=3bef48..242531 hash=86c680..0f2cb8 elapsed=4.297s
INFO [02-04|09:34:44.552] 🔗 block reached canonical chain number=363 hash=ca6c43..d3419f
INFO [02-04|09:34:44.552] 🔨 mined potential block number=370 hash=86c680..0f2cb8
INFO [02-04|09:34:44.552] Commit new mining work number=371 sealhash=1abaed..a0abd1 uncles=0 txs=0 gas=0 fees=0 elapsed="164.403µs"
INFO [02-04|09:34:48.448] Successfully sealed new block number=371 sealhash=1abaed..a0abd1 hash=da3eb5..c4c4ad elapsed=3.896s
INFO [02-04|09:34:48.448] 🔗 block reached canonical chain number=364 hash=80ce69..2de92c
INFO [02-04|09:34:48.448] 🔨 mined potential block number=371 hash=da3eb5..c4c4ad
INFO [02-04|09:34:48.449] Commit new mining work number=372 sealhash=68ed7d..3a2da5 uncles=0 txs=0 gas=0 fees=0 elapsed="177.718µs"
INFO [02-04|09:34:57.250] Successfully sealed new block number=372 sealhash=68ed7d..3a2da5 hash=71a7da..0979a5 elapsed=8.801s
INFO [02-04|09:34:57.250] 🔗 block reached canonical chain number=365 hash=3b5946..022fec
INFO [02-04|09:34:57.250] 🔨 mined potential block number=372 hash=71a7da..0979a5
INFO [02-04|09:34:57.250] Commit new mining work number=373 sealhash=95eed2..1c58fe uncles=0 txs=0 gas=0 fees=0 elapsed="146.772µs"
INFO [02-04|09:35:03.762] Successfully sealed new block number=373 sealhash=95eed2..1c58fe hash=ccbc37..24ea52 elapsed=6.511s
INFO [02-04|09:35:03.762] 🔗 block reached canonical chain number=366 hash=469600..68e1af
INFO [02-04|09:35:03.762] 🔨 mined potential block number=373 hash=ccbc37..24ea52
INFO [02-04|09:35:03.762] Commit new mining work number=374 sealhash=98ae3b..4e19cd uncles=0 txs=0 gas=0 fees=0 elapsed="167.32µs"
INFO [02-04|09:35:09.875] Successfully sealed new block number=374 sealhash=98ae3b..4e19cd hash=e6e389..095411 elapsed=6.112s
INFO [02-04|09:35:09.875] 🔗 block reached canonical chain number=367 hash=a85203..60a97b
INFO [02-04|09:35:09.875] 🔨 mined potential block number=374 hash=e6e389..095411
INFO [02-04|09:35:09.875] Commit new mining work number=375 sealhash=d4bce1..263ad9 uncles=0 txs=0 gas=0 fees=0 elapsed="192.801µs"
INFO [02-04|09:35:18.853] Successfully sealed new block number=375 sealhash=d4bce1..263ad9 hash=bea852..4387ae elapsed=8.977s
INFO [02-04|09:35:18.853] 🔗 block reached canonical chain number=368 hash=c796b0..cb35f2
INFO [02-04|09:35:18.853] 🔨 mined potential block number=375 hash=bea852..4387ae
INFO [02-04|09:35:18.853] Commit new mining work number=376 sealhash=39bd80..565505 uncles=0 txs=0 gas=0 fees=0 elapsed="167.344µs"
INFO [02-04|09:35:19.211] Successfully sealed new block number=376 sealhash=39bd80..565505 hash=d21d71..4d3d05 elapsed=357.915ms
INFO [02-04|09:35:19.211] 🔗 block reached canonical chain number=369 hash=817d76..968280
INFO [02-04|09:35:19.211] 🔨 mined potential block number=376 hash=d21d71..4d3d05
INFO [02-04|09:35:19.211] Commit new mining work number=377 sealhash=dd1a6c..8e4742 uncles=
Commit new mining work 메세지와 함께 정기적으로 노드가 새로운 블록을 채굴하고있다.
로그에서 number 부분은 블록 넘버를 의미한다. txs=0과 같이 트랜잭션이 없더라도 블록 채굴을 계속한다.
블록 채굴을 하는 이유가 트랜잭션을 처리하는것도 있지만 새로운 Ether를 생성하는것에도 목적이 있기 때문이다.
❯ geth attach http://127.0.0.1:8545
Welcome to the Geth JavaScript console!
instance: Geth/v1.10.15-stable-8be800ff/darwin-amd64/go1.17.5
coinbase: 0x3227b17049ce43ebc5b5885089d002d35e55f06b
at block: 819 (Fri Feb 04 2022 10:18:43 GMT+0900 (KST))
modules: eth:1.0 net:1.0 personal:1.0 rpc:1.0 web3:1.0
To exit, press ctrl-d or type exit
geth attach는 백그라운드로 돌고있는 로컬 노드에 연결시켜서 자바스크립트 콘솔을 여는것이다.
coinbase는 첫 번째로 만들었던 계정을 의미하며 modules은 자바스크립트 콘솔창에서 쓸 수 있는 api를 나열한 것이다. (nodestart.cmd에 작성하였던 --http.api “eth,web3,personal,net,miner” 부분이 적용된 모습)
# 코인베이스 계정을 리턴
> eth.coinbase
"0x3227b17049ce43ebc5b5885089d002d35e55f06b"
# 현재 노드에 생성된 계정들을 리턴
> eth.accounts
["0x3227b17049ce43ebc5b5885089d002d35e55f06b", "0xc3884118ecacd04c460a149ec59bbf8b67cf5bbe", "0x9cc55b777acb90a0722c2cbb7d95ef2d16551aa1"]
# 특정 계정에 존재하는 이더 확인
> eth.getBalance(eth.accounts[0])
1.728e+21
> eth.getBalance(eth.accounts[1])
0
> eth.getBalance(eth.coinbase)
1.76e+21
# 위에서 출력되는 이더 단위는 wei인데 wei는 이더를 나타내는 단위 중 가장 낮은 단위이다.
#wei를 web3 api를 사용하여 이더 단위로 출력할 수 있다.
> web3.fromWei(eth.getBalance(eth.coinbase), "ether")
1816
# 현재 진행중인 채굴을 중지
> miner
{
getHashrate: function(),
setEtherbase: function(),
setExtra: function(),
setGasLimit: function(),
setGasPrice: function(),
setRecommitInterval: function(),
start: function(),
stop: function()
}
> miner.stop()
null
# 인자로 주어진 2는 채굴 쓰레드 수를 의미한다.
> miner.start(2)
null
# 계정 언락시키기, 계정의 프라이빗키를 열어서 트랜잭션에 서명할 수 있도록..
# 프라이빗키는 디폴트로 항상 잠겨있다.
# 계정의 비밀번호를 알고있어야 언락시킬 수 있다.
# 두 번째 계정을 언락시켜보기
> personal.unlockAccount(eth.accounts[1], "pwd1234", 200)
true
# 세 번째 인자 200은 얼마동안 언락시킬지를 의미(초단위)
# 송금하기
> eth.sendTransaction({from:eth.coinbase, to:eth.accounts[1], value:web3.toWei(20, "ether")})
"0xdcc070f0a44476ca9e1cfd5f8f93db95070998c0b2126968704ff60fac4e32f8"
# 전송 후 결과값으로 리턴대는 해시는 트랜잭션 해시이다.
# 잘 송금 되었는지 확인
> web3.fromWei(eth.getBalance(eth.accounts[1]), "ether")
20
# 현재 돌아가고있는 노드의 로그에서는 아래와 같이 트랜잭션 정보가 출력됨을 확인할 수 있다.
NFO [02-04|10:44:56.145] Setting new local account address=0x3227B17049ce43ebC5b5885089d002D35E55F06b
INFO [02-04|10:44:56.146] Submitted transaction hash=0xdcc070f0a44476ca9e1cfd5f8f93db95070998c0b2126968704ff60fac4e32f8 from=0x3227B17049ce43ebC5b5885089d002D35E55F06b nonce=0 recipient=0xc3884118ecaCD04c460A149Ec59Bbf8b67CF5bBE value=20,000,000,000,000,000,000
# 이 전송건에 대한 트랜잭션은 다음 블록이 채굴될때 다음 블록안에 추가가 된다.