관리 메뉴

멍개의 연구소

[ethereum] block, transaction pool, state 각각 어디에 저장되는가 본문

블록체인

[ethereum] block, transaction pool, state 각각 어디에 저장되는가

멍개. 2022. 8. 27. 16:09

thereum에서 block, transaction pool, state가 어디에 저장되는지 알아보도록 하겠습니다.

먼저 block, state는 levelDB를 통해 저장이 됩니다. 근데 문득 그렇다면 transaction이 발생되고 pool에 저장된 tx들은 어디에 저장되는지 궁금해져서 테스트를 해보았습니다.

· 2개의 account 생성

> eth.accounts
["0xe28674672b353d2d4c80435b610734e68bcd4362", "0xbd83f6767a57da0c25b1437660adf43c3e1667be"]

> eth.getBalance(eth.accounts[0])
75000000030000000000

> eth.getBalance(eth.accounts[1])
0

2개의 account를 생성한 후 transaction을 발생시킨 후 geth 프로그램을 종료했다가 다시 접속하여 tx pool을 확인해 보겠습니다.

· tx 발생하기 전 tx pool 확인

> eth.pendingTransactions
[]

tx를 발생시키지 않았기 때문에 비어있습니다.

· tx 발생

> personal.unlockAccount(eth.accounts[0], "p")
true

> eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: 10000})
INFO [09-16|09:42:52] Submitted transaction                    fullhash=0x8360bedc21d02cd2c00e5dbc485949f6fee7cf3470e7bd94fe477d86c2152eff recipient=0xbd83f6767a57da0c25b1437660adf43c3e1667be
"0x8360bedc21d02cd2c00e5dbc485949f6fee7cf3470e7bd94fe477d86c2152eff"

geth에서는 account에 lock이 되있기 때문에 unlockAccount로 계정잠금을 풀어줘야 합니다.

· tx pool 확인

> eth.pendingTransactions
[{
    blockHash: null,
    blockNumber: null,
    from: "0xe28674672b353d2d4c80435b610734e68bcd4362",
    gas: 90000,
    gasPrice: 18000000000,
    hash: "0x8360bedc21d02cd2c00e5dbc485949f6fee7cf3470e7bd94fe477d86c2152eff",
    input: "0x",
    nonce: 0,
    r: "0x18e91ac9e352aa1353b31a4d544191e310a8fae75a1e8a63058a108a64c4f7b9",
    s: "0x55c4028befc7fdc02e0b3b0230f7873ea017effd37b5e1a0a0aba93a2619fe93",
    to: "0xbd83f6767a57da0c25b1437660adf43c3e1667be",
    transactionIndex: 0,
    v: "0x5cd84",
    value: 10000
}]

peding 중인 tx를 확인하니 방금 발생한 tx가 들어있습니다.

여기서 geth 프로그램을 종료한 후 pending을 확인하면 메모리에 저장되는지 db에 저장되는지 알 수 있습니다.

· geth 프로그램 종료

> exit
INFO [09-16|09:44:42] HTTP endpoint closed: http://0.0.0.0:8545
INFO [09-16|09:44:42] IPC endpoint closed: /Users/bagjeongtae/Desktop/geth_test/geth.ipc
INFO [09-16|09:44:42] Blockchain manager stopped
INFO [09-16|09:44:42] Stopping Ethereum protocol
INFO [09-16|09:44:42] Ethereum protocol stopped
INFO [09-16|09:44:42] Transaction pool stopped
INFO [09-16|09:44:42] Database closed                          database=/Users/bagjeongtae/Desktop/geth_test/geth/chaindata

· geth 프로그램 다시시작

$ vim start.sh
geth --networkid 1212121212 --maxpeers 3 --datadir $PWD --rpc --rpcport 8545 --rpcaddr "0.0.0.0" --rpccorsdomain "*" --rpcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --port 30303 console

