BCSkill (Block chain skill )
区块链中文技术社区

只讨论区块链底层技术
遵守一切相关法律政策!

WSL tail -f 命令失效

tail -f命令可以查看文件更新的记录,但是在wsl中,可能无法正常工作。

经查找发现,Linux是通过inotify来获取文件变动的,但是不知道是bug还是什么原因,感知不到文件变动,造成此问题。

解决方案:

tail -f ---disable-inotify info.log

转载自:http://www.txllive.top/?p=30

cleos查询账户RAM总购量与实际购买不一致

cleos get account

通过cleos 查询账户RAM余额

cleos -u http://127.0.0.1:8888 get account zer41iyhahwp
...
memory:
     quota:     9.366 KiB    used:     3.078 KiB

但实际创建账户时,RAM购买量为8192byte

cleos get table

通过查询用户资源表

cleos -u http://127.0.0.1:8888 get table bitconch zer41iyhahwp userres
$ cleos -u http://127.0.0.1:8888 get table eosio zer41iyhahwp userres
{
  "rows": [{
      "owner": "zer41iyhahwp",
      "net_weight": "10.00000000 EOS",
      "cpu_weight": "10.00000000 EOS",
      "ram_bytes": 8191
    }
  ],
  "more": false
}

ram_bytes的数据与创建时RAM数据基本(所差1byte是因为,购买RAM通过Bancor估价代币购买,会与实际少许误差)一致。那cleos查出的数据差距在哪?下面跟下系统合约源代码

系统合约源码

查看RAM购买后,设置资源的位置(跳转GitHub)

set_resource_limits( res_itr->owner, res_itr->ram_bytes + ram_gift_bytes, net, cpu );

发现设置资源的位置加上附加的ram_gift_bytes

查看ram_gift_bytes具体数值(跳转github

static constexpr int64_t  ram_gift_bytes        = 1400;

所以,查询账户RAM比实际购买多的部分为合约设置时赠送的部分(忽略运算误差)。

9.366 KiB = 8191 byte + 1400 byte

EOS Table 倒序删除

数据库中只保留最新的100条记录,旧纪录删除

// 最多100条
besthistory_tables besthistory_table(_self, _self.value);
total_count = 0;
auto itr_besthistory = besthistory_table.rbegin();
while(itr_besthistory != besthistory_table.rend()){
    if(total_count >= 99){
        auto itr = besthistory_table.erase(--itr_besthistory.base());
        itr_besthistory = std::reverse_iterator(itr);
    } else {
        total_count++;
        itr_besthistory++;
    }
}

error: use of undeclared identifier 'current_time_point'

包含头文件

#include <eosio/system.hpp>

https://github.com/EOSIO/eosio.cdt/issues/470

EOS nodeos api 中继模式

今天EOSIO官方开发提交的(New options for api nodes - 2.0) 审核通过了。

配置新增加配置

p2p-accept-transactions

允许评估通过p2p 网络接收的事务(如果有效)
默认值true

api-accept-transactions

允许评估和中继API事务(如果有效)
默认值true

配合read-mode一起使用

speculative

在“投机”模式下:数据库包含区块链中的交易状态变化,直到头块以及尚未包含在区块链中的某些交易。

head

数据库仅通过区块链中直到头部的交易包含状态更改; 如果有效,将中继节点接收到的事务。

配合配置
p2p-accept-transactions = false
api-accept-transactions = true

read-only

数据库仅包含区块链中直到主块的事务的状态更改;
通过P2P网络接收到的交易不会被中继,并且无法通过链API推送交易。
(不推荐使用此模式:可使用 p2p-accept-transactions和api-accept-transactions同为false代替)

irreversible

数据库仅包含区块链中直到最后一个不可逆块的事务的状态更改;
通过P2P网络接收到的交易不会被中继,并且无法通过链API推送交易。

配合配置
p2p-accept-transactions = false
api-accept-transactions = false

注意点

read-onlyirreversible模式下,api-accept-transactionsp2p-accept-transactions会强制修改为false.

更新支持

此时 2.0.4 以支持此更新
https://github.com/EOSIO/eos/releases/tag/v2.0.4

在read-only该选项read-mode的参数nodeos已被弃用。这是可能实现与相同的行为read-mode = head,p2p-accept-transactions = false和api-accept-transactions = false

使用read-mode = irreversiblenow需要进行设置p2p-accept-transactions = false并api-accept-transactions = false避免在启动时进行断言