Skip to content

Commit

Permalink
Merge pull request EOSIO#153 from eosiosg/release-v3
Browse files Browse the repository at this point in the history
Release v3
  • Loading branch information
Thaipanda authored Apr 23, 2020
2 parents 625918c + 50d1902 commit 33b34fc
Show file tree
Hide file tree
Showing 44 changed files with 5,208 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
[submodule "libraries/wabt"]
path = libraries/wabt
url = https://github.com/EOSIO/wabt
[submodule "libraries/eos-vm"]
path = libraries/eos-vm
url = https://github.com/eosio/eos-vm
23 changes: 23 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,26 @@ endif()
# * definition EOSIO_<RUNTIME>_RUNTIME_ENABLED defined in public libchain interface
# * ctest entries with --runtime
list(APPEND EOSIO_WASM_RUNTIMES wabt) #always enable wabt; it works everywhere and parts of eosio still assume it's always available
if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
list(APPEND EOSIO_WASM_RUNTIMES wavm)
# WAVM requires LLVM, but move the check up here to a central location so that the EosioTester.cmakes
# can be created with the exact version found
find_package(LLVM REQUIRED CONFIG)
if(LLVM_VERSION_MAJOR VERSION_LESS 7 OR LLVM_VERSION_MAJOR VERSION_GREATER 9)
message(FATAL_ERROR "EOSIO requires an LLVM version 7.0 to 9.0")
endif()

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64")
list(APPEND EOSIO_WASM_RUNTIMES eos-vm-oc)
endif()
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32)
list(APPEND EOSIO_WASM_RUNTIMES eos-vm)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
list(APPEND EOSIO_WASM_RUNTIMES eos-vm-jit)
endif()
endif()

if(UNIX)
if(APPLE)
Expand Down Expand Up @@ -266,13 +286,16 @@ configure_file(${CMAKE_SOURCE_DIR}/libraries/fc/secp256k1/upstream/COPYING
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.secp256k1 COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/libraries/fc/src/network/LICENSE.go
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.go COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/libraries/eos-vm/LICENSE
${CMAKE_BINARY_DIR}/licenses/eosio/LICENSE.eos-vm COPYONLY)

install(FILES LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/)
install(FILES libraries/wabt/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.wabt)
install(FILES libraries/softfloat/COPYING.txt DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.softfloat)
install(FILES libraries/wasm-jit/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.wavm)
install(FILES libraries/fc/secp256k1/upstream/COPYING DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.secp256k1)
install(FILES libraries/fc/src/network/LICENSE.go DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ )
install(FILES libraries/eos-vm/LICENSE DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/licenses/eosio/ RENAME LICENSE.eos-vm COMPONENT base)

include(package)
include(doxygen)
3 changes: 3 additions & 0 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ set(BUILD_TOOLS OFF CACHE BOOL "Build wabt tools")
set(RUN_RE2C OFF CACHE BOOL "Run re2c")
set(WITH_EXCEPTIONS ON CACHE BOOL "Build with exceptions enabled" FORCE)
add_subdirectory( wabt )
if(eos-vm IN_LIST EOSIO_WASM_RUNTIMES OR eos-vm-jit IN_LIST EOSIO_WASM_RUNTIMES)
add_subdirectory( eos-vm )
endif()
4 changes: 4 additions & 0 deletions libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ foreach(RUNTIME ${EOSIO_WASM_RUNTIMES})
target_compile_definitions(eosio_chain PUBLIC "EOSIO_${RUNTIMEUC}_RUNTIME_ENABLED")
endforeach()

if(EOSVMOC_ENABLE_DEVELOPER_OPTIONS)
message(WARNING "EOS VM OC Developer Options are enabled; these are NOT supported")
target_compile_definitions(eosio_chain PUBLIC EOSIO_EOS_VM_OC_DEVELOPER)
endif()

