Geth私有网络问题产生以太

时间:2017-07-12 09:47:32

标签: blockchain ethereum mining

简短说明

我在私有网络中连接了三个以太坊节点,我正在使用带有geth的交互式Javascript控制台。

问题是,我无法找到在任何帐户上获得以太的方法。余额始终为0.

详细

对于所有三个节点,配置和输出类似,区别仅在于它们的地址和帐号。

运行geth之前的文件树:

~/eth/
    database/
        keystore/
    genesis/
        CustomGenesis.json

CustomGenesis.json的内容:

{
  "config": {
    "chainId": 15,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
  },
  "nonce": "0x0000000000000042",
  "timestamp": "0x00",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "extraData": "0x00",
  "gasLimit": "0x08000000",
  "difficulty": "0x0400",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0xd77821c8b92e3e29bc63c8f2a94a6c6a64b28b53",
  "alloc": {
    "0x862e90e6b6ebfe0535081d07be8e0f38e422932c": {"balance": "100"},
    "0x47e4cf0cc71e7257663f3d2f95e3f8982ece3ad8": {"balance": "200"},
    "0x1df2f4f40c03367a9bf42b28a090fed1cccb3068": {"balance": "300"},
    "0xd77821c8b92e3e29bc63c8f2a94a6c6a64b28b53": {"balance": "4444444444444444444"},
    "0x28685a4b9418c1cb85725318756aa815e8e34497": {"balance": "5555555555555555555"},
    "0x86f0526280fea57255c6391a4c7dbdbe8e1181ab": {"balance": "6666666666666666666"}
  }
}

~/eth/目录中,我使用以下内容geth启动了

sudo geth --networkid 15 --datadir ./database --nodiscover --maxpeers 2 --rpc --rpcport 8080 --rpccorsdomain * --rpcapi "db,eth,net,web3" --port 30303 --identity TestNet init ./genesis/CustomGenesis.json

...产生了以下输出:

INFO [07-12|13:12:46] Starting peer-to-peer node               instance=Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1
INFO [07-12|13:12:46] Allocated cache and file handles         database=/home/ethereum6/eth/database/geth/chaindata cache=128 handles=1024
INFO [07-12|13:12:46] Writing default main-net genesis block 
INFO [07-12|13:12:47] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Metropolis: 9223372036854775807 Engine: ethash}"
INFO [07-12|13:12:47] Disk storage enabled for ethash caches   dir=/home/ethereum6/eth/database/geth/ethash count=3
INFO [07-12|13:12:47] Disk storage enabled for ethash DAGs     dir=/home/ethereum6/.ethash                  count=2
WARN [07-12|13:12:47] Upgrading db log bloom bins 
INFO [07-12|13:12:47] Bloom-bin upgrade completed              elapsed=222.754µs
INFO [07-12|13:12:47] Initialising Ethereum protocol           versions="[63 62]" network=15
INFO [07-12|13:12:47] Loaded most recent local header          number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [07-12|13:12:47] Loaded most recent local full block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [07-12|13:12:47] Loaded most recent local fast block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [07-12|13:12:47] Starting P2P networking 
INFO [07-12|13:12:47] HTTP endpoint opened: http://127.0.0.1:8080 
INFO [07-12|13:12:47] RLPx listener up                         self="enode://5ded12c388e755791590cfe848635c7bb47d3b007d21787993e0f6259933c78033fd6fa17cbb884ed772f1c90aebaccc64c5c88cddc1260e875ac8f6f07067bf@[::]:30303?discport=0"
INFO [07-12|13:12:47] IPC endpoint opened: /home/ethereum6/eth/database/geth.ipc

交互式Javascript控制台在另一个终端中启动:

sudo geth attach ipc:$HOME/eth/database/geth.ipc

...给出:

Welcome to the Geth JavaScript console!

instance: Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1
coinbase: 0x1fb9fb0502cb57fb654b88dd2d24e19a0eb91540
at block: 0 (Thu, 01 Jan 1970 03:00:00 MSK)
 datadir: /home/ethereum6/eth/database
 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

> 

miner.setEtherbase(personal.listAccounts[0])的所有节点上设置Etherbase。每个节点只有一个帐户。 (3个节点,3个帐户)

