Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
a6f7ef6a
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,发现更多精彩内容 >>
提交
a6f7ef6a
编写于
10月 04, 2017
作者:
K
Kevin Heifner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Messages now pushed to mongodb #172
上级
4446b3c1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
52 addition
and
26 deletion
+52
-26
plugins/db_plugin/db_plugin.cpp
plugins/db_plugin/db_plugin.cpp
+52
-26
未找到文件。
plugins/db_plugin/db_plugin.cpp
浏览文件 @
a6f7ef6a
...
...
@@ -83,6 +83,7 @@ public:
static
const
std
::
string
db_name
;
static
const
std
::
string
blocks_col
;
static
const
std
::
string
trans_col
;
static
const
std
::
string
msgs_col
;
};
const
AccountName
db_plugin_impl
::
NEW_ACCOUNT
=
"newaccount"
;
...
...
@@ -95,6 +96,7 @@ const PermissionName db_plugin_impl::RECOVERY = "recovery";
const
std
::
string
db_plugin_impl
::
db_name
=
"EOS"
;
const
std
::
string
db_plugin_impl
::
blocks_col
=
"Blocks"
;
const
std
::
string
db_plugin_impl
::
trans_col
=
"Transactions"
;
const
std
::
string
db_plugin_impl
::
msgs_col
=
"Messages"
;
void
db_plugin_impl
::
applied_irreversible_block
(
const
signed_block
&
block
)
{
...
...
@@ -114,6 +116,7 @@ void db_plugin_impl::consum_blocks() {
signed_block
block
;
while
(
!
done
)
{
while
(
queue
->
pop
(
block
))
{
ilog
(
"queue size: ${q}"
,
(
"q"
,
queue
->
read_available
()
+
1
));
process_irreversible_block
(
block
);
}
}
...
...
@@ -137,34 +140,39 @@ void db_plugin_impl::process_irreversible_block(const signed_block& block)
using
namespace
bsoncxx
::
builder
;
bool
transactions_in_block
=
false
;
mongocxx
::
bulk_write
bulk
;
mongocxx
::
options
::
bulk_write
bulk_opts
;
bulk_opts
.
ordered
(
false
);
mongocxx
::
bulk_write
bulk_trans
{
bulk_opts
};
auto
blocks
=
mongo_conn
[
db_name
][
blocks_col
];
auto
trans
=
mongo_conn
[
db_name
][
trans_col
];
stream
::
document
doc
{};
auto
blocks
=
mongo_conn
[
db_name
][
blocks_col
];
// Blocks
auto
trans
=
mongo_conn
[
db_name
][
trans_col
];
// Transactions
auto
msgs
=
mongo_conn
[
db_name
][
msgs_col
];
// Messages
stream
::
document
block_doc
{};
const
auto
block_id
=
block
.
id
();
const
auto
block_id_str
=
block_id
.
str
();
doc
<<
"block_num"
<<
b_int32
{
static_cast
<
int32_t
>
(
block
.
block_num
())}
block_doc
<<
"block_num"
<<
b_int32
{
static_cast
<
int32_t
>
(
block
.
block_num
())}
<<
"block_id"
<<
block_id_str
<<
"prev_block_id"
<<
block
.
previous
.
str
()
<<
"timestamp"
<<
b_date
{
std
::
chrono
::
milliseconds
{
std
::
chrono
::
seconds
{
block
.
timestamp
.
sec_since_epoch
()}}}
<<
"transaction_merkle_root"
<<
block
.
transaction_merkle_root
.
str
()
<<
"producer_account_id"
<<
block
.
producer
.
toString
();
if
(
!
blocks
.
insert_one
(
doc
.
view
()))
{
if
(
!
blocks
.
insert_one
(
block_
doc
.
view
()))
{
elog
(
"Failed to insert block ${bid}"
,
(
"bid"
,
block_id
));
}
const
bool
check_relevance
=
filter_on
.
size
()
>
0
;
const
bool
check_relevance
=
!
filter_on
.
empty
()
;
for
(
const
auto
&
cycle
:
block
.
cycles
)
{
for
(
const
auto
&
thread
:
cycle
)
{
for
(
const
auto
&
trx
:
thread
.
user_input
)
{
if
(
check_relevance
&&
!
is_scope_relevant
(
trx
.
scope
))
continue
;
doc
.
clear
();
stream
::
document
doc
{};
const
auto
trans_id_str
=
trx
.
id
().
str
();
auto
trx_doc
=
doc
<<
"transaction_id"
<<
tr
x
.
id
().
str
()
<<
"transaction_id"
<<
tr
ans_id_str
<<
"block_id"
<<
block_id_str
<<
"ref_block_num"
<<
b_int32
{
static_cast
<
int32_t
>
(
trx
.
refBlockNum
)}
<<
"ref_block_prefix"
<<
trx
.
refBlockPrefix
.
str
()
...
...
@@ -183,27 +191,45 @@ void db_plugin_impl::process_irreversible_block(const signed_block& block)
for
(
const
auto
&
sig
:
trx
.
signatures
)
{
trx_doc
=
trx_doc
<<
fc
::
json
::
to_string
(
sig
);
}
auto
complete
_doc
=
trx_doc
trx
_doc
=
trx_doc
<<
stream
::
close_array
<<
"messages"
<<
stream
::
open_array
<<
stream
::
close_array
<<
stream
::
finalize
;
<<
"messages"
<<
stream
::
open_array
;
mongocxx
::
bulk_write
bulk_msgs
{
bulk_opts
};
int32_t
i
=
0
;
for
(
const
chain
::
Message
&
msg
:
trx
.
messages
)
{
auto
msg_oid
=
bsoncxx
::
oid
{};
trx_doc
=
trx_doc
<<
msg_oid
;
// add to transaction.messages array
stream
::
document
msg_builder
{};
auto
msg_doc
=
msg_builder
<<
"_id"
<<
b_oid
{
msg_oid
}
<<
"message_id"
<<
b_int32
{
i
}
<<
"transaction_id"
<<
trans_id_str
<<
"authorization"
<<
stream
::
open_array
;
for
(
const
auto
&
auth
:
msg
.
authorization
)
{
msg_doc
=
msg_doc
<<
stream
::
open_document
<<
"account"
<<
auth
.
account
.
toString
()
<<
"permission"
<<
auth
.
permission
.
toString
()
<<
stream
::
close_document
;
}
auto
msg_complete
=
msg_doc
<<
stream
::
close_array
<<
stream
::
finalize
;
mongocxx
::
model
::
insert_one
insert_msg
{
msg_complete
.
view
()};
bulk_msgs
.
append
(
insert_msg
);
++
i
;
}
if
(
!
trx
.
messages
.
empty
())
{
auto
result
=
msgs
.
bulk_write
(
bulk_msgs
);
if
(
!
result
)
{
elog
(
"Bulk message insert failed for block: ${bid}, transaction: ${trx}"
,
(
"bid"
,
block_id
)(
"trx"
,
trx
.
id
()));
}
}
auto
complete_doc
=
trx_doc
<<
stream
::
close_array
<<
stream
::
finalize
;
mongocxx
::
model
::
insert_one
insert_op
{
complete_doc
.
view
()};
transactions_in_block
=
true
;
bulk
.
append
(
insert_op
);
// db.create<transaction_history_object>([&block_id,&trx](transaction_history_object& transaction_history) {
// transaction_history.block_id = block_id;
// transaction_history.transaction_id = trx.id();
// });
bulk_trans
.
append
(
insert_op
);
for
(
const
auto
&
account_name
:
trx
.
scope
)
{
// db.create<account_transaction_history_object>([&trx,&account_name](account_transaction_history_object& account_transaction_history) {
// account_transaction_history.account_name = account_name;
// account_transaction_history.transaction_id = trx.id();
// });
}
for
(
const
chain
::
Message
&
msg
:
trx
.
messages
)
{
...
...
@@ -244,7 +270,7 @@ void db_plugin_impl::process_irreversible_block(const signed_block& block)
if
(
transactions_in_block
)
{
auto
result
=
trans
.
bulk_write
(
bulk
);
auto
result
=
trans
.
bulk_write
(
bulk
_trans
);
if
(
!
result
)
{
elog
(
"Bulk transaction insert failed for block: ${bid}"
,
(
"bid"
,
block_id
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录