install( TARGETS eosio_chain
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
Expand Down
18 changes: 13 additions & 5 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ struct controller_impl {
map< account_name, map<handler_key, apply_handler> > apply_handlers;
platform_timer timer;

#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
vm::wasm_allocator wasm_alloc;
#endif

/**
* Transactions that were undone by pop_block or abort_block, transactions
* are removed from this list if they are re-applied in other blocks. Producers
Expand Down Expand Up @@ -199,7 +203,7 @@ struct controller_impl {
cfg.reversible_cache_size ),
blog( cfg.blocks_dir ),
fork_db( cfg.state_dir ),
wasmif( cfg.wasm_runtime, db ),
wasmif( cfg.wasm_runtime, cfg.eosvmoc_tierup, db, cfg.state_dir, cfg.eosvmoc_config ),
resource_limits( db ),
authorization( s, db ),
conf( cfg ),
Expand Down Expand Up @@ -244,10 +248,7 @@ struct controller_impl {
template<typename Signal, typename Arg>
void emit( const Signal& s, Arg&& a ) {
try {
s( std::forward<Arg>( a ));
} catch (std::bad_alloc& e) {
wlog( "std::bad_alloc" );
throw e;
s(std::forward<Arg>(a));
} catch (boost::interprocess::bad_alloc& e) {
wlog( "bad alloc" );
throw e;
Expand Down Expand Up @@ -767,6 +768,7 @@ struct controller_impl {
return enc.result();
}


/**
* Sets fork database head to the genesis state.
*/
Expand Down Expand Up @@ -2857,4 +2859,10 @@ void controller::set_upo(uint32_t target_block_num) {
}
}

#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
vm::wasm_allocator& controller::get_wasm_allocator() {
return my->wasm_alloc;
}
#endif

} } /// eosio::chain
7 changes: 7 additions & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <eosio/chain/abi_serializer.hpp>
#include <eosio/chain/account_object.hpp>
#include <eosio/chain/snapshot.hpp>
#include <eosio/chain/webassembly/eos-vm-oc/config.hpp>

