EOS Dawn 4.0 启动 --- part1

EOS Dawn 4.0 发布了。。。一段时间了,因为项目忙的原因,4.0一直没有细细研究,不过,稍微看了一下,感觉系统复杂了好多;比如RAM购买问题,创建账户也需要购买RAM,所有之前的net、cpu操作都实装了,mongodb插件暂不支持,貌似要用sqlite了?大部分基础操作都是eosio.system来实现等等。稍微说说吧;

先说下,RAM问题

开发智能合约知道,智能合约的数据都是存储在内存当中,比如eth,我们讨论的时候,总在担心,等着合约不断壮大,eth节点的内存肯定要爆吧。所以,EOS给了一个解决方案:买!
至于EOS内存的详细信息,见文章 【IMEOS 解读】EOS DAWN 4.0 的 RAM 究竟是什么;

开始启动--准备工作

  1. 下载最新的EOS源码,或是docker、或者直接nodeos就不说了;
    主要说下注意事项:
  • account_history_api_plugin插件修改为history_api_plugin
  • mongo_db_plugin 插件暂不支持,请关闭;
  • db_size_api_plugin 应该是关于数据库方面的rpc接口,后续研究;
    然后正常启动就行:
./nodeos --config-dir=./data-dir --resync

用cleos看看信息:

$ cleos get info
{
  "server_version": "e4980b1e",
  "head_block_num": 10,
  "last_irreversible_block_num": 9,
  "last_irreversible_block_id": "00000009fefac3ab442288d54ee1e6275aeb21f405ac69cfa8ab72602d7fda42",
  "head_block_id": "0000000a0b28b457d18df5d56fa37b81d390003167ee3b236e3cd8ae104fdfd0",
  "head_block_time": "2018-05-18T03:15:47",
  "head_block_producer": "eosio",
  "virtual_block_cpu_limit": 105700244,
  "virtual_block_net_limit": 1058054,
  "block_cpu_limit": 104857500,
  "block_net_limit": 1048576
}
  1. 不用像3.0一样,需要自己部署eosio.bioseosio本身已经部署bios合约。
    我们最先要部署的是eosio.token,因为之后所有操作,都要有RAM,要有RAM先要用EOS买,所以,我们最先要部署token;
    (PS:创建钱包的操作和之前一样,不在赘述;)
// 创建eosio.token账户
$ cleos create account eosio eosio.token EOS51qH8V3aDwaAfsPMoytkb625KukS2z1mXzJRJJsyTMoNtuMMvx EOS51qH8V3aDwaAfsPMoytkb625KukS2z1mXzJRJJsyTMoNtuMMvx

