This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from eosnetworkfoundation/backport-ship
backport 29233b8 ship
- Loading branch information
Showing
23 changed files
with
966 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,3 +87,6 @@ var/lib/node_* | |
.DS_Store | ||
|
||
!*.swagger.* | ||
|
||
node_modules | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
BasedOnStyle: LLVM | ||
IndentWidth: 3 | ||
ColumnLimit: 120 | ||
PointerAlignment: Left | ||
AlwaysBreakTemplateDeclarations: true | ||
AlignConsecutiveAssignments: true | ||
AlignConsecutiveDeclarations: true | ||
BreakConstructorInitializers: BeforeComma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
file(GLOB HEADERS "include/eosio/state-history/*.hpp") | ||
|
||
add_library( state_history | ||
abi.cpp | ||
compression.cpp | ||
create_deltas.cpp | ||
trace_converter.cpp | ||
${HEADERS} | ||
) | ||
|
||
target_link_libraries( state_history | ||
PUBLIC eosio_chain fc chainbase softfloat | ||
) | ||
|
||
target_include_directories( state_history | ||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../wasm-jit/Include" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include <eosio/state_history/compression.hpp> | ||
|
||
#include <boost/iostreams/device/back_inserter.hpp> | ||
#include <boost/iostreams/filter/zlib.hpp> | ||
#include <boost/iostreams/filtering_stream.hpp> | ||
|
||
namespace eosio { | ||
namespace state_history { | ||
|
||
namespace bio = boost::iostreams; | ||
bytes zlib_compress_bytes(const bytes& in) { | ||
bytes out; | ||
bio::filtering_ostream comp; | ||
comp.push(bio::zlib_compressor(bio::zlib::default_compression)); | ||
comp.push(bio::back_inserter(out)); | ||
bio::write(comp, in.data(), in.size()); | ||
bio::close(comp); | ||
return out; | ||
} | ||
|
||
bytes zlib_decompress(const bytes& in) { | ||
bytes out; | ||
bio::filtering_ostream decomp; | ||
decomp.push(bio::zlib_decompressor()); | ||
decomp.push(bio::back_inserter(out)); | ||
bio::write(decomp, in.data(), in.size()); | ||
bio::close(decomp); | ||
return out; | ||
} | ||
|
||
} // namespace state_history | ||
} // namespace eosio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
#include <eosio/state_history/create_deltas.hpp> | ||
#include <eosio/state_history/serialization.hpp> | ||
|
||
namespace eosio { | ||
namespace state_history { | ||
|
||
template <typename T> | ||
bool include_delta(const T& old, const T& curr) { | ||
return true; | ||
} | ||
|
||
bool include_delta(const chain::table_id_object& old, const chain::table_id_object& curr) { | ||
return old.payer != curr.payer; | ||
} | ||
|
||
bool include_delta(const chain::resource_limits::resource_limits_object& old, | ||
const chain::resource_limits::resource_limits_object& curr) { | ||
return // | ||
old.net_weight != curr.net_weight || // | ||
old.cpu_weight != curr.cpu_weight || // | ||
old.ram_bytes != curr.ram_bytes; | ||
} | ||
|
||
bool include_delta(const chain::resource_limits::resource_limits_state_object& old, | ||
const chain::resource_limits::resource_limits_state_object& curr) { | ||
return // | ||
old.average_block_net_usage.last_ordinal != curr.average_block_net_usage.last_ordinal || // | ||
old.average_block_net_usage.value_ex != curr.average_block_net_usage.value_ex || // | ||
old.average_block_net_usage.consumed != curr.average_block_net_usage.consumed || // | ||
old.average_block_cpu_usage.last_ordinal != curr.average_block_cpu_usage.last_ordinal || // | ||
old.average_block_cpu_usage.value_ex != curr.average_block_cpu_usage.value_ex || // | ||
old.average_block_cpu_usage.consumed != curr.average_block_cpu_usage.consumed || // | ||
old.total_net_weight != curr.total_net_weight || // | ||
old.total_cpu_weight != curr.total_cpu_weight || // | ||
old.total_ram_bytes != curr.total_ram_bytes || // | ||
old.virtual_net_limit != curr.virtual_net_limit || // | ||
old.virtual_cpu_limit != curr.virtual_cpu_limit; | ||
} | ||
|
||
bool include_delta(const chain::account_metadata_object& old, const chain::account_metadata_object& curr) { | ||
return // | ||
old.name != curr.name || // | ||
old.is_privileged() != curr.is_privileged() || // | ||
old.last_code_update != curr.last_code_update || // | ||
old.vm_type != curr.vm_type || // | ||
old.vm_version != curr.vm_version || // | ||
old.code_hash != curr.code_hash; | ||
} | ||
|
||
bool include_delta(const chain::code_object& old, const chain::code_object& curr) { // | ||
return false; | ||
} | ||
|
||
bool include_delta(const chain::protocol_state_object& old, const chain::protocol_state_object& curr) { | ||
return old.activated_protocol_features != curr.activated_protocol_features; | ||
} | ||
|
||
std::vector<table_delta> create_deltas(const chainbase::database& db, bool full_snapshot) { | ||
std::vector<table_delta> deltas; | ||
const auto& table_id_index = db.get_index<chain::table_id_multi_index>(); | ||
std::map<uint64_t, const chain::table_id_object*> removed_table_id; | ||
for (auto& rem : table_id_index.stack().back().removed_values) | ||
removed_table_id[rem.first._id] = &rem.second; | ||
|
||
auto get_table_id = [&](uint64_t tid) -> const chain::table_id_object& { | ||
auto obj = table_id_index.find(tid); | ||
if (obj) | ||
return *obj; | ||
auto it = removed_table_id.find(tid); | ||
EOS_ASSERT(it != removed_table_id.end(), chain::plugin_exception, "can not found table id ${tid}", ("tid", tid)); | ||
return *it->second; | ||
}; | ||
|
||
auto pack_row = [&](auto& row) { return fc::raw::pack(make_history_serial_wrapper(db, row)); }; | ||
auto pack_contract_row = [&](auto& row) { | ||
return fc::raw::pack(make_history_context_wrapper(db, get_table_id(row.t_id._id), row)); | ||
}; | ||
|
||
auto process_table = [&](auto* name, auto& index, auto& pack_row) { | ||
if (full_snapshot) { | ||
if (index.indices().empty()) | ||
return; | ||
deltas.push_back({}); | ||
auto& delta = deltas.back(); | ||
delta.name = name; | ||
for (auto& row : index.indices()) | ||
delta.rows.obj.emplace_back(true, pack_row(row)); | ||
} else { | ||
if (index.stack().empty()) | ||
return; | ||
auto& undo = index.stack().back(); | ||
if (undo.old_values.empty() && undo.new_ids.empty() && undo.removed_values.empty()) | ||
return; | ||
deltas.push_back({}); | ||
auto& delta = deltas.back(); | ||
delta.name = name; | ||
for (auto& old : undo.old_values) { | ||
auto& row = index.get(old.first); | ||
if (include_delta(old.second, row)) | ||
delta.rows.obj.emplace_back(true, pack_row(row)); | ||
} | ||
for (auto& old : undo.removed_values) | ||
delta.rows.obj.emplace_back(false, pack_row(old.second)); | ||
for (auto id : undo.new_ids) { | ||
auto& row = index.get(id); | ||
delta.rows.obj.emplace_back(true, pack_row(row)); | ||
} | ||
} | ||
}; | ||
|
||
process_table("account", db.get_index<chain::account_index>(), pack_row); | ||
process_table("account_metadata", db.get_index<chain::account_metadata_index>(), pack_row); | ||
process_table("code", db.get_index<chain::code_index>(), pack_row); | ||
|
||
process_table("contract_table", db.get_index<chain::table_id_multi_index>(), pack_row); | ||
process_table("contract_row", db.get_index<chain::key_value_index>(), pack_contract_row); | ||
process_table("contract_index64", db.get_index<chain::index64_index>(), pack_contract_row); | ||
process_table("contract_index128", db.get_index<chain::index128_index>(), pack_contract_row); | ||
process_table("contract_index256", db.get_index<chain::index256_index>(), pack_contract_row); | ||
process_table("contract_index_double", db.get_index<chain::index_double_index>(), pack_contract_row); | ||
process_table("contract_index_long_double", db.get_index<chain::index_long_double_index>(), pack_contract_row); | ||
|
||
process_table("global_property", db.get_index<chain::global_property_multi_index>(), pack_row); | ||
process_table("generated_transaction", db.get_index<chain::generated_transaction_multi_index>(), pack_row); | ||
process_table("protocol_state", db.get_index<chain::protocol_state_multi_index>(), pack_row); | ||
|
||
process_table("permission", db.get_index<chain::permission_index>(), pack_row); | ||
process_table("permission_link", db.get_index<chain::permission_link_index>(), pack_row); | ||
|
||
process_table("resource_limits", db.get_index<chain::resource_limits::resource_limits_index>(), pack_row); | ||
process_table("resource_usage", db.get_index<chain::resource_limits::resource_usage_index>(), pack_row); | ||
process_table("resource_limits_state", db.get_index<chain::resource_limits::resource_limits_state_index>(), | ||
pack_row); | ||
process_table("resource_limits_config", db.get_index<chain::resource_limits::resource_limits_config_index>(), | ||
pack_row); | ||
|
||
return deltas; | ||
} | ||
|
||
} // namespace state_history | ||
} // namespace eosio |
14 changes: 14 additions & 0 deletions
14
libraries/state_history/include/eosio/state_history/compression.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#pragma once | ||
|
||
#include <eosio/chain/types.hpp> | ||
|
||
namespace eosio { | ||
namespace state_history { | ||
|
||
using chain::bytes; | ||
|
||
bytes zlib_compress_bytes(const bytes& in); | ||
bytes zlib_decompress(const bytes& in); | ||
|
||
} // namespace state_history | ||
} // namespace eosio |
11 changes: 11 additions & 0 deletions
11
libraries/state_history/include/eosio/state_history/create_deltas.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include <eosio/state_history/types.hpp> | ||
|
||
namespace eosio { | ||
namespace state_history { | ||
|
||
std::vector<table_delta> create_deltas(const chainbase::database& db, bool full_snapshot); | ||
|
||
} // namespace state_history | ||
} // namespace eosio |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.