Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
902053d7
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,发现更多精彩内容 >>
提交
902053d7
编写于
4月 23, 2018
作者:
A
arhag
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add forking test to chain_tester
上级
2e77b41f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
74 addition
and
8 deletion
+74
-8
libraries/chain/controller.cpp
libraries/chain/controller.cpp
+10
-4
libraries/chain/fork_database.cpp
libraries/chain/fork_database.cpp
+1
-1
libraries/testing/test.cpp
libraries/testing/test.cpp
+57
-2
libraries/testing/tester.cpp
libraries/testing/tester.cpp
+6
-1
未找到文件。
libraries/chain/controller.cpp
浏览文件 @
902053d7
...
...
@@ -437,7 +437,8 @@ struct controller_impl {
void
start_block
(
block_timestamp_type
when
)
{
FC_ASSERT
(
!
pending
);
FC_ASSERT
(
db
.
revision
()
==
head
->
block_num
);
FC_ASSERT
(
db
.
revision
()
==
head
->
block_num
,
""
,
(
"db_head_block"
,
db
.
revision
())(
"controller_head_block"
,
head
->
block_num
)(
"fork_db_head_block"
,
fork_db
.
head
()
->
block_num
)
);
pending
=
db
.
start_undo_session
(
true
);
pending
->
_pending_block_state
=
std
::
make_shared
<
block_state
>
(
*
head
,
when
);
...
...
@@ -506,6 +507,8 @@ struct controller_impl {
throw
;
}
}
else
if
(
new_head
->
id
!=
head
->
id
)
{
wlog
(
"switching forks from ${current_head_id} (block number ${current_head_num}) to ${new_head_id} (block number ${new_head_num})"
,
(
"current_head_id"
,
head
->
id
)(
"current_head_num"
,
head
->
block_num
)(
"new_head_id"
,
new_head
->
id
)(
"new_head_num"
,
new_head
->
block_num
)
);
auto
branches
=
fork_db
.
fetch_branch_from
(
new_head
->
id
,
head
->
id
);
for
(
auto
itr
=
branches
.
second
.
begin
();
itr
!=
branches
.
second
.
end
();
++
itr
)
{
...
...
@@ -546,6 +549,7 @@ struct controller_impl {
throw
*
except
;
}
// end if exception
}
/// end for each block in branch
wlog
(
"successfully switched fork to new head ${head_id}"
,
(
"new_head_id"
,
new_head
->
id
));
}
}
/// push_block
...
...
@@ -584,13 +588,15 @@ struct controller_impl {
void
finalize_block
()
{
try
{
ilog
(
"finalize block ${p} ${t} schedule_version: ${v} lib: ${lib} ${np} ${signed}"
,
(
"p"
,
pending
->
_pending_block_state
->
header
.
producer
)
ilog
(
"finalize block ${n} (${id}) at ${t} by ${p} (${signing_key}); schedule_version: ${v} lib: ${lib} ${np}"
,
(
"n"
,
pending
->
_pending_block_state
->
block_num
)
(
"id"
,
pending
->
_pending_block_state
->
header
.
id
())
(
"t"
,
pending
->
_pending_block_state
->
header
.
timestamp
)
(
"p"
,
pending
->
_pending_block_state
->
header
.
producer
)
(
"signing_key"
,
pending
->
_pending_block_state
->
block_signing_key
)
(
"v"
,
pending
->
_pending_block_state
->
header
.
schedule_version
)
(
"lib"
,
pending
->
_pending_block_state
->
dpos_last_irreversible_blocknum
)
(
"np"
,
pending
->
_pending_block_state
->
header
.
new_producers
)
(
"signed"
,
pending
->
_pending_block_state
->
block_signing_key
)
);
set_action_merkle
();
...
...
libraries/chain/fork_database.cpp
浏览文件 @
902053d7
...
...
@@ -123,7 +123,7 @@ namespace eosio { namespace chain {
FC_ASSERT
(
existing
==
by_id_idx
.
end
(),
"we already know about this block"
);
auto
prior
=
by_id_idx
.
find
(
b
->
previous
);
FC_ASSERT
(
prior
!=
by_id_idx
.
end
(),
"unlinkable block"
);
FC_ASSERT
(
prior
!=
by_id_idx
.
end
(),
"unlinkable block"
,
(
"id"
,
b
->
id
())(
"previous"
,
b
->
previous
)
);
auto
result
=
std
::
make_shared
<
block_state
>
(
**
prior
,
move
(
b
)
);
return
add
(
result
);
...
...
libraries/testing/test.cpp
浏览文件 @
902053d7
...
...
@@ -44,16 +44,71 @@ int main( int argc, char** argv ) {
tester
c2
;
wlog
(
"push to c2"
);
wlog
(
"push
c1 blocks
to c2"
);
while
(
c2
.
control
->
head_block_num
()
<
c
.
control
->
head_block_num
()
)
{
auto
fb
=
c
.
control
->
fetch_block_by_number
(
c2
.
control
->
head_block_num
()
+
1
);
c2
.
control
->
push_block
(
fb
);
}
wlog
(
"end push c1 blocks to c2"
);
wlog
(
"c1 blocks:"
);
c
.
produce_blocks
(
3
);
signed_block_ptr
b
;
b
=
c
.
produce_block
();
account_name
expected_producer
=
N
(
dan
);
FC_ASSERT
(
b
->
producer
==
expected_producer
,
"expected block ${n} to be produced by ${expected_producer} but was instead produced by ${actual_producer}"
,
(
"n"
,
b
->
block_num
())(
"expected_producer"
,
expected_producer
.
to_string
())(
"actual_producer"
,
b
->
producer
.
to_string
())
);
b
=
c
.
produce_block
();
expected_producer
=
N
(
sam
);
FC_ASSERT
(
b
->
producer
==
expected_producer
,
"expected block ${n} to be produced by ${expected_producer} but was instead produced by ${actual_producer}"
,
(
"n"
,
b
->
block_num
())(
"expected_producer"
,
expected_producer
.
to_string
())(
"actual_producer"
,
b
->
producer
.
to_string
())
);
c
.
produce_blocks
(
11
);
// The next block should be produced by pam.
// Sync second chain with first chain.
wlog
(
"push c1 blocks to c2"
);
while
(
c2
.
control
->
head_block_num
()
<
c
.
control
->
head_block_num
()
)
{
auto
fb
=
c
.
control
->
fetch_block_by_number
(
c2
.
control
->
head_block_num
()
+
1
);
c2
.
control
->
push_block
(
fb
);
}
wlog
(
"end push c1 blocks to c2"
);
// Now sam and pam go on their own fork while dan is producing blocks by himself.
wlog
(
"sam and pam go off on their own fork on c2 while dan produces blocks by himself in c1"
);
auto
fork_block_num
=
c
.
control
->
head_block_num
();
wlog
(
"c2 blocks:"
);
c2
.
produce_blocks
(
12
);
// pam produces 12 blocks
b
=
c2
.
produce_block
(
fc
::
milliseconds
(
config
::
block_interval_ms
*
13
)
);
// sam skips over dan's blocks
expected_producer
=
N
(
sam
);
FC_ASSERT
(
b
->
producer
==
expected_producer
,
"expected block ${n} to be produced by ${expected_producer} but was instead produced by ${actual_producer}"
,
(
"n"
,
b
->
block_num
())(
"expected_producer"
,
expected_producer
.
to_string
())(
"actual_producer"
,
b
->
producer
.
to_string
())
);
c2
.
produce_blocks
(
11
+
12
);
wlog
(
"c1 blocks:"
);
b
=
c
.
produce_block
(
fc
::
milliseconds
(
config
::
block_interval_ms
*
13
)
);
// dan skips over pam's blocks
expected_producer
=
N
(
dan
);
FC_ASSERT
(
b
->
producer
==
expected_producer
,
"expected block ${n} to be produced by ${expected_producer} but was instead produced by ${actual_producer}"
,
(
"n"
,
b
->
block_num
())(
"expected_producer"
,
expected_producer
.
to_string
())(
"actual_producer"
,
b
->
producer
.
to_string
())
);
c
.
produce_blocks
(
11
);
// dan on chain 1 now gets all of the blocks from chain 2 which should cause fork switch
wlog
(
"push c2 blocks to c1"
);
for
(
uint32_t
start
=
fork_block_num
+
1
,
end
=
c2
.
control
->
head_block_num
();
start
<=
end
;
++
start
)
{
auto
fb
=
c2
.
control
->
fetch_block_by_number
(
start
);
c
.
control
->
push_block
(
fb
);
}
wlog
(
"end push c2 blocks to c1"
);
}
FC_CAPTURE_AND_RETHROW
()
}
FC_CAPTURE_AND_RETHROW
()
}
catch
(
const
fc
::
exception
&
e
)
{
edump
((
e
.
to_detail_string
()));
}
...
...
libraries/testing/tester.cpp
浏览文件 @
902053d7
...
...
@@ -103,8 +103,13 @@ namespace eosio { namespace testing {
auto
head_time
=
control
->
head_block_time
();
auto
next_time
=
head_time
+
skip_time
;
if
(
!
control
->
pending_block_state
()
)
if
(
!
control
->
pending_block_state
()
)
{
control
->
start_block
(
next_time
);
}
else
if
(
control
->
pending_block_state
()
->
header
.
timestamp
!=
next_time
)
{
control
->
abort_block
();
control
->
start_block
(
next_time
);
// TODO: Schedule all transactions in unapplied_transactions and deferred ones?
}
control
->
finalize_block
();
control
->
sign_block
(
[
&
](
digest_type
d
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录