Last active
September 19, 2019 10:16
-
-
Save michaeljyeates/b6392e36f0a3328939082f210bfc7fc7 to your computer and use it in GitHub Desktop.
Replace producer keys patch for eosio 1.8.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --cc libraries/chain/controller.cpp | |
index 0717f2a4b,17e9c961c..3154b6a67 | |
--- a/libraries/chain/controller.cpp | |
+++ b/libraries/chain/controller.cpp | |
@@@ -2211,31 -3018,68 +3018,95 @@@ const flat_set<account_name> &controlle | |
return my->conf.resource_greylist; | |
} | |
+void controller::replace_producer_keys( const public_key_type& key ) { | |
+ ilog("Replace producer keys with ${k}", ("k", key)); | |
+ mutable_db().modify( db().get<global_property_object>(), [&]( auto& gp ) { | |
+ gp.proposed_schedule_block_num = {}; | |
+ gp.proposed_schedule.clear(); | |
+ }); | |
+ my->head->pending_schedule_lib_num = 0; | |
+ my->head->pending_schedule_hash = {}; | |
+ my->head->pending_schedule = {}; | |
+ for (auto& prod: my->head->active_schedule.producers ) { | |
+ ilog("${n}", ("n", prod.producer_name)); | |
+ prod.block_signing_key = key; | |
+ auto* owner = db().find<permission_object, by_owner>(boost::make_tuple(prod.producer_name, N(owner))); | |
+ if (owner) { | |
+ mutable_db().modify(*owner, [&](auto& p) { | |
+ p.auth = authority(key); | |
+ }); | |
+ } | |
+ auto* active = db().find<permission_object, by_owner>(boost::make_tuple(prod.producer_name, N(active))); | |
+ if (active) { | |
+ mutable_db().modify(*active, [&](auto& p) { | |
+ p.auth = authority(key); | |
+ }); | |
+ } | |
+ } | |
+} | |
+ | |
+ | |
+ void controller::add_to_ram_correction( account_name account, uint64_t ram_bytes ) { | |
+ if( auto ptr = my->db.find<account_ram_correction_object, by_name>( account ) ) { | |
+ my->db.modify<account_ram_correction_object>( *ptr, [&]( auto& rco ) { | |
+ rco.ram_correction += ram_bytes; | |
+ } ); | |
+ } else { | |
+ my->db.create<account_ram_correction_object>( [&]( auto& rco ) { | |
+ rco.name = account; | |
+ rco.ram_correction = ram_bytes; | |
+ } ); | |
+ } | |
+ } | |
+ | |
+ bool controller::all_subjective_mitigations_disabled()const { | |
+ return my->conf.disable_all_subjective_mitigations; | |
+ } | |
+ | |
+ fc::optional<uint64_t> controller::convert_exception_to_error_code( const fc::exception& e ) { | |
+ const chain_exception* e_ptr = dynamic_cast<const chain_exception*>( &e ); | |
+ | |
+ if( e_ptr == nullptr ) return {}; | |
+ | |
+ if( !e_ptr->error_code ) return static_cast<uint64_t>(system_error_code::generic_system_error); | |
+ | |
+ return e_ptr->error_code; | |
+ } | |
+ | |
+ /// Protocol feature activation handlers: | |
+ | |
+ template<> | |
+ void controller_impl::on_activation<builtin_protocol_feature_t::preactivate_feature>() { | |
+ db.modify( db.get<protocol_state_object>(), [&]( auto& ps ) { | |
+ add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "preactivate_feature" ); | |
+ add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "is_feature_activated" ); | |
+ } ); | |
+ } | |
+ | |
+ template<> | |
+ void controller_impl::on_activation<builtin_protocol_feature_t::get_sender>() { | |
+ db.modify( db.get<protocol_state_object>(), [&]( auto& ps ) { | |
+ add_intrinsic_to_whitelist( ps.whitelisted_intrinsics, "get_sender" ); | |
+ } ); | |
+ } | |
+ | |
+ template<> | |
+ void controller_impl::on_activation<builtin_protocol_feature_t::replace_deferred>() { | |
+ const auto& indx = db.get_index<account_ram_correction_index, by_id>(); | |
+ for( auto itr = indx.begin(); itr != indx.end(); itr = indx.begin() ) { | |
+ int64_t current_ram_usage = resource_limits.get_account_ram_usage( itr->name ); | |
+ int64_t ram_delta = -static_cast<int64_t>(itr->ram_correction); | |
+ if( itr->ram_correction > static_cast<uint64_t>(current_ram_usage) ) { | |
+ ram_delta = -current_ram_usage; | |
+ elog( "account ${name} was to be reduced by ${adjust} bytes of RAM despite only using ${current} bytes of RAM", | |
+ ("name", itr->name)("adjust", itr->ram_correction)("current", current_ram_usage) ); | |
+ } | |
+ | |
+ resource_limits.add_pending_ram_usage( itr->name, ram_delta ); | |
+ db.remove( *itr ); | |
+ } | |
+ } | |
+ | |
+ /// End of protocol feature activation handlers | |
+ | |
} } /// eosio::chain | |
diff --cc plugins/chain_plugin/chain_plugin.cpp | |
index 576ff2ffb,596edf733..1c4cf7573 | |
--- a/plugins/chain_plugin/chain_plugin.cpp | |
+++ b/plugins/chain_plugin/chain_plugin.cpp | |
@@@ -638,13 -888,15 +890,19 @@@ void chain_plugin::plugin_initialize(co | |
my->chain_config->block_validation_mode = options.at("validation-mode").as<validation_mode>(); | |
} | |
- my->chain.emplace( *my->chain_config ); | |
+ my->chain_config->db_map_mode = options.at("database-map-mode").as<pinnable_mapped_file::map_mode>(); | |
+ #ifdef __linux__ | |
+ if( options.count("database-hugepage-path") ) | |
+ my->chain_config->db_hugepage_paths = options.at("database-hugepage-path").as<std::vector<std::string>>(); | |
+ #endif | |
+ | |
+ my->chain.emplace( *my->chain_config, std::move(pfs) ); | |
my->chain_id.emplace( my->chain->get_chain_id()); | |
+ if( options.count( "replace-producer-keys" ) ) { | |
+ my->replace_producer_keys.emplace( options.at( "replace-producer-keys" ).as<string>() ); | |
+ } | |
+ | |
// set up method providers | |
my->get_block_by_number_provider = app().get_method<methods::get_block_by_number>().register_provider( | |
[this]( uint32_t block_num ) -> signed_block_ptr { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment