Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
b0d596bd
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,发现更多精彩内容 >>
提交
b0d596bd
编写于
4月 19, 2017
作者:
D
Daniel Larimer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
misc cleanup
上级
44a679b8
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
86 addition
and
103 deletion
+86
-103
libraries/chain/database.cpp
libraries/chain/database.cpp
+8
-9
libraries/chain/include/eos/chain/database.hpp
libraries/chain/include/eos/chain/database.hpp
+2
-2
libraries/chain/include/eos/chain/global_property_object.hpp
libraries/chain/include/eos/chain/global_property_object.hpp
+28
-45
libraries/chain/include/eos/chain/message.hpp
libraries/chain/include/eos/chain/message.hpp
+16
-8
libraries/chain/include/eos/chain/producer_object.hpp
libraries/chain/include/eos/chain/producer_object.hpp
+5
-5
libraries/chain/include/eos/chain/protocol/block.hpp
libraries/chain/include/eos/chain/protocol/block.hpp
+6
-5
libraries/chain/include/eos/chain/protocol/types.hpp
libraries/chain/include/eos/chain/protocol/types.hpp
+1
-1
tests/tests/block_tests.cpp
tests/tests/block_tests.cpp
+20
-28
未找到文件。
libraries/chain/database.cpp
浏览文件 @
b0d596bd
...
...
@@ -353,7 +353,8 @@ signed_block database::_generate_block(
pending_block
.
previous
=
head_block_id
();
pending_block
.
timestamp
=
when
;
pending_block
.
transaction_merkle_root
=
pending_block
.
calculate_merkle_root
();
pending_block
.
producer
=
producer_id
;
pending_block
.
producer
=
static_cast
<
uint16_t
>
(
producer_id
.
_id
);
//pa.name.c_str(); //producer_id;
if
(
!
(
skip
&
skip_producer_signature
)
)
pending_block
.
sign
(
block_signing_private_key
);
...
...
@@ -662,11 +663,10 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create initial producers
std
::
vector
<
producer_id_type
>
initial_producers
;
for
(
const
auto
&
producer
:
genesis_state
.
initial_producers
)
{
auto
owner
=
find
<
account_object
,
by_name
>
(
producer
.
owner_name
);
FC_ASSERT
(
owner
!=
nullptr
,
"Producer belongs to an unknown account: ${acct}"
,
(
"acct"
,
producer
.
owner_name
));
auto
id
=
create
<
producer_object
>
([
&
producer
](
producer_object
&
w
)
{
const
auto
&
owner
=
get
<
account_object
,
by_name
>
(
producer
.
owner_name
);
auto
id
=
create
<
producer_object
>
([
&
](
producer_object
&
w
)
{
w
.
signing_key
=
producer
.
block_signing_key
;
w
.
owner
_name
=
producer
.
owner_name
.
c_str
()
;
w
.
owner
=
owner
.
id
;
}).
id
;
initial_producers
.
push_back
(
id
);
}
...
...
@@ -679,13 +679,12 @@ void database::init_genesis(const genesis_state_type& genesis_state)
// Create global properties
create
<
global_property_object
>
([
&
](
global_property_object
&
p
)
{
p
.
parameters
=
genesis_state
.
initial_parameters
;
p
.
active_producers
.
resize
(
initial_producers
.
size
());
//
p.active_producers.resize(initial_producers.size());
std
::
copy
(
initial_producers
.
begin
(),
initial_producers
.
end
(),
p
.
active_producers
.
begin
());
});
create
<
dynamic_global_property_object
>
([
&
](
dynamic_global_property_object
&
p
)
{
p
.
time
=
genesis_state
.
initial_timestamp
;
p
.
dynamic_flags
=
0
;
p
.
recent_slots_filled
=
fc
::
uint128
::
max_value
();
p
.
recent_slots_filled
=
uint64_t
(
-
1
);
});
FC_ASSERT
(
(
genesis_state
.
immutable_parameters
.
min_producer_count
&
1
)
==
1
,
"min_producer_count must be odd"
);
...
...
@@ -973,7 +972,7 @@ uint32_t database::get_slot_at_time(fc::time_point_sec when)const
uint32_t
database
::
producer_participation_rate
()
const
{
const
dynamic_global_property_object
&
dpo
=
get_dynamic_global_properties
();
return
uint64_t
(
EOS_100_PERCENT
)
*
dpo
.
recent_slots_filled
.
popcount
()
/
128
;
return
uint64_t
(
EOS_100_PERCENT
)
*
__builtin_popcountll
(
dpo
.
recent_slots_filled
)
/
64
;
}
void
database
::
update_producer_schedule
()
...
...
libraries/chain/include/eos/chain/database.hpp
浏览文件 @
b0d596bd
...
...
@@ -128,13 +128,13 @@ namespace eos { namespace chain {
signed_block
generate_block
(
const
fc
::
time_point_sec
when
,
producer_id_type
producer
_id
,
producer_id_type
producer
,
const
fc
::
ecc
::
private_key
&
block_signing_private_key
,
uint32_t
skip
);
signed_block
_generate_block
(
const
fc
::
time_point_sec
when
,
producer_id_type
producer
_id
,
producer_id_type
producer
,
const
fc
::
ecc
::
private_key
&
block_signing_private_key
);
...
...
libraries/chain/include/eos/chain/global_property_object.hpp
浏览文件 @
b0d596bd
...
...
@@ -45,15 +45,15 @@ namespace eos { namespace chain {
*/
class
global_property_object
:
public
chainbase
::
object
<
global_property_object_type
,
global_property_object
>
{
OBJECT_CTOR
(
global_property_object
,
(
active_producers
)
)
OBJECT_CTOR
(
global_property_object
)
id_type
id
;
chain_parameters
parameters
;
optional
<
chain_parameters
>
pending_parameters
;
shared_vector
<
producer_id_type
>
active_producers
;
std
::
array
<
producer_id_type
,
21
>
active_producers
;
};
/**
* @class dynamic_global_property_object
* @brief Maintains global state information (committee_member list, current fees)
...
...
@@ -73,16 +73,6 @@ namespace eos { namespace chain {
time_point_sec
time
;
producer_id_type
current_producer
;
uint32_t
accounts_registered_this_interval
=
0
;
/**
* Every time a block is missed this increases by
* RECENTLY_MISSED_COUNT_INCREMENT,
* every time a block is found it decreases by
* RECENTLY_MISSED_COUNT_DECREMENT. It is
* never less than 0.
*
* If the recently_missed_count hits 2*UNDO_HISTORY then no new blocks may be pushed.
*/
uint32_t
recently_missed_count
=
0
;
/**
* The current absolute slot number. Equal to the total
...
...
@@ -92,15 +82,9 @@ namespace eos { namespace chain {
uint64_t
current_aslot
=
0
;
/**
*
u
sed to compute producer participation.
*
U
sed to compute producer participation.
*/
fc
::
uint128_t
recent_slots_filled
;
/**
* dynamic_flags specifies chain state properties that can be
* expressed in one bit.
*/
uint32_t
dynamic_flags
=
0
;
uint64_t
recent_slots_filled
;
uint32_t
last_irreversible_block_num
=
0
;
};
...
...
@@ -113,6 +97,7 @@ namespace eos { namespace chain {
>
>
>
;
using
dynamic_global_property_multi_index
=
chainbase
::
shared_multi_index_container
<
dynamic_global_property_object
,
indexed_by
<
...
...
@@ -136,12 +121,10 @@ FC_REFLECT(eos::chain::dynamic_global_property_object,
(
accounts_registered_this_interval
)
(
current_aslot
)
(
recent_slots_filled
)
(
dynamic_flags
)
(
last_irreversible_block_num
)
)
FC_REFLECT
(
eos
::
chain
::
global_property_object
,
(
parameters
)
(
pending_parameters
)
(
active_producers
)
)
libraries/chain/include/eos/chain/message.hpp
浏览文件 @
b0d596bd
...
...
@@ -7,22 +7,30 @@ namespace eos { namespace chain {
/**
* @brief The message struct defines a blockchain message
*
* Messages are the heart of all activity on the blockchain -- all events and actions which take place in the chain are
* recorded as messages. Messages are sent from one account (@ref sender) to another account (@ref recipient), and are
* Messages are the heart of all activity on the blockchain,
* -- all events and actions which take place in the chain are
* recorded as messages. Messages are sent from one account
* (@ref sender) to another account (@ref recipient), and are
* optionally also delivered to several other accounts (@ref notify_accounts).
*
* A message has a header that defines who sent it and who will be processing it. The message content is a binary blob,
* @ref data, whose type is determined by @ref type, which is dynamic and defined by the scripting language.
* A message has a header that defines who sent it and who will
* be processing it. The message content is a binary blob,
* @ref data, whose type is determined by @ref type, which is
* dynamic and defined by the scripting language.
*/
struct
message
{
/// The account which sent the message
account_name
sender
;
/// The account to receive the message
account_name
recipient
;
/// Other accounts to notify about this message
vector
<
account_name
>
notify_accounts
;
/// The message type -- this is defined by the contract(s) which create and/or process this message
message_type
type
;
/// The message contents
vector
<
char
>
data
;
};
...
...
libraries/chain/include/eos/chain/producer_object.hpp
浏览文件 @
b0d596bd
...
...
@@ -29,22 +29,23 @@
namespace
eos
{
namespace
chain
{
class
producer_object
:
public
chainbase
::
object
<
producer_object_type
,
producer_object
>
{
OBJECT_CTOR
(
producer_object
,
(
owner_name
)(
url
)
)
OBJECT_CTOR
(
producer_object
)
id_type
id
;
shared_string
owner_name
;
account_id_type
owner
;
uint64_t
last_aslot
=
0
;
public_key_type
signing_key
;
shared_string
url
;
int64_t
total_missed
=
0
;
uint32_t
last_confirmed_block_num
=
0
;
};
struct
by_key
;
struct
by_owner
;
using
producer_multi_index
=
chainbase
::
shared_multi_index_container
<
producer_object
,
indexed_by
<
ordered_unique
<
tag
<
by_id
>
,
member
<
producer_object
,
producer_object
::
id_type
,
&
producer_object
::
id
>>
,
ordered_unique
<
tag
<
by_owner
>
,
member
<
producer_object
,
account_id_type
,
&
producer_object
::
owner
>>
,
ordered_non_unique
<
tag
<
by_key
>
,
member
<
producer_object
,
public_key_type
,
&
producer_object
::
signing_key
>>
>
>
;
...
...
@@ -54,10 +55,9 @@ CHAINBASE_SET_INDEX_TYPE(eos::chain::producer_object, eos::chain::producer_multi
FC_REFLECT
(
eos
::
chain
::
producer_object
,
(
id
)
(
owner
_name
)
(
owner
)
(
last_aslot
)
(
signing_key
)
(
url
)
(
total_missed
)
(
last_confirmed_block_num
)
)
libraries/chain/include/eos/chain/protocol/block.hpp
浏览文件 @
b0d596bd
...
...
@@ -29,13 +29,14 @@ namespace eos { namespace chain {
struct
block_header
{
digest_type
digest
()
const
;
block_id_type
previous
;
uint32_t
block_num
()
const
{
return
num_from_id
(
previous
)
+
1
;
}
static
uint32_t
num_from_id
(
const
block_id_type
&
id
);
block_id_type
previous
;
fc
::
time_point_sec
timestamp
;
producer_id_type
producer
;
checksum_type
transaction_merkle_root
;
static
uint32_t
num_from_id
(
const
block_id_type
&
id
);
uint16_t
producer
=
0
;
};
struct
signed_block_header
:
public
block_header
...
...
@@ -66,7 +67,7 @@ namespace eos { namespace chain {
}
}
// eos::chain
FC_REFLECT
(
eos
::
chain
::
block_header
,
(
previous
)(
timestamp
)(
producer
)(
transaction_merkle_root
)
)
FC_REFLECT
(
eos
::
chain
::
block_header
,
(
previous
)(
timestamp
)(
transaction_merkle_root
)(
producer
)
)
FC_REFLECT_DERIVED
(
eos
::
chain
::
signed_block_header
,
(
eos
::
chain
::
block_header
),
(
producer_signature
))
FC_REFLECT
(
eos
::
chain
::
thread
,
(
generated_input
)(
user_input
)(
output_transactions
))
FC_REFLECT_DERIVED
(
eos
::
chain
::
signed_block
,
(
eos
::
chain
::
signed_block_header
),
(
cycles
))
libraries/chain/include/eos/chain/protocol/types.hpp
浏览文件 @
b0d596bd
tests/tests/block_tests.cpp
浏览文件 @
b0d596bd
...
...
@@ -156,12 +156,12 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, testing_fixture )
auto
rsf
=
[
&
]()
->
string
{
fc
::
uint128
rsf
=
db
.
get_dynamic_global_properties
().
recent_slots_filled
;
auto
rsf
=
db
.
get_dynamic_global_properties
().
recent_slots_filled
;
string
result
=
""
;
result
.
reserve
(
128
);
for
(
int
i
=
0
;
i
<
128
;
i
++
)
result
.
reserve
(
64
);
for
(
int
i
=
0
;
i
<
64
;
i
++
)
{
result
+=
((
rsf
.
lo
&
1
)
==
0
)
?
'0'
:
'1'
;
result
+=
((
rsf
&
1
)
==
0
)
?
'0'
:
'1'
;
rsf
>>=
1
;
}
return
result
;
...
...
@@ -169,104 +169,96 @@ BOOST_FIXTURE_TEST_CASE( rsf_missed_blocks, testing_fixture )
auto
pct
=
[](
uint32_t
x
)
->
uint32_t
{
return
uint64_t
(
EOS_100_PERCENT
)
*
x
/
128
;
return
uint64_t
(
EOS_100_PERCENT
)
*
x
/
64
;
};
BOOST_CHECK_EQUAL
(
rsf
(),
"1111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
EOS_100_PERCENT
);
db
.
produce_blocks
(
1
,
1
);
BOOST_CHECK_EQUAL
(
rsf
(),
"0111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
127
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
127
-
64
)
);
db
.
produce_blocks
(
1
,
1
);
BOOST_CHECK_EQUAL
(
rsf
(),
"0101111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
126
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
126
-
64
)
);
db
.
produce_blocks
(
1
,
2
);
BOOST_CHECK_EQUAL
(
rsf
(),
"0010101111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
124
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
124
-
64
)
);
db
.
produce_blocks
(
1
,
3
);
BOOST_CHECK_EQUAL
(
rsf
(),
"0001001010111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
121
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
121
-
64
)
);
db
.
produce_blocks
(
1
,
5
);
BOOST_CHECK_EQUAL
(
rsf
(),
"0000010001001010111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
116
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
116
-
64
)
);
db
.
produce_blocks
(
1
,
8
);
BOOST_CHECK_EQUAL
(
rsf
(),
"0000000010000010001001010111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
108
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
108
-
64
)
);
db
.
produce_blocks
(
1
,
13
);
BOOST_CHECK_EQUAL
(
rsf
(),
"0000000000000100000000100000100010010101111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
-
64
)
);
db
.
produce_blocks
();
BOOST_CHECK_EQUAL
(
rsf
(),
"1000000000000010000000010000010001001010111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
-
64
)
);
db
.
produce_blocks
();
BOOST_CHECK_EQUAL
(
rsf
(),
"1100000000000001000000001000001000100101011111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
-
64
)
);
db
.
produce_blocks
();
BOOST_CHECK_EQUAL
(
rsf
(),
"1110000000000000100000000100000100010010101111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
-
64
)
);
db
.
produce_blocks
();
BOOST_CHECK_EQUAL
(
rsf
(),
"1111000000000000010000000010000010001001010111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111111111"
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
)
);
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
95
-
64
)
);
db
.
produce_blocks
(
1
,
64
);
/*
BOOST_CHECK_EQUAL( rsf(),
"0000000000000000000000000000000000000000000000000000000000000000"
"1111100000000000001000000001000001000100101011111111111111111111"
);
BOOST_CHECK_EQUAL( db.producer_participation_rate(), pct(31) );
*/
db
.
produce_blocks
(
1
,
32
);
/*
BOOST_CHECK_EQUAL( rsf(),
"0000000000000000000000000000000010000000000000000000000000000000"
"0000000000000000000000000000000001111100000000000001000000001000"
);
*/
BOOST_CHECK_EQUAL
(
db
.
producer_participation_rate
(),
pct
(
8
)
);
}
FC_LOG_AND_RETHROW
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录