Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #8181 from EOSIO/chainbase-rewrite
Browse files Browse the repository at this point in the history
Chainbase rewrite
  • Loading branch information
swatanabe-b1 authored Nov 6, 2019
2 parents 7c2e07a + 8676444 commit f72e254
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 49 deletions.
3 changes: 1 addition & 2 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,7 @@ struct controller_impl {
if( name == config::system_account_name ) {
// The initial eosio ABI value affects consensus; see https://github.com/EOSIO/eos/issues/7794
// TODO: This doesn't charge RAM; a fix requires a consensus upgrade.
a.abi.resize(sizeof(eosio_abi_bin));
memcpy(a.abi.data(), eosio_abi_bin, sizeof(eosio_abi_bin));
a.abi.assign(eosio_abi_bin, sizeof(eosio_abi_bin));
}
});
db.create<account_metadata_object>([&](auto & a) {
Expand Down
6 changes: 1 addition & 5 deletions libraries/chain/eosio_contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,7 @@ void apply_eosio_setabi(apply_context& context) {
int64_t new_size = abi_size;

db.modify( account, [&]( auto& a ) {
if (abi_size > 0) {
a.abi.assign(act.abi.data(), abi_size);
} else {
a.abi.resize(0);
}
a.abi.assign(act.abi.data(), abi_size);
});

const auto& account_metadata = db.get<account_metadata_object, by_name>(act.account);
Expand Down
7 changes: 4 additions & 3 deletions libraries/chain/include/eosio/chain/account_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ namespace eosio { namespace chain {
shared_blob abi;

void set_abi( const eosio::chain::abi_def& a ) {
abi.resize( fc::raw::pack_size( a ) );
fc::datastream<char*> ds( abi.data(), abi.size() );
fc::raw::pack( ds, a );
abi.resize_and_fill( fc::raw::pack_size( a ), [&a](char* data, std::size_t size) {
fc::datastream<char*> ds( data, size );
fc::raw::pack( ds, a );
});
}

eosio::chain::abi_def get_abi()const {
Expand Down
10 changes: 6 additions & 4 deletions libraries/chain/include/eosio/chain/authority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ struct shared_key_weight {
},
[&](const fc::crypto::webauthn::public_key& wa) {
size_t psz = fc::raw::pack_size(wa);
shared_string wa_ss(psz, boost::container::default_init, std::move(allocator));
fc::datastream<char*> ds(wa_ss.data(), wa_ss.size());
fc::raw::pack(ds, wa);
shared_string wa_ss(std::move(allocator));
wa_ss.resize_and_fill( psz, [&wa]( char* data, std::size_t sz ) {
fc::datastream<char*> ds(data, sz);
fc::raw::pack(ds, wa);
});

return shared_key_weight(std::move(wa_ss), k.weight);
}
Expand Down Expand Up @@ -306,4 +308,4 @@ FC_REFLECT(eosio::chain::wait_weight, (wait_sec)(weight) )
FC_REFLECT(eosio::chain::authority, (threshold)(keys)(accounts)(waits) )
FC_REFLECT(eosio::chain::shared_key_weight, (key)(weight) )
FC_REFLECT(eosio::chain::shared_authority, (threshold)(keys)(accounts)(waits) )
FC_REFLECT(eosio::chain::shared_public_key, (pubkey))
FC_REFLECT(eosio::chain::shared_public_key, (pubkey))
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ namespace eosio { namespace chain {

uint32_t set( const transaction& trx ) {
auto trxsize = fc::raw::pack_size( trx );
packed_trx.resize( trxsize );
fc::datastream<char*> ds( packed_trx.data(), trxsize );
fc::raw::pack( ds, trx );
packed_trx.resize_and_fill( trxsize, [&trx](char* data, std::size_t size) {
fc::datastream<char*> ds( data, size );
fc::raw::pack( ds, trx );
});
return trxsize;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ namespace eosio { namespace chain {
shared_string packedblock;

void set_block( const signed_block_ptr& b ) {
packedblock.resize( fc::raw::pack_size( *b ) );
fc::datastream<char*> ds( packedblock.data(), packedblock.size() );
fc::raw::pack( ds, *b );
packedblock.resize_and_fill( fc::raw::pack_size( *b ), [&b](char* data, std::size_t size) {
fc::datastream<char*> ds( data, size );
fc::raw::pack( ds, *b );
});
}

signed_block_ptr get_block()const {
Expand Down
31 changes: 21 additions & 10 deletions libraries/chain/include/eosio/chain/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace eosio { namespace chain {
struct void_t{};

using chainbase::allocator;
using shared_string = boost::interprocess::basic_string<char, std::char_traits<char>, allocator<char>>;
using shared_string = chainbase::shared_string;
template<typename T>
using shared_vector = boost::interprocess::vector<T, allocator<T>>;
template<typename T>
Expand All @@ -103,17 +103,10 @@ namespace eosio { namespace chain {
shared_blob() = delete;
shared_blob(shared_blob&&) = default;

shared_blob(const shared_blob& s)
:shared_string(s.get_allocator())
{
assign(s.c_str(), s.size());
}
shared_blob(const shared_blob& s) = default;


shared_blob& operator=(const shared_blob& s) {
assign(s.c_str(), s.size());
return *this;
}
shared_blob& operator=(const shared_blob& s) = default;

shared_blob& operator=(shared_blob&& ) = default;

Expand Down Expand Up @@ -393,4 +386,22 @@ namespace eosio { namespace chain {

} } // eosio::chain

namespace chainbase {
// chainbase::shared_cow_string
template<typename DataStream> inline DataStream& operator<<( DataStream& s, const chainbase::shared_cow_string& v ) {
FC_ASSERT( v.size() <= MAX_SIZE_OF_BYTE_ARRAYS );
fc::raw::pack( s, fc::unsigned_int((uint32_t)v.size()));
if( v.size() ) s.write( v.data(), v.size() );
return s;
}

template<typename DataStream> inline DataStream& operator>>( DataStream& s, chainbase::shared_cow_string& v ) {
fc::unsigned_int size; fc::raw::unpack( s, size );
FC_ASSERT( size.value <= MAX_SIZE_OF_BYTE_ARRAYS );
FC_ASSERT( v.size() == 0 );
v.resize_and_fill(size.value, [&s](char* buf, std::size_t sz) { s.read(buf, sz); });
return s;
}
}

FC_REFLECT_EMPTY( eosio::chain::void_t )
2 changes: 1 addition & 1 deletion libraries/chain/whitelisted_intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ namespace eosio { namespace chain {
std::set<std::string> s;

for( const auto& p : whitelisted_intrinsics ) {
s.emplace( p.second.c_str(), p.second.size() );
s.emplace( p.second.data(), p.second.size() );
}

return s;
Expand Down
7 changes: 4 additions & 3 deletions plugins/history_plugin/history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,10 @@ namespace eosio {

db.create<action_history_object>( [&]( auto& aho ) {
auto ps = fc::raw::pack_size( at );
aho.packed_action_trace.resize(ps);
datastream<char*> ds( aho.packed_action_trace.data(), ps );
fc::raw::pack( ds, at );
aho.packed_action_trace.resize_and_fill(ps, [&at](char* data, std::size_t size) {
fc::datastream<char*> ds( data, size );
fc::raw::pack( ds, at );
});
aho.action_sequence_num = at.receipt->global_sequence;
aho.block_num = chain.head_block_num() + 1;
aho.block_time = chain.pending_block_time();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,11 @@ datastream<ST>& operator<<(datastream<ST>& ds, const history_serial_wrapper<eosi
auto& index = obj.db.get_index<eosio::chain::permission_index>();
const auto* parent = index.find(obj.obj.parent);
if (!parent) {
auto& undo = index.stack().back();
auto it = undo.removed_values.find(obj.obj.parent);
auto undo = index.last_undo_session();
auto it = std::find_if(undo.removed_values.begin(), undo.removed_values.end(), [&](auto& x){ return x.id._id == obj.obj.parent; });
EOS_ASSERT(it != undo.removed_values.end(), eosio::chain::plugin_exception,
"can not find parent of permission_object");
parent = &it->second;
parent = &*it;
}
fc::raw::pack(ds, as_type<uint64_t>(parent->name.to_uint64_t()));
} else {
Expand Down
19 changes: 8 additions & 11 deletions plugins/state_history_plugin/state_history_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl

const auto& table_id_index = db.get_index<table_id_multi_index>();
std::map<uint64_t, const table_id_object*> removed_table_id;
for (auto& rem : table_id_index.stack().back().removed_values)
removed_table_id[rem.first._id] = &rem.second;
for (auto& rem : table_id_index.last_undo_session().removed_values)
removed_table_id[rem.id._id] = &rem;

auto get_table_id = [&](uint64_t tid) -> const table_id_object& {
auto obj = table_id_index.find(tid);
Expand All @@ -504,23 +504,20 @@ struct state_history_plugin_impl : std::enable_shared_from_this<state_history_pl
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())
auto undo = index.last_undo_session();
if (undo.old_values.empty() && undo.new_values.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))
auto& row = index.get(old.id);
if (include_delta(old, 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(false, pack_row(old));
for (auto& row : undo.new_values) {
delta.rows.obj.emplace_back(true, pack_row(row));
}
}
Expand Down

0 comments on commit f72e254

Please sign in to comment.