blockchain - geth - 使用docker, docker-compose 启动测试网络 lightmode eth, ethereum test network rinkeby goerli

访问量: 990

refer to: https://hub.docker.com/r/ethereum/client-go    

https://geth.ethereum.org/docs/getting-started

1. 在本地创建一个文件夹 d:/workspace/blockchain/geth

2. 在该文件夹下,创建 Dockerfile

FROM ethereum/client-go:alltools-latest-amd64

3. 创建 docker-compose.yml

version: '3'
services:

  geth-20220609:
    container_name: "geth"
    build: .
    volumes:
      - /d/workspace/docker_folder/geth:/root
        #command: 'tail -F /dev/null'
    command: 'mysqld'
    ports:
      - "8545:8545"
      - "8546:8546"
      - "30303:30303"
    stdin_open: true
    tty: true
    environment:
      - SAY_HI=hi
    command: tail -f /dev/null

4. 启动docker-compose:

docker-compose up

5. 启动后,登录该docker:

$ docker exec -it 6b93 sh
/ # which geth
/usr/local/bin/geth

6. 手动启动 geth的lightweight mode, 并且链接到测试网络

 geth --rinkeby --syncmode light --http --http.addr 0.0.0.0  --ws --ws.addr 0.0.0.0
就可以看到 geth 已经以 light模式启动了。
/ # geth --rinkeby --syncmode light --http --http.addr 0.0.0.0  --ws --ws.addr 0.0.0.0
INFO [06-09|00:03:19.218] Starting Geth on Rinkeby testnet...
INFO [06-09|00:03:19.218] Dropping default light client cache      provided=1024 updated=128
INFO [06-09|00:03:19.220] Maximum peer count                       ETH=0 LES=10 total=50
INFO [06-09|00:03:19.220] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [06-09|00:03:19.241] Set global gas cap                       cap=50,000,000
WARN [06-09|00:03:19.241]
WARN [06-09|00:03:19.241] --------------------------------------------------------------------------------
WARN [06-09|00:03:19.241] Please note, Rinkeby has been deprecated. It will still work for the time being,
WARN [06-09|00:03:19.241] but there will be no further hard-forks shipped for it. Eventually the network
WARN [06-09|00:03:19.241] will be permanently halted after the other networks transition through the merge
WARN [06-09|00:03:19.241] and prove stable enough. For the most future proof testnet, choose Sepolia as
WARN [06-09|00:03:19.242] your replacement environment (--sepolia instead of --rinkeby).
WARN [06-09|00:03:19.242] --------------------------------------------------------------------------------
WARN [06-09|00:03:19.242]
INFO [06-09|00:03:19.242] Allocated cache and file handles         database=/root/.ethereum/rinkeby/geth/lightchaindata cache=64.00MiB handles=524,288
INFO [06-09|00:03:19.442] Allocated cache and file handles         database=/root/.ethereum/rinkeby/geth/les.client cache=16.00MiB handles=16
INFO [06-09|00:03:19.709] Writing custom genesis block
INFO [06-09|00:03:19.718] Persisted trie from memory database      nodes=355 size=50.43KiB time=2.385332ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [06-09|00:03:19.722]
INFO [06-09|00:03:19.723] ---------------------------------------------------------------------------------------------------------------------------------------------------------
INFO [06-09|00:03:19.723] Chain ID:  4 (rinkeby)
INFO [06-09|00:03:19.723] Consensus: Clique (proof-of-authority)
INFO [06-09|00:03:19.723]
INFO [06-09|00:03:19.723] Pre-Merge hard forks:
INFO [06-09|00:03:19.723]  - Homestead:                   1        (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/homestead.md)
INFO [06-09|00:03:19.723]  - Tangerine Whistle (EIP 150): 2        (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/tangerine-whistle.md)
INFO [06-09|00:03:19.723]  - Spurious Dragon/1 (EIP 155): 3        (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)
INFO [06-09|00:03:19.723]  - Spurious Dragon/2 (EIP 158): 3        (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)
INFO [06-09|00:03:19.723]  - Byzantium:                   1035301  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/byzantium.md)
INFO [06-09|00:03:19.723]  - Constantinople:              3660663  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/constantinople.md)
INFO [06-09|00:03:19.723]  - Petersburg:                  4321234  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/petersburg.md)
INFO [06-09|00:03:19.723]  - Istanbul:                    5435345  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/istanbul.md)
INFO [06-09|00:03:19.723]  - Berlin:                      8290928  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md)
INFO [06-09|00:03:19.723]  - London:                      8897988  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md)
INFO [06-09|00:03:19.723]
INFO [06-09|00:03:19.723] Merge not configured!
INFO [06-09|00:03:19.723]  - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md)
INFO [06-09|00:03:19.723] ---------------------------------------------------------------------------------------------------------------------------------------------------------
INFO [06-09|00:03:19.723]
INFO [06-09|00:03:19.727] Added trusted checkpoint                 block=10,715,135 hash=941a41..67ce00
INFO [06-09|00:03:19.728] Loaded most recent local header          number=0 hash=6341fd..67e177 td=1 age=5y2mo3w
INFO [06-09|00:03:19.728] Configured checkpoint oracle             address=0xebe8eFA441B9302A0d7eaECc277c09d20D684540 signers=4 threshold=2
INFO [06-09|00:03:19.728] Gasprice oracle is ignoring threshold set threshold=2
WARN [06-09|00:03:19.729] Error reading unclean shutdown markers   error="leveldb: not found"
INFO [06-09|00:03:19.730] Starting peer-to-peer node               instance=Geth/v1.10.19-unstable-594e3216/linux-amd64/go1.18.3
INFO [06-09|00:03:20.138] New local node record                    seq=1,654,733,000,136 id=abe8cf761f0ac9e7 ip=127.0.0.1 udp=30303 tcp=30303
INFO [06-09|00:03:20.139] Started P2P networking                   self=enode://ee8a1a5370fea4203311c4291e63ae5c6f12e3c0a7262c52f9299eb14a955d4dd1a532a0dbcf59274322347bd4d117b794f85a3990ad
be253187f0a46758461b@127.0.0.1:30303
INFO [06-09|00:03:20.172] IPC endpoint opened                      url=/root/.ethereum/rinkeby/geth.ipc
INFO [06-09|00:03:20.172] HTTP server started                      endpoint=[::]:8545 auth=false prefix= cors= vhosts=localhost
INFO [06-09|00:03:20.173] WebSocket enabled                        url=ws://[::]:8546
WARN [06-09|00:03:20.173] Light client mode is an experimental feature
INFO [06-09|00:03:34.479] Looking for peers                        peercount=0 tried=1 static=0
INFO [06-09|00:03:46.153] Looking for peers                        peercount=0 tried=3 static=0
INFO [06-09|00:03:57.223] Looking for peers                        peercount=0 tried=1 static=0
INFO [06-09|00:04:08.153] Looking for peers                        peercount=0 tried=0 static=0
INFO [06-09|00:04:20.439] Looking for peers                        peercount=0 tried=1 static=0
INFO [06-09|00:04:36.227] Looking for peers                        peercount=0 tried=2 static=0
INFO [06-09|00:04:55.440] Looking for peers                        peercount=0 tried=2 static=0
INFO [06-09|00:05:08.599] Looking for peers                        peercount=0 tried=2 static=0
INFO [06-09|00:05:19.257] Looking for peers                        peercount=0 tried=0 static=0
INFO [06-09|00:05:31.290] Looking for peers                        peercount=0 tried=1 static=0
INFO [06-09|00:05:42.276] Looking for peers                        peercount=0 tried=1 static=0
INFO [06-09|00:05:52.574] Looking for peers                        peercount=0 tried=3 static=0
INFO [06-09|00:06:05.534] Looking for peers                        peercount=0 tried=0 static=0
INFO [06-09|00:06:12.079] New local node record                    seq=1,654,733,000,137 id=abe8cf761f0ac9e7 ip=183.254.61.156 udp=1755  tcp=30303
INFO [06-09|00:06:19.275] Looking for peers                        peercount=0 tried=0 static=0
INFO [06-09|00:06:29.634] Looking for peers                        peercount=0 tried=2 static=0