> eth.accounts
["0x1fb9fb0502cb57fb654b88dd2d24e19a0eb91540"]
> personal.listAccounts
["0x1fb9fb0502cb57fb654b88dd2d24e19a0eb91540"]
> 

致电admin.nodeInfo给出:

> admin.nodeInfo
{
  enode: "enode://5ded12c388e755791590cfe848635c7bb47d3b007d21787993e0f6259933c78033fd6fa17cbb884ed772f1c90aebaccc64c5c88cddc1260e875ac8f6f07067bf@[::]:30303?discport=0",
  id: "5ded12c388e755791590cfe848635c7bb47d3b007d21787993e0f6259933c78033fd6fa17cbb884ed772f1c90aebaccc64c5c88cddc1260e875ac8f6f07067bf",
  ip: "::",
  listenAddr: "[::]:30303",
  name: "Geth/v1.6.6-stable-10a45cb5/linux-amd64/go1.8.1",
  ports: {
    discovery: 0,
    listener: 30303
  },
  protocols: {
    eth: {
      difficulty: 17179869184,
      genesis: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
      head: "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
      network: 15
    }
  }
}
> 

节点与admin.addPeer(..)连接,以便每个节点在调用admin.peers时显示两个对等节点。

当我开始使用miner.start()挖掘时,这是我在交互式js控制台中收到的输出:

> miner.start()
null
>

...并在运行节点的另一个终端中:

INFO [07-12|13:16:34] Updated mining threads                   threads=0
INFO [07-12|13:16:34] Transaction pool price threshold updated price=18000000000
INFO [07-12|13:16:34] Starting mining operation 
INFO [07-12|13:16:34] Commit new mining work                   number=1 txs=0 uncles=0 elapsed=749.279µs

之后没有任何反应,使用eth.getBalance(eth.accounts[0])检查时,所有帐户的余额仍为0。

我必须尝试使用​​哪些选项让专用网络上的节点开始挖掘以太网?

为什么预先分配以太不适用于CustomGenesis.json

CustomGenesis.json中提供的难度是否被忽略了? admin.nodeInfo显示的号码不同。

欢迎所有意见和建议,谢谢!

3 个答案:

答案 0 :(得分:0)

您可能将创世难度设置得如此之高,以至于您的CPU矿工无法找到障碍物。您可能希望将难度设置为更合理的值,例如100万(十六进制0x100000)。

答案 1 :(得分:0)

好的,我会提供我的输入(请记住我也是新手,所以我们在同一条船上!)

我有信心的部分是整个平衡部分,所以: 1.建立一个新帐户(在任何节点上):personal.newAccount("密码") 2.将新帐户设置为此节点的coinbase:miner.setEtherbase(eth.accounts [0]) 3.开始挖掘:miner.start()

然后,您可以在挖掘时检查余额。尝试: web3.fromWei(eth.getBalance(eth.coinbase)," ether")

答案 2 :(得分:0)

这个问题显然是创世块被初始化的方式。

错误的方式

通过geth和其他命令行参数调用init

geth --networkid 15 --datadir ./database --nodiscover --maxpeers 2 --rpc --rpcport 8080 --rpccorsdomain * --rpcapi "db,eth,net,web3" --port 30303 --identity TestNet init ./genesis/CustomGenesis.json

节点以mainnet创建块启动:

...
INFO [07-12|13:12:46] Writing default main-net genesis block
...

之后,其他一切都无法按照预期的方式发挥作用。

解决方案

仅使用gethinit参数调用--datadir

geth --datadir /path/to/database init /path/to/CustomGenesis.json

在初始化完成后,会给出一个短输出并立即退出geth

INFO [07-13|10:30:49] Allocated cache and file handles         database=/path/to/database/geth/chaindata cache=16 handles=16
INFO [07-13|10:30:49] Writing custom genesis block 
INFO [07-13|10:30:49] Successfully wrote genesis state         database=chaindata                                   hash=ed4e11…f40ac3
INFO [07-13|10:30:49] Allocated cache and file handles         database=/path/to/database/geth/lightchaindata cache=16 handles=16
INFO [07-13|10:30:49] Writing custom genesis block 
INFO [07-13|10:30:49] Successfully wrote genesis state         database=lightchaindata                                   hash=ed4e11…f40ac3

在此之后,其他一切都按预期工作。

非常感谢Péter帮助我解决这个问题!