본문 바로가기
Blockchain/Ethereum

[ Geth ] 파헤치기 2 번 - 시작 Log 분석하기

by 기저귀찬개발자 2019. 5. 6.

관련글

2019/04/15 - [Blockchain/Ethereum] - [ Geth ] 파헤치기 1 번 - Geth 실행 및 디버깅 방법

2019/05/06 - [Blockchain/Ethereum] - [ Geth ] 파헤치기 2 번 - 시작 Log 분석하기

2019/06/14 - [Blockchain/Ethereum] - [ Geth ] 파헤치기 3 번 - geth Main 함수 살펴보기

2019/06/24 - [Blockchain/Ethereum] - [ Geth ] 파헤치기 4 번 - geth 함수 살펴보기

 

 

이전글 Geth 파헤치기 1번에서 geth 설치와 main 함수에서 Hello, world 를 출력하는 것까지 진행하였다.

이번 글에선 geth를 실행했을때 나오는 log들이 어떤 의미를 가지고 있는지 확인해보도록 하겠다.

아래의 log들은 geth에 아무런 옵션을 주지 않고 실행했을때 나오는 log이다.

 

[ 1] INFO [05-19|18:34:13.684] Bumping default cache on mainnet         provided=1024 updated=4096
[ 2] WARN [05-19|18:34:13.685] Sanitizing cache to Go's GC limits       provided=4096 updated=2613
[ 3] INFO [05-19|18:34:13.686] Maximum peer count                       ETH=25 LES=0 total=25
[ 4] WARN [05-19|18:34:13.990] Failed to start smart card hub, disabling: dial unix /run/pcscd/pcscd.comm: connect: no such file or directory
[ 5] INFO [05-19|18:34:14.042] Starting peer-to-peer node               instance=Geth/v1.9.0-unstable/linux-amd64/go1.10.1
[ 6] INFO [05-19|18:34:14.043] Allocated trie memory caches             clean=653.00MiB dirty=653.00MiB
[ 7] INFO [05-19|18:34:14.043] Allocated cache and file handles         database=/home/jude/.ethereum/geth/chaindata cache=1306.00MiB handles=2048
[ 8] INFO [05-19|18:34:16.705] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: 7280000  ConstantinopleFix: 7280000 Engine: ethash}"
[ 9] INFO [05-19|18:34:16.705] Disk storage enabled for ethash caches   dir=/home/jude/.ethereum/geth/ethash count=3
[10] INFO [05-19|18:34:16.705] Disk storage enabled for ethash DAGs     dir=/home/jude/.ethash               count=2
[11] INFO [05-19|18:34:16.733] Initialising Ethereum protocol           versions="[63 62]" network=1 dbversion=5
[12] INFO [05-19|18:34:17.518] Loaded most recent local header          number=7025734 hash=04994f…c394ab td=8613414531064451687296 age=4mo1w4d
[13] INFO [05-19|18:34:17.518] Loaded most recent local full block      number=0       hash=d4e567…cb8fa3 td=17179869184            age=50y1mo5d
[14] INFO [05-19|18:34:17.518] Loaded most recent local fast block      number=6994600 hash=358c0b…8369ca td=8532686611222296645336 age=4mo2w3d
[15] INFO [05-19|18:34:20.874] Loaded local transaction journal         transactions=0 dropped=0
[16] INFO [05-19|18:34:20.882] Regenerated local transaction journal    transactions=0 accounts=0
[17] INFO [05-19|18:34:21.708] New local node record                    seq=6 id=3c0e0f6ceeaa60a8 ip=127.0.0.1 udp=30303 tcp=30303
[18] INFO [05-19|18:34:21.709] Started P2P networking                   self=enode://30b9006ea36af0cab2926592fdd60c3ab2c44ab35fded424fa5c6c1559eb821749fa3c1744e1d811348a454ca8a5dcdba7a6b82c6309b4fe55d66e4ca9c4952d@127.0.0.1:30303
[19] INFO [05-19|18:34:21.783] IPC endpoint opened                      url=/home/jude/.ethereum/geth.ipc
[20] INFO [05-19|18:34:23.866] Mapped network port                      proto=tcp extport=30303 intport=30303 interface="UPNP IGDv1-IP1"
[21] INFO [05-19|18:34:23.881] Mapped network port                      proto=udp extport=30303 intport=30303 interface="UPNP IGDv1-IP1"
[22] INFO [05-19|18:34:25.659] New local node record                    seq=7 id=3c0e0f6ceeaa60a8 ip=121.129.130.32 udp=30303 tcp=30303
[23] INFO [05-19|18:38:11.712] Block synchronisation started
[24] INFO [05-19|18:38:19.385] Imported new block headers               count=0 elapsed=27.200ms number=6994860 hash=d61d50…048bce age=4mo2w3d  ignored=192
[25] INFO [05-19|18:38:19.932] Imported new block headers               count=0 elapsed=11.392ms number=6995052 hash=8d7e37…4dcba0 age=4mo2w3d  ignored=192
[26] INFO [05-19|18:38:20.156] Imported new block receipts              count=2 elapsed=3.290ms  number=6994670 hash=6792b5…ffcf6b age=4mo2w3d  size=68.95KiB
[27] INFO [05-19|18:38:20.645] Imported new block headers               count=0 elapsed=35.364ms number=6995244 hash=9a9132…e4c586 age=4mo2w3d  ignored=192
[28] INFO [05-19|18:38:21.064] Imported new block receipts              count=5 elapsed=23.127ms number=6994675 hash=60f461…2a55fa age=4mo2w3d  size=105.58KiB
[29] INFO [05-19|18:38:21.756] Imported new block headers               count=0 elapsed=22.301ms number=6995436 hash=07bc68…4d9ec9 age=4mo2w3d  ignored=192
[30] INFO [05-19|18:38:23.582] Imported new block receipts              count=13 elapsed=9.214ms  number=6994688 hash=52f882…94d9cc age=4mo2w3d  size=244.85KiB
[31] INFO [05-19|18:38:24.547] Imported new block headers               count=0  elapsed=50.526ms number=6995628 hash=9be109…9ef34a age=4mo2w3d  ignored=192

 

