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

Commit

Permalink
Merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Banks committed Aug 25, 2020
2 parents 26fc995 + 9a10d21 commit f1a24af
Show file tree
Hide file tree
Showing 19 changed files with 1,097 additions and 429 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}
endif()
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
endif()

if ("${CMAKE_GENERATOR}" STREQUAL "Ninja")
add_compile_options(-fdiagnostics-color=always)
endif()
Expand Down
2 changes: 1 addition & 1 deletion libraries/abieos
2 changes: 1 addition & 1 deletion libraries/appbase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ endif()

add_library( appbase
application.cpp
version.cpp
${HEADERS}
)

Expand All @@ -64,6 +63,7 @@ else()
set(VERSION_STRING "Unknown")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/version.cpp @ONLY ESCAPE_QUOTES)
endif()
target_sources(appbase PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.cpp)

set(CPACK_PACKAGING_INSTALL_PREFIX /)

Expand Down
22 changes: 12 additions & 10 deletions libraries/appbase/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,18 @@ void application::set_thread_priority_max() {
}

void application::exec() {
boost::asio::io_service::work work(*io_serv);
(void)work;
bool more = true;
while( more || io_serv->run_one() ) {
while( io_serv->poll_one() ) {}
// execute the highest priority item
more = pri_queue.execute_highest();
}
{
boost::asio::io_service::work work( *io_serv );
(void) work;
bool more = true;
while( more || io_serv->run_one() ) {
while( io_serv->poll_one() ) {}
// execute the highest priority item
more = pri_queue.execute_highest();
}

shutdown(); /// perform synchronous shutdown
shutdown(); /// perform synchronous shutdown
}
io_serv.reset();
}

Expand All @@ -446,7 +448,7 @@ void application::print_default_config(std::ostream& os) {
option_to_plug[opt->long_name()] = plug.second->name();
}

