EOS 编译Debug
./scripts/eosio_build.sh -o Debug
ubuntu设置coredump
sudo sysctl -w kernel.core_pattern=/corefiles/core.%p.%e
sudo mkdir /corefiles
sudo chmod -R 777 /corefiles
ulimit -c unlimited
当nodeos
异常退出时,就会在/corefiles/
生成dump
文件
./scripts/eosio_build.sh -o Debug
sudo sysctl -w kernel.core_pattern=/corefiles/core.%p.%e
sudo mkdir /corefiles
sudo chmod -R 777 /corefiles
ulimit -c unlimited
当nodeos
异常退出时,就会在/corefiles/
生成dump
文件
rm.get_account_limits( result.account_name, result.ram_quota, result.net_weight, result.cpu_weight );
set_resource_limits( res_itr->owner, res_itr->ram_bytes + ram_gift_bytes, net, cpu );
ram_bytes
是实际买的RAM 大小,ram_quota
是加上了 赠送的ram_gift_bytes
(等于1400)(github)
cleos -u https://api.eoslaomao.com get account bcskillsurou
返回
memory:
quota: 4.348 KiB used: 3.49 KiB
查看账户资源表
cleos -u https://api.eoslaomao.com get table eosio bcskillsurou userres
返回
{
"rows": [{
"owner": "bcskillsurou",
"net_weight": "0.0046 EOS",
"cpu_weight": "0.0147 EOS",
"ram_bytes": 3052
}
],
"more": false,
"next_key": ""
}
计算
quota 与 ram_bytes差值等于 1400,与ram_gift_bytes值一致。
最近链发送交易过大时容易发生一下错误
{
"message": "Internal Service Error",
"code": "500",
"error": {
"code": "3080004",
"name": "tx_cpu_usage_exceeded",
"what": "Transaction exceeded the current CPU usage limit imposed on the transaction",
"details": [{
"message": "transaction was executing for too long",
"file": "transaction_context.cpp",
"line_number": 488,
"method": "checktime"
}, {
"message": "pending console output: ",
"file": "apply_context.cpp",
"line_number": 113,
"method": "exec_one"
}]
}
}
根据错误信息,定位源代码位置 (github)
由于now > _deadline
并且 deadline_exception_code == tx_cpu_usage_exceeded::code_value
走到此断言逻辑
倒推到函数调用位置(github)
checktime(); // Fail early if deadline has already been exceeded
提示信息为:如果已超过截止日期,则提早失败
继续反推代码
由于(github)交易组装时trx.max_cpu_usage_ms
固定设置的0。所以,判断逻辑出自(github)
// Possibly lower objective_duration_limit to the maximum cpu usage a transaction is allowed to be billed
if( cfg.max_transaction_cpu_usage <= objective_duration_limit.count() ) {
objective_duration_limit = fc::microseconds(cfg.max_transaction_cpu_usage);
billing_timer_exception_code = tx_cpu_usage_exceeded::code_value;
_deadline = start + objective_duration_limit;
}
auto& rl = control.get_mutable_resource_limits_manager();
objective_duration_limit = fc::microseconds( rl.get_block_cpu_limit() );
_deadline = start + objective_duration_limit;
if(now > _deadline) {
// 报异常
}
get_mutable_resource_limits_manager(github)
resource_limits_manager& controller::get_mutable_resource_limits_manager()
{
return my->resource_limits;
}
get_block_cpu_limit(github)
uint64_t resource_limits_manager::get_block_cpu_limit() const {
const auto& state = _db.get<resource_limits_state_object>();
const auto& config = _db.get<resource_limits_config_object>();
return config.cpu_limit_parameters.max - state.pending_cpu_usage;
}
发现是由于合约中使用了std::vector<std::string>
持续存储大量数据,导致单次CPU运算执行耗时持续增长。
当合约中Table单条记录中,如果使用vector
不要存储过多数据,以及数据结构过于复杂的struct
。
如有对应需求,可以拆分子表,然后使用子表记录id索引对应。
tail -f命令可以查看文件更新的记录,但是在wsl中,可能无法正常工作。
经查找发现,Linux是通过inotify来获取文件变动的,但是不知道是bug还是什么原因,感知不到文件变动,造成此问题。
解决方案:
tail -f ---disable-inotify info.log
通过cleos 查询账户RAM余额
cleos -u http://127.0.0.1:8888 get account zer41iyhahwp
...
memory:
quota: 9.366 KiB used: 3.078 KiB
但实际创建账户时,RAM购买量为8192
byte
通过查询用户资源表
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查出的数据差距在哪?下面跟下系统合约源代码
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