Line 1.

INFO [05-19|18:34:13.684] Bumping default cache on mainnet         provided=1024 updated=4096

위치 : /cmd/evm/geth/main.go -> init()

 

해당 Log를 찾아보면 /cmd/evm/geth/main.go 의 init() 함수에 위치하는 것을 알 수 있다.

Go 언어에서 중요한 함수 중 하나 인데 init() 함수는 main() 함수가 실행되기 전에 실행된다.

아래 소스를 보면 메인넷일 경우에 cache 옵션을 지정하지 않을 경우 default 메모리를 4096으로 높이는 것을 알 수 있다.

// If we're a full node on mainnet without --cache specified, bump default cache allowance
// cache 옵션을 지정하지 않은 mainnet full node 라면 default cache 를 늘린다
if ctx.GlobalString(utils.SyncModeFlag.Name) != "light" && !ctx.GlobalIsSet(utils.CacheFlag.Name) && !ctx.GlobalIsSet(utils.NetworkIdFlag.Name) {
	// Make sure we're not on any supported preconfigured testnet either
    // 테스트 넷인지 확인
	if !ctx.GlobalIsSet(utils.TestnetFlag.Name) && !ctx.GlobalIsSet(utils.RinkebyFlag.Name) && !ctx.GlobalIsSet(utils.GoerliFlag.Name) {
		// Nope, we're really on mainnet. Bump that cache up!
        // 메인넷 확인
		log.Info("Bumping default cache on mainnet", "provided", ctx.GlobalInt(utils.CacheFlag.Name), "updated", 4096)
		ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(4096))
	}
}

 

Line 2.

WARN [05-19|18:34:13.685] Sanitizing cache to Go's GC limits       provided=4096 updated=2613
위치 : /cmd/evm/geth/main.go -> init()

 

뜻만 봤을때는 Go 환경의 GC limit에 걸린 것으로 확인된다.

cache 가 사양에 맞춰서 조절된 것으로 확인된다.

// Cap the cache allowance and tune the garbage collector
// cache 와 GC를 설정해라
var mem gosigar.Mem
if err := mem.Get(); err == nil {
	allowance := int(mem.Total / 1024 / 1024 / 3)
	if cache := ctx.GlobalInt(utils.CacheFlag.Name); cache > allowance {
		log.Warn("Sanitizing cache to Go's GC limits", "provided", cache, "updated", allowance)
		ctx.GlobalSet(utils.CacheFlag.Name, strconv.Itoa(allowance))
	}
}

 

 