namespace chainbase {
class database;
Expand Down Expand Up @@ -98,6 +99,9 @@ namespace eosio { namespace chain {

genesis_state genesis;
wasm_interface::vm_type wasm_runtime = chain::config::default_wasm_runtime;
eosvmoc::config eosvmoc_config;
bool eosvmoc_tierup = false;


db_read_mode read_mode = db_read_mode::SPECULATIVE;
validation_mode block_validation_mode = validation_mode::FULL;
Expand Down Expand Up @@ -296,6 +300,9 @@ namespace eosio { namespace chain {
void reset_pbft_my_prepare();
void reset_pbft_prepared();
void maybe_switch_forks();
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
vm::wasm_allocator& get_wasm_allocator();
#endif

signal<void(const signed_block_ptr&)> pre_accepted_block;
signal<void(const block_state_ptr&)> accepted_block_header;
Expand Down
14 changes: 11 additions & 3 deletions libraries/chain/include/eosio/chain/wasm_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include <eosio/chain/types.hpp>
#include <eosio/chain/whitelisted_intrinsics.hpp>
#include <eosio/chain/exceptions.hpp>
#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
#include <eosio/vm/allocator.hpp>
#endif
#include "Runtime/Linker.h"
#include "Runtime/Runtime.h"

Expand All @@ -10,6 +13,8 @@ namespace eosio { namespace chain {
class apply_context;
class wasm_runtime_interface;
class controller;
namespace eosvmoc { struct config; }

struct wasm_exit {
int32_t code = 0;
};
Expand Down Expand Up @@ -71,10 +76,13 @@ namespace eosio { namespace chain {
public:
enum class vm_type {
wavm,
wabt
wabt,
eos_vm,
eos_vm_jit,
eos_vm_oc
};

wasm_interface(vm_type vm, const chainbase::database& d);
wasm_interface(vm_type vm, bool eosvmoc_tierup, const chainbase::database& d, const boost::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config);
~wasm_interface();

//call before dtor to skip what can be minutes of dtor overhead with some runtimes; can cause leaks
Expand Down Expand Up @@ -106,4 +114,4 @@ namespace eosio{ namespace chain {
std::istream& operator>>(std::istream& in, wasm_interface::vm_type& runtime);
}}

FC_REFLECT_ENUM( eosio::chain::wasm_interface::vm_type, (wavm)(wabt) )
FC_REFLECT_ENUM( eosio::chain::wasm_interface::vm_type, (wavm)(wabt)(eos_vm)(eos_vm_jit)(eos_vm_oc) )
54 changes: 52 additions & 2 deletions libraries/chain/include/eosio/chain/wasm_interface_private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
#include <eosio/chain/wasm_interface.hpp>
#include <eosio/chain/webassembly/wavm.hpp>
#include <eosio/chain/webassembly/wabt.hpp>
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
#include <eosio/chain/webassembly/eos-vm-oc.hpp>
#else
#define _REGISTER_EOSVMOC_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)
#endif
#include <eosio/chain/webassembly/eos-vm.hpp>
#include <eosio/chain/webassembly/runtime_interface.hpp>
#include <eosio/chain/wasm_eosio_injection.hpp>
#include <eosio/chain/transaction_context.hpp>
Expand All @@ -16,6 +22,10 @@
#include "WAST/WAST.h"
#include "IR/Validate.h"

#if defined(EOSIO_EOS_VM_RUNTIME_ENABLED) || defined(EOSIO_EOS_VM_JIT_RUNTIME_ENABLED)
#include <eosio/vm/allocator.hpp>
#endif

using namespace fc;
using namespace eosio::chain::webassembly;
using namespace IR;
Expand All @@ -25,6 +35,8 @@ using boost::multi_index_container;

namespace eosio { namespace chain {

namespace eosvmoc { struct config; }

struct wasm_interface_impl {
struct wasm_cache_entry {
digest_type code_hash;
Expand All @@ -38,15 +50,44 @@ namespace eosio { namespace chain {
struct by_first_block_num;
struct by_last_block_num;

wasm_interface_impl(wasm_interface::vm_type vm, const chainbase::database& d) : db(d), wasm_runtime_time(vm) {
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
struct eosvmoc_tier {
eosvmoc_tier(const boost::filesystem::path& d, const eosvmoc::config& c, const chainbase::database& db) : cc(d, c, db), exec(cc) {}
eosvmoc::code_cache_async cc;
eosvmoc::executor exec;
eosvmoc::memory mem;
};
#endif

wasm_interface_impl(wasm_interface::vm_type vm, bool eosvmoc_tierup, const chainbase::database& d, const boost::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config) : db(d), wasm_runtime_time(vm) {
#ifdef EOSIO_WAVM_RUNTIME_ENABLED
if(vm == wasm_interface::vm_type::wavm)
runtime_interface = std::make_unique<webassembly::wavm::wavm_runtime>();
#endif
if(vm == wasm_interface::vm_type::wabt)
runtime_interface = std::make_unique<webassembly::wabt_runtime::wabt_runtime>();
#ifdef EOSIO_EOS_VM_RUNTIME_ENABLED
if(vm == wasm_interface::vm_type::eos_vm)
runtime_interface = std::make_unique<webassembly::eos_vm_runtime::eos_vm_runtime<eosio::vm::interpreter>>();
#endif
#ifdef EOSIO_EOS_VM_JIT_RUNTIME_ENABLED
if(vm == wasm_interface::vm_type::eos_vm_jit)
runtime_interface = std::make_unique<webassembly::eos_vm_runtime::eos_vm_runtime<eosio::vm::jit>>();
#endif
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
if(vm == wasm_interface::vm_type::eos_vm_oc)
runtime_interface = std::make_unique<webassembly::eosvmoc::eosvmoc_runtime>(data_dir, eosvmoc_config, d);
#endif
if(!runtime_interface)
EOS_THROW(wasm_exception, "${r} wasm runtime not supported on this platform and/or configuration", ("r", vm));

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
if(eosvmoc_tierup) {
EOS_ASSERT(vm != wasm_interface::vm_type::wavm, wasm_exception, "WAVM is incompatible with EOS VM OC");
EOS_ASSERT(vm != wasm_interface::vm_type::eos_vm_oc, wasm_exception, "You can't use EOS VM OC as the base runtime when tier up is activated");
eosvmoc.emplace(data_dir, eosvmoc_config, d);
}
#endif
}

~wasm_interface_impl() {
Expand Down Expand Up @@ -87,6 +128,10 @@ namespace eosio { namespace chain {
//anything last used before or on the LIB can be evicted
const auto first_it = wasm_instantiation_cache.get<by_last_block_num>().begin();
const auto last_it = wasm_instantiation_cache.get<by_last_block_num>().upper_bound(lib);
#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
if(eosvmoc) for(auto it = first_it; it != last_it; it++)
eosvmoc->cc.free_code(it->code_hash, it->vm_version);
#endif
wasm_instantiation_cache.get<by_last_block_num>().erase(first_it, last_it);
}

Expand Down Expand Up @@ -174,6 +219,9 @@ namespace eosio { namespace chain {
const chainbase::database& db;
const wasm_interface::vm_type wasm_runtime_time;

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
fc::optional<eosvmoc_tier> eosvmoc;
#endif
};

#define _ADD_PAREN_1(...) ((__VA_ARGS__)) _ADD_PAREN_2
Expand All @@ -184,7 +232,9 @@ namespace eosio { namespace chain {

#define _REGISTER_INTRINSIC_EXPLICIT(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)\
_REGISTER_WAVM_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG) \
_REGISTER_WABT_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)
_REGISTER_WABT_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG) \
_REGISTER_EOS_VM_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG) \
_REGISTER_EOSVMOC_INTRINSIC(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)

#define _REGISTER_INTRINSIC4(CLS, MOD, METHOD, WASM_SIG, NAME, SIG)\
_REGISTER_INTRINSIC_EXPLICIT(CLS, MOD, METHOD, WASM_SIG, NAME, SIG )
Expand Down
Loading

0 comments on commit 33b34fc

Please sign in to comment.