7. 但是发现在light 模式下,我无法查询到自己的account的最新数据。明明账户尾号 e48a 有0.15 ETH, 如下图:

但是在light 模式下, 却查不出来

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBalance","params": ["0xc0dD5021e298dB57bEF361C735cd1C04cef2E48A", "latest"],"id":1}' 127.0.0.1:8545
结果:
{"jsonrpc":"2.0","id":1,"result":"0x0"}

重新跑了2次,都是这个问题。查看docker占用空间,不到1MB.

root@DESKTOP-GG23M21:/mnt/d/workspace/docker_folder/geth/.ethereum# du . -kh
8.0K    ./rinkeby/geth/les.client
60K     ./rinkeby/geth/lightchaindata
16K     ./rinkeby/geth/nodes
84K     ./rinkeby/geth
0       ./rinkeby/keystore
84K     ./rinkeby
84K     .

8. 没办法,只好重新运行 goerli 测试网络, --syncmode = snap 完整命令如下:

geth --rinkeby --syncmode snap --http --http.addr 0.0.0.0 --ws --ws.addr 0.0.0.0

完整日志如下:

INFO [06-09|00:14:20.940] Starting Geth on Rinkeby testnet...
INFO [06-09|00:14:20.942] Maximum peer count                       ETH=50 LES=0 total=50
INFO [06-09|00:14:20.942] Smartcard socket not found, disabling    err="stat /run/pcscd/pcscd.comm: no such file or directory"
INFO [06-09|00:14:20.956] Set global gas cap                       cap=50,000,000
WARN [06-09|00:14:20.956]
WARN [06-09|00:14:20.956] --------------------------------------------------------------------------------
WARN [06-09|00:14:20.956] Please note, Rinkeby has been deprecated. It will still work for the time being,
WARN [06-09|00:14:20.956] but there will be no further hard-forks shipped for it. Eventually the network
WARN [06-09|00:14:20.956] will be permanently halted after the other networks transition through the merge
WARN [06-09|00:14:20.956] and prove stable enough. For the most future proof testnet, choose Sepolia as
WARN [06-09|00:14:20.956] your replacement environment (--sepolia instead of --rinkeby).
WARN [06-09|00:14:20.956] --------------------------------------------------------------------------------
WARN [06-09|00:14:20.956]
INFO [06-09|00:14:20.957] Allocated trie memory caches             clean=154.00MiB dirty=256.00MiB
INFO [06-09|00:14:20.957] Allocated cache and file handles         database=/root/.ethereum/rinkeby/geth/chaindata cache=512.00MiB handles=524,288
INFO [06-09|00:14:21.761] Opened ancient database                  database=/root/.ethereum/rinkeby/geth/chaindata/ancient readonly=false
INFO [06-09|00:14:21.762] Writing custom genesis block
INFO [06-09|00:14:21.771] Persisted trie from memory database      nodes=355 size=50.43KiB time=3.685833ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [06-09|00:14:21.776]
INFO [06-09|00:14:21.776] ---------------------------------------------------------------------------------------------------------------------------------------------------------
INFO [06-09|00:14:21.776] Chain ID:  4 (rinkeby)
INFO [06-09|00:14:21.776] Consensus: Clique (proof-of-authority)
INFO [06-09|00:14:21.776]
INFO [06-09|00:14:21.776] Pre-Merge hard forks:
INFO [06-09|00:14:21.777]  - Homestead:                   1        (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/homestead.md)
INFO [06-09|00:14:21.777]  - Tangerine Whistle (EIP 150): 2        (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/tangerine-whistle.md)
INFO [06-09|00:14:21.777]  - Spurious Dragon/1 (EIP 155): 3        (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)
INFO [06-09|00:14:21.777]  - Spurious Dragon/2 (EIP 158): 3        (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/spurious-dragon.md)
INFO [06-09|00:14:21.777]  - Byzantium:                   1035301  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/byzantium.md)
INFO [06-09|00:14:21.777]  - Constantinople:              3660663  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/constantinople.md)
INFO [06-09|00:14:21.777]  - Petersburg:                  4321234  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/petersburg.md)
INFO [06-09|00:14:21.777]  - Istanbul:                    5435345  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/istanbul.md)
INFO [06-09|00:14:21.777]  - Berlin:                      8290928  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md)
INFO [06-09|00:14:21.777]  - London:                      8897988  (https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md)
INFO [06-09|00:14:21.777]
INFO [06-09|00:14:21.777] Merge not configured!
INFO [06-09|00:14:21.777]  - Hard-fork specification: https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/paris.md)
INFO [06-09|00:14:21.777] ---------------------------------------------------------------------------------------------------------------------------------------------------------
INFO [06-09|00:14:21.777]
INFO [06-09|00:14:21.817] Initialising Ethereum protocol           network=4 dbversion=
INFO [06-09|00:14:21.818] Loaded most recent local header          number=0 hash=6341fd..67e177 td=1 age=5y2mo3w
INFO [06-09|00:14:21.818] Loaded most recent local full block      number=0 hash=6341fd..67e177 td=1 age=5y2mo3w
INFO [06-09|00:14:21.818] Loaded most recent local fast block      number=0 hash=6341fd..67e177 td=1 age=5y2mo3w
WARN [06-09|00:14:21.819] Failed to load snapshot, regenerating    err="missing or corrupted snapshot"
INFO [06-09|00:14:21.819] Rebuilding state snapshot
INFO [06-09|00:14:21.820] Resuming state snapshot generation       root=535805..8e8c2d accounts=0 slots=0 storage=0.00B dangling=0 elapsed="744.541µs"
INFO [06-09|00:14:21.826] Regenerated local transaction journal    transactions=0 accounts=0
INFO [06-09|00:14:21.826] Gasprice oracle is ignoring threshold set threshold=2
WARN [06-09|00:14:21.827] Error reading unclean shutdown markers   error="leveldb: not found"
INFO [06-09|00:14:21.827] Stored checkpoint snapshot to disk       number=0 hash=6341fd..67e177
INFO [06-09|00:14:21.828] Starting peer-to-peer node               instance=Geth/v1.10.19-unstable-594e3216/linux-amd64/go1.18.3
INFO [06-09|00:14:21.829] Generated state snapshot                 accounts=257 slots=0 storage=9.57KiB dangling=0 elapsed=9.590ms
INFO [06-09|00:14:22.068] New local node record                    seq=1,654,733,000,138 id=abe8cf761f0ac9e7 ip=127.0.0.1 udp=30303 tcp=30303
INFO [06-09|00:14:22.069] Started P2P networking                   self=enode://ee8a1a5370fea4203311c4291e63ae5c6f12e3c0a7262c52f9299eb14a955d4dd1a532a0dbcf59274322347bd4d117b794f85a3990adbe253187f0a46758461b@127.0.0.1:30303
INFO [06-09|00:14:22.073] IPC endpoint opened                      url=/root/.ethereum/rinkeby/geth.ipc
INFO [06-09|00:14:22.073] HTTP server started                      endpoint=[::]:8545 auth=false prefix= cors= vhosts=localhost
INFO [06-09|00:14:22.073] WebSocket enabled                        url=ws://[::]:8546
INFO [06-09|00:14:30.341] New local node record                    seq=1,654,733,000,139 id=abe8cf761f0ac9e7 ip=183.254.61.156 udp=1787  tcp=30303
INFO [06-09|00:14:32.074] Block synchronisation started
INFO [06-09|00:14:32.613] Looking for peers                        peercount=1 tried=19 static=0
WARN [06-09|00:14:40.953] Snapshot extension registration failed   peer=369195b1 err="peer connected on snap without compatible eth support"
INFO [06-09|00:14:40.991] Imported new block headers               count=192 elapsed=35.050ms    number=192 hash=8c570c..ba360c age=5y2mo3w
INFO [06-09|00:14:40.992] Downloader queue stats                   receiptTasks=0 blockTasks=137 itemSize=647.72B throttle=8192
INFO [06-09|00:14:40.995] Wrote genesis to ancients
INFO [06-09|00:14:41.487] Imported new block receipts              count=54  elapsed=494.523ms   number=54  hash=dafe6e..02bf13 age=5y2mo3w size=18.23KiB
INFO [06-09|00:14:41.721] Imported new block headers               count=192 elapsed=33.581ms    number=384 hash=6d95fa..a59e49 age=5y2mo3w
INFO [06-09|00:14:42.196] Imported new block receipts              count=138 elapsed=506.030ms   number=192 hash=8c570c..ba360c age=5y2mo3w size=46.20KiB
INFO [06-09|00:14:42.462] Imported new block headers               count=192 elapsed=34.046ms    number=576 hash=8cb307..7e165a age=5y2mo3w
INFO [06-09|00:14:42.654] Imported new block receipts              count=192 elapsed=454.694ms   number=384 hash=6d95fa..a59e49 age=5y2mo3w size=64.39KiB
INFO [06-09|00:14:42.700] Imported new block headers               count=192 elapsed=34.744ms    number=768 hash=d2f106..d25b87 age=5y2mo3w
INFO [06-09|00:14:43.063] Imported new block receipts              count=192 elapsed=407.514ms   number=576 hash=8cb307..7e165a age=5y2mo3w size=64.51KiB
INFO [06-09|00:14:43.121] Looking for peers                        peercount=1 tried=24 static=0
INFO [06-09|00:14:43.395] Imported new block headers               count=192 elapsed=37.311ms    number=960 hash=413833..8d126d age=5y2mo3w
INFO [06-09|00:14:43.555] Imported new block receipts              count=192 elapsed=490.070ms   number=768 hash=d2f106..d25b87 age=5y2mo3w size=64.51KiB
INFO [06-09|00:14:44.141] Imported new block headers               count=192 elapsed=37.034ms    number=1152 hash=9d3964..5b5a49 age=5y2mo3w
INFO [06-09|00:14:44.180] Imported new block receipts              count=192 elapsed=624.012ms   number=960  hash=413833..8d126d age=5y2mo3w size=64.51KiB
INFO [06-09|00:14:44.690] Imported new block receipts              count=192 elapsed=508.951ms   number=1152 hash=9d3964..5b5a49 age=5y2mo3w size=64.51KiB
INFO [06-09|00:14:44.886] Imported new block headers               count=192 elapsed=34.001ms    number=1344 hash=4524ae..5d3fff age=5y2mo3w
INFO [06-09|00:14:45.356] Imported new block receipts              count=192 elapsed=467.824ms   number=1344 hash=4524ae..5d3fff age=5y2mo3w size=64.51KiB
INFO [06-09|00:14:45.495] Imported new block headers               count=192 elapsed=35.502ms    number=1536 hash=ebcd68..10b559 age=5y2mo3w
INFO [06-09|00:14:45.737] Imported new block headers               count=192 elapsed=39.107ms    number=1728 hash=7eff72..2707a2 age=5y2mo3w
INFO [06-09|00:14:45.976] Imported new block headers               count=192 elapsed=39.811ms    number=1920 hash=d7b761..1129c2 age=5y2mo3w
INFO [06-09|00:14:46.090] Imported new block receipts              count=192 elapsed=592.190ms   number=1536 hash=ebcd68..10b559 age=5y2mo3w size=64.51KiB
INFO [06-09|00:14:46.212] Imported new block headers               count=192 elapsed=36.701ms    number=2112 hash=cc3a9a..11d37c age=5y2mo3w
INFO [06-09|00:14:46.453] Imported new block headers               count=192 elapsed=38.992ms    number=2304 hash=59a265..e4db8b age=5y2mo3w
INFO [06-09|00:14:46.610] Imported new block receipts              count=384 elapsed=519.010ms   number=1920 hash=d7b761..1129c2 age=5y2mo3w size=129.00KiB
INFO [06-09|00:14:46.689] Imported new block headers               count=192 elapsed=37.230ms    number=2496 hash=dd9acd..90331d age=5y2mo3w
INFO [06-09|00:14:46.927] Imported new block headers               count=192 elapsed=36.077ms    number=2688 hash=d6eab2..23c318 age=5y2mo3w

9. 再次测试一下:

# 在刚刚运行节点的时候,会发现无法查询
$ curl -X POST -H "Content-Type: application/json"  --data '{"jsonrpc":"2.0","method":"eth_getBalance","params": ["0xc0dd5021e298db57bef361c735cd1c04cef2e48a", "late
st"],"id":1}' localhost:8545
{"jsonrpc":"2.0","id":1,"error":{"code":-32000,"message":"getDeleteStateObject (c0dd5021e298db57bef361c735cd1c04cef2e48a) error: no suitable peers available"}}

# 在运行一段时间后(例如几分钟),就可以查询了
$ curl -X POST -H "Content-Type: application/json"  --data '{"jsonrpc":"2.0","method":"eth_getBalance","params": ["0xc0dd5021e298db57bef361c735cd1c04cef2e48a", "latest"],"id":1}' localhost:8545
{"jsonrpc":"2.0","id":1,"result":"0x37aaa8adc98407f4"}

订阅/RSS Feed

Subscribe