for(const boost::shared_ptr<bpo::option_description> od : my->_cfg_options.options())
for(const auto& od : my->_cfg_options.options())
{
if(!od->description().empty()) {
std::string desc = od->description();
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if("eos-vm-oc" IN_LIST EOSIO_WASM_RUNTIMES)
endif()

if("eos-vm" IN_LIST EOSIO_WASM_RUNTIMES OR "eos-vm-jit" IN_LIST EOSIO_WASM_RUNTIMES)
set(CHAIN_EOSVM_SOURCES "webassembly/runtimes/eos-vm.cpp" "webassembly/runtimes/host_function_registrator.cpp")
set(CHAIN_EOSVM_SOURCES "webassembly/runtimes/eos-vm.cpp")
set(CHAIN_EOSVM_LIBRARIES eos-vm)
endif()

Expand Down
45 changes: 44 additions & 1 deletion libraries/chain/abi_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ namespace eosio { namespace chain {
structs.clear();
actions.clear();
tables.clear();
kv_tables.clear();
error_messages.clear();
variants.clear();
action_results.clear();
Expand All @@ -153,6 +154,9 @@ namespace eosio { namespace chain {
for( const auto& t : abi.tables )
tables[t.name] = t.type;

for( const auto& kt : abi.kv_tables.value )
kv_tables[kt.first] = kt.second;

for( const auto& e : abi.error_messages )
error_messages[e.error_code] = e.error_msg;

Expand All @@ -170,6 +174,7 @@ namespace eosio { namespace chain {
EOS_ASSERT( structs.size() == abi.structs.size(), duplicate_abi_struct_def_exception, "duplicate struct definition detected" );
EOS_ASSERT( actions.size() == abi.actions.size(), duplicate_abi_action_def_exception, "duplicate action definition detected" );
EOS_ASSERT( tables.size() == abi.tables.size(), duplicate_abi_table_def_exception, "duplicate table definition detected" );
EOS_ASSERT( kv_tables.size() == abi.kv_tables.value.size(), duplicate_abi_kv_table_def_exception, "duplicate kv table definition detected" );
EOS_ASSERT( error_messages.size() == abi.error_messages.size(), duplicate_abi_err_msg_def_exception, "duplicate error message definition detected" );
EOS_ASSERT( variants.size() == abi.variants.value.size(), duplicate_abi_variant_def_exception, "duplicate variant definition detected" );
EOS_ASSERT( action_results.size() == abi.action_results.value.size(), duplicate_abi_action_results_def_exception, "duplicate action results definition detected" );
Expand Down Expand Up @@ -211,6 +216,10 @@ namespace eosio { namespace chain {
return _is_type(type, ctx);
}

bool abi_serializer::is_kv_table(const std::string_view& type)const {
return kv_tables.find(name(type)) != kv_tables.end();
}

std::string_view abi_serializer::fundamental_type(const std::string_view& type)const {
if( is_array(type) ) {
return type.substr(0, type.size()-2);
Expand All @@ -235,6 +244,9 @@ namespace eosio { namespace chain {
if( typedefs.find(type) != typedefs.end() ) return _is_type(typedefs.find(type)->second, ctx);
if( structs.find(type) != structs.end() ) return true;
if( variants.find(type) != variants.end() ) return true;
if( eosio::chain::is_string_valid_name(type) ) {
if( kv_tables.find(name(type)) != kv_tables.end() ) return true;
}
return false;
}

Expand Down Expand Up @@ -294,6 +306,13 @@ namespace eosio { namespace chain {
EOS_ASSERT(_is_type(t.second, ctx), invalid_type_inside_abi, "${type}", ("type",impl::limit_size(t.second)) );
} FC_CAPTURE_AND_RETHROW( (t) ) }

for( const auto& kt : kv_tables ) {
ctx.check_deadline();
EOS_ASSERT(_is_type(kt.second.type, ctx), invalid_type_inside_abi,
"Invalid reference in struct ${type}", ("type", impl::limit_size(kt.second.type)));
EOS_ASSERT( !kt.second.primary_index.type.empty(), invalid_type_inside_abi, "missing primary index$ {p}", ("p",impl::limit_size(kt.first.to_string())));
}

for( const auto& r : action_results ) { try {
ctx.check_deadline();
EOS_ASSERT(_is_type(r.second, ctx), invalid_type_inside_abi, "${type}", ("type",impl::limit_size(r.second)) );
Expand Down Expand Up @@ -391,7 +410,7 @@ namespace eosio { namespace chain {
} else {
auto v_itr = variants.find(rtype);
if( v_itr != variants.end() ) {
ctx.hint_variant_type_if_in_array( v_itr );
ctx.hint_variant_type_if_in_array(v_itr);
fc::unsigned_int select;
try {
fc::raw::unpack(stream, select);
Expand All @@ -401,6 +420,13 @@ namespace eosio { namespace chain {
auto h1 = ctx.push_to_path( impl::variant_path_item{ .variant_itr = v_itr, .variant_ordinal = static_cast<uint32_t>(select) } );
return vector<fc::variant>{v_itr->second.types[select], _binary_to_variant(v_itr->second.types[select], stream, ctx)};
}

if( !kv_tables.empty() && is_string_valid_name(rtype) ) {
if( auto kv_itr = kv_tables.find(name(rtype)); kv_itr != kv_tables.end() ) {
auto &kv_table = kv_itr->second;
return _binary_to_variant(kv_table.type, stream, ctx);
}
}
}

fc::mutable_variant_object mvo;
Expand Down Expand Up @@ -529,6 +555,15 @@ namespace eosio { namespace chain {
} else {
EOS_THROW( pack_exception, "Unexpected input encountered while processing struct '${p}'", ("p",ctx.get_path_string()) );
}
} else if( var.is_object() ) {
if( !kv_tables.empty() && is_string_valid_name(rtype) ) {
if( auto kv_itr = kv_tables.find(name(rtype));kv_itr != kv_tables.end() ) {
auto& kv_table = kv_itr->second;
_variant_to_binary( kv_table.type, var, ds, ctx );
}
} else {
EOS_THROW(invalid_type_inside_abi, "Unknown type ${type}", ("type", ctx.maybe_shorten(type)));
}
} else {
EOS_THROW( invalid_type_inside_abi, "Unknown type ${type}", ("type",ctx.maybe_shorten(type)) );
}
Expand Down Expand Up @@ -570,6 +605,14 @@ namespace eosio { namespace chain {
if( itr != tables.end() ) return itr->second;
return type_name();
}

type_name abi_serializer::get_kv_table_type(name action)const {
if( auto itr = kv_tables.find(action);itr != kv_tables.end() )
return itr->second.type;

return type_name();
}

type_name abi_serializer::get_action_result_type(name action_result)const {
auto itr = action_results.find(action_result);
if( itr != action_results.end() ) return itr->second;
Expand Down
14 changes: 7 additions & 7 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ struct building_block {
,_trx_mroot_or_receipt_digests( digests_t{} )
{}

pending_block_header_state _pending_block_header_state;
pending_block_header_state _pending_block_header_state;
std::optional<producer_authority_schedule> _new_pending_producer_schedule;
vector<digest_type> _new_protocol_feature_activations;
size_t _num_new_protocol_features_that_have_activated = 0;
deque<transaction_metadata_ptr> _pending_trx_metas;
deque<transaction_receipt> _pending_trx_receipts; // boost deque in 1.71 with 1024 elements performs better
std::variant<checksum256_type, digests_t> _trx_mroot_or_receipt_digests;
digests_t _action_receipt_digests;
vector<digest_type> _new_protocol_feature_activations;
size_t _num_new_protocol_features_that_have_activated = 0;
deque<transaction_metadata_ptr> _pending_trx_metas;
deque<transaction_receipt> _pending_trx_receipts; // boost deque in 1.71 with 1024 elements performs better
std::variant<checksum256_type, digests_t> _trx_mroot_or_receipt_digests;
digests_t _action_receipt_digests;
};

struct assembled_block {
Expand Down
125 changes: 123 additions & 2 deletions libraries/chain/include/eosio/chain/abi_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace eosio { namespace chain {

using type_name = string;
using field_name = string;
using index_name = name;

struct type_def {
type_def() = default;
Expand Down Expand Up @@ -70,6 +71,53 @@ struct table_def {
type_name type; // type of binary data stored in this table
};

struct primary_index_def {
primary_index_def() = default;
primary_index_def(const index_name &name, const type_name &type)
: name(name), type(type)
{}

index_name name; // the name of primary index
type_name type; // the kind of index

bool operator==(const primary_index_def &other) const {
return std::tie(name, type) == std::tie(other.name, other.type);
}

bool operator!=(const primary_index_def &other) const {
return !operator==(other);
}
};

struct secondary_index_def
{
secondary_index_def() = default;
secondary_index_def(const type_name &type)
: type(type)
{}

type_name type; // the kind of index

bool operator==(const secondary_index_def &other) const {
return type == other.type;
}

bool operator!=(const secondary_index_def &other) const {
return !operator==(other);
}
};

struct kv_table_def {
kv_table_def() = default;
kv_table_def(const type_name& type, const primary_index_def& primary_index, const map<index_name, secondary_index_def>& secondary_indices)
:type(type), primary_index(primary_index), secondary_indices(secondary_indices)
{}

type_name type; // the name of the struct_def
primary_index_def primary_index; // primary index field
map<index_name, secondary_index_def> secondary_indices; // secondary indices fields
};

struct clause_pair {
clause_pair() = default;
clause_pair( const string& id, const string& body )
Expand Down Expand Up @@ -110,15 +158,23 @@ struct may_not_exist {
T value{};
};

// Needed for custom from_variant and to_variant of kv_table_def
template<typename T>
struct kv_tables_as_object {
T value{};
};

struct abi_def {
abi_def() = default;
abi_def(const vector<type_def>& types, const vector<struct_def>& structs, const vector<action_def>& actions, const vector<table_def>& tables, const vector<clause_pair>& clauses, const vector<error_message>& error_msgs)
abi_def(const vector<type_def>& types, const vector<struct_def>& structs, const vector<action_def>& actions, const vector<table_def>& tables, const vector<clause_pair>& clauses, const vector<error_message>& error_msgs, const kv_tables_as_object<map<table_name, kv_table_def>>& kv_tables)
:types(types)
,structs(structs)
,actions(actions)
,tables(tables)
,ricardian_clauses(clauses)
,error_messages(error_msgs)
,kv_tables(kv_tables)

{}

string version = "";
Expand All @@ -131,6 +187,7 @@ struct abi_def {
extensions_type abi_extensions;
may_not_exist<vector<variant_def>> variants;
may_not_exist<vector<action_result_def>> action_results;
kv_tables_as_object<map<table_name, kv_table_def>> kv_tables;
};

abi_def eosio_contract_abi(const abi_def& eosio_system_abi);
Expand Down Expand Up @@ -165,16 +222,80 @@ void from_variant(const fc::variant& v, eosio::chain::may_not_exist<T>& e) {
from_variant( v, e.value );
}


template<typename ST, typename T>
ST& operator << (ST& s, const eosio::chain::kv_tables_as_object<T>& v) {
raw::pack(s, v.value);
return s;
}

template<typename ST, typename T>
ST& operator >> (ST& s, eosio::chain::kv_tables_as_object<T>& v) {
if( s.remaining() )
raw::unpack(s, v.value);
return s;
}

template<typename T>
void to_variant(const eosio::chain::kv_tables_as_object<T>& o, fc::variant& v) {
const auto &kv_tables = o.value;
mutable_variant_object mvo;

for( const auto &table : kv_tables ) {
mutable_variant_object vo_table;

variant primary_index;
to_variant(table.second.primary_index, primary_index);

mutable_variant_object secondary_indices;
for( const auto &sec_index : table.second.secondary_indices ) {
variant sidx;
to_variant(sec_index.second, sidx);
secondary_indices(sec_index.first.to_string(), sidx);
}

vo_table("type", variant(table.second.type))("primary_index", primary_index)("secondary_indices", variant(secondary_indices));
mvo(table.first.to_string(), variant(vo_table));
}
v = variant(mvo);
}

template<typename T>
void from_variant(const fc::variant& v, eosio::chain::kv_tables_as_object<T>& o) {
EOS_ASSERT( v.is_object(), eosio::chain::invalid_type_inside_abi, "variant is not an variant_object type");

auto &kv_tables = o.value;
const auto& tables = v.get_object();

for( const auto table_it : tables ) {
const auto &table_obj = table_it.value().get_object();
eosio::chain::kv_table_def kv_tbl_def;
from_variant(table_obj["type"], kv_tbl_def.type);
from_variant(table_obj["primary_index"], kv_tbl_def.primary_index);
if( const auto st_it = table_obj.find("secondary_indices"); st_it != table_obj.end() ) {
const auto &sec_indices_obj = st_it->value().get_object();
for( const auto sidx_it : sec_indices_obj ) {
eosio::chain::secondary_index_def idx_def;
from_variant(sidx_it.value(), idx_def);
kv_tbl_def.secondary_indices[eosio::chain::index_name(sidx_it.key())] = idx_def;
}
}
kv_tables[eosio::chain::name(table_it.key())] = kv_tbl_def;
}
}
} // namespace fc

FC_REFLECT( eosio::chain::type_def , (new_type_name)(type) )
FC_REFLECT( eosio::chain::field_def , (name)(type) )
FC_REFLECT( eosio::chain::struct_def , (name)(base)(fields) )
FC_REFLECT( eosio::chain::action_def , (name)(type)(ricardian_contract) )
FC_REFLECT( eosio::chain::table_def , (name)(index_type)(key_names)(key_types)(type) )
FC_REFLECT( eosio::chain::primary_index_def , (name)(type) )
FC_REFLECT( eosio::chain::secondary_index_def , (type) )
FC_REFLECT( eosio::chain::kv_table_def , (type)(primary_index)(secondary_indices) )
FC_REFLECT( eosio::chain::clause_pair , (id)(body) )
FC_REFLECT( eosio::chain::error_message , (error_code)(error_msg) )
FC_REFLECT( eosio::chain::variant_def , (name)(types) )
FC_REFLECT( eosio::chain::action_result_def , (name)(result_type) )
FC_REFLECT( eosio::chain::abi_def , (version)(types)(structs)(actions)(tables)
(ricardian_clauses)(error_messages)(abi_extensions)(variants)(action_results) )
(ricardian_clauses)(error_messages)(abi_extensions)(variants)(action_results)(kv_tables) )
Loading

0 comments on commit f1a24af

Please sign in to comment.