Scorum
witness_plugin.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 <scorum/app/plugin.hpp>
28 
29 #include <fc/thread/future.hpp>
30 #include <fc/api.hpp>
31 
32 #define RESERVE_RATIO_PRECISION ((int64_t)10000)
33 #define RESERVE_RATIO_MIN_INCREMENT ((int64_t)5000)
34 
35 namespace scorum {
36 namespace witness {
37 
38 using protocol::public_key_type;
39 using app::application;
41 
42 namespace block_production_condition {
44 {
45  produced = 0,
51  lag = 6,
55 };
56 }
57 
58 namespace detail {
60 }
61 
69 {
70 public:
72  virtual ~witness_plugin();
73 
74  std::string plugin_name() const override;
75 
76  virtual void plugin_set_program_options(boost::program_options::options_description& command_line_options,
77  boost::program_options::options_description& config_file_options) override;
78 
79  void set_block_production(bool allow)
80  {
81  _production_enabled = allow;
82  }
83 
84  virtual void plugin_initialize(const boost::program_options::variables_map& options) override;
85  virtual void plugin_startup() override;
86  virtual void plugin_shutdown() override;
87 
88 private:
89  void schedule_production_loop();
90  void block_production_loop();
92  maybe_produce_block(fc::mutable_variant_object& capture);
93 
94  boost::program_options::variables_map _options;
95  bool _production_enabled = false;
96  uint32_t _required_witness_participation = 33 * SCORUM_1_PERCENT;
97  uint32_t _production_skip_flags = scorum::chain::database::skip_nothing;
98 
99  block_id_type _head_block_id = block_id_type();
100  fc::time_point _hash_start_time;
101 
102  std::map<public_key_type, fc::ecc::private_key> _private_keys;
103  std::set<std::string> _witnesses;
104  fc::future<void> _block_production_task;
105 
107  std::unique_ptr<detail::witness_plugin_impl> _my;
108 };
109 }
110 } // scorum::witness
111 
application & app() const
Definition: plugin.hpp:119
virtual void plugin_initialize(const boost::program_options::variables_map &options) override
Perform early startup routines and register plugin indexes, callbacks, etc.
virtual void plugin_startup() override
Begin normal runtime operations.
virtual 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.
virtual void plugin_shutdown() override
Cleanly shut down the plugin.
std::string plugin_name() const override
#define SCORUM_1_PERCENT
Definition: config.hpp:201
FC_REFLECT_ENUM(scorum::protocol::game_status,(created)(started)(finished)(resolved)(expired)(cancelled)) namespace fc
Definition: game_status.hpp:18
fc::ripemd160 block_id_type
Definition: types.hpp:63
Definition: asset.cpp:15