Scorum
|
tracks the blockchain state in an extensible manner More...
#include <database.hpp>
Public Types | |
enum | creation_option { opt_none = 0 , opt_log_hardforks = 1 << 0 , opt_notify_virtual_op_applying = 1 << 1 , opt_default = opt_log_hardforks | opt_notify_virtual_op_applying } |
enum | validation_steps { skip_nothing = 0 , skip_witness_signature = 1 << 0 , skip_transaction_signatures = 1 << 1 , skip_transaction_dupe_check = 1 << 2 , skip_fork_db = 1 << 3 , skip_block_size_check = 1 << 4 , skip_tapos_check = 1 << 5 , skip_authority_check = 1 << 6 , skip_merkle_check = 1 << 7 , skip_undo_history_check = 1 << 8 , skip_witness_schedule_check = 1 << 9 , skip_validate = 1 << 10 , skip_validate_invariants = 1 << 11 , skip_undo_block = 1 << 12 , skip_block_log = 1 << 13 } |
Public Member Functions | |
database (uint32_t opt) | |
virtual | ~database () |
bool | is_producing () const |
uint32_t | get_reindex_skip_flags () const |
void | open (const fc::path &data_dir, const fc::path &shared_mem_dir, uint64_t shared_file_size, uint32_t chainbase_flags, const genesis_state_type &genesis_state) |
Open a database, creating a new one if necessary. More... | |
void | reindex (const fc::path &data_dir, const fc::path &shared_mem_dir, uint64_t shared_file_size, uint32_t skip_flags, const genesis_state_type &genesis_state) |
Rebuild object graph from block history and open detabase. More... | |
void | wipe (const fc::path &data_dir, const fc::path &shared_mem_dir, bool include_blocks) |
wipe Delete database from disk, and potentially the raw chain as well. More... | |
void | close () |
time_point_sec | get_genesis_time () const |
bool | is_known_block (const block_id_type &id) const |
bool | is_known_transaction (const transaction_id_type &id) const |
block_id_type | find_block_id_for_num (uint32_t block_num) const |
block_id_type | get_block_id_for_num (uint32_t block_num) const |
optional< signed_block > | fetch_block_by_id (const block_id_type &id) const |
optional< signed_block > | fetch_block_by_number (uint32_t num) const |
optional< signed_block > | read_block_by_number (uint32_t num) const |
const signed_transaction | get_recent_transaction (const transaction_id_type &trx_id) const |
std::vector< block_id_type > | get_block_ids_on_fork (block_id_type head_of_fork) const |
chain_id_type | get_chain_id () const |
const node_property_object & | get_node_properties () const |
const time_point_sec | calculate_discussion_payout_time (const comment_object &comment) const |
uint32_t | witness_participation_rate () const |
void | add_checkpoints (const flat_map< uint32_t, block_id_type > &checkpts) |
const flat_map< uint32_t, block_id_type > | get_checkpoints () const |
bool | before_last_checkpoint () const |
bool | push_block (const signed_block &b, uint32_t skip=skip_nothing) |
void | push_transaction (const signed_transaction &trx, uint32_t skip=skip_nothing) |
void | _push_transaction (const signed_transaction &trx) |
signed_block | generate_block (const fc::time_point_sec when, const account_name_type &witness_owner, const fc::ecc::private_key &block_signing_private_key, uint32_t skip) |
void | pop_block () |
void | clear_pending () |
void | notify_pre_apply_operation (const operation_notification ¬e) |
void | notify_post_apply_operation (const operation_notification ¬e) |
operation_notification | create_notification (const operation &op) const |
void | push_virtual_operation (const operation &op) |
void | push_hf_operation (const operation &op) |
void | notify_pre_applied_block (const signed_block &block) |
void | notify_applied_block (const signed_block &block) |
void | notify_on_pending_transaction (const signed_transaction &tx) |
void | notify_on_pre_apply_transaction (const signed_transaction &tx) |
void | notify_on_applied_transaction (const signed_transaction &tx) |
account_name_type | get_scheduled_witness (uint32_t slot_num) const |
Get the witness scheduled for block production in a slot. More... | |
fc::time_point_sec | get_slot_time (uint32_t slot_num) const |
uint32_t | get_slot_at_time (fc::time_point_sec when) const |
void | account_recovery_processing () |
void | expire_escrow_ratification () |
void | process_decline_voting_rights () |
time_point_sec | head_block_time () const |
uint32_t | head_block_num () const |
block_id_type | head_block_id () const |
block_info | head_block_context () const |
node_property_object & | node_properties () |
uint32_t | last_non_undoable_block_num () const |
void | initialize_evaluators () |
void | initialize_indexes () |
Reset the object graph in-memory. More... | |
void | set_initial_timestamp (const genesis_state_type &genesis_state) |
void | init_genesis (const genesis_state_type &genesis_state) |
void | validate_transaction (const signed_transaction &trx) |
bool | has_hardfork (uint32_t hardfork) const |
void | set_hardfork (uint32_t hardfork, bool process_now=true) |
void | validate_invariants () const |
void | set_flush_interval (uint32_t flush_blocks) |
void | show_free_memory (bool force) |
template<typename MultiIndexType > | |
void | add_plugin_index () |
const genesis_persistent_state_type & | genesis_persistent_state () const |
![]() | |
template<typename ConcreteService > | |
ConcreteService & | obtain_service () const |
template<typename ConcreteService , typename... TDependencies> | |
ConcreteService & | obtain_service_explicit (TDependencies &... dependencies) const |
![]() | |
db_accessor_factory (db_index &db) | |
template<typename TObject > | |
db_accessor< TObject > & | get_dba () const |
![]() | |
virtual | ~database_virtual_operations_emmiter_i ()=default |
Static Public Member Functions | |
static fc::path | block_log_path (const fc::path &data_dir) |
Public Attributes | |
fc::signal< void(const operation_notification &)> | pre_apply_operation |
fc::signal< void(const operation_notification &)> | post_apply_operation |
fc::signal< void(const signed_block &)> | pre_applied_block |
fc::signal< void(const signed_block &)> | applied_block |
fc::signal< void(const signed_transaction &)> | on_pending_transaction |
fc::signal< void(const signed_transaction &)> | on_pre_apply_transaction |
fc::signal< void(const signed_transaction &)> | on_applied_transaction |
std::deque< signed_transaction > | _popped_tx |
![]() | |
boost::container::flat_map< boost::typeindex::type_index, boost::any > | _db_accessors |
db_index & | _db |
tracks the blockchain state in an extensible manner
Definition at line 47 of file database.hpp.
Enumerator | |
---|---|
opt_none | |
opt_log_hardforks | |
opt_notify_virtual_op_applying | |
opt_default |
Definition at line 55 of file database.hpp.
Definition at line 76 of file database.hpp.
scorum::chain::database::database | ( | uint32_t | opt | ) |
Definition at line 168 of file database.cpp.
|
virtual |
Definition at line 178 of file database.cpp.
|
protected |
modify current witness so transaction evaluators can know who included the transaction, this is mostly for POW operations which must pay the current_witness
parse witness version reporting
Definition at line 1514 of file database.cpp.
|
protected |
Definition at line 1710 of file database.cpp.
void scorum::chain::database::_push_transaction | ( | const signed_transaction & | trx | ) |
Definition at line 774 of file database.cpp.
void scorum::chain::database::account_recovery_processing | ( | ) |
Definition at line 1132 of file database.cpp.
void scorum::chain::database::add_checkpoints | ( | const flat_map< uint32_t, block_id_type > & | checkpts | ) |
Definition at line 554 of file database.cpp.
|
inline |
Definition at line 326 of file database.hpp.
|
protected |
check invariants
Definition at line 1415 of file database.cpp.
|
protected |
Definition at line 2155 of file database.cpp.
|
protected |
Definition at line 1807 of file database.cpp.
|
protected |
Definition at line 1704 of file database.cpp.
bool scorum::chain::database::before_last_checkpoint | ( | ) | const |
Definition at line 562 of file database.cpp.
|
static |
Definition at line 183 of file database.cpp.
const time_point_sec scorum::chain::database::calculate_discussion_payout_time | ( | const comment_object & | comment | ) | const |
Definition at line 543 of file database.cpp.
|
protected |
Definition at line 2047 of file database.cpp.
|
protected |
Definition at line 2035 of file database.cpp.
void scorum::chain::database::clear_pending | ( | ) |
Definition at line 1008 of file database.cpp.
void scorum::chain::database::close | ( | ) |
Definition at line 350 of file database.cpp.
|
protected |
Definition at line 1854 of file database.cpp.
operation_notification scorum::chain::database::create_notification | ( | const operation & | op | ) | const |
Definition at line 1029 of file database.cpp.
void scorum::chain::database::expire_escrow_ratification | ( | ) |
Definition at line 1170 of file database.cpp.
optional< signed_block > scorum::chain::database::fetch_block_by_id | ( | const block_id_type & | id | ) | const |
Definition at line 447 of file database.cpp.
optional< signed_block > scorum::chain::database::fetch_block_by_number | ( | uint32_t | num | ) | const |
Definition at line 470 of file database.cpp.
block_id_type scorum::chain::database::find_block_id_for_num | ( | uint32_t | block_num | ) | const |
Definition at line 400 of file database.cpp.
signed_block scorum::chain::database::generate_block | ( | const fc::time_point_sec | when, |
const account_name_type & | witness_owner, | ||
const fc::ecc::private_key & | block_signing_private_key, | ||
uint32_t | skip | ||
) |
Definition at line 800 of file database.cpp.
const genesis_persistent_state_type & scorum::chain::database::genesis_persistent_state | ( | ) | const |
Definition at line 2065 of file database.cpp.
block_id_type scorum::chain::database::get_block_id_for_num | ( | uint32_t | block_num | ) | const |
Definition at line 440 of file database.cpp.
std::vector< block_id_type > scorum::chain::database::get_block_ids_on_fork | ( | block_id_type | head_of_fork | ) | const |
Definition at line 511 of file database.cpp.
chain_id_type scorum::chain::database::get_chain_id | ( | ) | const |
Definition at line 533 of file database.cpp.
|
inline |
Definition at line 167 of file database.hpp.
fc::time_point_sec scorum::chain::database::get_genesis_time | ( | ) | const |
Definition at line 30 of file genesis.cpp.
const node_property_object & scorum::chain::database::get_node_properties | ( | ) | const |
Definition at line 538 of file database.cpp.
const signed_transaction scorum::chain::database::get_recent_transaction | ( | const transaction_id_type & | trx_id | ) | const |
Definition at line 496 of file database.cpp.
uint32_t scorum::chain::database::get_reindex_skip_flags | ( | ) | const |
Definition at line 188 of file database.cpp.
account_name_type scorum::chain::database::get_scheduled_witness | ( | uint32_t | slot_num | ) | const |
Get the witness scheduled for block production in a slot.
slot_num always corresponds to a time in the future.
If slot_num == 1, returns the next scheduled witness. If slot_num == 2, returns the next scheduled witness after 1 block gap.
Use the get_slot_time() and get_slot_at_time() functions to convert between slot_num and timestamp.
Passing slot_num == 0 returns SCORUM_NULL_WITNESS
Definition at line 1086 of file database.cpp.
uint32_t scorum::chain::database::get_slot_at_time | ( | fc::time_point_sec | when | ) | const |
Get the last slot which occurs AT or BEFORE the given time.
The return value is the greatest value N such that get_slot_time( N ) <= when.
If no such N exists, return 0.
Definition at line 1122 of file database.cpp.
fc::time_point_sec scorum::chain::database::get_slot_time | ( | uint32_t | slot_num | ) | const |
Get the time at which the given slot occurs.
If slot_num == 0, return time_point_sec().
If slot_num == N for N > 0, return the Nth next block-interval-aligned time greater than head_block_time().
Definition at line 1095 of file database.cpp.
bool scorum::chain::database::has_hardfork | ( | uint32_t | hardfork | ) | const |
Definition at line 2132 of file database.cpp.
block_info scorum::chain::database::head_block_context | ( | ) | const |
Definition at line 1237 of file database.cpp.
block_id_type scorum::chain::database::head_block_id | ( | ) | const |
Definition at line 1232 of file database.cpp.
uint32_t scorum::chain::database::head_block_num | ( | ) | const |
Definition at line 1227 of file database.cpp.
time_point_sec scorum::chain::database::head_block_time | ( | ) | const |
Definition at line 1222 of file database.cpp.
void scorum::chain::database::init_genesis | ( | const genesis_state_type & | genesis_state | ) |
Definition at line 40 of file genesis.cpp.
|
protected |
Definition at line 2070 of file database.cpp.
void scorum::chain::database::initialize_evaluators | ( | ) |
Definition at line 1262 of file database.cpp.
void scorum::chain::database::initialize_indexes | ( | ) |
Reset the object graph in-memory.
Definition at line 1336 of file database.cpp.
bool scorum::chain::database::is_known_block | ( | const block_id_type & | id | ) | const |
Definition at line 376 of file database.cpp.
bool scorum::chain::database::is_known_transaction | ( | const transaction_id_type & | id | ) | const |
Only return true if the transaction has not expired or been invalidated. If this method is called with a VERY old transaction we will return false, they should query things by blocks if they are that old.
Definition at line 390 of file database.cpp.
|
inline |
Definition at line 71 of file database.hpp.
uint32_t scorum::chain::database::last_non_undoable_block_num | ( | ) | const |
Definition at line 1257 of file database.cpp.
node_property_object & scorum::chain::database::node_properties | ( | ) |
Definition at line 1252 of file database.cpp.
void scorum::chain::database::notify_applied_block | ( | const signed_block & | block | ) |
Definition at line 1066 of file database.cpp.
void scorum::chain::database::notify_on_applied_transaction | ( | const signed_transaction & | tx | ) |
Definition at line 1081 of file database.cpp.
void scorum::chain::database::notify_on_pending_transaction | ( | const signed_transaction & | tx | ) |
Definition at line 1071 of file database.cpp.
void scorum::chain::database::notify_on_pre_apply_transaction | ( | const signed_transaction & | tx | ) |
Definition at line 1076 of file database.cpp.
void scorum::chain::database::notify_post_apply_operation | ( | const operation_notification & | note | ) |
Definition at line 1024 of file database.cpp.
void scorum::chain::database::notify_pre_applied_block | ( | const signed_block & | block | ) |
Definition at line 1061 of file database.cpp.
void scorum::chain::database::notify_pre_apply_operation | ( | const operation_notification & | note | ) |
This method is used to track applied operations during the evaluation of a block, these operations should include any operation actually included in a transaction as well as any implied/virtual operations that resulted, such as filling an order. The applied operations are cleared after post_apply_operation.
Definition at line 1019 of file database.cpp.
void scorum::chain::database::open | ( | const fc::path & | data_dir, |
const fc::path & | shared_mem_dir, | ||
uint64_t | shared_file_size, | ||
uint32_t | chainbase_flags, | ||
const genesis_state_type & | genesis_state | ||
) |
Open a database, creating a new one if necessary.
Opens a database in the specified directory. If no initialized database is found the database will be initialized with the default state.
data_dir | Path to open or create database in |
Definition at line 203 of file database.cpp.
void scorum::chain::database::pop_block | ( | ) |
Removes the most recent block from the database and undoes any changes it made.
save the head block so we can recover its transactions
Definition at line 977 of file database.cpp.
void scorum::chain::database::process_decline_voting_rights | ( | ) |
remove all current votes
Definition at line 1190 of file database.cpp.
|
protected |
Definition at line 2109 of file database.cpp.
|
protected |
Definition at line 1657 of file database.cpp.
bool scorum::chain::database::push_block | ( | const signed_block & | new_block, |
uint32_t | skip = skip_nothing |
||
) |
Push block "may fail" in which case every partial change is unwound. After push block is successful the block is appended to the chain database on disk.
Definition at line 573 of file database.cpp.
|
inline |
Definition at line 1052 of file database.cpp.
void scorum::chain::database::push_transaction | ( | const signed_transaction & | trx, |
uint32_t | skip = skip_nothing |
||
) |
Attempts to push the transaction into the pending queue
When called to push a locally generated transaction, set the skip_block_size_check bit on the skip argument. This will allow the transaction to be pushed even if it causes the pending block size to exceed the maximum block size. Although the transaction will probably not propagate further now, as the peers are likely to have their pending queues full as well, it will be kept in the queue to be propagated later when a new block flushes out the pending queues.
Definition at line 751 of file database.cpp.
|
inlinevirtual |
Implements scorum::chain::database_virtual_operations_emmiter_i.
Definition at line 1034 of file database.cpp.
optional< signed_block > scorum::chain::database::read_block_by_number | ( | uint32_t | num | ) | const |
Definition at line 491 of file database.cpp.
void scorum::chain::database::reindex | ( | const fc::path & | data_dir, |
const fc::path & | shared_mem_dir, | ||
uint64_t | shared_file_size, | ||
uint32_t | skip_flags, | ||
const genesis_state_type & | genesis_state | ||
) |
Rebuild object graph from block history and open detabase.
This method may be called after or instead of database::open, and will rebuild the object graph by replaying blockchain history. When this method exits successfully, the database will be open.
Definition at line 284 of file database.cpp.
void scorum::chain::database::set_flush_interval | ( | uint32_t | flush_blocks | ) |
Definition at line 1407 of file database.cpp.
void scorum::chain::database::set_hardfork | ( | uint32_t | hardfork, |
bool | process_now = true |
||
) |
Definition at line 2137 of file database.cpp.
void scorum::chain::database::set_initial_timestamp | ( | const genesis_state_type & | genesis_state | ) |
Definition at line 35 of file genesis.cpp.
|
inlineprotected |
Definition at line 349 of file database.hpp.
void scorum::chain::database::show_free_memory | ( | bool | force | ) |
Definition at line 1494 of file database.cpp.
|
protected |
Definition at line 1864 of file database.cpp.
|
protected |
Prior to voting taking over, we must be more conservative...
Definition at line 1947 of file database.cpp.
|
protected |
Definition at line 1938 of file database.cpp.
|
protected |
Steps involved in applying a new block
Definition at line 1816 of file database.cpp.
void scorum::chain::database::validate_invariants | ( | ) | const |
Verifies all supply invariants check out
verify no witness has too many votes
Definition at line 2185 of file database.cpp.
void scorum::chain::database::validate_transaction | ( | const signed_transaction & | trx | ) |
This method validates transactions without adding it to the pending state.
if | an error occurs |
Definition at line 1399 of file database.cpp.
void scorum::chain::database::wipe | ( | const fc::path & | data_dir, |
const fc::path & | shared_mem_dir, | ||
bool | include_blocks | ||
) |
wipe Delete database from disk, and potentially the raw chain as well.
include_blocks | If true, delete the raw chain as well as the database. |
Will close the database before wiping. Database will be closed when this function returns.
Definition at line 338 of file database.cpp.
uint32_t scorum::chain::database::witness_participation_rate | ( | ) | const |
Calculate the percent of block production slots that were missed in the past 128 blocks, not including the current block.
Definition at line 548 of file database.cpp.
std::deque<signed_transaction> scorum::chain::database::_popped_tx |
when popping a block, the transactions that were removed get cached here so they can be reapplied at the proper time
Definition at line 311 of file database.hpp.
fc::signal<void(const signed_block&)> scorum::chain::database::applied_block |
This signal is emitted after all operations and virtual operation for a block have been applied but before the get_applied_operations() are cleared.
You may not yield from this callback because the blockchain is holding the write lock and may be in an "inconstant state" until after it is released.
Definition at line 221 of file database.hpp.
fc::signal<void(const signed_transaction&)> scorum::chain::database::on_applied_transaction |
This signal is emitted any time a new transaction has been applied to the chain state.
Definition at line 239 of file database.hpp.
fc::signal<void(const signed_transaction&)> scorum::chain::database::on_pending_transaction |
This signal is emitted any time a new transaction is added to the pending block state.
Definition at line 227 of file database.hpp.
fc::signal<void(const signed_transaction&)> scorum::chain::database::on_pre_apply_transaction |
This signla is emitted any time a new transaction is about to be applied to the chain state.
Definition at line 233 of file database.hpp.
fc::signal<void(const operation_notification&)> scorum::chain::database::post_apply_operation |
Definition at line 210 of file database.hpp.
fc::signal<void(const signed_block&)> scorum::chain::database::pre_applied_block |
Definition at line 211 of file database.hpp.
fc::signal<void(const operation_notification&)> scorum::chain::database::pre_apply_operation |
This signal is emitted for plugins to process every operation before/after it has been fully applied.
Definition at line 209 of file database.hpp.