Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
7221b73b
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,发现更多精彩内容 >>
提交
7221b73b
编写于
5月 08, 2018
作者:
K
Khaled Al-Hassanieh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More producer pay testing, fixes
上级
a0f0c8ec
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
94 addition
and
28 deletion
+94
-28
contracts/eosio.system/eosio.system.abi
contracts/eosio.system/eosio.system.abi
+1
-2
contracts/eosio.system/producer_pay.cpp
contracts/eosio.system/producer_pay.cpp
+6
-8
unittests/eosio.system_tests.cpp
unittests/eosio.system_tests.cpp
+87
-18
未找到文件。
contracts/eosio.system/eosio.system.abi
浏览文件 @
7221b73b
...
@@ -116,8 +116,7 @@
...
@@ -116,8 +116,7 @@
"name": "eosio_parameters",
"name": "eosio_parameters",
"base": "blockchain_parameters",
"base": "blockchain_parameters",
"fields": [
"fields": [
{"name":"max_ram_size", "type":"uint64"},
{"name":"max_ram_size", "type":"uint64"}
{"name":"percent_of_max_inflation_rate", "type":"uint32"}
]
]
},{
},{
"name": "eosio_global_state",
"name": "eosio_global_state",
...
...
contracts/eosio.system/producer_pay.cpp
浏览文件 @
7221b73b
...
@@ -33,7 +33,7 @@ namespace eosiosystem {
...
@@ -33,7 +33,7 @@ namespace eosiosystem {
return
;
return
;
if
(
_gstate
.
last_pervote_bucket_fill
==
0
)
/// start the presses
if
(
_gstate
.
last_pervote_bucket_fill
==
0
)
/// start the presses
_gstate
.
last_pervote_bucket_fill
=
timestamp
;
_gstate
.
last_pervote_bucket_fill
=
current_time
()
;
auto
prod
=
_producers
.
find
(
producer
);
auto
prod
=
_producers
.
find
(
producer
);
if
(
prod
!=
_producers
.
end
()
)
{
if
(
prod
!=
_producers
.
end
()
)
{
...
@@ -102,9 +102,8 @@ namespace eosiosystem {
...
@@ -102,9 +102,8 @@ namespace eosiosystem {
eosio_assert
(
current_time
()
>=
prod
->
last_claim_time
+
useconds_per_day
,
"already claimed rewards within a day"
);
eosio_assert
(
current_time
()
>=
prod
->
last_claim_time
+
useconds_per_day
,
"already claimed rewards within a day"
);
}
}
auto
parameters
=
_global
.
get
();
const
asset
token_supply
=
token
(
N
(
eosio
.
token
)).
get_supply
(
symbol_type
(
system_token_symbol
).
name
()
);
const
asset
token_supply
=
token
(
N
(
eosio
.
token
)).
get_supply
(
symbol_type
(
system_token_symbol
).
name
()
);
const
uint32_t
secs_since_last_fill
=
static_cast
<
uint32_t
>
(
(
current_time
()
-
parameters
.
last_pervote_bucket_fill
)
/
1000000
);
const
uint32_t
secs_since_last_fill
=
static_cast
<
uint32_t
>
(
(
current_time
()
-
_gstate
.
last_pervote_bucket_fill
)
/
1000000
);
const
asset
to_eos_bucket
=
supply_growth
(
standby_rate
,
token_supply
,
secs_since_last_fill
);
const
asset
to_eos_bucket
=
supply_growth
(
standby_rate
,
token_supply
,
secs_since_last_fill
);
const
asset
to_savings
=
supply_growth
(
continuous_rate
-
(
perblock_rate
+
standby_rate
),
token_supply
,
secs_since_last_fill
);
const
asset
to_savings
=
supply_growth
(
continuous_rate
-
(
perblock_rate
+
standby_rate
),
token_supply
,
secs_since_last_fill
);
...
@@ -114,12 +113,11 @@ namespace eosiosystem {
...
@@ -114,12 +113,11 @@ namespace eosiosystem {
INLINE_ACTION_SENDER
(
eosio
::
token
,
issue
)(
N
(
eosio
.
token
),
{{
N
(
eosio
),
N
(
active
)}},
INLINE_ACTION_SENDER
(
eosio
::
token
,
issue
)(
N
(
eosio
.
token
),
{{
N
(
eosio
),
N
(
active
)}},
{
N
(
eosio
),
issue_amount
,
std
::
string
(
"issue tokens for producer pay and savings"
)}
);
{
N
(
eosio
),
issue_amount
,
std
::
string
(
"issue tokens for producer pay and savings"
)}
);
const
asset
pervote_pay
=
payment_per_vote
(
owner
,
prod
->
total_votes
,
to_eos_bucket
+
parameters
.
eos_bucket
);
const
asset
pervote_pay
=
payment_per_vote
(
owner
,
prod
->
total_votes
,
to_eos_bucket
+
_gstate
.
eos_bucket
);
parameters
.
eos_bucket
+=
(
to_eos_bucket
-
pervote_pay
);
_gstate
.
eos_bucket
+=
(
to_eos_bucket
-
pervote_pay
);
parameters
.
last_pervote_bucket_fill
=
current_time
();
_gstate
.
last_pervote_bucket_fill
=
current_time
();
parameters
.
savings
+=
to_savings
;
_gstate
.
savings
+=
to_savings
;
_global
.
set
(
parameters
,
_self
);
INLINE_ACTION_SENDER
(
eosio
::
token
,
transfer
)(
N
(
eosio
.
token
),
{
N
(
eosio
),
N
(
active
)},
INLINE_ACTION_SENDER
(
eosio
::
token
,
transfer
)(
N
(
eosio
.
token
),
{
N
(
eosio
),
N
(
active
)},
{
N
(
eosio
),
owner
,
perblock_pay
+
pervote_pay
,
std
::
string
(
"producer claiming rewards"
)
}
);
{
N
(
eosio
),
owner
,
perblock_pay
+
pervote_pay
,
std
::
string
(
"producer claiming rewards"
)
}
);
...
...
unittests/eosio.system_tests.cpp
浏览文件 @
7221b73b
...
@@ -45,8 +45,6 @@ public:
...
@@ -45,8 +45,6 @@ public:
issue
(
config
::
system_account_name
,
"1000000000.0000 EOS"
);
issue
(
config
::
system_account_name
,
"1000000000.0000 EOS"
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"1000000000.0000 EOS"
),
get_balance
(
"eosio"
)
);
BOOST_REQUIRE_EQUAL
(
asset
::
from_string
(
"1000000000.0000 EOS"
),
get_balance
(
"eosio"
)
);
// create_accounts_with_resources ( { N(inita), N(initb), N(voter1), N(voter2) }, asset::from_string("100000.0000 EOS") );
set_code
(
config
::
system_account_name
,
eosio_system_wast
);
set_code
(
config
::
system_account_name
,
eosio_system_wast
);
set_abi
(
config
::
system_account_name
,
eosio_system_abi
);
set_abi
(
config
::
system_account_name
,
eosio_system_abi
);
...
@@ -62,10 +60,18 @@ public:
...
@@ -62,10 +60,18 @@ public:
produce_blocks
();
produce_blocks
();
const
auto
&
accnt
=
control
->
db
().
get
<
account_object
,
by_name
>
(
config
::
system_account_name
);
{
abi_def
abi
;
const
auto
&
accnt
=
control
->
db
().
get
<
account_object
,
by_name
>
(
config
::
system_account_name
);
BOOST_REQUIRE_EQUAL
(
abi_serializer
::
to_abi
(
accnt
.
abi
,
abi
),
true
);
abi_def
abi
;
abi_ser
.
set_abi
(
abi
);
BOOST_REQUIRE_EQUAL
(
abi_serializer
::
to_abi
(
accnt
.
abi
,
abi
),
true
);
abi_ser
.
set_abi
(
abi
);
}
{
const
auto
&
accnt
=
control
->
db
().
get
<
account_object
,
by_name
>
(
N
(
eosio
.
token
)
);
abi_def
abi
;
BOOST_REQUIRE_EQUAL
(
abi_serializer
::
to_abi
(
accnt
.
abi
,
abi
),
true
);
token_abi_ser
.
set_abi
(
abi
);
}
/*
/*
const global_property_object &gpo = control->get_global_properties();
const global_property_object &gpo = control->get_global_properties();
FC_ASSERT(0 < gpo.active_producers.producers.size(), "No producers");
FC_ASSERT(0 < gpo.active_producers.producers.size(), "No producers");
...
@@ -311,8 +317,25 @@ public:
...
@@ -311,8 +317,25 @@ public:
);
);
}
}
fc
::
variant
get_stats
(
const
string
&
symbolname
)
{
auto
symb
=
eosio
::
chain
::
symbol
::
from_string
(
symbolname
);
auto
symbol_code
=
symb
.
to_symbol_code
().
value
;
vector
<
char
>
data
=
get_row_by_account
(
N
(
eosio
.
token
),
symbol_code
,
N
(
stat
),
symbol_code
);
return
data
.
empty
()
?
fc
::
variant
()
:
token_abi_ser
.
binary_to_variant
(
"currency_stats"
,
data
);
}
asset
get_token_supply
()
{
return
get_stats
(
"4,EOS"
)[
"supply"
].
as
<
asset
>
();
}
fc
::
variant
get_global_state
()
{
vector
<
char
>
data
=
get_row_by_account
(
N
(
eosio
),
N
(
eosio
),
N
(
global
),
N
(
global
)
);
if
(
data
.
empty
())
std
::
cout
<<
"
\n
Data is empty
\n
"
<<
std
::
endl
;
return
data
.
empty
()
?
fc
::
variant
()
:
abi_ser
.
binary_to_variant
(
"eosio_global_state"
,
data
);
}
abi_serializer
abi_ser
;
abi_serializer
abi_ser
;
abi_serializer
token_abi_ser
;
};
};
fc
::
mutable_variant_object
voter
(
account_name
acct
)
{
fc
::
mutable_variant_object
voter
(
account_name
acct
)
{
...
@@ -1180,7 +1203,6 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester) try {
...
@@ -1180,7 +1203,6 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester) try {
produce_block
();
produce_block
();
// 1 block produced
BOOST_REQUIRE_EQUAL
(
success
(),
regproducer
(
N
(
inita
)));
BOOST_REQUIRE_EQUAL
(
success
(),
regproducer
(
N
(
inita
)));
auto
prod
=
get_producer_info
(
N
(
inita
)
);
auto
prod
=
get_producer_info
(
N
(
inita
)
);
...
@@ -1197,19 +1219,66 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester) try {
...
@@ -1197,19 +1219,66 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester) try {
)
)
);
);
produce_blocks
(
200
);
// inita is the only active producer
prod
=
get_producer_info
(
"inita"
);
// produce enough blocks so new schedule kicks in and inita produces some blocks
{
BOOST_REQUIRE
(
1
<
prod
[
"produced_blocks"
].
as
<
uint32_t
>
());
produce_blocks
(
50
);
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
inita
),
N
(
claimrewards
),
mvo
()(
"owner"
,
"inita"
)));
const
auto
initial_global_state
=
get_global_state
();
prod
=
get_producer_info
(
"inita"
);
const
uint64_t
initial_claim_time
=
initial_global_state
[
"last_pervote_bucket_fill"
].
as_uint64
();
BOOST_REQUIRE_EQUAL
(
1
,
prod
[
"produced_blocks"
].
as
<
uint32_t
>
());
const
asset
initial_eos_bucket
=
initial_global_state
[
"eos_bucket"
].
as
<
asset
>
();
const
asset
initial_savings
=
initial_global_state
[
"savings"
].
as
<
asset
>
();
prod
=
get_producer_info
(
"inita"
);
const
uint32_t
produced_blocks
=
prod
[
"produced_blocks"
].
as
<
uint32_t
>
();
BOOST_REQUIRE
(
1
<
produced_blocks
);
BOOST_REQUIRE_EQUAL
(
0
,
prod
[
"last_claim_time"
].
as
<
uint64_t
>
());
const
asset
initial_supply
=
get_token_supply
();
const
asset
initial_balance
=
get_balance
(
N
(
inita
));
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
inita
),
N
(
claimrewards
),
mvo
()(
"owner"
,
"inita"
)));
const
auto
global_state
=
get_global_state
();
const
uint64_t
claim_time
=
global_state
[
"last_pervote_bucket_fill"
].
as_uint64
();
const
asset
eos_bucket
=
global_state
[
"eos_bucket"
].
as
<
asset
>
();
const
asset
savings
=
global_state
[
"savings"
].
as
<
asset
>
();
prod
=
get_producer_info
(
"inita"
);
BOOST_REQUIRE_EQUAL
(
1
,
prod
[
"produced_blocks"
].
as
<
uint32_t
>
());
const
asset
supply
=
get_token_supply
();
const
asset
balance
=
get_balance
(
N
(
inita
));
BOOST_REQUIRE_EQUAL
(
claim_time
,
prod
[
"last_claim_time"
].
as
<
uint64_t
>
());
const
int32_t
secs_between_fills
=
static_cast
<
int32_t
>
((
claim_time
-
initial_claim_time
)
/
1000000
);
BOOST_REQUIRE_EQUAL
(
0
,
initial_eos_bucket
.
amount
);
BOOST_REQUIRE_EQUAL
(
0
,
eos_bucket
.
amount
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
secs_between_fills
*
((
4.879
-
1.0
)
/
100.0
))
/
(
52
*
7
*
24
*
3600
)
),
savings
.
amount
-
initial_savings
.
amount
);
int64_t
block_payments
=
int64_t
(
initial_supply
.
amount
*
produced_blocks
*
(
0.25
/
100.0
)
/
(
52
*
7
*
24
*
3600
*
2
)
);
int64_t
from_eos_bucket
=
int64_t
(
initial_supply
.
amount
*
secs_between_fills
*
(
0.75
/
100.0
)
/
(
52
*
7
*
24
*
3600
)
);
BOOST_REQUIRE_EQUAL
(
block_payments
+
from_eos_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
}
{
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: already claimed rewards within a day"
),
push_action
(
N
(
inita
),
N
(
claimrewards
),
mvo
()(
"owner"
,
"inita"
)));
}
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: already claimed rewards within a day"
),
// inita waits for 23 hours and 55 minutes, can't claim rewards yet
push_action
(
N
(
inita
),
N
(
claimrewards
),
mvo
()(
"owner"
,
"inita"
)));
{
produce_block
(
fc
::
seconds
(
23
*
3600
+
55
*
60
));
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: already claimed rewards within a day"
),
push_action
(
N
(
inita
),
N
(
claimrewards
),
mvo
()(
"owner"
,
"inita"
)));
}
produce_block
(
fc
::
seconds
(
1
));
// wait 5 more minutes, inita can now claim rewards again
{
produce_block
(
fc
::
seconds
(
5
*
60
));
BOOST_REQUIRE_EQUAL
(
success
(),
push_action
(
N
(
inita
),
N
(
claimrewards
),
mvo
()(
"owner"
,
"inita"
)));
BOOST_REQUIRE_EQUAL
(
1
,
prod
[
"produced_blocks"
].
as
<
uint32_t
>
());
}
}
FC_LOG_AND_RETHROW
()
}
FC_LOG_AND_RETHROW
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录