executed transaction: cc2dc7bd267d2aa5644f7742a2c2b88f3316b2559b2361b76983c1c41f0966eb  288 bytes  771 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"eosio.token","owner":{"threshold":1,"keys":[{"key":"EOS51qH8V3aDwaAfsPMoy...
warning: transaction executed locally, but may not be confirmed by the network yet

//部署token合约
$ cleos set contract eosio.token eosio.token -p eosio.token

Reading WAST/WASM from eosio.token/eosio.token.wasm...
Using already assembled WASM...
Publishing contract...
executed transaction: 204d24a3c552b93c5bb9f7b4dcd1b6a654b36d43d3451f8b628d52efdee0c3f0  8112 bytes  1412 us
#         eosio <= eosio::setcode               {"account":"eosio.token","vmtype":0,"vmversion":0,"code":"0061736d01000000017f1560037f7e7f0060057f7e...
#         eosio <= eosio::setabi                {"account":"eosio.token","abi":{"types":[],"structs":[{"name":"transfer","base":"","fields":[{"name"...
warning: transaction executed locally, but may not be confirmed by the network yet

部署好eosio.token合约之后,创建EOS币,并发行给eosio账户:

//创建EOS
$ cleos push action eosio.token create '["eosio","1000000000.0000 EOS",0,0,0]' -p eosio.token

executed transaction: 1098b558beaa54427a070356f5495e5503f1f7ac71ca944272bf147a1c7fd22a  208 bytes  1088 us
#   eosio.token <= eosio.token::create          {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS"}
warning: transaction executed locally, but may not be confirmed by the network yet

//发行EOS
$ cleos push action eosio.token issue '["eosio","1000000000.0000 EOS","issue"]' -p eosio
executed transaction: e2c5c12f9db8fa07f801f5cea406df973bff0f8c6c00d148269a67050a027557  216 bytes  1589 us
#   eosio.token <= eosio.token::issue           {"to":"eosio","quantity":"1000000000.0000 EOS","memo":"issue"}
warning: transaction executed locally, but may not be confirmed by the network yet

部署系统合约

Dawn 4.0主要就是完善了系统合约eosio.system,并且系统合约的相关操作,也都添加到了cleos工具中 (并没有添加RPC接口,反正都是action)
部署系统合约:

cleos set contract eosio eosio.system -p eosio  -x 1000

执行的时候,不设置-x属性的话,假如部署的机器不是太好的话,可能会执行失败,比如下面的错误;

Reading WAST/WASM from eosio.system/eosio.system.wasm...
Using already assembled WASM...
Publishing contract...
Error 3080006: transaction took too long
Error Details:
deadline exceeded

已经部署成功,咱们来看看system合约的主要功能,该列表是cleos system命令下的,当然也可以看eosio.system.abi,略有不同:

newaccount            创建新账户、同时购买RAM、抵押获取带宽
regproducer            注册新的生产者
unregprod               注销一个生产者
voteproducer          为生产者投票
listproducers          列举生产者
delegatebw              抵押EOS获取net和cpu
undelegatebw          解押EOS
buyram                      购买内存
sellram                     售卖内存
claimrewards              索要生产者奖励?
regproxy                   注册一个代理账户 (用于投票)
unregproxy               注销代理账户 (用于投票)
canceldelay                取消一个延迟的交易

今天我只讲述其中几个功能;

1. newaccount

其实,咱们已经有create account,为啥还要在system添加这个功能呢?首先,在我们部署eosio.tokeneosio.system之前,我们是能用cleos create account注册一个账户,注册之后有啥呢:

privileged: false
permissions:
     owner     1:    1 EOS51qH8V3aDwaAfsPMoytkb625KukS2z1mXzJRJJsyTMoNtuMMvx
        active     1:    1 EOS51qH8V3aDwaAfsPMoytkb625KukS2z1mXzJRJJsyTMoNtuMMvx
memory:
     quota:        -1 bytes  used:     187.5 Kb

net bandwidth: (averaged over 3 days)
     used:                -1 bytes
     available:           -1 bytes
     limit:               -1 bytes

cpu bandwidth: (averaged over 3 days)
     used:                -1 us
     available:           -1 us
     limit:               -1 us

我们可以看到,什么都没有,其实也就是啥也干不了。并且,在我们部署完之后两个合约,我们就不能用create account注册账户了。因为会提示如下错误:

Error 3080001: account using more than allotted RAM usage
Error Details:
account test22 has insufficient ram bytes; needs 2996 has 0

所以,让我们用system newaccount来创建账户:

//设置参数:--stake-net 配置带宽, --stake-cpu 配置cpu,--buy-ram-EOS 用EOS作为单位购买RAM
$ cleos system newaccount eosio tester EOS5DDSwnRjU434ANktLrqhubHPZ5HwG2zDg5jLgT2DKH5yB6TydN EOS5DDSwnRjU434ANktLrqhubHPZ5HwG2zDg5jLgT2DKH5yB6TydN --stake-net '10.0000 EOS' --stake-cpu '10.0000 EOS' --buy-ram-EOS '10.0000 EOS'

2267308ms thread-0   main.cpp:418                  create_action        ] result: {"binargs":"0000000000ea3055000000005c95b1caa08601000000000004454f5300000000"} arg: {"code":"eosio","action":"buyram","args":{"payer":"eosio","receiver":"tester","quant":"10.0000 EOS"}}
2267310ms thread-0   main.cpp:418                  create_action        ] result: {"binargs":"0000000000ea3055000000005c95b1caa08601000000000004454f5300000000a08601000000000004454f530000000000"} arg: {"code":"eosio","action":"delegatebw","args":{"from":"eosio","receiver":"tester","stake_net_quantity":"10.0000 EOS","stake_cpu_quantity":"10.0000 EOS","transfer":false}}
executed transaction: b9bec89227b541c90d050fca858c89947f7deeb2b2ad355d3af20a2e66e56a16  432 bytes  4880 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"tester","owner":{"threshold":1,"keys":[{"key":"EOS5DDSwnRjU434ANktLrqhubH...
#         eosio <= eosio::buyram                {"payer":"eosio","receiver":"tester","quant":"10.0000 EOS"}
#         eosio <= eosio::delegatebw            {"from":"eosio","receiver":"tester","stake_net_quantity":"10.0000 EOS","stake_cpu_quantity":"10.0000...
warning: transaction executed locally, but may not be confirmed by the network yet

查看下,我们的账户tester的信息吧:

privileged: false
permissions:
     owner     1:    1 EOS5DDSwnRjU434ANktLrqhubHPZ5HwG2zDg5jLgT2DKH5yB6TydN
        active     1:    1 EOS5DDSwnRjU434ANktLrqhubHPZ5HwG2zDg5jLgT2DKH5yB6TydN
memory:
     quota:     671.1 Kb     used:     2.926 Kb

net bandwidth: (averaged over 3 days)
     staked:          0.0000 EOS           (total stake delegated from account to self)
     delegated:      10.0000 EOS           (total staked delegated to account from others)
     used:                 0 bytes
     available:         82.4 Tb
     limit:             82.4 Tb

cpu bandwidth: (averaged over 3 days)
     staked:          0.0000 EOS           (total stake delegated from account to self)
     delegated:      10.0000 EOS           (total staked delegated to account from others)
     used:                 0 us
     available:    2.517e+06 hr
     limit:        2.517e+06 hr

默认创建的账户,只有8 KiB (这个单位不用我解释吧),但是,我们购买了10EOS的ram,所以memory现在是671.1KiB;

当然,这会有很多疑问在这:是不是创建账户,必须要有EOS?都要购买RAM等等,具体实际的测试结果,不在这贴了,总结如下:

  • 除了eosio账户,用其他账户创建的账户名长度必须为12(和BM在发布4.0时,说的一致);
  • 创建账户的时候,用于购买新用户的带宽、CPU和ram的钱,都是创建者来出;
  • 从目前测试链上,创建一个新账户,至少需要0.0449EOS,即:
    • 0.0001 EOS 的 net bandwidth ------ 432 Mb;
    • 0.0001 EOS 的 cpu bandwidth ------- 12.58 hr;
    • 0.00447 EOS 的 RAM -------- 3 KiB; 创建账户之后,即立刻占用 2.926 KiB

至于,在eosio创建账户的时候不限制长度,是因为eosio是合约账户,还是因为是生产者节点,需要看看合约源码再说;

4. RAM

买卖RAM,这个实际操作比较简单,即两个操作buyramsellram
购买ram:

$ cleos system buyram tester tester '10.0000 EOS'

1836455ms thread-0   main.cpp:418                  create_action        ] result: {"binargs":"000000005c95b1ca000000005c95b1caa08601000000000004454f5300000000"} arg: {"code":"eosio","action":"buyram","args":{"payer":"tester","receiver":"tester","quant":"10.0000 EOS"}}
executed transaction: b53976b770d746c02280e3c17966070c210bf267c11f9f47fb47dae709f0248a  216 bytes  4348 us
#         eosio <= eosio::buyram                {"payer":"tester","receiver":"tester","quant":"10.0000 EOS"}
#   eosio.token <= eosio.token::transfer        {"from":"tester","to":"eosio","quantity":"10.0000 EOS","memo":"buy ram"}
#        tester <= eosio.token::transfer        {"from":"tester","to":"eosio","quantity":"10.0000 EOS","memo":"buy ram"}
#         eosio <= eosio.token::transfer        {"from":"tester","to":"eosio","quantity":"10.0000 EOS","memo":"buy ram"}
warning: transaction executed locally, but may not be confirmed by the network yet

然后通过get account 就能看到已经购买到的ram;
售卖ram:

//售卖的单位是 B,下面是卖了1KiB的ram
$ cleos system sellram tester 1024

2290501ms thread-0   main.cpp:418                  create_action        ] result: {"binargs":"000000005c95b1ca0004000000000000"} arg: {"code":"eosio","action":"sellram","args":{"account":"tester","bytes":1024}}
executed transaction: 323929d8c6dcb690212625ab8b36f79b2a530ff8f4e7d541c5de2818351efba3  200 bytes  1621 us
#         eosio <= eosio::sellram               {"account":"tester","bytes":1024}
#   eosio.token <= eosio.token::transfer        {"from":"eosio","to":"tester","quantity":"0.0149 EOS","memo":"sell ram"}
#         eosio <= eosio.token::transfer        {"from":"eosio","to":"tester","quantity":"0.0149 EOS","memo":"sell ram"}
#        tester <= eosio.token::transfer        {"from":"eosio","to":"tester","quantity":"0.0149 EOS","memo":"sell ram"}
warning: transaction executed locally, but may not be confirmed by the network yet

在自己的测试网中可以看到,暂时的ram价格是 1KiB = 0.0149 EOS

3. producer & delegatebw

用于注册为生产者,任何账户都可注册:

$ cleos system regproducer tester EOS82ym9meArJMWubVnT4vFGTCDJrBFjj3hXtJ9h5oqUCzcGAD4LK

1132753ms thread-0   main.cpp:418                  create_action        ] result: {"binargs":"0000000038b5a66900039e5d8be071e86b1b5968911703c6f4cf3819bec41dd8da6551b8682bf01ef71c000000"} arg: {"code":"eosio","action":"regproducer","args":{"producer":"tester","producer_key":"EOS82ym9meArJMWubVnT4vFGTCDJrBFjj3hXtJ9h5oqUCzcGAD4LK","url":"","location":0}}
executed transaction: ba4b8216247d4b954677cd3b991078202d9b6872d0b86940bfaae5e58f01a4bf  232 bytes  997 us
#         eosio <= eosio::regproducer           {"producer":"tester","producer_key":"EOS82ym9meArJMWubVnT4vFGTCDJrBFjj3hXtJ9h5oqUCzcGAD4LK","url":""...
warning: transaction executed locally, but may not be confirmed by the network yet

注册之后,可以通过listproducers查看:

$ cleos system listproducers

Producer      Producer key                                           Url                                               Total votes
tester        EOS82ym9meArJMWubVnT4vFGTCDJrBFjj3hXtJ9h5oqUCzcGAD4LK                                                    0.00000000000000000

之后,用户就可以为生产者进行投票了,在讲解投票之前呢,需要先说明另一个方法,delegatebw;也就是抵押EOS以获取net和cpu;

$ cleos system delegatebw tester1 tester1 '100000000.0000 EOS' '50000000.0000 EOS'
1623538ms thread-0   main.cpp:999                  operator()           ] act_payload: {"from":"tester1","receiver":"tester1","stake_net_quantity":"100000000.0000 EOS","stake_cpu_quantity":"50000000.0000 EOS","transfer":false}
1623540ms thread-0   main.cpp:418                  create_action        ] result: {"binargs":"000000005c95b1ca000000005c95b1ca0010a5d4e800000004454f53000000000088526a7400000004454f530000000000"} arg: {"code":"eosio","action":"delegatebw","args":{"from":"tester1","receiver":"tester1","stake_net_quantity":"100000000.0000 EOS","stake_cpu_quantity":"50000000.0000 EOS","transfer":false}}
executed transaction: 95e2d036175c2275385824bf4a26c83072cee1d24e9d96cfa0881bdcd0c8e1ae  232 bytes  2988 us
#         eosio <= eosio::delegatebw            {"from":"tester1","receiver":"tester1","stake_net_quantity":"100000000.0000 EOS","stake_cpu_quantity":...
>> last_vote_weight: 6.132311161639800e+26
#   eosio.token <= eosio.token::transfer        {"from":"tester1","to":"eosio","quantity":"150000000.0000 EOS","memo":"stake bandwidth"}
#        tester <= eosio.token::transfer        {"from":"tester1","to":"eosio","quantity":"150000000.0000 EOS","memo":"stake bandwidth"}
#         eosio <= eosio.token::transfer        {"from":"tester1","to":"eosio","quantity":"150000000.0000 EOS","memo":"stake bandwidth"}
warning: transaction executed locally, but may not be confirmed by the network yet

