pchain-org / pchain

Pchain client-in-Go
https://plian.org
GNU General Public License v3.0
24 stars 12 forks source link

Init with creating accounts and assigning balance #1

Closed pchain-org closed 6 years ago

pchain-org commented 6 years ago

参考 https://github.com/pchain-org/pchain/blob/master/!!restore!!/readme.txt

在步骤3.1中,

#package the genesis.json and init chain data
ethermint -datadir /home/ubuntu/.ethermint init ./src/github.com/tendermint/ethermint/dev/genesis.json

#create default user
cp -r ./src/github.com/tendermint/ethermint/dev/keystore /home/ubuntu/.ethermint/keystore

分别生成了tendermint和ethereum中账号。

需要改为通过上述的 init 命令,就能完成上述的两个动作: 1,在 datadir 目录下生成 genesis.json文件和keystore目录,内容为是同一个ethereum账号的密钥和余额 2,可以生成priv_validator.json文件,这样现有对priv_validator.json进行访问的代码可以不做改动。但是私钥的明文就暴露了。 也可以不生成priv_validator.json,这样需要改动现有访问priv_validator.json的代码,改成直接从keystore中读取。

pchain-org commented 6 years ago

对上述的需求加以进一步描述:

ethermint --datadir /home/ubuntu/.ethermint init_eth_genesis "10000000000000000000000000000000000, 10000000000000000000000000000000000, 10000000000000000000000000000000000, 10000000000000000000000000000000000, 10000000000000000000000000000000000"

字符串内为每个账号的初始化的balance,以 ‘,’ 隔开

执行后结果为: 1,在 --datadir 目录下,产生keystore文件夹,里面存放和账户个数对应的若干个私钥文件;该文件夹和ethereum兼容 2,产生和账户个数对应的若干个priv_validator.json文件;内容应该和keystore里面的内容保持一致,保存为json文件是为了和tendermint兼容 3,生成/home/ubuntu/.ethermint/eth_genesis.json。只是里面的账号和余额变成如下形式: "alloc": {

"0x7eff122b94897ea5b0e2a9abf47b86337fafebdc": {

"balance": "10000000000000000000000000000000000"

},

"0x1234122b94897ea5b0e2a9abf47b86337fafebdc": {

"balance": "20000000000000000000000000000000000"

},

"0x5678122b94897ea5b0e2a9abf47b86337fafebdc": {

"balance": "30000000000000000000000000000000000"

}, ... }

1, ethermint --datadir /home/ubuntu/.ethermint init_eth_genesis "10000000000000000000000000000000000, 10000000000000000000000000000000000, 10000000000000000000000000000000000, 10000000000000000000000000000000000, 10000000000000000000000000000000000"

2,ethermint -datadir /home/ubuntu/.ethermint init /home/ubuntu/.ethermint/eth_genesis.json

执行上述两个命令后,应该产生如下结果: 1,产生类似下面的genesis.json文件 { "app_hash": "", "chain_id": "test-chain-IsbFzq", "consensus": "pos", "current_epoch": { "block_generated": "0", "end_block": "1295999", "end_time": "0", "number": "0", "reward_per_block": "368267746913580247", "start_block": "0", "start_time": "0", "status": "0", "validators": [ { "amount": 10, "eth_account": "7EFF122B94897EA5B0E2A9ABF47B86337FAFEBDC", "name": "", "pub_key": [ 3, "046E5ACDC1CF2C6C61CF6528A0A33DF44ADEBCED18C0CDA4AF88A76B14DA33BD014B97E33A277685EA1787776364E4CE3A83593B5FC231D3EB69F5514E387680A7" ] } ] }, "genesis_time": "0001-01-01T00:00:00.000Z", "reward_scheme": { "added_per_year": "0", "allocated": "0", "descend_per_year": "572730000000000000000000", "pre_allocated": "178500000000000000000000000", "reward_first_year": "5727300000000000000000000", "total_reward": "210000000000000000000000000" } } 2,其他如config.toml等内容照常生成 3,调整genesis.json和config.toml文件,即可启动系统正常运行

pchain-org commented 6 years ago

增加描述。对于 init_eth_genesis 命令,调用方式调整为: ethermint --datadir /home/ubuntu/.ethermint init_eth_genesis "{10000000000000000000000000000000000, 100}, {10000000000000000000000000000000000, 100},{ 10000000000000000000000000000000000, 100}, {10000000000000000000000000000000000, 100},{ 10000000000000000000000000000000000,100}"

每一组的前面一个是balance,后面一个是amount;相应的api是xxxBalance和xxxLockedBalance

pchain-org commented 6 years ago

上一楼的命令中有中文逗号,两条完整的命令为:

1,ethermint --datadir /home/ubuntu/.ethermint init_eth_genesis "{10000000000000000000000000000000000, 100}, {10000000000000000000000000000000000, 100}, { 10000000000000000000000000000000000, 100}, {10000000000000000000000000000000000, 100}, { 10000000000000000000000000000000000, 100}"

