【发布时间】:2018-08-12 15:52:01
【问题描述】:
Fedora 27、CentOS 1708、Go-ethereum 1.8.1
我正在尝试使用它来制作私有区块链和硬币。
Genesis.json:
{
"config": {
"chainId": 42,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc": {},
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x1000000",
"extraData" : "",
"gasLimit" : "0x2fefd8",
"nonce" : "0x0000000012345678",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
我在控制台中运行 geth:
geth init genesis.json --datadir datadir
geth console --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "datadir" --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 7296
然后我创建了新帐户并开始挖矿。有用。但是当我重新启动geth时,区块链状态似乎没有保存。
INFO [03-05|11:39:03] Successfully sealed new block number=21 hash=ef088f…8b62cb
INFO [03-05|11:39:03] ???? block reached canonical chain number=16 hash=4dea2d…c41401
INFO [03-05|11:39:03] ???? mined potential block number=21 hash=ef088f…8b62cb
INFO [03-05|11:39:03] Commit new mining work number=22 txs=0 uncles=0 elapsed=101.305µs
> miner.stop()
true
> exit
INFO [03-05|11:39:28] IPC endpoint closed endpoint=/home/hansoli/.ethereum/geth.ipc
ERROR[03-05|11:39:28] Dangling trie nodes after full cleanup
INFO [03-05|11:39:28] Blockchain manager stopped
INFO [03-05|11:39:28] Stopping Ethereum protocol
INFO [03-05|11:39:28] Ethereum protocol stopped
INFO [03-05|11:39:28] Transaction pool stopped
INFO [03-05|11:39:28] Database closed database=/home/hansoli/.ethereum/geth/chaindata
[hansoli@localhost ethereum]$ geth console --rpc --rpcport "8080" --rpccorsdomain "*" --datadir "datadir" --port "30303" --nodiscover --rpcapi "db,eth,net,web3" --networkid 7296
INFO [03-05|11:39:59] Maximum peer count ETH=25 LES=0 total=25
INFO [03-05|11:39:59] Starting peer-to-peer node instance=Geth/v1.8.1-stable-1e67410e/linux-amd64/go1.9.4
INFO [03-05|11:39:59] Allocated cache and file handles database=/home/hansoli/.ethereum/geth/chaindata cache=768 handles=512
INFO [03-05|11:39:59] Initialised chain configuration config="{ChainID: 42 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Engine: unknown}"
INFO [03-05|11:39:59] Disk storage enabled for ethash caches dir=/home/hansoli/.ethereum/geth/ethash count=3
INFO [03-05|11:39:59] Disk storage enabled for ethash DAGs dir=/home/hansoli/.ethash count=2
INFO [03-05|11:39:59] Initialising Ethereum protocol versions="[63 62]" network=1
WARN [03-05|11:39:59] Head state missing, repairing chain number=21 hash=ef088f…8b62cb
INFO [03-05|11:39:59] Rewound blockchain to past state number=0 hash=7016ba…d4738f
INFO [03-05|11:39:59] Loaded most recent local header number=21 hash=ef088f…8b62cb td=351436106
INFO [03-05|11:39:59] Loaded most recent local full block number=0 hash=7016ba…d4738f td=16777216
INFO [03-05|11:39:59] Loaded most recent local fast block number=21 hash=ef088f…8b62cb td=351436106
INFO [03-05|11:39:59] Loaded local transaction journal transactions=0 dropped=0
INFO [03-05|11:39:59] Regenerated local transaction journal transactions=0 accounts=0
INFO [03-05|11:39:59] Starting P2P networking
INFO [03-05|11:39:59] RLPx listener up self="enode://0482a34d9871d20c8beee1b227d7bd0b8e54a5c084d4f55afc86fac65e8d92c4ab51f669aee196c112a4ca6e6461e069ee111a82208f1fcaaff138c3d1a6254b@[::]:30303?discport=0"
INFO [03-05|11:39:59] IPC endpoint opened url=/home/hansoli/.ethereum/geth.ipc
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.1-stable-1e67410e/linux-amd64/go1.9.4
INFO [03-05|11:39:59] Etherbase automatically configured address=0x8eDE74913b1BbFA2be354B3B1E70635E96B6b158
coinbase: 0x8ede74913b1bbfa2be354b3b1e70635e96b6b158
at block: 0 (Thu, 01 Jan 1970 09:00:00 KST)
datadir: /home/hansoli/.ethereum
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
> eth.blockNumber
0
>
如何解决?退出geth后能否保持区块链状态?
【问题讨论】:
-
networkid应该与您的 genesis.json 中的chainid匹配(输出显示您的节点正在连接到主网 (network=1))。确保您只运行一次init。而且,为什么你的datadir用引号括起来?输出显示您保存到默认目录(database=/home/hansoli/.ethereum/geth/chaindata)。使用默认目录在技术上没有任何问题,但您需要进行更改,这样您就可以运行不同的网络而不会相互交叉。 -
并且
console应该出现在您的geth命令的末尾。 -
@AdamKipnis 感谢您的回答!我尝试这个命令:
geth --rpc --rpcport 8080 --rpccorsdomain "*" --datadir datadir --port 30303 --nodiscover --rpcapi db,eth,net,web3 --networkid 42 console并且我可以确认网络号是 42 并且 datadir 是我在控制台中的 datadir 目录。但是还是不行。 -
您是否也重新运行了挖矿?您的输出显示挖掘也进入了错误的 datadir 目录。我建议从头开始。清除数据目录,重新初始化你的区块链,挖掘一些交易,然后重启你的控制台。仔细检查每个命令后的输出,以确保使用了正确的数据目录、密钥库目录和网络 ID。我刚刚重复了这些步骤,一切正常。
-
@AdamKipnis 这似乎是geth中的一个错误。它在 geth 1.8.2(几天前发布)中完美运行
标签: go ethereum go-ethereum geth