Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
controller.hpp
Go to the documentation of this file.
1#pragma once
7#include <boost/signals2/signal.hpp>
8
15
16namespace chainbase {
17 class database;
18}
19namespace boost { namespace asio {
20 class thread_pool;
21}}
22
23namespace sysio { namespace vm { class wasm_allocator; }}
24
25namespace sysio { namespace chain {
26
28
29 namespace resource_limits {
31 };
32
33 struct controller_impl;
36 using boost::signals2::signal;
37
41 class account_object;
44 using apply_handler = std::function<void(apply_context&)>;
45 using forked_branch_callback = std::function<void(const branch_type&)>;
46 // lookup transaction_metadata via supplied function to avoid re-creation
48
49 class fork_database;
50
51 enum class db_read_mode {
53 HEAD,
56 };
57
58 enum class validation_mode {
59 FULL,
60 LIGHT
61 };
62
63 class controller {
64 public:
65 struct config {
66 flat_set<account_name> sender_bypass_whiteblacklist;
67 flat_set<account_name> actor_whitelist;
68 flat_set<account_name> actor_blacklist;
69 flat_set<account_name> contract_whitelist;
70 flat_set<account_name> contract_blacklist;
71 flat_set< pair<account_name, action_name> > action_blacklist;
72 flat_set<public_key_type> key_blacklist;
73 path blocks_dir = chain::config::default_blocks_dir_name;
74 std::optional<block_log_prune_config> prune_config;
75 path state_dir = chain::config::default_state_dir_name;
76 uint64_t state_size = chain::config::default_state_size;
77 uint64_t state_guard_size = chain::config::default_state_guard_size;
78 uint32_t sig_cpu_bill_pct = chain::config::default_sig_cpu_bill_pct;
79 uint16_t thread_pool_size = chain::config::default_controller_thread_pool_size;
80 uint32_t max_nonprivileged_inline_action_size = chain::config::default_max_nonprivileged_inline_action_size;
81 bool read_only = false;
82 bool force_all_checks = false;
83 bool disable_replay_opts = false;
84 bool contracts_console = false;
86 uint32_t maximum_variable_signature_length = chain::config::default_max_variable_signature_length;
87 bool disable_all_subjective_mitigations = false; //< for developer & testing purposes, can be configured using `disable-all-subjective-mitigations` when `SYSIO_DEVELOPER` build option is provided
88 uint32_t terminate_at_block = 0; //< primarily for testing purposes
89
90 wasm_interface::vm_type wasm_runtime = chain::config::default_wasm_runtime;
92 bool eosvmoc_tierup = false;
93
96
98
99 flat_set<account_name> resource_greylist;
100 flat_set<account_name> trusted_producers;
101 uint32_t greylist_limit = chain::config::maximum_elastic_resource_multiplier;
102
103 flat_set<account_name> profile_accounts;
104 };
105
106 enum class block_status {
107 irreversible = 0,
108 validated = 1,
109 complete = 2,
110 incomplete = 3,
111 };
112
113 controller( const config& cfg, const chain_id_type& chain_id );
114 controller( const config& cfg, protocol_feature_set&& pfs, const chain_id_type& chain_id );
115 ~controller();
116
117 void add_indices();
118 void startup( std::function<void()> shutdown, std::function<bool()> check_shutdown, const snapshot_reader_ptr& snapshot);
119 void startup( std::function<void()> shutdown, std::function<bool()> check_shutdown, const genesis_state& genesis);
120 void startup( std::function<void()> shutdown, std::function<bool()> check_shutdown);
121
122 void preactivate_feature( const digest_type& feature_digest );
123
125
126 void validate_protocol_features( const vector<digest_type>& features_to_activate )const;
127
134 void start_block( block_timestamp_type time = block_timestamp_type(), uint16_t confirm_block_count = 0 );
135
141 uint16_t confirm_block_count,
142 const vector<digest_type>& new_protocol_feature_activations,
143 const fc::time_point& deadline = fc::time_point::maximum() );
144
149
154 fc::time_point deadline, fc::microseconds max_transaction_time,
155 uint32_t billed_cpu_time_us, bool explicit_billed_cpu_time,
156 int64_t subjective_cpu_bill_us );
157
163 fc::time_point block_deadline, fc::microseconds max_transaction_time,
164 uint32_t billed_cpu_time_us, bool explicit_billed_cpu_time );
165
166 block_state_ptr finalize_block( const signer_callback_type& signer_callback );
167 void sign_block( const signer_callback_type& signer_callback );
168 void commit_block();
169
170 // thread-safe
171 std::future<block_state_ptr> create_block_state_future( const block_id_type& id, const signed_block_ptr& b );
172 // thread-safe
174
180 void push_block( const block_state_ptr& bsp,
181 const forked_branch_callback& cb,
182 const trx_meta_cache_lookup& trx_lookup );
183
184 boost::asio::io_context& get_thread_pool();
185
186 const chainbase::database& db()const;
187
188 const fork_database& fork_db()const;
189
190 const account_object& get_account( account_name n )const;
199
200 const flat_set<account_name>& get_actor_whitelist() const;
201 const flat_set<account_name>& get_actor_blacklist() const;
202 const flat_set<account_name>& get_contract_whitelist() const;
203 const flat_set<account_name>& get_contract_blacklist() const;
204 const flat_set< pair<account_name, action_name> >& get_action_blacklist() const;
205 const flat_set<public_key_type>& get_key_blacklist() const;
206
207 void set_actor_whitelist( const flat_set<account_name>& );
208 void set_actor_blacklist( const flat_set<account_name>& );
209 void set_contract_whitelist( const flat_set<account_name>& );
210 void set_contract_blacklist( const flat_set<account_name>& );
211 void set_action_blacklist( const flat_set< pair<account_name, action_name> >& );
212 void set_key_blacklist( const flat_set<public_key_type>& );
213 void set_s_header( const s_header& );
214
219 const block_header& head_block_header()const;
221
226
231
235 std::optional<block_id_type> pending_producer_block_id()const;
237
239
242 std::optional<producer_authority_schedule> proposed_producers()const;
243
247
250
252 // return block_state from forkdb, thread-safe
254
256
258 void write_snapshot( const snapshot_writer_ptr& snapshot );
259
261 void check_actor_list( const flat_set<account_name>& actors )const;
262 void check_contract_list( account_name code )const;
264 void check_key_list( const public_key_type& key )const;
265 bool is_building_block()const;
266 bool is_producing_block()const;
267
269
270 //This is only an accessor to the user configured subjective limit: i.e. it does not do a
271 // check similar to is_ram_billing_in_notify_allowed() to check if controller is currently
272 // producing a block
274
277 bool is_resource_greylisted(const account_name &name) const;
278 const flat_set<account_name> &get_resource_greylist() const;
279
280 void validate_expiration( const transaction& t )const;
281 void validate_tapos( const transaction& t )const;
282 void validate_db_available_size() const;
283
284 bool is_protocol_feature_activated( const digest_type& feature_digest )const;
286
288
290
291 bool light_validation_allowed() const;
292 bool skip_auth_check()const;
293 bool skip_trx_checks()const;
294 bool skip_db_sessions()const;
295 bool skip_db_sessions( block_status bs )const;
296 bool is_trusted_producer( const account_name& producer) const;
297
298 bool contracts_console()const;
299
300 bool is_profiling(account_name name) const;
301
303
307
309 std::optional<fc::microseconds> get_subjective_cpu_leeway() const;
310 void set_greylist_limit( uint32_t limit );
312
313 void add_to_ram_correction( account_name account, uint64_t ram_bytes );
315
319
320#if defined(SYSIO_SYS_VM_RUNTIME_ENABLED) || defined(SYSIO_SYS_VM_JIT_RUNTIME_ENABLED)
322#endif
323
324 static std::optional<uint64_t> convert_exception_to_error_code( const fc::exception& e );
325
326 signal<void(uint32_t)> block_start; // block_num
329 signal<void(const block_state_ptr&)> accepted_block;
332 signal<void(std::tuple<const transaction_trace_ptr&, const packed_transaction_ptr&>)> applied_transaction;
333 signal<void(const int&)> bad_alloc;
334
335 /*
336 signal<void()> pre_apply_block;
337 signal<void()> post_apply_block;
338 signal<void()> abort_apply_block;
339 signal<void(const transaction_metadata_ptr&)> pre_apply_transaction;
340 signal<void(const transaction_trace_ptr&)> post_apply_transaction;
341 signal<void(const transaction_trace_ptr&)> pre_apply_action;
342 signal<void(const transaction_trace_ptr&)> post_apply_action;
343 */
344
345 const apply_handler* find_apply_handler( account_name contract, scope_name scope, action_name act )const;
347
348
349 std::optional<abi_serializer> get_abi_serializer( account_name n, const abi_serializer::yield_function_t& yield )const {
350 if( n.good() ) {
351 try {
352 const auto& a = get_account( n );
353 abi_def abi;
354 if( abi_serializer::to_abi( a.abi, abi ))
355 return abi_serializer( abi, yield );
356 } FC_CAPTURE_AND_LOG((n))
357 }
358 return std::optional<abi_serializer>();
359 }
360
361 template<typename T>
363 fc::variant pretty_output;
364 abi_serializer::to_variant( obj, pretty_output,
365 [&]( account_name n ){ return get_abi_serializer( n, yield ); }, yield );
366 return pretty_output;
367 }
368
370
371 static std::optional<chain_id_type> extract_chain_id_from_db( const path& state_dir );
372
373 void replace_producer_keys( const public_key_type& key );
374 void replace_account_keys( name account, name permission, const public_key_type& key );
375
376 private:
377 friend class apply_context;
379
380 chainbase::database& mutable_db()const;
381
382 std::unique_ptr<controller_impl> my;
383
384 };
385
386} }
Used to generate a useful error report when an exception is thrown.
Definition exception.hpp:58
wraps boost::filesystem::path to provide platform independent path manipulation.
static constexpr time_point maximum()
Definition time.hpp:46
stores null, int64, uint64, double, bool, string, std::vector<variant>, and variant_object's.
Definition variant.hpp:191
void set_greylist_limit(uint32_t limit)
block_state_ptr fetch_block_state_by_number(uint32_t block_num) const
signal< void(const transaction_metadata_ptr &)> accepted_transaction
void set_actor_whitelist(const flat_set< account_name > &)
const flat_set< account_name > & get_actor_blacklist() const
void check_action_list(account_name code, action_name action) const
signal< void(const block_state_ptr &)> accepted_block_header
bool is_protocol_feature_activated(const digest_type &feature_digest) const
const global_property_object & get_global_properties() const
const chainbase::database & db() const
bool is_producing_block() const
void sign_block(const signer_callback_type &signer_callback)
bool is_trusted_producer(const account_name &producer) const
validation_mode get_validation_mode() const
signed_block_ptr fetch_block_by_number(uint32_t block_num) const
const dynamic_global_property_object & get_dynamic_global_properties() const
account_name fork_db_pending_head_block_producer() const
block_id_type fork_db_pending_head_block_id() const
void set_actor_blacklist(const flat_set< account_name > &)
static std::optional< chain_id_type > extract_chain_id_from_db(const path &state_dir)
signal< void(const block_state_ptr &)> accepted_block
void add_to_ram_correction(account_name account, uint64_t ram_bytes)
signal< void(const block_state_ptr &)> irreversible_block
db_read_mode get_read_mode() const
static chain_id_type extract_chain_id(snapshot_reader &snapshot)
vector< transaction_metadata_ptr > abort_block()
account_name head_block_producer() const
transaction_trace_ptr push_transaction(const transaction_metadata_ptr &trx, fc::time_point deadline, fc::microseconds max_transaction_time, uint32_t billed_cpu_time_us, bool explicit_billed_cpu_time, int64_t subjective_cpu_bill_us)
block_state_ptr create_block_state(const block_id_type &id, const signed_block_ptr &b) const
uint32_t head_block_num() const
void push_block(const block_state_ptr &bsp, const forked_branch_callback &cb, const trx_meta_cache_lookup &trx_lookup)
block_id_type head_block_id() const
std::optional< producer_authority_schedule > proposed_producers() const
void validate_expiration(const transaction &t) const
block_state_ptr head_block_state() const
void write_snapshot(const snapshot_writer_ptr &snapshot)
bool is_profiling(account_name name) const
uint32_t pending_block_num() const
const apply_handler * find_apply_handler(account_name contract, scope_name scope, action_name act) const
bool is_ram_billing_in_notify_allowed() const
authorization_manager & get_mutable_authorization_manager()
deep_mind_handler * get_deep_mind_logger() const
signal< void(const signed_block_ptr &)> pre_accepted_block
uint32_t last_irreversible_block_num() const
const producer_authority_schedule & pending_producers() const
void set_key_blacklist(const flat_set< public_key_type > &)
void set_s_header(const s_header &)
uint32_t fork_db_pending_head_block_num() const
uint32_t get_max_nonprivileged_inline_action_size() const
boost::asio::io_context & get_thread_pool()
block_id_type fork_db_head_block_id() const
const protocol_feature_manager & get_protocol_feature_manager() const
uint32_t configured_subjective_signature_length_limit() const
bool light_validation_allowed() const
void replace_account_keys(name account, name permission, const public_key_type &key)
account_name fork_db_head_block_producer() const
const flat_set< account_name > & get_contract_whitelist() const
account_name pending_block_producer() const
const block_signing_authority & pending_block_signing_authority() const
void validate_db_available_size() const
signed_block_ptr fetch_block_by_id(block_id_type id) const
time_point fork_db_head_block_time() const
void enable_deep_mind(deep_mind_handler *logger)
time_point last_irreversible_block_time() const
wasm_interface & get_wasm_interface()
const flat_set< pair< account_name, action_name > > & get_action_blacklist() const
std::optional< block_id_type > pending_producer_block_id() const
@ incomplete
this is an incomplete block (either being produced by a producer or speculatively produced by a node)
@ irreversible
this block has already been applied before by this node and is considered irreversible
@ validated
this is a complete block signed by a valid producer and has been previously applied by this node and ...
@ complete
this is a complete block signed by a valid producer but is not yet irreversible nor has it yet been a...
uint32_t get_terminate_at_block() const
const authorization_manager & get_authorization_manager() const
void set_contract_blacklist(const flat_set< account_name > &)
block_state_ptr finalize_block(const signer_callback_type &signer_callback)
void validate_tapos(const transaction &t) const
block_id_type last_irreversible_block_id() const
const flat_set< account_name > & get_contract_blacklist() const
block_id_type get_block_id_for_num(uint32_t block_num) const
uint32_t get_greylist_limit() const
void remove_resource_greylist(const account_name &name)
bool is_resource_greylisted(const account_name &name) const
void check_key_list(const public_key_type &key) const
void check_actor_list(const flat_set< account_name > &actors) const
chain_id_type get_chain_id() const
bool is_builtin_activated(builtin_protocol_feature_t f) const
bool sender_avoids_whitelist_blacklist_enforcement(account_name sender) const
const flat_set< public_key_type > & get_key_blacklist() const
const flat_set< account_name > & get_resource_greylist() const
transaction_trace_ptr push_scheduled_transaction(const transaction_id_type &scheduled, fc::time_point block_deadline, fc::microseconds max_transaction_time, uint32_t billed_cpu_time_us, bool explicit_billed_cpu_time)
const account_object & get_account(account_name n) const
void set_contract_whitelist(const flat_set< account_name > &)
std::optional< abi_serializer > get_abi_serializer(account_name n, const abi_serializer::yield_function_t &yield) const
int64_t set_proposed_producers(vector< producer_authority > producers)
uint32_t earliest_available_block_num() const
time_point fork_db_pending_head_block_time() const
time_point pending_block_time() const
void validate_protocol_features(const vector< digest_type > &features_to_activate) const
signal< void(std::tuple< const transaction_trace_ptr &, const packed_transaction_ptr & >)> applied_transaction
vector< digest_type > get_preactivated_protocol_features() const
void set_subjective_cpu_leeway(fc::microseconds leeway)
void replace_producer_keys(const public_key_type &key)
block_state_ptr fetch_block_state_by_id(block_id_type id) const
void add_resource_greylist(const account_name &name)
const block_header & head_block_header() const
bool is_known_unexpired_transaction(const transaction_id_type &id) const
std::future< block_state_ptr > create_block_state_future(const block_id_type &id, const signed_block_ptr &b)
const vector< transaction_receipt > & get_pending_trx_receipts() const
signal< void(uint32_t)> block_start
resource_limits_manager & get_mutable_resource_limits_manager()
const fork_database & fork_db() const
const producer_authority_schedule & active_producers() const
uint32_t fork_db_head_block_num() const
const flat_set< account_name > & get_actor_whitelist() const
static std::optional< uint64_t > convert_exception_to_error_code(const fc::exception &e)
time_point head_block_time() const
const resource_limits_manager & get_resource_limits_manager() const
controller_impl
void set_action_blacklist(const flat_set< pair< account_name, action_name > > &)
std::optional< fc::microseconds > get_subjective_cpu_leeway() const
signal< void(const int &)> bad_alloc
bool all_subjective_mitigations_disabled() const
void startup(std::function< void()> shutdown, std::function< bool()> check_shutdown, const snapshot_reader_ptr &snapshot)
fc::variant to_variant_with_abi(const T &obj, const abi_serializer::yield_function_t &yield) const
controller(const config &cfg, const chain_id_type &chain_id)
void start_block(block_timestamp_type time=block_timestamp_type(), uint16_t confirm_block_count=0)
void check_contract_list(account_name code) const
Maintains global state information that frequently change.
manages light-weight state for all potential unconfirmed forks
Maintains global state information about block producer schedules and chain configuration parameters.
#define FC_CAPTURE_AND_LOG(...)
block_timestamp< config::block_interval_ms, config::block_timestamp_epoch > block_timestamp_type
std::function< std::vector< signature_type >(const digest_type &)> signer_callback_type
deque< block_state_ptr > branch_type
std::shared_ptr< transaction_trace > transaction_trace_ptr
Definition trace.hpp:20
std::variant< block_signing_authority_v0 > block_signing_authority
sysio::chain::action_name action_name
std::shared_ptr< snapshot_writer > snapshot_writer_ptr
Definition snapshot.hpp:155
std::shared_ptr< signed_block > signed_block_ptr
Definition block.hpp:105
std::shared_ptr< snapshot_reader > snapshot_reader_ptr
Definition snapshot.hpp:294
std::function< void(apply_context &)> apply_handler
std::shared_ptr< block_state > block_state_ptr
std::shared_ptr< transaction_metadata > transaction_metadata_ptr
std::function< transaction_metadata_ptr(const transaction_id_type &)> trx_meta_cache_lookup
std::function< void(const branch_type &)> forked_branch_callback
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
#define T(meth, val, expected)
schedule config_dir_name data_dir_name p2p_port http_port file_size name name keys peers producers(dont_start)) FC_REFLECT(testnet_def
unsigned short uint16_t
Definition stdint.h:125
signed __int64 int64_t
Definition stdint.h:135
unsigned int uint32_t
Definition stdint.h:126
unsigned __int64 uint64_t
Definition stdint.h:136
static bool to_abi(const Vec &abi_vec, abi_def &abi)
static void to_variant(const T &o, fc::variant &vo, Resolver resolver, const yield_function_t &yield)
namespace sysio::chain::impl
validation_mode block_validation_mode
pinnable_mapped_file::map_mode db_map_mode
flat_set< account_name > contract_whitelist
std::optional< block_log_prune_config > prune_config
flat_set< account_name > actor_blacklist
flat_set< account_name > actor_whitelist
flat_set< account_name > resource_greylist
flat_set< account_name > contract_blacklist
flat_set< account_name > sender_bypass_whiteblacklist
flat_set< pair< account_name, action_name > > action_blacklist
flat_set< account_name > profile_accounts
flat_set< public_key_type > key_blacklist
flat_set< account_name > trusted_producers
wasm_interface::vm_type wasm_runtime
Immutable except for fc::from_variant.
Definition name.hpp:43
constexpr bool good() const
Definition name.hpp:54
sysio::vm::wasm_allocator * get_wasm_allocator()
Definition utils.hpp:50