BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
witness.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cryptonomex, Inc., and contributors.
3  *
4  * The MIT License
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <graphene/app/plugin.hpp>
28 
29 #include <fc/thread/future.hpp>
30 
31 namespace graphene { namespace witness_plugin {
32 
33 namespace block_production_condition
34 {
36  {
37  produced = 0,
43  lag = 6,
45  shutdown = 8,
47  };
48 }
49 
51 public:
52  using graphene::app::plugin::plugin;
53  ~witness_plugin() override { cleanup(); }
54 
55  std::string plugin_name()const override;
56 
58  boost::program_options::options_description &command_line_options,
59  boost::program_options::options_description &config_file_options
60  ) override;
61 
62  void set_block_production(bool allow) { _production_enabled = allow; }
63  void stop_block_production();
64 
65  void plugin_initialize( const boost::program_options::variables_map& options ) override;
66  void plugin_startup() override;
67  void plugin_shutdown() override { cleanup(); }
68 
69  inline const fc::flat_map< chain::witness_id_type, fc::optional<chain::public_key_type> >& get_witness_key_cache()
70  { return _witness_key_cache; }
71 
72 private:
73  void cleanup() { stop_block_production(); }
74 
75  void schedule_production_loop();
78  void add_private_key(const std::string& key_id_to_wif_pair_string);
79 
81  void refresh_witness_key_cache();
82 
83  boost::program_options::variables_map _options;
84  bool _production_enabled = false;
85  bool _shutting_down = false;
86  uint32_t _required_witness_participation = 33 * GRAPHENE_1_PERCENT;
87  uint32_t _production_skip_flags = graphene::chain::database::skip_nothing;
88 
89  std::map<chain::public_key_type, fc::ecc::private_key, chain::pubkey_comparator> _private_keys;
90  std::set<chain::witness_id_type> _witnesses;
91  fc::future<void> _block_production_task;
92 
94  fc::flat_map< chain::witness_id_type, fc::optional<chain::public_key_type> > _witness_key_cache;
95 
96 };
97 
98 } } //graphene::witness_plugin
GRAPHENE_1_PERCENT
#define GRAPHENE_1_PERCENT
Definition: config.hpp:103
graphene::witness_plugin::witness_plugin::plugin_shutdown
void plugin_shutdown() override
Cleanly shut down the plugin.
Definition: witness.hpp:67
graphene::witness_plugin::witness_plugin::set_block_production
void set_block_production(bool allow)
Definition: witness.hpp:62
graphene::witness_plugin::block_production_condition::exception_producing_block
@ exception_producing_block
Definition: witness.hpp:44
database.hpp
graphene::witness_plugin::witness_plugin::~witness_plugin
~witness_plugin() override
Definition: witness.hpp:53
graphene::witness_plugin::block_production_condition::not_synced
@ not_synced
Definition: witness.hpp:38
plugin.hpp
graphene::witness_plugin::block_production_condition::block_production_condition_enum
block_production_condition_enum
Definition: witness.hpp:35
graphene::witness_plugin::block_production_condition::not_time_yet
@ not_time_yet
Definition: witness.hpp:40
graphene::witness_plugin::block_production_condition::not_my_turn
@ not_my_turn
Definition: witness.hpp:39
graphene::witness_plugin::block_production_condition::no_network
@ no_network
Definition: witness.hpp:46
graphene::witness_plugin::block_production_condition::shutdown
@ shutdown
Definition: witness.hpp:45
graphene::witness_plugin::block_production_condition::no_private_key
@ no_private_key
Definition: witness.hpp:41
graphene::witness_plugin::witness_plugin
Definition: witness.hpp:50
graphene::app::plugin
Definition: plugin.hpp:100
graphene::witness_plugin::block_production_condition::low_participation
@ low_participation
Definition: witness.hpp:42
graphene::witness_plugin::block_production_condition::produced
@ produced
Definition: witness.hpp:37
fc::limited_mutable_variant_object
Definition: variant_object.hpp:220
graphene::witness_plugin::witness_plugin::stop_block_production
void stop_block_production()
Definition: witness.cpp:198
future.hpp
graphene::witness_plugin::witness_plugin::plugin_startup
void plugin_startup() override
Begin normal runtime operations.
Definition: witness.cpp:170
graphene::witness_plugin::witness_plugin::plugin_name
std::string plugin_name() const override
Get the name of the plugin.
Definition: witness.cpp:88
graphene::witness_plugin::block_production_condition::lag
@ lag
Definition: witness.hpp:43
graphene::witness_plugin::witness_plugin::plugin_set_program_options
void plugin_set_program_options(boost::program_options::options_description &command_line_options, boost::program_options::options_description &config_file_options) override
Fill in command line parameters used by the plugin.
Definition: witness.cpp:62
graphene::witness_plugin::witness_plugin::plugin_initialize
void plugin_initialize(const boost::program_options::variables_map &options) override
Perform early startup routines and register plugin indexes, callbacks, etc.
Definition: witness.cpp:119
graphene::witness_plugin::witness_plugin::get_witness_key_cache
const fc::flat_map< chain::witness_id_type, fc::optional< chain::public_key_type > > & get_witness_key_cache()
Definition: witness.hpp:69
graphene
Definition: api.cpp:48
fc::future< void >
Definition: future.hpp:283
graphene::chain::database::skip_nothing
@ skip_nothing
Definition: database.hpp:79