EOS Dawn 4.0 發(fā)布了盒使。崩掘。。一段時間了少办,因為項目忙的原因苞慢,4.0一直沒有細(xì)細(xì)研究,不過英妓,稍微看了一下挽放,感覺系統(tǒng)復(fù)雜了好多;比如RAM購買問題鞋拟,創(chuàng)建賬戶也需要購買RAM骂维,所有之前的net、cpu操作都實裝了贺纲,mongodb插件暫不支持航闺,貌似要用sqlite了?大部分基礎(chǔ)操作都是eosio.system
來實現(xiàn)等等猴誊。稍微說說吧潦刃;
先說下,RAM問題
開發(fā)智能合約知道懈叹,智能合約的數(shù)據(jù)都是存儲在內(nèi)存當(dāng)中乖杠,比如eth,我們討論的時候澄成,總在擔(dān)心胧洒,等著合約不斷壯大畏吓,eth節(jié)點的內(nèi)存肯定要爆吧。所以卫漫,EOS給了一個解決方案:買菲饼!
至于EOS內(nèi)存的詳細(xì)信息,見文章 【IMEOS 解讀】EOS DAWN 4.0 的 RAM 究竟是什么;
開始啟動--準(zhǔn)備工作
- 下載最新的EOS源碼列赎,或是docker宏悦、或者直接nodeos就不說了;
主要說下注意事項:
-
account_history_api_plugin
插件修改為history_api_plugin
包吝; -
mongo_db_plugin
插件暫不支持饼煞,請關(guān)閉; -
db_size_api_plugin
應(yīng)該是關(guān)于數(shù)據(jù)庫方面的rpc接口诗越,后續(xù)研究砖瞧;
然后正常啟動就行:
./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
}
- 不用像3.0一樣,需要自己部署
eosio.bios
嚷狞,eosio
本身已經(jīng)部署bios合約芭届。
我們最先要部署的是eosio.token
,因為之后所有操作感耙,都要有RAM褂乍,要有RAM先要用EOS買,所以即硼,我們最先要部署token逃片;
(PS:創(chuàng)建錢包的操作和之前一樣,不在贅述只酥;)
// 創(chuàng)建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
合約之后褥实,創(chuàng)建EOS幣,并發(fā)行給eosio
賬戶:
//創(chuàng)建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
//發(fā)行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
部署系統(tǒng)合約
Dawn 4.0主要就是完善了系統(tǒng)合約eosio.system
裂允,并且系統(tǒng)合約的相關(guān)操作损离,也都添加到了cleos工具中 (并沒有添加RPC接口,反正都是action)绝编;
部署系統(tǒng)合約:
cleos set contract eosio eosio.system -p eosio -x 1000
執(zhí)行的時候僻澎,不設(shè)置-x屬性的話,假如部署的機(jī)器不是太好的話十饥,可能會執(zhí)行失敗窟勃,比如下面的錯誤;
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
已經(jīng)部署成功逗堵,咱們來看看system合約的主要功能秉氧,該列表是cleos system
命令下的,當(dāng)然也可以看eosio.system.abi蜒秤,略有不同:
newaccount 創(chuàng)建新賬戶汁咏、同時購買RAM亚斋、抵押獲取帶寬
regproducer 注冊新的生產(chǎn)者
unregprod 注銷一個生產(chǎn)者
voteproducer 為生產(chǎn)者投票
listproducers 列舉生產(chǎn)者
delegatebw 抵押EOS獲取net和cpu
undelegatebw 解押EOS
buyram 購買內(nèi)存
sellram 售賣內(nèi)存
claimrewards 索要生產(chǎn)者獎勵?
regproxy 注冊一個代理賬戶 (用于投票)
unregproxy 注銷代理賬戶 (用于投票)
canceldelay 取消一個延遲的交易
今天我只講述其中幾個功能攘滩;
1. newaccount
其實伞访,咱們已經(jīng)有create account
,為啥還要在system添加這個功能呢轰驳?首先,在我們部署eosio.token
和eosio.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
來創(chuàng)建賬戶:
//設(shè)置參數(shù):--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
默認(rèn)創(chuàng)建的賬戶涮帘,只有8 KiB (這個單位不用我解釋吧)拼苍,但是,我們購買了10EOS的ram调缨,所以memory現(xiàn)在是671.1KiB疮鲫;
當(dāng)然,這會有很多疑問在這:是不是創(chuàng)建賬戶弦叶,必須要有EOS俊犯?都要購買RAM等等,具體實際的測試結(jié)果伤哺,不在這貼了燕侠,總結(jié)如下:
- 除了
eosio
賬戶,用其他賬戶創(chuàng)建的賬戶名長度必須為12(和BM在發(fā)布4.0時立莉,說的一致)贬循; - 創(chuàng)建賬戶的時候,用于購買新用戶的帶寬桃序、CPU和ram的錢杖虾,都是創(chuàng)建者來出;
- 從目前測試鏈上媒熊,創(chuàng)建一個新賬戶奇适,至少需要0.0449EOS坟比,即:
- 0.0001 EOS 的 net bandwidth ------ 432 Mb;
- 0.0001 EOS 的 cpu bandwidth ------- 12.58 hr嚷往;
- 0.00447 EOS 的 RAM -------- 3 KiB葛账; 創(chuàng)建賬戶之后,即立刻占用 2.926 KiB
至于皮仁,在eosio
創(chuàng)建賬戶的時候不限制長度籍琳,是因為eosio
是合約賬戶,還是因為是生產(chǎn)者節(jié)點贷祈,需要看看合約源碼再說趋急;
4. RAM
買賣RAM,這個實際操作比較簡單势誊,即兩個操作buyram
呜达,sellram
;
購買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 就能看到已經(jīng)購買到的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
在自己的測試網(wǎng)中可以看到,暫時的ram價格是 1KiB = 0.0149 EOS
3. producer & delegatebw
用于注冊為生產(chǎn)者挤忙,任何賬戶都可注冊:
$ 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
之后,用戶就可以為生產(chǎn)者進(jìn)行投票了册烈,在講解投票之前呢侥祭,需要先說明另一個方法,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都是直接轉(zhuǎn)賬給eosio
次哈,然后我們就能獲取響應(yīng)的net和cpu胎署;
用戶已經(jīng)抵押了EOS,這時候在對生產(chǎn)者投票窑滞,才會有比較重要的的票數(shù)琼牧;
使用voteproducer
進(jìn)行投票:
$ 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
先這么多,之后在繼續(xù)哀卫;
還有很多問題待解決巨坊,比如:
- 投票的權(quán)重;
- 注冊生產(chǎn)者到多少票此改,才能夠場成為實際的BP趾撵;
- 投票給生產(chǎn)者的賬戶,如何獲取收益等等共啃;