Line 3.

INFO [05-19|18:34:13.686] Maximum peer count                       ETH=25 LES=0 total=25

위치 : /cmd/utils/flags.go -> SetP2PConfig()

 

추가 가능한 Peer의 Max값을 나타낸다. 사양에 따라 --maxpeers 옵션을 통해 변경할 수 있다.

 

Line 4.

WARN [05-19|18:34:13.990] Failed to start smart card hub, disabling: dial unix /run/pcscd/pcscd.comm: connect: no such file or directory

위치 : /node/config.go

 

참고 : https://github.com/ethereum/go-ethereum/pull/19439

 

Line 5.

INFO [05-19|18:34:14.042] Starting peer-to-peer node               instance=Geth/v1.9.0-unstable/linux-amd64/go1.10.1

위치 : /node/node.go

 

필요한 데이터를 주고받을 노드가 선정되었음을 의미한다.

 

Line 6.

INFO [05-19|18:34:14.043] Allocated trie memory caches             clean=653.00MiB dirty=653.00MiB

위치 : /eth/backend.go

 

eth 객체를 설정하는 부분에서 노출되는 로그이다.

trie memory cache....? (추후 첨부)

 

 

 

Line 7.

INFO [05-19|18:34:14.043] Allocated cache and file handles         database=/home/jude/.ethereum/geth/chaindata cache=1306.00MiB handles=2048

위치 : /ethdb/leveldb

 

LevelDB? Key-Value 기반의 Storage

levelDB 객체의 정보를 보여준다.

 

Line 8.

INFO [05-19|18:34:16.705] Initialised chain configuration          config="{ChainID: 1 

Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: 7280000  ConstantinopleFix: 7280000 Engine: ethash}"

위치 : /eth/backend.go

 

ChainID : network 구분 ID 이다. 일반적으로 network ID와 

1 Ethereum mainnet
2 Morden (disused), Expanse mainnet
3 Ropsten
4 Rinkeby
5 Goerli
42 Kovan
1337 Geth private chains (default)

참고: https://ethereum.stackexchange.com/questions/37533/what-is-a-chainid-in-ethereum-how-is-it-different-than-networkid-and-how-is-it 

 

chainID 다음으로 는 각각 릴리즈 시점을 의미한다. 안드로이드의 킷캣, 롤리팝 등 릴리즈 버전에 따라 붙이는 호칭과 비슷하다.

Homestead - 이더리움의 두번째 릴리즈 버전

DAO - dApp 개발자들에게 지급될 DAO 토큰이 적용된 시점 하지만 해당 컨트랙트가 해킹 당하여 그 뒤에 하드 포크를 진행하게 된다.

EIP150 - 가스 가격 상승 등에 대한 개선안이 적용된 시점이다 155나 158도 github issue 사항에서 확인 가능하다.

참조 : https://github.com/ethereum/EIPs/issues/150

Engine:ethash - Pow 알고리즘이 적용된 마이닝 프로토콜

 

Line 9,10

INFO [05-19|18:34:16.705] Disk storage enabled for ethash caches   dir=/home/jude/.ethereum/geth/ethash count=3

INFO [05-19|18:34:16.705] Disk storage enabled for ethash DAGs     dir=/home/jude/.ethash               count=2

위치 : /consensus/ethash/ethash.go

 

ethash 를 적용할 준비 시점을 알려준다.

 

Line 11.

INFO [05-19|18:34:16.733] Initialising Ethereum protocol           versions="[63 62]" network=1 dbversion=5

위치 : /eth/backend.go

 

생성된 Ethereum 객체의 버전 정보들

 

Line 12, 13, 14

INFO [05-19|18:34:17.518] Loaded most recent local header          number=7025734 hash=04994f…c394ab td=8613414531064451687296 age=4mo1w4d

INFO [05-19|18:34:17.518] Loaded most recent local full block      number=0       hash=d4e567…cb8fa3 td=17179869184            age=50y1mo5d

INFO [05-19|18:34:17.518] Loaded most recent local fast block      number=6994600 hash=358c0b…8369ca td=8532686611222296645336 age=4mo2w3d

위치 : /core/blockchain.go

 

