Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
23748ae0
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,发现更多精彩内容 >>
提交
23748ae0
编写于
9月 04, 2017
作者:
P
Phil Mesnier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement the purger of entries in the local transaction cache. Ref #291 and #318
上级
a198cf3f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
125 addition
and
51 deletion
+125
-51
plugins/net_plugin/net_plugin.cpp
plugins/net_plugin/net_plugin.cpp
+125
-51
未找到文件。
plugins/net_plugin/net_plugin.cpp
浏览文件 @
23748ae0
...
...
@@ -255,24 +255,41 @@ namespace eos {
fc
::
time_point
received
;
fc
::
time_point_sec
expires
;
// vector<char> packed_transaction; //just for the moment
SignedTransaction
transaction
;
uint32_t
block_num
=
-
1
;
/// block transaction was included in
bool
validated
=
false
;
/// whether or not our node has validated it
};
struct
update_block_num
{
UInt16
new_bnum
;
update_block_num
(
UInt16
bnum
)
:
new_bnum
(
bnum
)
{}
void
operator
()
(
node_transaction_state
&
nts
)
{
nts
.
block_num
=
static_cast
<
uint32_t
>
(
new_bnum
);
}
};
struct
by_expiry
;
struct
by_block_num
;
typedef
multi_index_container
<
node_transaction_state
,
indexed_by
<
ordered_unique
<
tag
<
by_id
>
,
member
<
node_transaction_state
,
transaction_id_type
,
&
node_transaction_state
::
id
>
>
,
tag
<
by_id
>
,
member
<
node_transaction_state
,
transaction_id_type
,
&
node_transaction_state
::
id
>
>
,
ordered_non_unique
<
tag
<
by_expiry
>
,
member
<
node_transaction_state
,
fc
::
time_point_sec
,
&
node_transaction_state
::
expires
>
>
,
ordered_non_unique
<
tag
<
by_expiry
>
,
member
<
node_transaction_state
,
fc
::
time_point_sec
,
&
node_transaction_state
::
expires
>
>
tag
<
by_block_num
>
,
member
<
node_transaction_state
,
uint32_t
,
&
node_transaction_state
::
block_num
>
>
>
>
node_transaction_index
;
...
...
@@ -335,7 +352,7 @@ namespace eos {
auto
current_endpoint
=
*
endpoint_itr
;
++
endpoint_itr
;
c
->
socket
->
async_connect
(
current_endpoint
,
[
c
,
endpoint_itr
,
this
]
[
c
,
endpoint_itr
,
this
]
(
const
boost
::
system
::
error_code
&
err
)
{
if
(
!
err
)
{
start_session
(
c
);
...
...
@@ -542,7 +559,12 @@ namespace eos {
for
(
auto
t
:
msg
.
req_trx
)
{
auto
txn
=
local_txns
.
get
<
by_id
>
().
find
(
t
);
if
(
txn
!=
local_txns
.
end
())
{
send_now
.
push_back
(
txn
->
transaction
);
chain_controller
&
cc
=
chain_plug
->
chain
();
try
{
send_now
.
push_back
(
cc
.
get_recent_transaction
(
t
));
}
catch
(...)
{
elog
(
"failed to retieve transaction"
);
}
}
else
{
int
cycle_count
=
2
;
...
...
@@ -550,7 +572,7 @@ namespace eos {
while
(
conn_ndx
!=
loop_start
)
{
if
(
conn_ndx
==
connections
.
end
())
{
if
(
--
cycle_count
==
0
)
{
elog
(
"loop cycled twice, something is wrong"
);
elog
(
"loop cycled twice, something is wrong"
);
break
;
}
conn_ndx
=
connections
.
begin
();
...
...
@@ -563,7 +585,7 @@ namespace eos {
auto
txn
=
conn_ndx
->
get
()
->
trx_state
.
get
<
by_id
>
().
find
(
t
);
if
(
txn
!=
conn_ndx
->
get
()
->
trx_state
.
end
())
{
//forward_to[conn_ndx]->push_back(t);
//forward_to[conn_ndx]->push_back(t);
break
;
}
++
conn_ndx
;
...
...
@@ -620,10 +642,16 @@ namespace eos {
}
void
handle_message
(
connection_ptr
c
,
const
SignedTransaction
&
msg
)
{
auto
txn
=
local_txns
.
get
<
by_id
>
().
find
(
msg
.
id
());
if
(
txn
!=
local_txns
.
end
())
{
if
(
handle_transaction
(
msg
,
true
))
{
return
;
}
if
(
sizeof
(
msg
)
<=
just_send_it_max
)
{
send_all
(
msg
,
[
c
](
connection_ptr
conn
)
->
bool
{
return
(
c
!=
conn
);
});
}
chain_controller
&
cc
=
chain_plug
->
chain
();
if
(
!
cc
.
is_known_transaction
(
msg
.
id
()))
{
chain_plug
->
accept_transaction
(
msg
);
...
...
@@ -647,19 +675,25 @@ namespace eos {
}
}
if
(
num
==
0
)
{
elog
(
"
G
ot out-of-order block ${n}"
,(
"n"
,
msg
.
block_num
()));
close
(
c
);
elog
(
"
syncing, g
ot out-of-order block ${n}"
,(
"n"
,
msg
.
block_num
()));
//
close (c);
return
;
}
}
else
{
send_all
(
msg
,
[
c
](
connection_ptr
conn
)
->
bool
{
return
(
c
!=
conn
);
});
}
try
{
chain_plug
->
accept_block
(
msg
,
syncing
);
}
catch
(
const
unlinkable_block_exception
&
ex
)
{
elog
(
"unable to accpt block #${n}"
,(
"n"
,
num
));
close
(
c
);
elog
(
"unable to acc
e
pt block #${n}"
,(
"n"
,
num
));
//
close (c);
}
catch
(
const
assert_exception
&
ex
)
{
elog
(
"unable to accept block
cuz my asserts!
#${n}"
,(
"n"
,
num
));
close
(
c
);
elog
(
"unable to accept block
on assert exception
#${n}"
,(
"n"
,
num
));
//
close (c);
}
}
...
...
@@ -734,7 +768,16 @@ namespace eos {
void
expire_txns
()
{
start_txn_timer
();
#warning ("TODO: Add by-expiry purging code");
auto
&
old
=
local_txns
.
get
<
by_expiry
>
();
auto
ex_up
=
old
.
upper_bound
(
time_point
::
now
());
auto
ex_lo
=
old
.
lower_bound
(
fc
::
time_point_sec
(
0
));
old
.
erase
(
ex_lo
,
ex_up
);
auto
&
stale
=
local_txns
.
get
<
by_block_num
>
();
chain_controller
&
cc
=
chain_plug
->
chain
();
uint32_t
bn
=
cc
.
last_irreversible_block_num
();
auto
bn_up
=
stale
.
upper_bound
(
bn
);
auto
bn_lo
=
stale
.
lower_bound
(
0
);
stale
.
erase
(
bn_lo
,
bn_up
);
}
void
connection_monitor
()
{
...
...
@@ -762,12 +805,29 @@ namespace eos {
c
->
close
();
}
void
send_all_txn
(
const
SignedTransaction
&
txn
)
{
uint16_t
bn
=
static_cast
<
uint16_t
>
(
txn
.
refBlockNum
);
node_transaction_state
nts
=
{
txn
.
id
(),
time_point
::
now
(),
txn
.
expiration
,
txn
,
bn
,
true
};
local_txns
.
insert
(
nts
);
bool
handle_transaction
(
const
SignedTransaction
&
txn
,
bool
check_expire
)
{
if
(
check_expire
)
{
//expire_txns ();
}
auto
t
=
local_txns
.
get
<
by_id
>
().
find
(
txn
.
id
());
bool
isKnown
=
t
!=
local_txns
.
end
();
if
(
!
isKnown
)
{
uint16_t
bn
=
static_cast
<
uint16_t
>
(
txn
.
refBlockNum
);
node_transaction_state
nts
=
{
txn
.
id
(),
time_point
::
now
(),
txn
.
expiration
,
bn
,
true
};
local_txns
.
insert
(
nts
);
}
return
isKnown
;
}
void
send_all_txn
(
const
SignedTransaction
&
txn
)
{
if
(
handle_transaction
(
txn
,
true
))
{
return
;
}
if
(
sizeof
(
txn
)
<=
just_send_it_max
)
{
send_all
(
txn
,
[
txn
](
connection_ptr
c
)
->
bool
{
const
auto
&
bs
=
c
->
trx_state
.
find
(
txn
.
id
());
...
...
@@ -800,6 +860,45 @@ namespace eos {
my_impl
->
send_all_txn
(
txn
);
}
void
broadcast_block_impl
(
const
chain
::
signed_block
&
sb
)
{
if
(
send_whole_blocks
)
{
send_all
(
sb
,[](
connection_ptr
c
)
->
bool
{
return
true
;
});
}
chain_controller
&
cc
=
chain_plug
->
chain
();
vector
<
transaction_id_type
>
trxs
;
if
(
!
sb
.
cycles
.
empty
())
{
for
(
const
auto
&
cyc
:
sb
.
cycles
)
{
for
(
const
auto
&
thr
:
cyc
)
{
for
(
auto
ui
:
thr
.
user_input
)
{
auto
&
txn
=
cc
.
get_recent_transaction
(
ui
.
id
());
auto
&
id_iter
=
local_txns
.
get
<
by_id
>
();
auto
lt
=
id_iter
.
find
(
ui
.
id
());
if
(
lt
!=
local_txns
.
end
())
{
id_iter
.
modify
(
lt
,
update_block_num
(
txn
.
refBlockNum
));
}
else
{
handle_transaction
(
txn
,
false
);
}
trxs
.
push_back
(
ui
.
id
());
}
}
}
}
if
(
!
send_whole_blocks
)
{
block_summary_message
bsm
=
{
sb
.
id
(),
trxs
};
send_all
(
bsm
,[
sb
](
connection_ptr
c
)
->
bool
{
return
true
;
const
auto
&
bs
=
c
->
block_state
.
find
(
sb
.
id
());
if
(
bs
==
c
->
block_state
.
end
())
{
c
->
block_state
.
insert
((
block_state
){
sb
.
id
(),
true
,
true
,
fc
::
time_point
()});
return
true
;
}
return
false
;
});
}
}
};
// class net_plugin_impl
...
...
@@ -955,31 +1054,6 @@ namespace eos {
}
FC_CAPTURE_AND_RETHROW
()
}
void
net_plugin
::
broadcast_block
(
const
chain
::
signed_block
&
sb
)
{
if
(
my
->
send_whole_blocks
)
{
my
->
send_all
(
sb
,[](
connection_ptr
c
)
->
bool
{
return
true
;
});
return
;
}
vector
<
transaction_id_type
>
trxs
;
if
(
!
sb
.
cycles
.
empty
())
{
for
(
const
auto
&
cyc
:
sb
.
cycles
)
{
for
(
const
auto
&
thr
:
cyc
)
{
for
(
auto
ui
:
thr
.
user_input
)
{
trxs
.
push_back
(
ui
.
id
());
}
}
}
}
block_summary_message
bsm
=
{
sb
.
id
(),
trxs
};
my
->
send_all
(
bsm
,[
sb
](
connection_ptr
c
)
->
bool
{
return
true
;
const
auto
&
bs
=
c
->
block_state
.
find
(
sb
.
id
());
if
(
bs
==
c
->
block_state
.
end
())
{
c
->
block_state
.
insert
((
block_state
){
sb
.
id
(),
true
,
true
,
fc
::
time_point
()});
return
true
;
}
return
false
;
});
my
->
broadcast_block_impl
(
sb
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录