Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
13952d45
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
13952d45
编写于
5月 13, 2018
作者:
D
Daniel Larimer
提交者:
GitHub
5月 13, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3000 from EOSIO/dandev
Fix Numerous Bugs
上级
a29e14b7
6305224e
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
131 addition
and
144 deletion
+131
-144
contracts/eosio.system/eosio.system.abi
contracts/eosio.system/eosio.system.abi
+2
-3
contracts/eosio.system/eosio.system.cpp
contracts/eosio.system/eosio.system.cpp
+1
-1
contracts/eosiolib/print.hpp
contracts/eosiolib/print.hpp
+5
-0
libraries/chain/block_header_state.cpp
libraries/chain/block_header_state.cpp
+9
-50
libraries/chain/block_state.cpp
libraries/chain/block_state.cpp
+2
-2
libraries/chain/controller.cpp
libraries/chain/controller.cpp
+20
-18
libraries/chain/eosio_contract.cpp
libraries/chain/eosio_contract.cpp
+0
-9
libraries/chain/fork_database.cpp
libraries/chain/fork_database.cpp
+2
-2
libraries/chain/include/eosio/chain/block_header_state.hpp
libraries/chain/include/eosio/chain/block_header_state.hpp
+2
-2
libraries/chain/include/eosio/chain/block_state.hpp
libraries/chain/include/eosio/chain/block_state.hpp
+1
-1
libraries/chain/include/eosio/chain/controller.hpp
libraries/chain/include/eosio/chain/controller.hpp
+1
-1
libraries/chain/include/eosio/chain/fork_database.hpp
libraries/chain/include/eosio/chain/fork_database.hpp
+1
-1
libraries/chain/include/eosio/chain/resource_limits.hpp
libraries/chain/include/eosio/chain/resource_limits.hpp
+2
-2
libraries/chain/resource_limits.cpp
libraries/chain/resource_limits.cpp
+5
-1
plugins/producer_plugin/producer_plugin.cpp
plugins/producer_plugin/producer_plugin.cpp
+15
-6
programs/cleos/main.cpp
programs/cleos/main.cpp
+63
-45
未找到文件。
contracts/eosio.system/eosio.system.abi
浏览文件 @
13952d45
...
...
@@ -54,9 +54,8 @@
"fields": [
{"name":"from", "type":"account_name"},
{"name":"to", "type":"account_name"},
{"name":"net_weight", "type":"uint64"},
{"name":"cpu_weight", "type":"uint64"},
{"name":"ram_bytes", "type":"uint64"}
{"name":"net_weight", "type":"asset"},
{"name":"cpu_weight", "type":"asset"}
]
},{
"name": "user_resources",
...
...
contracts/eosio.system/eosio.system.cpp
浏览文件 @
13952d45
...
...
@@ -81,8 +81,8 @@ EOSIO_ABI( eosiosystem::system_contract,
(
delegatebw
)(
undelegatebw
)(
refund
)
(
buyram
)(
buyrambytes
)(
sellram
)
// voting.cpp
(
regproxy
)(
regproducer
)(
unregprod
)(
voteproducer
)
// producer_pay.cpp
(
regproxy
)(
regproducer
)(
unregprod
)(
voteproducer
)
(
claimrewards
)
// native.hpp
//XXX
...
...
contracts/eosiolib/print.hpp
浏览文件 @
13952d45
...
...
@@ -7,6 +7,7 @@
#include <eosiolib/types.hpp>
#include <eosiolib/fixed_key.hpp>
#include <utility>
#include <string>
namespace
eosio
{
...
...
@@ -21,6 +22,10 @@ namespace eosio {
prints
(
ptr
);
}
inline
void
print
(
const
std
::
string
&
s
)
{
prints
(
s
.
c_str
());
}
/**
* Prints signed integer
* @brief Prints signed integer as a 64 bit signed integer
...
...
libraries/chain/block_header_state.cpp
浏览文件 @
13952d45
...
...
@@ -4,60 +4,17 @@
namespace
eosio
{
namespace
chain
{
/*
uint32_t block_header_state::calc_dpos_last_irreversible()const {
if( producer_to_last_produced.size() == 0 )
return 0;
vector<uint32_t> irb;
irb.reserve( producer_to_last_produced.size() );
for( const auto& item : producer_to_last_produced )
irb.push_back(item.second);
size_t offset = EOS_PERCENT(irb.size(), config::percent_100- config::irreversible_threshold_percent);
std::nth_element( irb.begin(), irb.begin() + offset, irb.end() );
return irb[offset];
}
*/
bool
block_header_state
::
is_active_producer
(
account_name
n
)
const
{
return
producer_to_last_produced
.
find
(
n
)
!=
producer_to_last_produced
.
end
();
}
/*
block_timestamp_type block_header_state::get_slot_time( uint32_t slot_num )const {
auto t = header.timestamp;
FC_ASSERT( std::numeric_limits<decltype(t.slot)>::max() - t.slot >= slot_num, "block timestamp overflow" );
t.slot += slot_num;
return t;
}
uint32_t block_header_state::get_slot_at_time( block_timestamp_type t )const {
auto first_slot_time = get_slot_time(1);
if( t < first_slot_time )
return 0;
return (t.slot - first_slot_time.slot + 1);
}
producer_key block_header_state::get_scheduled_producer( uint32_t slot_num )const {
return get_scheduled_producer( get_slot_time(slot_num) );
}
*/
producer_key
block_header_state
::
get_scheduled_producer
(
block_timestamp_type
t
)
const
{
auto
index
=
t
.
slot
%
(
active_schedule
.
producers
.
size
()
*
config
::
producer_repetitions
);
index
/=
config
::
producer_repetitions
;
return
active_schedule
.
producers
[
index
];
}
/*
uint32_t block_header_state::producer_participation_rate()const
{
return static_cast<uint32_t>(config::percent_100); // Ignore participation rate for now until we construct a better metric.
}
*/
/**
* Generate a template block header state for a given block time, it will not
...
...
@@ -153,7 +110,7 @@ namespace eosio { namespace chain {
*
* If the header specifies new_producers then apply them accordingly.
*/
block_header_state
block_header_state
::
next
(
const
signed_block_header
&
h
)
const
{
block_header_state
block_header_state
::
next
(
const
signed_block_header
&
h
,
bool
trust
)
const
{
FC_ASSERT
(
h
.
timestamp
!=
block_timestamp_type
(),
""
,
(
"h"
,
h
)
);
FC_ASSERT
(
h
.
header_extensions
.
size
()
==
0
,
"no supported extensions"
);
...
...
@@ -178,16 +135,16 @@ namespace eosio { namespace chain {
result
.
set_confirmed
(
h
.
confirmed
);
// idump( (result.confirm_count.size()) );
result
.
header
.
action_mroot
=
h
.
action_mroot
;
result
.
header
.
transaction_mroot
=
h
.
transaction_mroot
;
result
.
header
.
producer_signature
=
h
.
producer_signature
;
//idump((result.header));
result
.
id
=
result
.
header
.
id
();
FC_ASSERT
(
result
.
block_signing_key
==
result
.
signee
(),
"block not signed by expected key"
,
(
"result.block_signing_key"
,
result
.
block_signing_key
)(
"signee"
,
result
.
signee
()
)
);
if
(
!
trust
)
{
FC_ASSERT
(
result
.
block_signing_key
==
result
.
signee
(),
"block not signed by expected key"
,
(
"result.block_signing_key"
,
result
.
block_signing_key
)(
"signee"
,
result
.
signee
()
)
);
}
return
result
;
}
/// next
...
...
@@ -232,10 +189,12 @@ namespace eosio { namespace chain {
return
digest_type
::
hash
(
std
::
make_pair
(
header_bmroot
,
pending_schedule_hash
)
);
}
void
block_header_state
::
sign
(
const
std
::
function
<
signature_type
(
const
digest_type
&
)
>&
signer
)
{
void
block_header_state
::
sign
(
const
std
::
function
<
signature_type
(
const
digest_type
&
)
>&
signer
,
bool
trust
)
{
auto
d
=
sig_digest
();
header
.
producer_signature
=
signer
(
d
);
FC_ASSERT
(
block_signing_key
==
fc
::
crypto
::
public_key
(
header
.
producer_signature
,
d
)
);
if
(
!
trust
)
{
FC_ASSERT
(
block_signing_key
==
fc
::
crypto
::
public_key
(
header
.
producer_signature
,
d
)
);
}
}
public_key_type
block_header_state
::
signee
()
const
{
...
...
libraries/chain/block_state.cpp
浏览文件 @
13952d45
...
...
@@ -10,8 +10,8 @@ namespace eosio { namespace chain {
static_cast
<
block_header
&>
(
*
block
)
=
header
;
}
block_state
::
block_state
(
const
block_header_state
&
prev
,
signed_block_ptr
b
)
:
block_header_state
(
prev
.
next
(
*
b
)),
block
(
move
(
b
)
)
block_state
::
block_state
(
const
block_header_state
&
prev
,
signed_block_ptr
b
,
bool
trust
)
:
block_header_state
(
prev
.
next
(
*
b
,
trust
)),
block
(
move
(
b
)
)
{
}
...
...
libraries/chain/controller.cpp
浏览文件 @
13952d45
...
...
@@ -260,14 +260,14 @@ struct controller_impl {
auto
start
=
fc
::
time_point
::
now
();
while
(
auto
next
=
blog
.
read_block_by_num
(
head
->
block_num
+
1
)
)
{
self
.
push_block
(
next
);
if
(
next
->
block_num
()
%
10
==
0
)
{
self
.
push_block
(
next
,
true
);
if
(
next
->
block_num
()
%
10
0
==
0
)
{
std
::
cerr
<<
std
::
setw
(
10
)
<<
next
->
block_num
()
<<
" of "
<<
end
->
block_num
()
<<
"
\r
"
;
}
}
std
::
cerr
<<
"
\n
"
;
auto
end
=
fc
::
time_point
::
now
();
ilog
(
"replayed blocks in ${n} seconds
"
,
(
"n"
,
(
end
-
start
).
count
()
/
1000000.0
)
);
ilog
(
"replayed blocks in ${n} seconds
, ${spb} spb"
,
(
"n"
,
(
end
-
start
).
count
()
/
1000000.0
)(
"spb"
,
((
end
-
start
).
count
()
/
1000000.0
)
/
head
->
block_num
)
);
replaying
=
false
;
}
else
if
(
!
end
)
{
...
...
@@ -700,18 +700,20 @@ struct controller_impl {
void
sign_block
(
const
std
::
function
<
signature_type
(
const
digest_type
&
)
>&
signer_callback
)
{
void
sign_block
(
const
std
::
function
<
signature_type
(
const
digest_type
&
)
>&
signer_callback
,
bool
trust
)
{
auto
p
=
pending
->
_pending_block_state
;
try
{
p
->
sign
(
signer_callback
);
p
->
sign
(
signer_callback
,
false
);
//trust
);
}
catch
(
...
)
{
edump
((
fc
::
json
::
to_pretty_string
(
*
p
->
block
)
)
);
edump
((
fc
::
json
::
to_pretty_string
(
p
->
header
)
)
);
throw
;
}
static_cast
<
signed_block_header
&>
(
*
p
->
block
)
=
p
->
header
;
}
/// sign_block
void
apply_block
(
const
signed_block_ptr
&
b
)
{
try
{
void
apply_block
(
const
signed_block_ptr
&
b
,
bool
trust
)
{
try
{
try
{
FC_ASSERT
(
b
->
block_extensions
.
size
()
==
0
,
"no supported extensions"
);
start_block
(
b
->
timestamp
,
b
->
confirmed
);
...
...
@@ -728,7 +730,7 @@ struct controller_impl {
}
finalize_block
();
sign_block
(
[
&
](
const
auto
&
){
return
b
->
producer_signature
;
}
);
sign_block
(
[
&
](
const
auto
&
){
return
b
->
producer_signature
;
}
,
trust
);
// this is implied by the signature passing
//FC_ASSERT( b->id() == pending->_pending_block_state->block->id(),
...
...
@@ -744,14 +746,14 @@ struct controller_impl {
}
FC_CAPTURE_AND_RETHROW
()
}
/// apply_block
void
push_block
(
const
signed_block_ptr
&
b
)
{
void
push_block
(
const
signed_block_ptr
&
b
,
bool
trust
)
{
// idump((fc::json::to_pretty_string(*b)));
FC_ASSERT
(
!
pending
,
"it is not valid to push a block when there is a pending block"
);
try
{
FC_ASSERT
(
b
);
auto
new_header_state
=
fork_db
.
add
(
b
);
auto
new_header_state
=
fork_db
.
add
(
b
,
trust
);
emit
(
self
.
accepted_block_header
,
new_header_state
);
maybe_switch_forks
();
maybe_switch_forks
(
trust
);
}
FC_LOG_AND_RETHROW
(
)
}
...
...
@@ -762,12 +764,12 @@ struct controller_impl {
maybe_switch_forks
();
}
void
maybe_switch_forks
()
{
void
maybe_switch_forks
(
bool
trust
=
false
)
{
auto
new_head
=
fork_db
.
head
();
if
(
new_head
->
header
.
previous
==
head
->
id
)
{
try
{
apply_block
(
new_head
->
block
);
apply_block
(
new_head
->
block
,
trust
);
fork_db
.
mark_in_current_chain
(
new_head
,
true
);
fork_db
.
set_validity
(
new_head
,
true
);
head
=
new_head
;
...
...
@@ -790,7 +792,7 @@ struct controller_impl {
for
(
auto
ritr
=
branches
.
first
.
rbegin
();
ritr
!=
branches
.
first
.
rend
();
++
ritr
)
{
optional
<
fc
::
exception
>
except
;
try
{
apply_block
(
(
*
ritr
)
->
block
);
apply_block
(
(
*
ritr
)
->
block
,
false
/*don't trust*/
);
head
=
*
ritr
;
fork_db
.
mark_in_current_chain
(
*
ritr
,
true
);
}
...
...
@@ -813,7 +815,7 @@ struct controller_impl {
// re-apply good blocks
for
(
auto
ritr
=
branches
.
second
.
rbegin
();
ritr
!=
branches
.
second
.
rend
();
++
ritr
)
{
apply_block
(
(
*
ritr
)
->
block
);
apply_block
(
(
*
ritr
)
->
block
,
true
/* we previously validated these blocks*/
);
head
=
*
ritr
;
fork_db
.
mark_in_current_chain
(
*
ritr
,
true
);
}
...
...
@@ -1046,7 +1048,7 @@ void controller::finalize_block() {
}
void
controller
::
sign_block
(
const
std
::
function
<
signature_type
(
const
digest_type
&
)
>&
signer_callback
)
{
my
->
sign_block
(
signer_callback
);
my
->
sign_block
(
signer_callback
,
false
/* don't trust */
);
}
void
controller
::
commit_block
()
{
...
...
@@ -1057,8 +1059,8 @@ void controller::abort_block() {
my
->
abort_block
();
}
void
controller
::
push_block
(
const
signed_block_ptr
&
b
)
{
my
->
push_block
(
b
);
void
controller
::
push_block
(
const
signed_block_ptr
&
b
,
bool
trust
)
{
my
->
push_block
(
b
,
trust
);
log_irreversible_blocks
();
}
...
...
libraries/chain/eosio_contract.cpp
浏览文件 @
13952d45
...
...
@@ -121,7 +121,6 @@ void apply_eosio_newaccount(apply_context& context) {
void
apply_eosio_setcode
(
apply_context
&
context
)
{
const
auto
&
cfg
=
context
.
control
.
get_global_properties
().
configuration
;
context
.
checktime
(
cfg
.
base_setcode_cpu_usage
);
auto
&
db
=
context
.
db
;
auto
act
=
context
.
act
.
data_as
<
setcode
>
();
...
...
@@ -131,7 +130,6 @@ void apply_eosio_setcode(apply_context& context) {
FC_ASSERT
(
act
.
vmtype
==
0
);
FC_ASSERT
(
act
.
vmversion
==
0
);
context
.
checktime
(
act
.
code
.
size
()
*
20
);
auto
code_id
=
fc
::
sha256
::
hash
(
act
.
code
.
data
(),
(
uint32_t
)
act
.
code
.
size
()
);
...
...
@@ -180,7 +178,6 @@ void apply_eosio_setabi(apply_context& context) {
int64_t
old_size
=
(
int64_t
)
account
.
abi
.
size
();
int64_t
new_size
=
(
int64_t
)
fc
::
raw
::
pack_size
(
act
.
abi
);
context
.
checktime
(
new_size
*
2
);
db
.
modify
(
account
,
[
&
](
auto
&
a
)
{
a
.
set_abi
(
act
.
abi
);
...
...
@@ -223,7 +220,6 @@ void apply_eosio_updateauth(apply_context& context) {
validate_authority_precondition
(
context
,
update
.
auth
);
context
.
checktime
(
5000
);
auto
permission
=
authorization
.
find_permission
({
update
.
account
,
update
.
permission
});
...
...
@@ -284,7 +280,6 @@ void apply_eosio_deleteauth(apply_context& context) {
context
.
trx_context
.
add_ram_usage
(
remove
.
account
,
-
old_size
);
context
.
checktime
(
3000
);
}
void
apply_eosio_linkauth
(
apply_context
&
context
)
{
...
...
@@ -332,7 +327,6 @@ void apply_eosio_linkauth(apply_context& context) {
);
}
context
.
checktime
(
3000
);
}
FC_CAPTURE_AND_RETHROW
((
requirement
))
}
...
...
@@ -353,7 +347,6 @@ void apply_eosio_unlinkauth(apply_context& context) {
);
db
.
remove
(
*
link
);
context
.
checktime
(
3000
);
}
static
const
abi_serializer
&
get_abi_serializer
()
{
...
...
@@ -373,8 +366,6 @@ void apply_eosio_canceldelay(apply_context& context) {
const
auto
&
trx_id
=
cancel
.
trx_id
;
context
.
cancel_deferred_transaction
(
transaction_id_to_sender_id
(
trx_id
),
account_name
());
context
.
checktime
(
1000
);
}
}
}
// namespace eosio::chain
libraries/chain/fork_database.cpp
浏览文件 @
13952d45
...
...
@@ -141,7 +141,7 @@ namespace eosio { namespace chain {
return
n
;
}
block_state_ptr
fork_database
::
add
(
signed_block_ptr
b
)
{
block_state_ptr
fork_database
::
add
(
signed_block_ptr
b
,
bool
trust
)
{
FC_ASSERT
(
b
,
"attempt to add null block"
);
FC_ASSERT
(
my
->
head
,
"no head block set"
);
...
...
@@ -152,7 +152,7 @@ namespace eosio { namespace chain {
auto
prior
=
by_id_idx
.
find
(
b
->
previous
);
FC_ASSERT
(
prior
!=
by_id_idx
.
end
(),
"unlinkable block"
,
(
"id"
,
b
->
id
())(
"previous"
,
b
->
previous
)
);
auto
result
=
std
::
make_shared
<
block_state
>
(
**
prior
,
move
(
b
)
);
auto
result
=
std
::
make_shared
<
block_state
>
(
**
prior
,
move
(
b
)
,
trust
);
FC_ASSERT
(
result
);
return
add
(
result
);
}
...
...
libraries/chain/include/eosio/chain/block_header_state.hpp
浏览文件 @
13952d45
...
...
@@ -24,7 +24,7 @@ struct block_header_state {
vector
<
uint8_t
>
confirm_count
;
vector
<
header_confirmation
>
confirmations
;
block_header_state
next
(
const
signed_block_header
&
h
)
const
;
block_header_state
next
(
const
signed_block_header
&
h
,
bool
trust
=
false
)
const
;
block_header_state
generate_next
(
block_timestamp_type
when
)
const
;
void
set_new_producers
(
producer_schedule_type
next_pending
);
...
...
@@ -46,7 +46,7 @@ struct block_header_state {
producer_key
get_scheduled_producer
(
block_timestamp_type
t
)
const
;
const
block_id_type
&
prev
()
const
{
return
header
.
previous
;
}
digest_type
sig_digest
()
const
;
void
sign
(
const
std
::
function
<
signature_type
(
const
digest_type
&
)
>&
signer
);
void
sign
(
const
std
::
function
<
signature_type
(
const
digest_type
&
)
>&
signer
,
bool
trust
=
false
);
public_key_type
signee
()
const
;
};
...
...
libraries/chain/include/eosio/chain/block_state.hpp
浏览文件 @
13952d45
...
...
@@ -13,7 +13,7 @@ namespace eosio { namespace chain {
struct
block_state
:
public
block_header_state
{
block_state
(
const
block_header_state
&
cur
)
:
block_header_state
(
cur
){}
block_state
(
const
block_header_state
&
prev
,
signed_block_ptr
b
);
block_state
(
const
block_header_state
&
prev
,
signed_block_ptr
b
,
bool
trust
=
false
);
block_state
(
const
block_header_state
&
prev
,
block_timestamp_type
when
);
block_state
()
=
default
;
...
...
libraries/chain/include/eosio/chain/controller.hpp
浏览文件 @
13952d45
...
...
@@ -99,7 +99,7 @@ namespace eosio { namespace chain {
void
log_irreversible_blocks
();
void
pop_block
();
void
push_block
(
const
signed_block_ptr
&
b
);
void
push_block
(
const
signed_block_ptr
&
b
,
bool
trust
=
false
/* does the caller trust the block*/
);
/**
* Call this method when a producer confirmation is received, this might update
...
...
libraries/chain/include/eosio/chain/fork_database.hpp
浏览文件 @
13952d45
...
...
@@ -40,7 +40,7 @@ namespace eosio { namespace chain {
* block_state and will return a pointer to the new block state or
* throw on error.
*/
block_state_ptr
add
(
signed_block_ptr
b
);
block_state_ptr
add
(
signed_block_ptr
b
,
bool
trust
=
false
);
block_state_ptr
add
(
block_state_ptr
next_block
);
void
remove
(
const
block_id_type
&
id
);
...
...
libraries/chain/include/eosio/chain/resource_limits.hpp
浏览文件 @
13952d45
...
...
@@ -29,7 +29,7 @@ namespace eosio { namespace chain { namespace resource_limits {
struct
account_resource_limit
{
int64_t
used
=
0
;
///< quantity used in current window
int64_t
available
=
0
;
///< quantity available in current window (based upon fractional reserve)
int64_t
max
_gauranteed
=
0
;
///< max per window under 100%
congestion
int64_t
max
=
0
;
///< max per window under current
congestion
};
class
resource_limits_manager
{
...
...
@@ -76,4 +76,4 @@ namespace eosio { namespace chain { namespace resource_limits {
};
}
}
}
/// eosio::chain
FC_REFLECT
(
eosio
::
chain
::
resource_limits
::
account_resource_limit
,
(
used
)(
available
)(
max
_gauranteed
)
)
FC_REFLECT
(
eosio
::
chain
::
resource_limits
::
account_resource_limit
,
(
used
)(
available
)(
max
)
)
libraries/chain/resource_limits.cpp
浏览文件 @
13952d45
...
...
@@ -401,7 +401,9 @@ account_resource_limit resource_limits_manager::get_account_cpu_limit_ex( const
uint128_t
user_weight
=
cpu_weight
;
uint128_t
all_user_weight
=
state
.
total_cpu_weight
;
auto
max_user_use_in_window
=
(
virtual_cpu_capacity_in_window
*
user_weight
)
/
all_user_weight
;
wdump
((
cpu_weight
));
auto
max_user_use_in_window
=
(
uint128_t
(
virtual_cpu_capacity_in_window
)
*
user_weight
)
/
all_user_weight
;
auto
cpu_used_in_window
=
(
usage
.
cpu_usage
.
value_ex
*
window_size
)
/
config
::
rate_limiting_precision
;
if
(
max_user_use_in_window
<=
cpu_used_in_window
)
...
...
@@ -410,6 +412,7 @@ account_resource_limit resource_limits_manager::get_account_cpu_limit_ex( const
arl
.
available
=
max_user_use_in_window
-
cpu_used_in_window
;
arl
.
used
=
cpu_used_in_window
;
arl
.
max
=
max_user_use_in_window
;
return
arl
;
}
...
...
@@ -471,6 +474,7 @@ account_resource_limit resource_limits_manager::get_account_net_limit_ex( const
arl
.
available
=
max_user_use_in_window
-
net_used_in_window
;
arl
.
used
=
net_used_in_window
;
arl
.
max
=
max_user_use_in_window
;
return
arl
;
}
...
...
plugins/producer_plugin/producer_plugin.cpp
浏览文件 @
13952d45
...
...
@@ -181,6 +181,12 @@ class producer_plugin_impl {
};
void
on_incoming_block
(
const
signed_block_ptr
&
block
)
{
if
(
block
->
timestamp
>
fc
::
time_point
::
now
()
)
{
FC_ASSERT
(
block
->
timestamp
<
fc
::
time_point
::
now
(),
"received a block from the future, ignoring it"
);
}
chain
::
controller
&
chain
=
app
().
get_plugin
<
chain_plugin
>
().
chain
();
// abort the pending block
chain
.
abort_block
();
...
...
@@ -197,10 +203,13 @@ class producer_plugin_impl {
if
(
chain
.
head_block_state
()
->
header
.
timestamp
.
next
().
to_time_point
()
>=
fc
::
time_point
::
now
()
)
_production_enabled
=
true
;
ilog
(
"Received block ${id}... #${n} @ ${t} signed by ${p} [trxs: ${count}, lib: ${lib}, confirmed: ${confs}]"
,
(
"p"
,
block
->
producer
)(
"id"
,
fc
::
variant
(
block
->
id
()).
as_string
().
substr
(
0
,
16
))
(
"n"
,
block_header
::
num_from_id
(
block
->
id
()))(
"t"
,
block
->
timestamp
)
(
"count"
,
block
->
transactions
.
size
())(
"lib"
,
chain
.
last_irreversible_block_num
())(
"confs"
,
block
->
confirmed
)
);
if
(
fc
::
time_point
::
now
()
-
block
->
timestamp
<
fc
::
seconds
(
5
)
||
(
block
->
block_num
()
%
1000
==
0
)
)
{
ilog
(
"Received block ${id}... #${n} @ ${t} signed by ${p} [trxs: ${count}, lib: ${lib}, confirmed: ${confs}]"
,
(
"p"
,
block
->
producer
)(
"id"
,
fc
::
variant
(
block
->
id
()).
as_string
().
substr
(
0
,
16
))
(
"n"
,
block_header
::
num_from_id
(
block
->
id
()))(
"t"
,
block
->
timestamp
)
(
"count"
,
block
->
transactions
.
size
())(
"lib"
,
chain
.
last_irreversible_block_num
())(
"confs"
,
block
->
confirmed
)
);
}
}
...
...
@@ -409,8 +418,8 @@ producer_plugin_impl::start_block_result producer_plugin_impl::start_block() {
if
((
block_time
-
now
)
<
fc
::
microseconds
(
config
::
block_interval_us
/
10
)
)
{
// we must sleep for at least 50ms
ilog
(
"Less than ${t}us to next block time, time_to_next_block_time ${bt}"
,
(
"t"
,
config
::
block_interval_us
/
10
)(
"bt"
,
block_time
));
//
ilog("Less than ${t}us to next block time, time_to_next_block_time ${bt}",
//
("t", config::block_interval_us/10)("bt", block_time));
block_time
+=
fc
::
microseconds
(
config
::
block_interval_us
);
}
...
...
programs/cleos/main.cpp
浏览文件 @
13952d45
...
...
@@ -1194,10 +1194,34 @@ void get_account( const string& accountName, bool json_format ) {
dfs_print
(
r
,
0
);
}
auto
to_pretty_net
=
[](
double
bytes
)
{
string
unit
=
"bytes"
;
if
(
bytes
>=
1024
*
1024
*
1024
*
1024ll
){
unit
=
"Tb"
;
bytes
/=
1024
*
1024
*
1024
*
1024ll
;
}
else
if
(
bytes
>=
1024
*
1024
*
1024
){
unit
=
"Gb"
;
bytes
/=
1024
*
1024
*
1024
;
}
else
if
(
bytes
>=
1024
*
1024
){
unit
=
"Mb"
;
bytes
/=
1024
*
1024
;
}
else
if
(
bytes
>=
1024
)
{
unit
=
"Kb"
;
bytes
/=
1024
;
}
std
::
stringstream
ss
;
ss
<<
setprecision
(
4
);
ss
<<
bytes
<<
" "
<<
std
::
left
<<
setw
(
5
)
<<
unit
;
return
ss
.
str
();
};
std
::
cout
<<
"memory: "
<<
std
::
endl
<<
indent
<<
"quota: "
<<
std
::
setw
(
15
)
<<
res
.
ram_quota
<<
" bytes used: "
<<
std
::
setw
(
15
)
<<
res
.
ram_usage
<<
" bytes"
<<
std
::
endl
<<
std
::
endl
;
<<
indent
<<
"quota: "
<<
std
::
setw
(
15
)
<<
to_pretty_net
(
res
.
ram_quota
)
<<
" used: "
<<
std
::
setw
(
15
)
<<
to_pretty_net
(
res
.
ram_usage
)
<<
std
::
endl
<<
std
::
endl
;
std
::
cout
<<
"net bandwidth:"
<<
std
::
endl
;
std
::
cout
<<
"net bandwidth:
(averaged over 3 days)
"
<<
std
::
endl
;
if
(
res
.
total_resources
.
is_object
()
)
{
asset
net_own
(
res
.
delegated_bandwidth
.
is_object
()
?
stoll
(
res
.
delegated_bandwidth
.
get_object
()[
"net_weight"
].
as_string
()
)
:
0
);
auto
net_others
=
to_asset
(
res
.
total_resources
.
get_object
()[
"net_weight"
].
as_string
())
-
net_own
;
...
...
@@ -1207,47 +1231,41 @@ void get_account( const string& accountName, bool json_format ) {
<<
std
::
string
(
11
,
' '
)
<<
"(total staked delegated to account from others)"
<<
std
::
endl
;
}
string
unit
=
"bytes"
;
double
net_usage
=
res
.
net_limit
.
available
;
if
(
res
.
net_limit
.
available
>=
1024
*
1024
*
1024
){
unit
=
"Gb"
;
net_usage
/=
1024
*
1024
*
1024
;
}
else
if
(
res
.
net_limit
.
available
>=
1024
*
1024
){
unit
=
"Mb"
;
net_usage
/=
1024
*
1024
;
}
else
if
(
res
.
net_limit
.
available
>=
1024
)
{
unit
=
"Kb"
;
net_usage
/=
1024
;
}
std
::
cout
<<
std
::
fixed
<<
setprecision
(
3
);
std
::
cout
<<
indent
<<
"used:"
<<
std
::
setw
(
15
)
<<
(
"~"
+
std
::
to_string
(
res
.
net_limit
.
used
))
<<
" bytes (past 3 days)"
<<
std
::
string
(
3
,
' '
)
<<
"(assuming current congestion and current usage)"
<<
std
::
endl
<<
indent
<<
"available:"
<<
std
::
setw
(
19
)
<<
(
"~"
+
std
::
to_string
(
net_usage
))
<<
" "
<<
unit
<<
std
::
string
(
3
,
' '
)
<<
"(assuming current congestion and 0 usage in current window)"
<<
std
::
endl
/*
<< indent << "guaranteed: " << std::setw(11) << res.net_limit.guaranteed_per_day << " bytes/day"
<< std::string(5, ' ') << "(assuming 100% congestion and 0 usage in current window)" << std::endl
*/
<<
std
::
endl
;
auto
to_pretty_time
=
[](
double
micro
)
{
string
unit
=
"us"
;
if
(
micro
>
1000000
*
60
)
{
micro
/=
1000000
*
60
*
60ll
;
unit
=
"hr"
;
}
else
if
(
micro
>
1000000
*
60
)
{
micro
/=
1000000
*
60
;
unit
=
"min"
;
}
else
if
(
micro
>
1000000
)
{
micro
/=
1000000
;
unit
=
"sec"
;
}
else
if
(
micro
>
1000
)
{
micro
/=
1000
;
unit
=
"ms"
;
}
std
::
stringstream
ss
;
ss
<<
setprecision
(
4
);
ss
<<
micro
<<
" "
<<
std
::
left
<<
setw
(
5
)
<<
unit
;
return
ss
.
str
();
};
std
::
cout
<<
"cpu bandwidth:"
<<
std
::
endl
;
std
::
cout
<<
std
::
fixed
<<
setprecision
(
3
);
std
::
cout
<<
indent
<<
std
::
left
<<
std
::
setw
(
11
)
<<
"used:"
<<
std
::
right
<<
std
::
setw
(
18
)
<<
to_pretty_net
(
res
.
net_limit
.
used
)
<<
"
\n
"
;
std
::
cout
<<
indent
<<
std
::
left
<<
std
::
setw
(
11
)
<<
"available:"
<<
std
::
right
<<
std
::
setw
(
18
)
<<
to_pretty_net
(
res
.
net_limit
.
available
)
<<
"
\n
"
;
std
::
cout
<<
indent
<<
std
::
left
<<
std
::
setw
(
11
)
<<
"limit:"
<<
std
::
right
<<
std
::
setw
(
18
)
<<
to_pretty_net
(
res
.
net_limit
.
max
)
<<
"
\n
"
;
std
::
cout
<<
std
::
endl
;
double
cpu_avail
=
res
.
cpu_limit
.
available
/
1000000.
;
string
cunit
=
"sec"
;
if
(
cpu_avail
>
60
*
60
*
24
)
{
cunit
=
"days"
;
cpu_avail
/=
60
*
60
*
24
;
}
else
if
(
cpu_avail
>
60
*
60
)
{
cunit
=
"hr"
;
cpu_avail
/=
60
*
60
;
}
else
if
(
cpu_avail
>
60
)
{
cunit
=
"min"
;
cpu_avail
/=
60
;
}
std
::
cout
<<
"cpu bandwidth: (averaged over 3 days)"
<<
std
::
endl
;
if
(
res
.
total_resources
.
is_object
()
)
{
...
...
@@ -1259,13 +1277,13 @@ void get_account( const string& accountName, bool json_format ) {
<<
std
::
string
(
11
,
' '
)
<<
"(total staked delegated to account from others)"
<<
std
::
endl
;
}
std
::
cout
<<
indent
<<
"used:"
<<
std
::
setw
(
15
)
<<
(
"~"
+
std
::
to_string
(
double
(
res
.
cpu_limit
.
used
/
1000000.
)))
<<
" sec (past 3 days)
\n
"
<<
indent
<<
"available:"
<<
std
::
setw
(
19
)
<<
(
"~"
+
std
::
to_string
(
cpu_avail
)
)
<<
" "
<<
cunit
<<
"
\n
"
/*
<< indent << "guaranteed:" << std::setw(12) << res.cpu_limit.guaranteed_per_day/1024 << " kcycle/day"
<< std::string(4, ' ') << "(assuming 100% congestion and 0 usage in current window)" << std::endl
*/
<<
std
::
endl
;
std
::
cout
<<
std
::
fixed
<<
setprecision
(
3
);
std
::
cout
<<
indent
<<
std
::
left
<<
std
::
setw
(
11
)
<<
"used:"
<<
std
::
right
<<
std
::
setw
(
18
)
<<
to_pretty_time
(
res
.
cpu_limit
.
used
)
<<
"
\n
"
;
std
::
cout
<<
indent
<<
std
::
left
<<
std
::
setw
(
11
)
<<
"available:"
<<
std
::
right
<<
std
::
setw
(
18
)
<<
to_pretty_time
(
res
.
cpu_limit
.
available
)
<<
"
\n
"
;
std
::
cout
<<
indent
<<
std
::
left
<<
std
::
setw
(
11
)
<<
"limit:"
<<
std
::
right
<<
std
::
setw
(
18
)
<<
to_pretty_time
(
res
.
cpu_limit
.
max
)
<<
"
\n
"
;
std
::
cout
<<
std
::
endl
;
if
(
res
.
voter_info
.
is_object
()
)
{
auto
&
obj
=
res
.
voter_info
.
get_object
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录