Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
7f065ae8
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,发现更多精彩内容 >>
提交
7f065ae8
编写于
2月 27, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
some types/variables name changed to more meaningfull ones
上级
b897a82a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
41 addition
and
41 deletion
+41
-41
contracts/eosio.system/producers_election.hpp
contracts/eosio.system/producers_election.hpp
+41
-41
未找到文件。
contracts/eosio.system/producers_election.hpp
浏览文件 @
7f065ae8
...
...
@@ -61,7 +61,7 @@ namespace eosiosystem {
typedef
eosio
::
multi_index
<
N
(
producervote
),
producer_info
,
indexed_by
<
N
(
prototalvote
),
const_mem_fun
<
producer_info
,
uint128_t
,
&
producer_info
::
by_votes
>
>
>
producer
_info_index_typ
e
;
>
producer
s_tabl
e
;
typedef
singleton
<
SystemAccount
,
N
(
inflation
),
SystemAccount
,
uint32_t
>
inflation_singleton
;
...
...
@@ -83,7 +83,7 @@ namespace eosiosystem {
EOSLIB_SERIALIZE
(
account_votes
,
(
owner
)(
proxy
)(
last_update
)(
is_proxy
)(
staked
)(
unstaking
)(
unstake_per_week
)(
proxied_votes
)(
producers
)(
deferred_trx_id
)(
last_unstake_time
)
)
};
typedef
eosio
::
multi_index
<
N
(
accountvotes
),
account_votes
>
account_votes_
index_typ
e
;
typedef
eosio
::
multi_index
<
N
(
accountvotes
),
account_votes
>
account_votes_
tabl
e
;
struct
producer_config
{
...
...
@@ -115,7 +115,7 @@ namespace eosiosystem {
static
void
on
(
const
register_producer
&
reg
)
{
require_auth
(
reg
.
producer
);
producer
_info_index_typ
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
producer
s_tabl
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
const
auto
*
existing
=
producers_tbl
.
find
(
reg
.
producer
);
eosio_assert
(
!
existing
,
"producer already registered"
);
...
...
@@ -143,11 +143,11 @@ namespace eosiosystem {
static
void
on
(
const
change_producer_preferences
&
change
)
{
require_auth
(
change
.
producer
);
producer
_info_index_typ
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
const
auto
*
p
tr
=
producers_tbl
.
find
(
change
.
producer
);
eosio_assert
(
bool
(
p
tr
),
"producer is not registered"
);
producer
s_tabl
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
const
auto
*
p
rod
=
producers_tbl
.
find
(
change
.
producer
);
eosio_assert
(
bool
(
p
rod
),
"producer is not registered"
);
producers_tbl
.
update
(
*
p
tr
,
change
.
producer
,
[
&
](
producer_info
&
info
){
producers_tbl
.
update
(
*
p
rod
,
change
.
producer
,
[
&
](
producer_info
&
info
){
info
.
prefs
=
change
.
prefs
;
});
}
...
...
@@ -160,7 +160,7 @@ namespace eosiosystem {
};
static
void
increase_voting_power
(
account_name
voter
,
system_token_type
amount
)
{
account_votes_
index_typ
e
avotes
(
SystemAccount
,
SystemAccount
);
account_votes_
tabl
e
avotes
(
SystemAccount
,
SystemAccount
);
const
auto
*
acv
=
avotes
.
find
(
voter
);
if
(
!
acv
)
{
...
...
@@ -189,11 +189,11 @@ namespace eosiosystem {
}
if
(
producers
)
{
producer
_info_index_typ
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
producer
s_tabl
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
for
(
auto
p
:
*
producers
)
{
auto
p
tr
=
producers_tbl
.
find
(
p
);
eosio_assert
(
bool
(
p
tr
),
"never existed producer"
);
//data corruption
producers_tbl
.
update
(
*
p
tr
,
0
,
[
&
](
auto
&
v
)
{
auto
p
rod
=
producers_tbl
.
find
(
p
);
eosio_assert
(
bool
(
p
rod
),
"never existed producer"
);
//data corruption
producers_tbl
.
update
(
*
p
rod
,
0
,
[
&
](
auto
&
v
)
{
v
.
total_votes
+=
amount
.
quantity
;
});
}
...
...
@@ -201,7 +201,7 @@ namespace eosiosystem {
}
static
void
update_elected_producers
()
{
producer
_info_index_typ
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
producer
s_tabl
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
auto
&
idx
=
producers_tbl
.
template
get
<
>(
N
(
prototalvote
)
);
std
::
array
<
uint32_t
,
21
>
target_block_size
;
...
...
@@ -294,7 +294,7 @@ namespace eosiosystem {
static
void
on
(
const
unstake_vote
&
usv
)
{
require_auth
(
usv
.
voter
);
account_votes_
index_typ
e
avotes
(
SystemAccount
,
SystemAccount
);
account_votes_
tabl
e
avotes
(
SystemAccount
,
SystemAccount
);
const
auto
*
acv
=
avotes
.
find
(
usv
.
voter
);
eosio_assert
(
bool
(
acv
),
"stake not found"
);
...
...
@@ -328,7 +328,7 @@ namespace eosiosystem {
}
if
(
producers
)
{
producer
_info_index_typ
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
producer
s_tabl
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
for
(
auto
p
:
*
producers
)
{
auto
prod
=
producers_tbl
.
find
(
p
);
eosio_assert
(
bool
(
prod
),
"never existed producer"
);
//data corruption
...
...
@@ -359,7 +359,7 @@ namespace eosiosystem {
static
void
on
(
const
unstake_vote_deferred
&
usv
)
{
require_auth
(
usv
.
voter
);
account_votes_
index_typ
e
avotes
(
SystemAccount
,
SystemAccount
);
account_votes_
tabl
e
avotes
(
SystemAccount
,
SystemAccount
);
const
auto
*
acv
=
avotes
.
find
(
usv
.
voter
);
eosio_assert
(
bool
(
acv
),
"stake not found"
);
...
...
@@ -405,27 +405,27 @@ namespace eosiosystem {
eosio_assert
(
std
::
is_sorted
(
vp
.
producers
.
begin
(),
vp
.
producers
.
end
()
),
"producer votes must be sorted"
);
}
account_votes_
index_typ
e
avotes
(
SystemAccount
,
SystemAccount
);
auto
pt
r
=
avotes
.
find
(
vp
.
voter
);
account_votes_
tabl
e
avotes
(
SystemAccount
,
SystemAccount
);
auto
vote
r
=
avotes
.
find
(
vp
.
voter
);
eosio_assert
(
bool
(
pt
r
),
"no stake to vote"
);
if
(
pt
r
->
is_proxy
)
{
eosio_assert
(
bool
(
vote
r
),
"no stake to vote"
);
if
(
vote
r
->
is_proxy
)
{
eosio_assert
(
vp
.
proxy
==
0
,
"accounts elected to be proxy are not allowed to use another proxy"
);
}
//find old producers, update old proxy if needed
const
std
::
vector
<
account_name
>*
old_producers
=
nullptr
;
if
(
pt
r
->
proxy
)
{
if
(
pt
r
->
proxy
==
vp
.
proxy
)
{
if
(
vote
r
->
proxy
)
{
if
(
vote
r
->
proxy
==
vp
.
proxy
)
{
return
;
// nothing changed
}
auto
old_proxy
=
avotes
.
find
(
pt
r
->
proxy
);
avotes
.
update
(
*
old_proxy
,
0
,
[
&
](
auto
&
a
)
{
a
.
proxied_votes
-=
pt
r
->
staked
.
quantity
;
}
);
auto
old_proxy
=
avotes
.
find
(
vote
r
->
proxy
);
avotes
.
update
(
*
old_proxy
,
0
,
[
&
](
auto
&
a
)
{
a
.
proxied_votes
-=
vote
r
->
staked
.
quantity
;
}
);
if
(
old_proxy
->
is_proxy
)
{
//if proxy stoped being proxy, the votes were already taken back from producers by on( const unregister_proxy& )
old_producers
=
&
old_proxy
->
producers
;
}
}
else
{
old_producers
=
&
pt
r
->
producers
;
old_producers
=
&
vote
r
->
producers
;
}
//find new producers, update new proxy if needed
...
...
@@ -433,13 +433,13 @@ namespace eosiosystem {
if
(
vp
.
proxy
)
{
auto
new_proxy
=
avotes
.
find
(
vp
.
proxy
);
eosio_assert
(
new_proxy
->
is_proxy
,
"selected proxy has not elected to be a proxy"
);
avotes
.
update
(
*
new_proxy
,
0
,
[
&
](
auto
&
a
)
{
a
.
proxied_votes
+=
pt
r
->
staked
.
quantity
;
}
);
avotes
.
update
(
*
new_proxy
,
0
,
[
&
](
auto
&
a
)
{
a
.
proxied_votes
+=
vote
r
->
staked
.
quantity
;
}
);
new_producers
=
&
new_proxy
->
producers
;
}
else
{
new_producers
=
&
vp
.
producers
;
}
producer
_info_index_typ
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
producer
s_tabl
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
if
(
old_producers
)
{
//old_producers == 0 if proxy has stoped being a proxy and votes were taken back from producers at that moment
//revoke votes only from no longer elected
...
...
@@ -448,7 +448,7 @@ namespace eosiosystem {
for
(
auto
it
=
revoked
.
begin
();
it
!=
end_it
;
++
it
)
{
auto
prod
=
producers_tbl
.
find
(
*
it
);
eosio_assert
(
bool
(
prod
),
"never existed producer"
);
//data corruption
producers_tbl
.
update
(
*
prod
,
0
,
[
&
](
auto
&
pi
)
{
pi
.
total_votes
-=
pt
r
->
staked
.
quantity
;
});
producers_tbl
.
update
(
*
prod
,
0
,
[
&
](
auto
&
pi
)
{
pi
.
total_votes
-=
vote
r
->
staked
.
quantity
;
});
}
}
...
...
@@ -461,11 +461,11 @@ namespace eosiosystem {
if
(
vp
.
proxy
==
0
)
{
//direct voting, in case of proxy voting update total_votes even for inactive producers
eosio_assert
(
prod
->
active
(),
"can vote only for active producers"
);
}
producers_tbl
.
update
(
*
prod
,
0
,
[
&
](
auto
&
pi
)
{
pi
.
total_votes
+=
pt
r
->
staked
.
quantity
;
});
producers_tbl
.
update
(
*
prod
,
0
,
[
&
](
auto
&
pi
)
{
pi
.
total_votes
+=
vote
r
->
staked
.
quantity
;
});
}
// save new values to the account itself
avotes
.
update
(
*
pt
r
,
0
,
[
&
](
account_votes
&
a
)
{
avotes
.
update
(
*
vote
r
,
0
,
[
&
](
account_votes
&
a
)
{
a
.
proxy
=
vp
.
proxy
;
a
.
last_update
=
now
();
a
.
producers
=
vp
.
producers
;
...
...
@@ -481,12 +481,12 @@ namespace eosiosystem {
static
void
on
(
const
register_proxy
&
reg
)
{
require_auth
(
reg
.
proxy_to_register
);
account_votes_
index_typ
e
avotes
(
SystemAccount
,
SystemAccount
);
auto
pt
r
=
avotes
.
find
(
reg
.
proxy_to_register
);
if
(
pt
r
)
{
eosio_assert
(
pt
r
->
is_proxy
==
0
,
"account is already a proxy"
);
eosio_assert
(
pt
r
->
proxy
==
0
,
"account that uses a proxy is not allowed to become a proxy"
);
avotes
.
update
(
*
pt
r
,
0
,
[
&
](
account_votes
&
a
)
{
account_votes_
tabl
e
avotes
(
SystemAccount
,
SystemAccount
);
auto
vote
r
=
avotes
.
find
(
reg
.
proxy_to_register
);
if
(
vote
r
)
{
eosio_assert
(
vote
r
->
is_proxy
==
0
,
"account is already a proxy"
);
eosio_assert
(
vote
r
->
proxy
==
0
,
"account that uses a proxy is not allowed to become a proxy"
);
avotes
.
update
(
*
vote
r
,
0
,
[
&
](
account_votes
&
a
)
{
a
.
is_proxy
=
1
;
a
.
last_update
=
now
();
//a.proxied_votes may be > 0, if the proxy has been unregistered, so we had to keep the value
...
...
@@ -512,16 +512,16 @@ namespace eosiosystem {
static
void
on
(
const
unregister_proxy
&
reg
)
{
require_auth
(
reg
.
proxy_to_unregister
);
account_votes_
index_typ
e
avotes
(
SystemAccount
,
SystemAccount
);
account_votes_
tabl
e
avotes
(
SystemAccount
,
SystemAccount
);
auto
proxy
=
avotes
.
find
(
reg
.
proxy_to_unregister
);
eosio_assert
(
bool
(
proxy
),
"proxy not found"
);
eosio_assert
(
proxy
->
is_proxy
==
1
,
"account is already a proxy"
);
producer
_info_index_typ
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
producer
s_tabl
e
producers_tbl
(
SystemAccount
,
SystemAccount
);
for
(
auto
p
:
proxy
->
producers
)
{
auto
p
tr
=
producers_tbl
.
find
(
p
);
eosio_assert
(
bool
(
p
tr
),
"never existed producer"
);
//data corruption
producers_tbl
.
update
(
*
p
tr
,
0
,
[
&
](
auto
&
pi
)
{
pi
.
total_votes
-=
proxy
->
proxied_votes
;
});
auto
p
rod
=
producers_tbl
.
find
(
p
);
eosio_assert
(
bool
(
p
rod
),
"never existed producer"
);
//data corruption
producers_tbl
.
update
(
*
p
rod
,
0
,
[
&
](
auto
&
pi
)
{
pi
.
total_votes
-=
proxy
->
proxied_votes
;
});
}
avotes
.
update
(
*
proxy
,
0
,
[
&
](
account_votes
&
a
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录