Skip to content

Commit

Permalink
GH-1251 Use enum for eosvmoc_tierup instead of bool.
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jun 16, 2023
1 parent d86ba3a commit 9229b34
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 11 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,7 @@ struct controller_impl {

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
bool is_eos_vm_oc_enabled() const {
return ( conf.eosvmoc_tierup || conf.wasm_runtime == wasm_interface::vm_type::eos_vm_oc );
return ( (conf.eosvmoc_tierup != wasm_interface::vm_oc_enable::oc_none) || conf.wasm_runtime == wasm_interface::vm_type::eos_vm_oc );
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ namespace eosio { namespace chain {

wasm_interface::vm_type wasm_runtime = chain::config::default_wasm_runtime;
eosvmoc::config eosvmoc_config;
bool eosvmoc_tierup = false;
wasm_interface::vm_oc_enable eosvmoc_tierup = wasm_interface::vm_oc_enable::oc_auto;

db_read_mode read_mode = db_read_mode::HEAD;
validation_mode block_validation_mode = validation_mode::FULL;
Expand Down
8 changes: 7 additions & 1 deletion libraries/chain/include/eosio/chain/wasm_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ namespace eosio { namespace chain {
}
}

wasm_interface(vm_type vm, bool eosvmoc_tierup, const chainbase::database& d, const std::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config, bool profile);
enum class vm_oc_enable {
oc_auto,
oc_all,
oc_none
};

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

// initialize exec per thread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ namespace eosio { namespace chain {
uint8_t vm_version = 0;
};
struct by_hash;
struct by_first_block_num;
struct by_last_block_num;

#ifdef EOSIO_EOS_VM_OC_RUNTIME_ENABLED
Expand All @@ -65,7 +64,7 @@ namespace eosio { namespace chain {
};
#endif

wasm_interface_impl(wasm_interface::vm_type vm, bool eosvmoc_tierup, const chainbase::database& d, const std::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config, bool profile) : db(d), wasm_runtime_time(vm) {
wasm_interface_impl(wasm_interface::vm_type vm, wasm_interface::vm_oc_enable eosvmoc_tierup, const chainbase::database& d, const std::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config, bool profile) : db(d), wasm_runtime_time(vm) {
#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>>();
Expand All @@ -86,7 +85,7 @@ namespace eosio { namespace chain {
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) {
if(eosvmoc_tierup != wasm_interface::vm_oc_enable::oc_none) {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/wasm_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

namespace eosio { namespace chain {

wasm_interface::wasm_interface(vm_type vm, bool eosvmoc_tierup, const chainbase::database& d, const std::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config, bool profile)
wasm_interface::wasm_interface(vm_type vm, vm_oc_enable eosvmoc_tierup, const chainbase::database& d, const std::filesystem::path data_dir, const eosvmoc::config& eosvmoc_config, bool profile)
: my( new wasm_interface_impl(vm, eosvmoc_tierup, d, data_dir, eosvmoc_config, profile) ), vm( vm ) {}

wasm_interface::~wasm_interface() {}
Expand Down
49 changes: 45 additions & 4 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,43 @@ void validate(boost::any& v,
}
}

std::ostream& operator<<(std::ostream& os, wasm_interface::vm_oc_enable t) {
if (t == wasm_interface::vm_oc_enable::oc_auto) {
os << "auto";
} else if (t == wasm_interface::vm_oc_enable::oc_all) {
os << "all";
} else if (t == wasm_interface::vm_oc_enable::oc_none) {
os << "none";
}

return os;
}

void validate(boost::any& v,
const std::vector<std::string>& values,
wasm_interface::vm_oc_enable* /* target_type */,
int)
{
using namespace boost::program_options;

// Make sure no previous assignment to 'v' was made.
validators::check_first_occurrence(v);

// Extract the first string from 'values'. If there is more than
// one string, it's an error, and exception will be thrown.
std::string const& s = validators::get_single_string(values);

if (s == "auto") {
v = boost::any(wasm_interface::vm_oc_enable::oc_auto);
} else if (s == "all" || s == "true" || s == "on") {
v = boost::any(wasm_interface::vm_oc_enable::oc_all);
} else if (s == "none" || s == "false" || s == "off") {
v = boost::any(wasm_interface::vm_oc_enable::oc_none);
} else {
throw validation_error(validation_error::invalid_option_value);
}
}

} // namespace chain

using namespace eosio;
Expand Down Expand Up @@ -203,6 +240,7 @@ chain_plugin::chain_plugin()
app().register_config_type<eosio::chain::validation_mode>();
app().register_config_type<chainbase::pinnable_mapped_file::map_mode>();
app().register_config_type<eosio::chain::wasm_interface::vm_type>();
app().register_config_type<eosio::chain::wasm_interface::vm_oc_enable>();
}

chain_plugin::~chain_plugin() = default;
Expand All @@ -227,7 +265,7 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip

#ifdef EOSIO_EOS_VM_OC_DEVELOPER
wasm_runtime_opt += delim + "\"eos-vm-oc\"";
wasm_runtime_desc += "\"eos-vm-oc\" : Unsupported. Instead, use one of the other runtimes along with the option enable-eos-vm-oc.\n";
wasm_runtime_desc += "\"eos-vm-oc\" : Unsupported. Instead, use one of the other runtimes along with the option eos-vm-oc-enable.\n";
#endif
wasm_runtime_opt += ")\n" + wasm_runtime_desc;

Expand Down Expand Up @@ -334,7 +372,11 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip
EOS_ASSERT(false, plugin_exception, "");
}
}), "Number of threads to use for EOS VM OC tier-up")
("eos-vm-oc-enable", bpo::bool_switch(), "Enable EOS VM OC tier-up runtime")
("eos-vm-oc-enable", bpo::value<chain::wasm_interface::vm_oc_enable>()->default_value(chain::wasm_interface::vm_oc_enable::oc_auto),
"Enable EOS VM OC tier-up runtime ('auto', 'all', 'none').\n"
"'auto' - EOS VM OC tier-up is enabled for eosio.* accounts and read-only trxs.\n"
"'all' - EOS VM OC tier-up is enabled for all contract execution.\n"
"'none' - EOS VM OC tier-up is completely disabled.\n")
#endif
("enable-account-queries", bpo::value<bool>()->default_value(false), "enable queries to find accounts by various metadata.")
("max-nonprivileged-inline-action-size", bpo::value<uint32_t>()->default_value(config::default_max_nonprivileged_inline_action_size), "maximum allowed size (in bytes) of an inline action for a nonprivileged account")
Expand Down Expand Up @@ -907,8 +949,7 @@ void chain_plugin_impl::plugin_initialize(const variables_map& options) {
chain_config->eosvmoc_config.cache_size = options.at( "eos-vm-oc-cache-size-mb" ).as<uint64_t>() * 1024u * 1024u;
if( options.count("eos-vm-oc-compile-threads") )
chain_config->eosvmoc_config.threads = options.at("eos-vm-oc-compile-threads").as<uint64_t>();
if( options["eos-vm-oc-enable"].as<bool>() )
chain_config->eosvmoc_tierup = true;
chain_config->eosvmoc_tierup = options["eos-vm-oc-enable"].as<chain::wasm_interface::vm_oc_enable>();
#endif

account_queries_enabled = options.at("enable-account-queries").as<bool>();
Expand Down

0 comments on commit 9229b34

Please sign in to comment.