我们可以看到,抵押的EOS都是直接转账给eosio,然后我们就能获取响应的net和cpu;
用户已经抵押了EOS,这时候在对生产者投票,才会有比较重要的的票数;
使用voteproducer进行投票:

$ cleos system voteproducer prods tester hanfei

1335693ms thread-0   main.cpp:418                  create_action        ] result: {"binargs":"000000005c95b1ca0000000000000000010000000038b5a669"} arg: {"code":"eosio","action":"voteproducer","args":{"voter":"tester","proxy":"","producers":["hanfei"]}}
executed transaction: 164e74017ff8a027b1f00514dec8524a0bfb257201a335d4901b20e881f037b8  208 bytes  3464 us
#         eosio <= eosio::voteproducer          {"voter":"tester","proxy":"","producers":["hanfei"]}
>> last_vote_weight: 0.000000000000000e+00
warning: transaction executed locally, but may not be confirmed by the network yet

先这么多,之后在继续;

还有很多问题待解决,比如:

  • 投票的权重;
  • 注册生产者到多少票,才能够场成为实际的BP;
  • 投票给生产者的账户,如何获取收益等等;

https://press.one/p/address/v?s=fd405c615489ea682d190f8564c32845030523ad674f20711417f6f00735ca9a2526b70e0de746470d674426d0eb19d3b0321509f342978e19e2b8d21a18204c1&h=92fac6a29d2a86047cad69d6b298f6a87a9a3be74fbd04128046b12da3b5530f&a=b16935cdba3b68fce2f48b1ba52d43f0d171c7b2&f=P1&v=2

你可能感兴趣的:(EOS Dawn 4.0 启动 --- part1)