2,ethermint -datadir /home/ubuntu/.ethermint init /home/ubuntu/.ethermint/eth_genesis.json

liaoyd commented 6 years ago

执行完上一楼的两条命令后,理论上应该得到包含5个validator配置信息的genesis.json 比如:

{
  "reward_scheme": {
    "total_reward": "210000000000000000000000000",
    "reward_first_year": "5727300000000000000000000",
    "pre_allocated": "178500000000000000000000000",
    "epoch_no_per_year": "12",
    "descend_per_year": "572730000000000000000000",
    "allocated": "0",
    "added_per_year": "0"
  },
  "genesis_time": "0001-01-01T00:00:00.000Z",
  "current_epoch": {
    "validators": [
      {
        "pub_key": [
          3,
          "047DDF1EDB931CA173CAEA0CF7F4D2AB471A5B9BCD381452444F0BE5C17117027DD70035373950F5E9C4A0F2F576AEE0A139AB7292AF32C95B2AA3256BF78BABDE"
        ],
        "name": "",
        "eth_account": "238DD2A116126004AB09071F3C83F8E87A7B81E7",
        "amount": 100
      },
      {
        "pub_key": [
          3,
          "044F17A0310495D3633A189CCC475F46421AF7C4CF346AABE023F7CC63E9BD609739D24501657B561DC3578DB9541E3AA80B249E513C052A0EFC294D76555ED05B"
        ],
        "name": "",
        "eth_account": "3A828DD10B8E8A49E62DE0A0ADCF504BA5CF9D0F",
        "amount": 100
      },
      ...
      ...
      ...
    ],
    "block_generated": "0",
    "end_block": "1295999",
    "end_time": "0",
    "number": "0",
    "reward_per_block": "1666666666666666666666667",
    "start_block": "0",
    "start_time": "2018-03-28T16:19:02.800442971+08:00",
    "status": "0"
  },
  "consensus": "pos",
  "chain_id": "test-chain-0i4rta",
  "app_hash": ""
}

实际生成的genesis,json只含有一个validator的配置信息:

{
  "reward_scheme": {
    "total_reward": "210000000000000000000000000",
    "reward_first_year": "5727300000000000000000000",
    "pre_allocated": "178500000000000000000000000",
    "epoch_no_per_year": "12",
    "descend_per_year": "572730000000000000000000",
    "allocated": "0",
    "added_per_year": "0"
  },
  "genesis_time": "0001-01-01T00:00:00.000Z",
  "current_epoch": {
    "validators": [
      {
        "pub_key": [
          3,
          "047DDF1EDB931CA173CAEA0CF7F4D2AB471A5B9BCD381452444F0BE5C17117027DD70035373950F5E9C4A0F2F576AEE0A139AB7292AF32C95B2AA3256BF78BABDE"
        ],
        "name": "",
        "eth_account": "238DD2A116126004AB09071F3C83F8E87A7B81E7",
        "amount": 100
      }
    ],
    "block_generated": "0",
    "end_block": "1295999",
    "end_time": "0",
    "number": "0",
    "reward_per_block": "1666666666666666666666667",
    "start_block": "0",
    "start_time": "2018-03-28T16:19:02.800442971+08:00",
    "status": "0"
  },
  "consensus": "pos",
  "chain_id": "test-chain-0i4rta",
  "app_hash": ""
}
liaoyd commented 6 years ago

现脚本部署多节点的初始化步骤如下: (假设部署4个节点分别为n0, n1, n2, n3) 1,在n0上执行./bin/ethermint --datadir /mnt/vdb/pchain_test/.ethermint init_eth_genesis "{10000000000000000000000000000000000, 100}, {10000000000000000000000000000000000, 100},{ 10000000000000000000000000000000000, 100}, {10000000000000000000000000000000000, 100}"得到eth_genesis.json,4个账号对应的priv_validator.json及私钥文件。 2,在n0上执行./bin/ethermint -datadir/mnt/vdb/pchain_test/.ethermint init /mnt/vdb/pchain_test/.ethermint/eth_genesis.json初始化ethermint并得到genesis.json文件。 3,将n0上的priv_validator.json及私钥文件分别复制到 n1, n2, n3,保证每个节点只含有一份priv_validator.json及其对应的私钥文件。 4,将n0上的genesis.json复制到余下节点,并分别将Coinbase改为该节点对应的账号。 5,在余下节点上分别执行./bin/ethermint -datadir/mnt/vdb/pchain_test/.ethermint init /mnt/vdb/pchain_test/.ethermint/eth_genesis.json初始化ethermint。

问题:执行步骤5之后,余下节点会再次生成4个priv_validator.json,其中一个与该节点下已有的账号一致,三个是新生成的账号。 期望结果:不要再生成新的priv_validator.json。

OneDay2017 commented 6 years ago

bug已修复