local에 보관중인 블록들의 정보가 보인다. 

싱크를 맞추게 되면 해당 번호들이 올라갈 것으로 보인다.

 

Line 15, 16

INFO [05-19|18:34:20.874] Loaded local transaction journal         transactions=0 dropped=0

INFO [05-19|18:34:20.882] Regenerated local transaction journal    transactions=0 accounts=0

위치 : /core/tx_journal.go

 

보관중인 transactions pool에 대한 정보를 나타낸다.

해당 소스를 확인해보면 아래 파일들이 생기고 트랜잭션을 보관하는 것으로 보인다.

/.ethereum/geth/transactions.rlp

/.ethereum/geth/transactions.rlp.new

 

 

 

Line 17.

INFO [05-19|18:34:21.708] New local node record                   seq=6 id=3c0e0f6ceeaa60a8 ip=127.0.0.1 udp=30303 tcp=30303

위치 : /p2p/enode/localnode.go

 

내 자신 노드에 대한 정보들을 보여준다.

아래는 geth에서 가지고 다니는 LocalNode에 대한 구조체이다.

// LocalNode produces the signed node record of a local node, i.e. a node run in the

// current process. Setting ENR entries via the Set method updates the record. A new version

// of the record is signed on demand when the Node method is called.

type LocalNode struct {

    cur atomic.Value // holds a non-nil node pointer while the record is up-to-date.

    id ID

    key *ecdsa.PrivateKey

    db *DB



    // everything below is protected by a lock

    mu sync.Mutex

    seq uint64

    entries map[string]enr.Entry

    udpTrack *netutil.IPTracker // predicts external UDP endpoint

    staticIP net.IP

    fallbackIP net.IP

    fallbackUDP int

}

 

Line 18.

INFO [05-19|18:34:21.709] Started P2P networking                   self=enode://30b9006ea36af0cab2926592fdd60c3ab2c44ab35fded424fa5c6c1559eb821749fa3c1744e1d811348a454ca8a5dcdba7a6b82c6309b4fe55d66e4ca9c4952d@127.0.0.1:30303

위치 : /p2p/server.go

 

enode뒤에 주소는 Ethereum 노드를 @ 기호로 호스트와 구분 된 URI 형식이다.

512 byte 의 공개키 방식의 ID를 가지게 된다.

 

Line 19.

INFO [05-19|18:34:21.783] IPC endpoint opened                      url=/home/jude/.ethereum/geth.ipc

 

IPC 통신을 통해서 geth attach를 통해 geth 실행과정을 볼 수가 있다.

 

Line 20, 21

INFO [05-19|18:34:23.866] Mapped network port                      proto=tcp extport=30303 intport=30303 interface="UPNP IGDv1-IP1"

INFO [05-19|18:34:23.881] Mapped network port                      proto=udp extport=30303 intport=30303 interface="UPNP IGDv1-IP1"

 

다른 노드들과 통신할 tcp,udp의 정보들이 보인다.

 

Line 22.

INFO [05-19|18:34:25.659] New local node record                    seq=7 id=3c0e0f6ceeaa60a8 ip=121.129.130.32 udp=30303 tcp=30303

 

추가된 노드를 확인할 수 있다.

 

Line 23.

INFO [05-19|18:38:11.712] Block synchronisation started

 

Mainnet의 다른 노드들과 통신이 성공됐고 정상적으로 blockchain 데이터를 맞추는 것을 나타낸다.

 

Line 24,25,26

INFO [05-19|18:38:19.385] Imported new block headers               count=0 elapsed=27.200ms number=6994860 hash=d61d50…048bce age=4mo2w3d  ignored=192
INFO [05-19|18:38:19.932] Imported new block headers               count=0 elapsed=11.392ms number=6995052 hash=8d7e37…4dcba0 age=4mo2w3d  ignored=192
INFO [05-19|18:38:20.156] Imported new block receipts              count=2 elapsed=3.290ms  number=6994670 hash=6792b5…ffcf6b age=4mo2w3d  size=68.95KiB

위치 : /core/headerchain.go

 

block header는 싱크를 맞추는 와중에 가져온 블록 수와 경과 시간 현재 블록넘버를 확인할 수 있다.

block receipts는 트랜잭션을 검증한 영수증 블록(?)이다.

 

 

 

 

댓글