geth 시작명령어가 길기 때문에 매번치기 힘드므로 쉘 스크립트로 저장합니다. 머 물론 그냥 터미널에 복붙해도 됩니다.

$ ./start.sh
INFO [09-16|09:45:18] Starting peer-to-peer node               instance=Geth/v1.6.7-stable-ab5646c5/darwin-amd64/go1.9
INFO [09-16|09:45:18] Allocated cache and file handles         database=/Users/bagjeongtae/Desktop/geth_test/geth/chaindata cache=128 handles=1024
INFO [09-16|09:45:18] Initialised chain configuration          config="{ChainID: 190128 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Metropolis: <nil> Engine: unknown}"
INFO [09-16|09:45:18] Disk storage enabled for ethash caches   dir=/Users/bagjeongtae/Desktop/geth_test/geth/ethash count=3
INFO [09-16|09:45:18] Disk storage enabled for ethash DAGs     dir=/Users/bagjeongtae/.ethash                       count=2
INFO [09-16|09:45:18] Initialising Ethereum protocol           versions="[63 62]" network=1212121212
INFO [09-16|09:45:18] Loaded most recent local header          number=15 hash=8f3b47…271944 td=2103872
INFO [09-16|09:45:18] Loaded most recent local full block      number=15 hash=8f3b47…271944 td=2103872
INFO [09-16|09:45:18] Loaded most recent local fast block      number=15 hash=8f3b47…271944 td=2103872
WARN [09-16|09:45:18] Blockchain not empty, fast sync disabled
INFO [09-16|09:45:18] Starting P2P networking
INFO [09-16|09:45:20] Mapped network port                      proto=udp extport=30303 intport=30303 interface="UPNP IGDv2-IP1"
INFO [09-16|09:45:20] UDP listener up                          self=enode://d87594294e7e926cbc6de95361461550f5f7b726eeb93e7c609cb8bed0132296ef7f547c1f4284db1de8c3bc471688e0722d373aa882d0f43fdec427d5b4cc3c@121.161.16.47:30303
INFO [09-16|09:45:20] RLPx listener up                         self=enode://d87594294e7e926cbc6de95361461550f5f7b726eeb93e7c609cb8bed0132296ef7f547c1f4284db1de8c3bc471688e0722d373aa882d0f43fdec427d5b4cc3c@121.161.16.47:30303
INFO [09-16|09:45:20] IPC endpoint opened: /Users/bagjeongtae/Desktop/geth_test/geth.ipc
INFO [09-16|09:45:20] HTTP endpoint opened: http://0.0.0.0:8545
INFO [09-16|09:45:20] Mapped network port                      proto=tcp extport=30303 intport=30303 interface="UPNP IGDv2-IP1"
Welcome to the Geth JavaScript console!

instance: Geth/v1.6.7-stable-ab5646c5/darwin-amd64/go1.9
coinbase: 0xe28674672b353d2d4c80435b610734e68bcd4362
at block: 15 (Sun, 16 Sep 2018 09:34:51 KST)
 datadir: /Users/bagjeongtae/Desktop/geth_test
 modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0

>

· tx pool 확인

> eth.pendingTransactions
[]

프로그램을 다시 시작하니 pending이 비어있습니다. 이것은 해당 데이터는 메모리에 저장된다는 의미입니다.

· tx pool 직접확인

 
> txpool
{
  content: {
    pending: {
      0xe28674672b353d2d4c80435b610734e68bcd4362: {
        0: {...}
      }
    },
    queued: {}
  },
  inspect: {
    pending: {
      0xe28674672b353d2d4c80435b610734e68bcd4362: {
        0: "0xbd83f6767a57da0c25b1437660adf43c3e1667be: 10000 wei + 90000 × 18000000000 gas"
      }
    },
    queued: {}
  },
  status: {
    pending: 1,
    queued: 0
  },
  getContent: function(callback),
  getInspect: function(callback),
  getStatus: function(callback)
}

txpool을 이용하면 좀 더 자세히 확인할 수 있습니다. 

Comments