Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
bf439d4c
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,发现更多精彩内容 >>
提交
bf439d4c
编写于
5月 11, 2018
作者:
D
Daniel Larimer
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'slim' of github.com:EOSIO/eos into slim
上级
84deb27f
1f32df80
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
212 addition
and
15 deletion
+212
-15
libraries/chain/resource_limits.cpp
libraries/chain/resource_limits.cpp
+13
-9
unittests/CMakeLists.txt
unittests/CMakeLists.txt
+2
-2
unittests/eosio.system_tests.cpp
unittests/eosio.system_tests.cpp
+197
-4
未找到文件。
libraries/chain/resource_limits.cpp
浏览文件 @
bf439d4c
...
@@ -87,45 +87,49 @@ void resource_limits_manager::add_transaction_usage(const flat_set<account_name>
...
@@ -87,45 +87,49 @@ void resource_limits_manager::add_transaction_usage(const flat_set<account_name>
for
(
const
auto
&
a
:
accounts
)
{
for
(
const
auto
&
a
:
accounts
)
{
const
auto
&
usage
=
_db
.
get
<
resource_usage_object
,
by_owner
>
(
a
);
const
auto
&
usage
=
_db
.
get
<
resource_usage_object
,
by_owner
>
(
a
);
const
auto
&
limits
=
_db
.
get
<
resource_limits_object
,
by_owner
>
(
boost
::
make_tuple
(
false
,
a
));
int64_t
unused
;
int64_t
net_weight
;
int64_t
cpu_weight
;
get_account_limits
(
a
,
unused
,
net_weight
,
cpu_weight
);
_db
.
modify
(
usage
,
[
&
](
auto
&
bu
){
_db
.
modify
(
usage
,
[
&
](
auto
&
bu
){
bu
.
net_usage
.
add
(
net_usage
,
time_slot
,
config
.
account_net_usage_average_window
);
bu
.
net_usage
.
add
(
net_usage
,
time_slot
,
config
.
account_net_usage_average_window
);
bu
.
cpu_usage
.
add
(
cpu_usage
,
time_slot
,
config
.
account_cpu_usage_average_window
);
bu
.
cpu_usage
.
add
(
cpu_usage
,
time_slot
,
config
.
account_cpu_usage_average_window
);
});
});
if
(
limits
.
cpu_weight
>=
0
&&
state
.
total_cpu_weight
>
0
)
{
if
(
cpu_weight
>=
0
&&
state
.
total_cpu_weight
>
0
)
{
uint128_t
window_size
=
config
.
account_cpu_usage_average_window
;
uint128_t
window_size
=
config
.
account_cpu_usage_average_window
;
auto
virtual_network_capacity_in_window
=
state
.
virtual_cpu_limit
*
window_size
;
auto
virtual_network_capacity_in_window
=
state
.
virtual_cpu_limit
*
window_size
;
auto
cpu_used_in_window
=
(
usage
.
cpu_usage
.
value_ex
*
window_size
)
/
config
::
rate_limiting_precision
;
auto
cpu_used_in_window
=
(
usage
.
cpu_usage
.
value_ex
*
window_size
)
/
config
::
rate_limiting_precision
;
uint128_t
user_weight
=
limits
.
cpu_weight
;
uint128_t
user_weight
=
cpu_weight
;
uint128_t
all_user_weight
=
state
.
total_cpu_weight
;
uint128_t
all_user_weight
=
state
.
total_cpu_weight
;
auto
max_user_use_in_window
=
(
virtual_network_capacity_in_window
*
user_weight
)
/
all_user_weight
;
auto
max_user_use_in_window
=
(
virtual_network_capacity_in_window
*
user_weight
)
/
all_user_weight
;
EOS_ASSERT
(
cpu_used_in_window
<=
max_user_use_in_window
,
EOS_ASSERT
(
cpu_used_in_window
<=
max_user_use_in_window
,
tx_cpu_usage_exceeded
,
tx_cpu_usage_exceeded
,
"authorizing account '${n}' has insufficient cpu resources for this transaction"
,
"authorizing account '${n}' has insufficient cpu resources for this transaction"
,
(
"n"
,
name
(
a
))
(
"n"
,
name
(
a
))
(
"cpu_used_in_window"
,
cpu_used_in_window
)
(
"cpu_used_in_window"
,
cpu_used_in_window
)
(
"max_user_use_in_window"
,
max_user_use_in_window
)
);
(
"max_user_use_in_window"
,
max_user_use_in_window
)
);
}
}
if
(
limits
.
net_weight
>=
0
&&
state
.
total_net_weight
>
0
)
{
if
(
net_weight
>=
0
&&
state
.
total_net_weight
>
0
)
{
uint128_t
window_size
=
config
.
account_net_usage_average_window
;
uint128_t
window_size
=
config
.
account_net_usage_average_window
;
auto
virtual_network_capacity_in_window
=
state
.
virtual_net_limit
*
window_size
;
auto
virtual_network_capacity_in_window
=
state
.
virtual_net_limit
*
window_size
;
auto
net_used_in_window
=
(
usage
.
net_usage
.
value_ex
*
window_size
)
/
config
::
rate_limiting_precision
;
auto
net_used_in_window
=
(
usage
.
net_usage
.
value_ex
*
window_size
)
/
config
::
rate_limiting_precision
;
uint128_t
user_weight
=
limits
.
net_weight
;
uint128_t
user_weight
=
net_weight
;
uint128_t
all_user_weight
=
state
.
total_net_weight
;
uint128_t
all_user_weight
=
state
.
total_net_weight
;
auto
max_user_use_in_window
=
(
virtual_network_capacity_in_window
*
user_weight
)
/
all_user_weight
;
auto
max_user_use_in_window
=
(
virtual_network_capacity_in_window
*
user_weight
)
/
all_user_weight
;
EOS_ASSERT
(
net_used_in_window
<=
max_user_use_in_window
,
EOS_ASSERT
(
net_used_in_window
<=
max_user_use_in_window
,
tx_net_usage_exceeded
,
tx_net_usage_exceeded
,
"authorizing account '${n}' has insufficient net resources for this transaction"
,
"authorizing account '${n}' has insufficient net resources for this transaction"
,
(
"n"
,
name
(
a
))
(
"n"
,
name
(
a
))
(
"net_used_in_window"
,
net_used_in_window
)
(
"net_used_in_window"
,
net_used_in_window
)
(
"max_user_use_in_window"
,
max_user_use_in_window
)
);
(
"max_user_use_in_window"
,
max_user_use_in_window
)
);
...
...
unittests/CMakeLists.txt
浏览文件 @
bf439d4c
...
@@ -32,11 +32,11 @@ add_dependencies(unit_test asserter test_api test_api_mem test_api_db test_api_m
...
@@ -32,11 +32,11 @@ add_dependencies(unit_test asserter test_api test_api_mem test_api_db test_api_m
#Manually run unit_test for all supported runtimes
#Manually run unit_test for all supported runtimes
#To run unit_test with all log from blockchain displayed, put --verbose after --, i.e. unit_test -- --verbose
#To run unit_test with all log from blockchain displayed, put --verbose after --, i.e. unit_test -- --verbose
add_test
(
NAME unit_test_binaryen COMMAND unit_test
add_test
(
NAME unit_test_binaryen COMMAND unit_test
-t \!eosio_system_tests/
*
-t \!eosio_system_tests/
elect_producers
-t \!wasm_tests/weighted_cpu_limit_tests
-t \!wasm_tests/weighted_cpu_limit_tests
--report_level=detailed --color_output -- --binaryen
)
--report_level=detailed --color_output -- --binaryen
)
add_test
(
NAME unit_test_wavm COMMAND unit_test
add_test
(
NAME unit_test_wavm COMMAND unit_test
-t \!eosio_system_tests/
*
-t \!eosio_system_tests/
elect_producers
-t \!wasm_tests/weighted_cpu_limit_tests
-t \!wasm_tests/weighted_cpu_limit_tests
--report_level=detailed --color_output --catch_system_errors=no -- --wavm
)
--report_level=detailed --color_output --catch_system_errors=no -- --wavm
)
...
...
unittests/eosio.system_tests.cpp
浏览文件 @
bf439d4c
...
@@ -172,8 +172,8 @@ public:
...
@@ -172,8 +172,8 @@ public:
account_name
creator
(
N
(
eosio
));
account_name
creator
(
N
(
eosio
));
signed_transaction
trx
;
signed_transaction
trx
;
set_transaction_headers
(
trx
);
set_transaction_headers
(
trx
);
asset
cpu
=
asset
::
from_string
(
"
80.0000 EOS"
);
asset
cpu
=
asset
::
from_string
(
"
12000000.0000 EOS"
);
// why need to state too much CPU inorder to register inita-initz
asset
net
=
asset
::
from_string
(
"
8
0.0000 EOS"
);
asset
net
=
asset
::
from_string
(
"
100000
0.0000 EOS"
);
asset
ram
=
asset
::
from_string
(
"1.0000 EOS"
);
asset
ram
=
asset
::
from_string
(
"1.0000 EOS"
);
for
(
const
auto
&
a
:
accounts
)
{
for
(
const
auto
&
a
:
accounts
)
{
...
@@ -290,12 +290,13 @@ public:
...
@@ -290,12 +290,13 @@ public:
}
}
action_result
regproducer
(
const
account_name
&
acnt
,
int
params_fixture
=
1
)
{
action_result
regproducer
(
const
account_name
&
acnt
,
int
params_fixture
=
1
)
{
wdump
((
acnt
));
action_result
r
=
push_action
(
acnt
,
N
(
regproducer
),
mvo
()
return
push_action
(
acnt
,
N
(
regproducer
),
mvo
()
(
"producer"
,
acnt
)
(
"producer"
,
acnt
)
(
"producer_key"
,
get_public_key
(
acnt
,
"active"
)
)
(
"producer_key"
,
get_public_key
(
acnt
,
"active"
)
)
(
"url"
,
""
)
(
"url"
,
""
)
);
);
BOOST_REQUIRE_EQUAL
(
success
(),
r
);
return
r
;
}
}
uint32_t
last_block_time
()
const
{
uint32_t
last_block_time
()
const
{
...
@@ -1689,6 +1690,198 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester) try {
...
@@ -1689,6 +1690,198 @@ BOOST_FIXTURE_TEST_CASE(multiple_producer_pay, eosio_system_tester) try {
}
FC_LOG_AND_RETHROW
()
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
producer_onblock_check
,
eosio_system_tester
)
try
{
const
auto
tol
=
boost
::
test_tools
::
tolerance
(
0.0000000001
);
const
asset
large_asset
=
asset
::
from_string
(
"100000000.0000 EOS"
);
create_account_with_resources
(
N
(
vota
),
N
(
eosio
),
asset
::
from_string
(
"1.0000 EOS"
),
false
,
large_asset
,
large_asset
);
create_account_with_resources
(
N
(
votb
),
N
(
eosio
),
asset
::
from_string
(
"1.0000 EOS"
),
false
,
large_asset
,
large_asset
);
create_account_with_resources
(
N
(
votc
),
N
(
eosio
),
asset
::
from_string
(
"1.0000 EOS"
),
false
,
large_asset
,
large_asset
);
// create accounts {inita, initb, ..., initz} and register as producers
setup_producer_accounts
();
std
::
vector
<
account_name
>
producer_names
=
{
N
(
inita
),
N
(
initb
),
N
(
initc
),
N
(
initd
),
N
(
inite
),
N
(
initf
),
N
(
initg
),
N
(
inith
),
N
(
initi
),
N
(
initj
),
N
(
initk
),
N
(
initl
),
N
(
initm
),
N
(
initn
),
N
(
inito
),
N
(
initp
),
N
(
initq
),
N
(
initr
),
N
(
inits
),
N
(
initt
),
N
(
initu
),
N
(
initv
),
N
(
initw
),
N
(
initx
),
N
(
inity
),
N
(
initz
)};
for
(
auto
a
:
producer_names
)
regproducer
(
a
);
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
N
(
inita
)
)[
"total_votes"
].
as
<
double
>
());
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
N
(
initz
)
)[
"total_votes"
].
as
<
double
>
());
issue
(
"vota"
,
"100000000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"vota"
,
"30000000.0000 EOS"
,
"30000000.0000 EOS"
));
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
vota
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"vota"
)
(
"proxy"
,
name
(
0
).
to_string
())
(
"producers"
,
vector
<
account_name
>
(
producer_names
.
begin
(),
producer_names
.
begin
()
+
10
))
));
// give a chance for everyone to produce blocks
{
produce_blocks
(
21
*
12
);
bool
all_21_produced
=
true
;
for
(
uint32_t
i
=
0
;
i
<
21
;
++
i
)
{
if
(
0
==
get_producer_info
(
producer_names
[
i
])[
"produced_blocks"
].
as
<
uint32_t
>
())
{
all_21_produced
=
false
;
}
}
bool
rest_didnt_produce
=
true
;
for
(
uint32_t
i
=
21
;
i
<
producer_names
.
size
();
++
i
)
{
if
(
0
<
get_producer_info
(
producer_names
[
i
])[
"produced_blocks"
].
as
<
uint32_t
>
())
{
rest_didnt_produce
=
false
;
}
}
BOOST_REQUIRE_EQUAL
(
false
,
all_21_produced
);
BOOST_REQUIRE_EQUAL
(
true
,
rest_didnt_produce
);
}
// issue across 15% boundary
issue
(
"votb"
,
"100000000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"votb"
,
"30000000.0000 EOS"
,
"30000000.0000 EOS"
));
issue
(
"votc"
,
"100000000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"votc"
,
"30000000.0000 EOS"
,
"30000000.0000 EOS"
));
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
votb
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"votb"
)
(
"proxy"
,
name
(
0
).
to_string
())
(
"producers"
,
vector
<
account_name
>
(
producer_names
.
begin
(),
producer_names
.
begin
()
+
21
))
)
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
votc
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"votc"
)
(
"proxy"
,
name
(
0
).
to_string
())
(
"producers"
,
vector
<
account_name
>
(
producer_names
.
begin
(),
producer_names
.
end
()))
)
);
// give a chance for everyone to produce blocks
{
produce_blocks
(
21
*
12
);
bool
all_21_produced
=
true
;
for
(
uint32_t
i
=
0
;
i
<
21
;
++
i
)
{
if
(
0
==
get_producer_info
(
producer_names
[
i
])[
"produced_blocks"
].
as
<
uint32_t
>
())
{
all_21_produced
=
false
;
}
}
bool
rest_didnt_produce
=
true
;
for
(
uint32_t
i
=
21
;
i
<
producer_names
.
size
();
++
i
)
{
if
(
0
<
get_producer_info
(
producer_names
[
i
])[
"produced_blocks"
].
as
<
uint32_t
>
())
{
rest_didnt_produce
=
false
;
}
}
BOOST_REQUIRE_EQUAL
(
true
,
all_21_produced
);
BOOST_REQUIRE_EQUAL
(
true
,
rest_didnt_produce
);
}
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
multiple_producer_pay_unfair
,
eosio_system_tester
)
try
{
const
auto
tol
=
boost
::
test_tools
::
tolerance
(
0.0000000001
);
const
int64_t
secs_per_year
=
52
*
7
*
24
*
3600
;
const
int64_t
blocks_per_year
=
52
*
7
*
24
*
3600
*
2
;
const
double
cont_rate
=
4.879
/
100.
;
const
double
standby_rate
=
0.750
/
100.
;
const
double
block_rate
=
0.250
/
100.
;
const
asset
large_asset
=
asset
::
from_string
(
"100000000.0000 EOS"
);
create_account_with_resources
(
N
(
vota
),
N
(
eosio
),
asset
::
from_string
(
"1.0000 EOS"
),
false
,
large_asset
,
large_asset
);
create_account_with_resources
(
N
(
votb
),
N
(
eosio
),
asset
::
from_string
(
"1.0000 EOS"
),
false
,
large_asset
,
large_asset
);
create_account_with_resources
(
N
(
votc
),
N
(
eosio
),
asset
::
from_string
(
"1.0000 EOS"
),
false
,
large_asset
,
large_asset
);
// create accounts {inita, initb, ..., initz} and register as producers
setup_producer_accounts
();
std
::
vector
<
account_name
>
producer_names
=
{
N
(
inita
),
N
(
initb
),
N
(
initc
),
N
(
initd
),
N
(
inite
),
N
(
initf
),
N
(
initg
),
N
(
inith
),
N
(
initi
),
N
(
initj
),
N
(
initk
),
N
(
initl
),
N
(
initm
),
N
(
initn
),
N
(
inito
),
N
(
initp
),
N
(
initq
),
N
(
initr
),
N
(
inits
),
N
(
initt
),
N
(
initu
),
N
(
initv
),
N
(
initw
),
N
(
initx
),
N
(
inity
),
N
(
initz
)};
for
(
auto
a
:
producer_names
)
regproducer
(
a
);
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
N
(
inita
)
)[
"total_votes"
].
as
<
double
>
());
BOOST_REQUIRE_EQUAL
(
0
,
get_producer_info
(
N
(
initz
)
)[
"total_votes"
].
as
<
double
>
());
{
issue
(
"vota"
,
"100000000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"vota"
,
"30000000.0000 EOS"
,
"30000000.0000 EOS"
));
issue
(
"votb"
,
"100000000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"votb"
,
"30000000.0000 EOS"
,
"30000000.0000 EOS"
));
issue
(
"votc"
,
"100000000.0000 EOS"
,
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
success
(),
stake
(
"votc"
,
"30000000.0000 EOS"
,
"30000000.0000 EOS"
));
}
// vota votes for inita ... initj
// votb votes for inita ... initu
// votc votes for inita ... initz
{
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
vota
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"vota"
)
(
"proxy"
,
name
(
0
).
to_string
())
(
"producers"
,
vector
<
account_name
>
(
producer_names
.
begin
(),
producer_names
.
begin
()
+
10
))
)
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
votb
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"votb"
)
(
"proxy"
,
name
(
0
).
to_string
())
(
"producers"
,
vector
<
account_name
>
(
producer_names
.
begin
(),
producer_names
.
begin
()
+
21
))
)
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
votc
),
N
(
voteproducer
),
mvo
()
(
"voter"
,
"votc"
)
(
"proxy"
,
name
(
0
).
to_string
())
(
"producers"
,
vector
<
account_name
>
(
producer_names
.
begin
(),
producer_names
.
end
()))
)
);
}
// give a chance for everyone to produce blocks
{
produce_blocks
(
21
*
12
);
produce_block
(
fc
::
seconds
(
24
*
3600
*
3
));
produce_blocks
(
21
*
12
);
bool
all_21_produced
=
true
;
for
(
uint32_t
i
=
0
;
i
<
21
;
++
i
)
{
if
(
0
==
get_producer_info
(
producer_names
[
i
])[
"produced_blocks"
].
as
<
uint32_t
>
())
{
all_21_produced
=
false
;
}
}
bool
rest_didnt_produce
=
true
;
for
(
uint32_t
i
=
21
;
i
<
producer_names
.
size
();
++
i
)
{
if
(
0
<
get_producer_info
(
producer_names
[
i
])[
"produced_blocks"
].
as
<
uint32_t
>
())
{
rest_didnt_produce
=
false
;
}
}
BOOST_REQUIRE
(
all_21_produced
&&
rest_didnt_produce
);
}
BOOST_REQUIRE_EQUAL
(
0
,
get_balance
(
N
(
inita
)
).
amount
);
BOOST_REQUIRE_EQUAL
(
0
,
get_balance
(
N
(
initb
)
).
amount
);
account_name
prod
=
N
(
initb
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
prod
,
N
(
claimrewards
),
mvo
()(
"owner"
,
prod
)));
BOOST_REQUIRE_EQUAL
(
42346751
,
get_balance
(
prod
).
amount
);
prod
=
N
(
initc
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
prod
,
N
(
claimrewards
),
mvo
()(
"owner"
,
prod
)));
BOOST_REQUIRE_EQUAL
(
40118632
,
get_balance
(
prod
).
amount
);
prod
=
N
(
inita
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
prod
,
N
(
claimrewards
),
mvo
()(
"owner"
,
prod
)));
BOOST_REQUIRE_EQUAL
(
38007778
,
get_balance
(
prod
).
amount
);
}
FC_LOG_AND_RETHROW
()
BOOST_FIXTURE_TEST_CASE
(
voters_actions_affect_proxy_and_producers
,
eosio_system_tester
,
*
boost
::
unit_test
::
tolerance
(
1e+6
)
)
try
{
BOOST_FIXTURE_TEST_CASE
(
voters_actions_affect_proxy_and_producers
,
eosio_system_tester
,
*
boost
::
unit_test
::
tolerance
(
1e+6
)
)
try
{
create_accounts_with_resources
(
{
N
(
donald
),
N
(
producer1
),
N
(
producer2
),
N
(
producer3
)
}
);
create_accounts_with_resources
(
{
N
(
donald
),
N
(
producer1
),
N
(
producer2
),
N
(
producer3
)
}
);
BOOST_REQUIRE_EQUAL
(
success
(),
regproducer
(
"producer1"
,
1
)
);
BOOST_REQUIRE_EQUAL
(
success
(),
regproducer
(
"producer1"
,
1
)
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录