提交 36bc2a73 编写于 作者: T Todd Fleming

state history: fetch blocks

上级 6de4046d
......@@ -39,6 +39,8 @@ struct get_block_request_v0 {
struct get_block_result_v0 {
uint32_t block_num = 0;
fc::optional<bytes> block;
fc::optional<bytes> block_state;
fc::optional<bytes> traces;
fc::optional<bytes> deltas;
};
......@@ -70,4 +72,4 @@ FC_REFLECT_EMPTY(eosio::get_status_request_v0);
FC_REFLECT(eosio::get_status_result_v0,
(last_irreversible_block_num)(last_irreversible_block_id)(state_begin_block_num)(state_end_block_num));
FC_REFLECT(eosio::get_block_request_v0, (block_num));
FC_REFLECT(eosio::get_block_result_v0, (block_num)(traces)(deltas));
FC_REFLECT(eosio::get_block_result_v0, (block_num)(block)(block_state)(traces)(deltas));
......@@ -180,7 +180,6 @@ datastream<ST>& operator<<(datastream<ST>&
template <typename ST>
datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosio::chain::producer_key>& obj) {
fc::raw::pack(ds, fc::unsigned_int(0));
fc::raw::pack(ds, as_type<uint64_t>(obj.obj.producer_name.value));
fc::raw::pack(ds, as_type<eosio::chain::public_key_type>(obj.obj.block_signing_key));
return ds;
......@@ -189,9 +188,8 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosi
template <typename ST>
datastream<ST>& operator<<(datastream<ST>& ds,
const history_serial_wrapper<eosio::chain::shared_producer_schedule_type>& obj) {
fc::raw::pack(ds, fc::unsigned_int(0));
fc::raw::pack(ds, as_type<uint32_t>(obj.obj.version));
history_serialize_container(ds, obj.obj.producers);
history_serialize_container(ds, as_type<eosio::chain::shared_vector<eosio::chain::producer_key>>(obj.obj.producers));
return ds;
}
......
......@@ -70,6 +70,7 @@ auto catch_and_log(F f) {
struct state_history_plugin_impl : std::enable_shared_from_this<state_history_plugin_impl> {
chain_plugin* chain_plug = nullptr;
history_log block_state_log{"block_state_history"};
history_log trace_log{"trace_history"};
history_log chain_state_log{"chain_state_history"};
bool stopping = false;
......@@ -93,6 +94,11 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
stream.read(result->data(), s);
}
void get_block(uint32_t block_num, fc::optional<bytes>& result) {
auto p = chain_plug->chain().fetch_block_by_number(block_num);
result = fc::raw::pack(*p);
}
struct session : std::enable_shared_from_this<session> {
std::shared_ptr<state_history_plugin_impl> plugin;
std::unique_ptr<ws::stream<tcp::socket>> stream;
......@@ -183,6 +189,8 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
// ilog("${b} get_block_request_v0", ("b", req.block_num));
get_block_result_v0 result{req.block_num};
// todo: client select which datasets to receive
plugin->get_block(req.block_num, result.block);
plugin->get_data(plugin->block_state_log, req.block_num, result.block_state);
plugin->get_data(plugin->trace_log, req.block_num, result.traces);
plugin->get_data(plugin->chain_state_log, req.block_num, result.deltas);
send(std::move(result));
......@@ -276,10 +284,15 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
void on_accepted_block(const block_state_ptr& block_state) {
// todo: config options
store_block_state(block_state);
store_traces(block_state);
store_chain_state(block_state);
}
void store_block_state(const block_state_ptr& block_state) {
// todo
}
void store_traces(const block_state_ptr& block_state) {
std::vector<transaction_trace_ptr> traces;
for (auto& p : block_state->trxs) {
......@@ -406,6 +419,8 @@ void state_history_plugin::plugin_initialize(const variables_map& options) {
}
boost::filesystem::create_directories(state_history_dir);
my->block_state_log.open((state_history_dir / "block_state_history.log").string(),
(state_history_dir / "block_state_history.index").string());
my->trace_log.open((state_history_dir / "trace_history.log").string(),
(state_history_dir / "trace_history.index").string());
my->chain_state_log.open((state_history_dir / "chain_state_history.log").string(),
......
......@@ -20,6 +20,8 @@ extern const char* const state_history_plugin_abi = R"({
{
"name": "get_block_result_v0", "fields": [
{ "name": "block_num", "type": "uint32" },
{ "name": "block", "type": "bytes?" },
{ "name": "block_state", "type": "bytes?" },
{ "name": "traces", "type": "bytes?" },
{ "name": "deltas", "type": "bytes?" }
]
......@@ -94,6 +96,56 @@ extern const char* const state_history_plugin_abi = R"({
{ "name": "action_traces", "type": "action_trace[]" }
]
},
{
"name": "packed_transaction", "fields": [
{ "name": "signatures", "type": "signature[]" },
{ "name": "compression", "type": "uint8" },
{ "name": "packed_context_free_data", "type": "bytes" },
{ "name": "packed_trx", "type": "bytes" }
]
},
{
"name": "transaction_receipt_header", "fields": [
{ "name": "status", "type": "uint8" },
{ "name": "cpu_usage_us", "type": "uint32" },
{ "name": "net_usage_words", "type": "varuint32" }
]
},
{
"name": "transaction_receipt", "base": "transaction_receipt_header", "fields": [
{ "name": "trx", "type": "transaction_variant" }
]
},
{
"name": "extension", "fields": [
{ "name": "type", "type": "uint16" },
{ "name": "data", "type": "bytes" }
]
},
{
"name": "block_header", "fields": [
{ "name": "timestamp", "type": "block_timestamp_type" },
{ "name": "producer", "type": "name" },
{ "name": "confirmed; ", "type": "uint16" },
{ "name": "previous", "type": "checksum256" },
{ "name": "transaction_mroot", "type": "checksum256" },
{ "name": "action_mroot", "type": "checksum256" },
{ "name": "schedule_version", "type": "uint32" },
{ "name": "new_producers", "type": "producer_schedule?" },
{ "name": "header_extensions", "type": "extension[]" }
]
},
{
"name": "signed_block_header", "base": "block_header", "fields": [
{ "name": "producer_signature", "type": "signature" }
]
},
{
"name": "signed_block", "base": "signed_block_header", "fields": [
{ "name": "transactions", "type": "transaction_receipt[]" },
{ "name": "block_extensions", "type": "extension[]" }
]
},
{
"name": "account_v0", "fields": [
{ "type": "uint64", "name": "id" },
......@@ -189,13 +241,13 @@ extern const char* const state_history_plugin_abi = R"({
]
},
{
"name": "producer_key_v0", "fields": [
"name": "producer_key", "fields": [
{ "type": "name", "name": "producer_name" },
{ "type": "public_key", "name": "block_signing_key" }
]
},
{
"name": "shared_producer_schedule_type_v0", "fields": [
"name": "producer_schedule", "fields": [
{ "type": "uint32", "name": "version" },
{ "type": "producer_key[]", "name": "producers" }
]
......@@ -225,7 +277,7 @@ extern const char* const state_history_plugin_abi = R"({
"name": "global_property_v0", "fields": [
{ "type": "uint64", "name": "id" },
{ "type": "uint32?", "name": "proposed_schedule_block_num" },
{ "type": "shared_producer_schedule_type", "name": "proposed_schedule" },
{ "type": "producer_schedule", "name": "proposed_schedule" },
{ "type": "chain_config", "name": "configuration" }
]
},
......@@ -379,6 +431,9 @@ extern const char* const state_history_plugin_abi = R"({
]
}
],
"types": [
{ "new_type_name": "transaction_id", "type": "checksum256" }
],
"variants": [
{ "name": "request", "types": ["get_status_request_v0", "get_block_request_v0"] },
{ "name": "result", "types": ["get_status_result_v0", "get_block_result_v0"] },
......@@ -387,6 +442,7 @@ extern const char* const state_history_plugin_abi = R"({
{ "name": "action_receipt", "types": ["action_receipt_v0"] },
{ "name": "action_trace", "types": ["action_trace_v0"] },
{ "name": "transaction_trace", "types": ["transaction_trace_v0"] },
{ "name": "transaction_variant", "types": ["transaction_id", "packed_transaction"] },
{ "name": "table_delta", "types": ["table_delta_v0"] },
{ "name": "account", "types": ["account_v0"] },
......@@ -398,8 +454,6 @@ extern const char* const state_history_plugin_abi = R"({
{ "name": "index256", "types": ["index256_v0"] },
{ "name": "index_double", "types": ["index_double_v0"] },
{ "name": "index_long_double", "types": ["index_long_double_v0"] },
{ "name": "producer_key", "types": ["producer_key_v0"] },
{ "name": "shared_producer_schedule_type", "types": ["shared_producer_schedule_type_v0"] },
{ "name": "chain_config", "types": ["chain_config_v0"] },
{ "name": "global_property", "types": ["global_property_v0"] },
{ "name": "dynamic_global_property", "types": ["dynamic_global_property_v0"] },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册