Skip to content

Commit

Permalink
GH-1251 Disable oc on producer when applying blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jun 20, 2023
1 parent 025bc22 commit f2123ea
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/apply_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ action_name apply_context::get_sender() const {
bool apply_context::should_use_eos_vm_oc()const {
return trx_context.is_read_only()
|| receiver.prefix() == config::system_account_name // "eosio"_n
|| trx_context.explicit_billed_cpu_time // validating block, todo: disable if producer
|| (trx_context.explicit_billed_cpu_time && !control.is_producer_node()) // validating/applying block
|| false; // todo: could enable for p2p but may cause spam on producer
}

Expand Down
9 changes: 9 additions & 0 deletions libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ struct controller_impl {
controller::config conf;
const chain_id_type chain_id; // read by thread_pool threads, value will not be changed
bool replaying = false;
bool producer_node = false; // true if node is configured as a block producer
db_read_mode read_mode = db_read_mode::HEAD;
bool in_trx_requiring_checks = false; ///< if true, checks that are normally skipped on replay (e.g. auth checks) cannot be skipped
std::optional<fc::microseconds> subjective_cpu_leeway;
Expand Down Expand Up @@ -3677,6 +3678,14 @@ void controller::replace_account_keys( name account, name permission, const publ
rlm.verify_account_ram_usage(account);
}

void controller::set_producer_node(bool is_producer_node) {
my->producer_node = is_producer_node;
}

bool controller::is_producer_node()const {
return my->producer_node;
}

void controller::set_db_read_only_mode() {
mutable_db().set_read_only_mode();
}
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/include/eosio/chain/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ namespace eosio { namespace chain {
void replace_producer_keys( const public_key_type& key );
void replace_account_keys( name account, name permission, const public_key_type& key );

void set_producer_node(bool is_producer_node);
bool is_producer_node()const;

void set_db_read_only_mode();
void unset_db_read_only_mode();
void init_thread_local_data();
Expand Down
10 changes: 10 additions & 0 deletions libraries/chain/include/eosio/chain/wasm_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ namespace eosio { namespace chain {

namespace eosio{ namespace chain {
std::istream& operator>>(std::istream& in, wasm_interface::vm_type& runtime);
inline 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;
}
}}

FC_REFLECT_ENUM( eosio::chain::wasm_interface::vm_type, (eos_vm)(eos_vm_jit)(eos_vm_oc) )
12 changes: 0 additions & 12 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,6 @@ 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 */,
Expand Down
4 changes: 3 additions & 1 deletion plugins/producer_plugin/producer_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,9 @@ void producer_plugin_impl::plugin_initialize(const boost::program_options::varia
_options = &options;
LOAD_VALUE_SET(options, "producer-name", _producers)

chain::controller& chain = chain_plug->chain();
chain::controller& chain = chain_plug->chain();

chain.set_producer_node(!_producers.empty());

if (options.count("signature-provider")) {
const std::vector<std::string> key_spec_pairs = options["signature-provider"].as<std::vector<std::string>>();
Expand Down

0 comments on commit f2123ea

Please sign in to comment.