Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
52287ba1
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,发现更多精彩内容 >>
提交
52287ba1
编写于
5月 14, 2018
作者:
K
Khaled Al-Hassanieh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed producer_pay test, limited daily pay threshold to pervote
上级
77e14d3d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
55 addition
and
40 deletion
+55
-40
contracts/eosio.system/producer_pay.cpp
contracts/eosio.system/producer_pay.cpp
+3
-2
unittests/eosio.system_tests.cpp
unittests/eosio.system_tests.cpp
+52
-38
未找到文件。
contracts/eosio.system/producer_pay.cpp
浏览文件 @
52287ba1
...
...
@@ -83,10 +83,11 @@ namespace eosiosystem {
int64_t
producer_per_block_pay
=
(
_gstate
.
perblock_bucket
*
prod
.
produced_blocks
)
/
_gstate
.
total_unpaid_blocks
;
int64_t
producer_per_vote_pay
=
int64_t
((
_gstate
.
pervote_bucket
*
prod
.
total_votes
)
/
_gstate
.
total_producer_vote_weight
);
if
(
producer_per_vote_pay
<
100'0000
)
{
producer_per_vote_pay
=
0
;
}
int64_t
total_pay
=
producer_per_block_pay
+
producer_per_vote_pay
;
eosio_assert
(
total_pay
>
1000000
/* 100'0000 */
,
"insufficient pay to claim, require at least 100.0000 EOS"
);
_gstate
.
pervote_bucket
-=
producer_per_vote_pay
;
_gstate
.
perblock_bucket
-=
producer_per_block_pay
;
_gstate
.
total_unpaid_blocks
-=
prod
.
produced_blocks
;
...
...
unittests/eosio.system_tests.cpp
浏览文件 @
52287ba1
...
...
@@ -1328,7 +1328,7 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
// inita is the only active producer
// produce enough blocks so new schedule kicks in and inita produces some blocks
{
produce_blocks
(
100
0
);
produce_blocks
(
5
0
);
const
auto
initial_global_state
=
get_global_state
();
const
uint64_t
initial_claim_time
=
initial_global_state
[
"last_pervote_bucket_fill"
].
as_uint64
();
...
...
@@ -1368,23 +1368,21 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
BOOST_REQUIRE_EQUAL
(
0
,
initial_pervote_bucket
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
continuous_rate
)
/
usecs_per_year
),
supply
.
amount
-
initial_supply
.
amount
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
4.
*
continuous_rate
/
5.
)
/
usecs_per_year
)
),
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
4.
*
continuous_rate
/
5.
)
/
usecs_per_year
)
),
savings
-
initial_savings
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
0.25
*
continuous_rate
/
5.
)
/
usecs_per_year
)
),
balance
.
amount
-
initial_balance
.
amount
);
int64_t
from_perblock_bucket
=
int64_t
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
0.25
*
continuous_rate
/
5.
)
/
usecs_per_year
)
;
int64_t
from_pervote_bucket
=
int64_t
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
0.75
*
continuous_rate
/
5.
)
/
usecs_per_year
)
;
int64_t
block_payments
=
int64_t
(
initial_supply
.
amount
*
unpaid_blocks
*
(
0.25
/
100.0
)
/
(
52
*
7
*
24
*
3600
*
2
)
);
int64_t
from_pervote_bucket
=
int64_t
(
initial_supply
.
amount
*
usecs_between_fills
*
(
0.75
/
100.0
)
/
(
52
*
7
*
24
*
3600
)
);
return
;
/*
if
(
from_pervote_bucket
>=
100
*
10000
)
{
BOOST_REQUIRE_EQUAL(
block_payments
+ from_pervote_bucket, balance.amount - initial_balance.amount);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
+
from_pervote_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
0
,
pervote_bucket
);
}
else
{
BOOST_REQUIRE_EQUAL(
block_payments
, balance.amount - initial_balance.amount);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
from_pervote_bucket
,
pervote_bucket
);
}
*/
// const int64_t max_supply_growth = int64_t( (initial_supply.amount * usecs_between_fills * (4.879/100.0)) / (52*7*24*3600) );
// BOOST_REQUIRE(max_supply_growth >= supply.amount - initial_supply.amount);
}
{
...
...
@@ -1399,62 +1397,78 @@ BOOST_FIXTURE_TEST_CASE(producer_pay, eosio_system_tester, * boost::unit_test::t
push_action
(
N
(
inita
),
N
(
claimrewards
),
mvo
()(
"owner"
,
"inita"
)));
}
return
;
// wait 5 more minutes, inita can now claim rewards again
{
produce_block
(
fc
::
seconds
(
5
*
60
));
const
auto
initial_global_state
=
get_global_state
();
const
uint64_t
initial_claim_time
=
initial_global_state
[
"last_pervote_bucket_fill"
].
as_uint64
();
const
int64_t
initial_pervote_bucket
=
initial_global_state
[
"pervote_bucket"
].
as
<
int64_t
>
();
const
int64_t
initial_savings
=
initial_global_state
[
"savings"
].
as
<
int64_t
>
();
const
auto
initial_global_state
=
get_global_state
();
const
uint64_t
initial_claim_time
=
initial_global_state
[
"last_pervote_bucket_fill"
].
as_uint64
();
const
int64_t
initial_pervote_bucket
=
initial_global_state
[
"pervote_bucket"
].
as
<
int64_t
>
();
const
int64_t
initial_perblock_bucket
=
initial_global_state
[
"perblock_bucket"
].
as
<
int64_t
>
();
const
int64_t
initial_savings
=
initial_global_state
[
"savings"
].
as
<
int64_t
>
();
const
uint32_t
initial_tot_unpaid_blocks
=
initial_global_state
[
"total_unpaid_blocks"
].
as
<
uint32_t
>
();
prod
=
get_producer_info
(
"inita"
);
const
uint32_t
produced_blocks
=
prod
[
"produced_blocks"
].
as
<
uint32_t
>
();
BOOST_REQUIRE
(
1
<
produced_blocks
);
BOOST_REQUIRE
(
0
<
prod
[
"last_claim_time"
].
as
<
uint64_t
>
());
const
uint32_t
unpaid_blocks
=
prod
[
"produced_blocks"
].
as
<
uint32_t
>
();
BOOST_REQUIRE
(
1
<
unpaid_blocks
);
BOOST_REQUIRE_EQUAL
(
0
,
prod
[
"last_claim_time"
].
as
<
uint64_t
>
());
BOOST_REQUIRE_EQUAL
(
initial_tot_unpaid_blocks
,
unpaid_blocks
);
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
int64_t
pervote_bucket
=
global_state
[
"pervote_bucket"
].
as
<
int64_t
>
();
const
int64_t
savings
=
global_state
[
"savings"
].
as
<
int64_t
>
();
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
int64_t
pervote_bucket
=
global_state
[
"pervote_bucket"
].
as
<
int64_t
>
();
const
int64_t
perblock_bucket
=
global_state
[
"perblock_bucket"
].
as
<
int64_t
>
();
const
int64_t
savings
=
global_state
[
"savings"
].
as
<
int64_t
>
();
const
uint32_t
tot_unpaid_blocks
=
global_state
[
"total_unpaid_blocks"
].
as
<
uint32_t
>
();
prod
=
get_producer_info
(
"inita"
);
BOOST_REQUIRE_EQUAL
(
1
,
prod
[
"produced_blocks"
].
as
<
uint32_t
>
());
BOOST_REQUIRE_EQUAL
(
1
,
tot_unpaid_blocks
);
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
int64_t
usecs_between_fills
=
(
claim_time
-
initial_claim_time
)
;
auto
usecs_between_fills
=
claim_time
-
initial_claim_time
;
/*
BOOST_REQUIRE_EQUAL(int64_t( (initial_supply.amount * secs_between_fills * ((4.879-1.0)/100.0)) / (52*7*24*3600) ),
savings- initial_savings );
BOOST_REQUIRE_EQUAL
(
0
,
initial_pervote_bucket
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
continuous_rate
)
/
usecs_per_year
),
supply
.
amount
-
initial_supply
.
amount
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
4.
*
continuous_rate
/
5.
)
/
usecs_per_year
)
),
savings
-
initial_savings
);
BOOST_REQUIRE_EQUAL
(
int64_t
(
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
0.25
*
continuous_rate
/
5.
)
/
usecs_per_year
)
),
balance
.
amount
-
initial_balance
.
amount
);
int64_t
block_payments = int64_t( initial_supply.amount * produced_blocks * (0.25/100.0) / (52*7*24*3600*2) )
;
int64_t from_pervote_bucket
= int64_t( initial_pervote_bucket + initial_supply.amount * secs_between_fills * (0.75/100.0) / (52*7*24*3600) )
;
int64_t
from_perblock_bucket
=
int64_t
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
0.25
*
continuous_rate
/
5.
)
/
usecs_per_year
)
;
int64_t
from_pervote_bucket
=
int64_t
(
initial_supply
.
amount
*
double
(
usecs_between_fills
)
*
(
0.75
*
continuous_rate
/
5.
)
/
usecs_per_year
)
;
if
(
from_pervote_bucket
>=
100
*
10000
)
{
BOOST_REQUIRE_EQUAL(
block_payments
+ from_pervote_bucket, balance.amount - initial_balance.amount);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
+
from_pervote_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
0
,
pervote_bucket
);
}
else
{
BOOST_REQUIRE_EQUAL(
block_payments
, balance.amount - initial_balance.amount);
BOOST_REQUIRE_EQUAL
(
from_perblock_bucket
,
balance
.
amount
-
initial_balance
.
amount
);
BOOST_REQUIRE_EQUAL
(
from_pervote_bucket
,
pervote_bucket
);
}
*/
/// NOTE: this is fragile and merely replicating equation in contract, changing the order of math and/or types will change result
const
int64_t
max_supply_growth
=
int64_t
(
(
double
(
initial_supply
.
amount
)
*
double
(
usecs_between_fills
)
*
double
(
.04879
))
/
double
(
52
*
7
*
24
*
3600
*
1000000ll
)
);
wdump
((
max_supply_growth
)(
supply
.
amount
)(
initial_supply
.
amount
)(
supply
.
amount
-
initial_supply
.
amount
));
BOOST_REQUIRE
(
max_supply_growth
>=
supply
.
amount
-
initial_supply
.
amount
);
/// Using microseconds can lead to overflow issues if order or types is not chosen carefully
/// using seconds gives accurate results
{
uint32_t
secs_between_fills
=
((
claim_time
-
initial_claim_time
)
/
1000000
);
const
int64_t
max_supply_growth
=
int64_t
(
initial_supply
.
amount
*
secs_between_fills
*
continuous_rate
/
(
52
*
7
*
24
*
3600
)
);
wdump
((
max_supply_growth
)(
supply
.
amount
)(
initial_supply
.
amount
)(
supply
.
amount
-
initial_supply
.
amount
));
BOOST_REQUIRE
(
max_supply_growth
==
supply
.
amount
-
initial_supply
.
amount
);
}
}
// initb tries to claim rewards but he's not on the list
{
//BOOST_REQUIRE_EQUAL(error("condition: assertion failed: account name is not in producer list"),
BOOST_REQUIRE_EQUAL
(
error
(
"condition: assertion failed: unable to find key"
),
push_action
(
N
(
initb
),
N
(
claimrewards
),
mvo
()(
"owner"
,
"initb"
)));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录