BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
Public Types | Public Member Functions | Public Attributes | Protected Member Functions | List of all members
graphene::chain::database Class Reference

tracks the blockchain state in an extensible manner More...

#include <database.hpp>

Inheritance diagram for graphene::chain::database:
graphene::db::object_database

Public Types

enum  validation_steps {
  skip_nothing = 0, skip_witness_signature = 1 << 0, skip_transaction_signatures = 1 << 1, skip_transaction_dupe_check = 1 << 2,
  skip_block_size_check = 1 << 4, skip_tapos_check = 1 << 5, skip_merkle_check = 1 << 7, skip_assert_evaluation = 1 << 8,
  skip_undo_history_check = 1 << 9, skip_witness_schedule_check = 1 << 10
}
 
enum  match_result_type { match_result_type::none_filled = 0, match_result_type::only_taker_filled = 1, match_result_type::only_maker_filled = 2, match_result_type::both_filled = 3 }
 

Public Member Functions

 database ()
 
 ~database () override
 
void open (const fc::path &data_dir, std::function< genesis_state_type()> genesis_loader, const std::string &db_version)
 Open a database, creating a new one if necessary. More...
 
void reindex (fc::path data_dir)
 Rebuild object graph from block history and open detabase. More...
 
void wipe (const fc::path &data_dir, bool include_blocks)
 wipe Delete database from disk, and potentially the raw chain as well. More...
 
void close (bool rewind=true)
 
witness_id_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
 
uint32_t witness_participation_rate () const
 
const chain_id_typeget_chain_id () const
 
const asset_objectget_core_asset () const
 
const asset_dynamic_data_objectget_core_dynamic_data () const
 
const chain_property_objectget_chain_properties () const
 
const global_property_objectget_global_properties () const
 
const dynamic_global_property_objectget_dynamic_global_properties () const
 
const node_property_objectget_node_properties () const
 
const fee_schedulecurrent_fee_schedule () const
 
const account_statistics_objectget_account_stats_by_owner (account_id_type owner) const
 
const witness_schedule_objectget_witness_schedule_object () const
 
time_point_sec head_block_time () const
 
uint32_t head_block_num () const
 
block_id_type head_block_id () const
 
witness_id_type head_block_witness () const
 
node_property_objectnode_properties ()
 
vector< authorityget_viable_custom_authorities (account_id_type account, const operation &op, rejected_predicate_map *rejected_authorities=nullptr) const
 Get a list of custom authorities which can validate the provided operation for the provided account. More...
 
uint32_t last_non_undoable_block_num () const
 
const limit_order_objectfind_settled_debt_order (const asset_id_type &a) const
 
const call_order_objectfind_least_collateralized_short (const asset_bitasset_data_object &bitasset, bool force_by_collateral_index) const
 
asset get_balance (account_id_type owner, asset_id_type asset_id) const
 Retrieve a particular account's balance in a given asset. More...
 
asset get_balance (const account_object &owner, const asset_object &asset_obj) const
 This is an overloaded method. More...
 
void adjust_balance (account_id_type account, asset delta)
 Adjust a particular account's balance in a given asset by a delta. More...
 
void deposit_market_fee_vesting_balance (const account_id_type &account_id, const asset &delta)
 
asset get_market_fee_vesting_balance (const account_id_type &account_id, const asset_id_type &asset_id)
 Retrieve a particular account's market fee vesting balance in a given asset. More...
 
optional< vesting_balance_id_type > deposit_lazy_vesting (const optional< vesting_balance_id_type > &ovbid, share_type amount, uint32_t req_vesting_seconds, vesting_balance_type balance_type, account_id_type req_owner, bool require_vesting)
 Helper to make lazy deposit to CDD VBO. More...
 
void deposit_cashback (const account_object &acct, share_type amount, bool require_vesting=true)
 helper to handle cashback rewards More...
 
void deposit_witness_pay (const witness_object &wit, share_type amount)
 helper to handle witness pay More...
 
string to_pretty_string (const asset &a) const
 
void debug_dump ()
 
void apply_debug_updates ()
 
void debug_update (const fc::variant_object &update)
 
void apply_force_settlement (const force_settlement_object &new_settlement, const asset_bitasset_data_object &bitasset, const asset_object &asset_obj)
 Process a new force-settlement request. More...
 
bool check_call_orders (const asset_object &mia, bool enable_black_swan=true, bool for_new_limit_order=false, const asset_bitasset_data_object *bitasset_ptr=nullptr, bool mute_exceptions=false, bool skip_matching_settle_orders=false)
 
void check_settled_debt_order (const asset_bitasset_data_object &bitasset)
 Match the settled debt order of the specified asset as taker with other orders on the opposite side of the order book. More...
 
bool is_known_block (const block_id_type &id) const
 
bool is_known_transaction (const transaction_id_type &id) const
 
block_id_type get_block_id_for_num (uint32_t block_num) const
 
optional< signed_blockfetch_block_by_id (const block_id_type &id) const
 
optional< signed_blockfetch_block_by_number (uint32_t num) const
 
const signed_transactionget_recent_transaction (const transaction_id_type &trx_id) const
 
std::vector< block_id_typeget_block_ids_on_fork (block_id_type head_of_fork) const
 
void add_checkpoints (const flat_map< uint32_t, block_id_type > &checkpts)
 
const flat_map< uint32_t, block_id_typeget_checkpoints () const
 
bool before_last_checkpoint () const
 
bool push_block (const signed_block &b, uint32_t skip=skip_nothing)
 
processed_transaction push_transaction (const precomputable_transaction &trx, uint32_t skip=skip_nothing)
 
processed_transaction _push_transaction (const precomputable_transaction &trx)
 
processed_transaction push_proposal (const proposal_object &proposal)
 
signed_block generate_block (const fc::time_point_sec when, witness_id_type witness_id, const fc::ecc::private_key &block_signing_private_key, uint32_t skip)
 
void pop_block ()
 
void clear_pending ()
 
uint32_t push_applied_operation (const operation &op, bool is_virtual=true)
 
void set_applied_operation_result (uint32_t op_id, const operation_result &r)
 
const vector< optional< operation_history_object > > & get_applied_operations () const
 
fc::future< void > precompute_parallel (const signed_block &block, const uint32_t skip=skip_nothing) const
 
fc::future< void > precompute_parallel (const precomputable_transaction &trx) const
 
void apply_block (const signed_block &next_block, uint32_t skip=skip_nothing)
 
processed_transaction apply_transaction (const signed_transaction &trx, uint32_t skip=skip_nothing)
 
operation_result apply_operation (transaction_evaluation_state &eval_state, const operation &op, bool is_virtual=true)
 
void enable_standby_votes_tracking (bool enable)
 Enable or disable tracking of votes of standby witnesses and committee members. More...
 
- Public Member Functions inherited from graphene::db::object_database
 object_database ()
 
virtual ~object_database ()=default
 
void reset_indexes ()
 
void open (const fc::path &data_dir)
 
void flush ()
 
void wipe (const fc::path &data_dir)
 
void close ()
 
template<typename T , typename F >
const T & create (F &&constructor)
 
const objectget_object (const object_id_type &id) const
 
const objectfind_object (const object_id_type &id) const
 
template<typename T >
const T & get (const object_id_type &id) const
 
template<typename T >
const T * find (const object_id_type &id) const
 
template<uint8_t SpaceID, uint8_t TypeID>
auto find (const object_id< SpaceID, TypeID > &id) const -> const object_downcast_t< decltype(id)> *
 
template<uint8_t SpaceID, uint8_t TypeID>
auto get (const object_id< SpaceID, TypeID > &id) const -> const object_downcast_t< decltype(id)> &
 
template<typename IndexType >
IndexType * add_index ()
 
template<typename IndexType , typename SecondaryIndexType , typename... Args>
SecondaryIndexType * add_secondary_index (Args... args)
 
void pop_undo ()
 
fc::path get_data_dir () const
 
template<typename IndexType >
const IndexType & get_index_type () const
 
template<typename T >
const indexget_index () const
 
const indexget_index (uint8_t space_id, uint8_t type_id) const
 
const indexget_index (const object_id_type &id) const
 
const objectinsert (object &&obj)
 
void remove (const object &obj)
 
template<typename T , typename Lambda >
void modify (const T &obj, const Lambda &m)
 

Public Attributes

fc::signal< void(const signed_block &)> applied_block
 
fc::signal< void(const signed_transaction &)> on_pending_transaction
 
fc::signal< void(const vector< object_id_type > &, const flat_set< account_id_type > &)> new_objects
 
fc::signal< void(const vector< object_id_type > &, const flat_set< account_id_type > &)> changed_objects
 
fc::signal< void(const vector< object_id_type > &, const vector< const object * > &, const flat_set< account_id_type > &)> removed_objects
 
fc::time_point_sec _current_block_time
 
uint32_t _current_block_num = 0
 
- Public Attributes inherited from graphene::db::object_database
undo_database _undo_db
 

Protected Member Functions

void pop_undo ()
 
- Protected Member Functions inherited from graphene::db::object_database
template<typename IndexType >
IndexType & get_mutable_index_type ()
 
template<typename T >
indexget_mutable_index ()
 
indexget_mutable_index (const object_id_type &id)
 
indexget_mutable_index (uint8_t space_id, uint8_t type_id)
 
void initialize_indexes ()
 Reset the object graph in-memory. More...
 
void globally_settle_asset (const asset_object &bitasset, const price &settle_price, bool check_margin_calls=false)
 
void cancel_settle_order (const force_settlement_object &order)
 
void cancel_limit_order (const limit_order_object &order, bool create_virtual_op=true, bool skip_cancel_fee=false)
 
void revive_bitasset (const asset_object &bitasset, const asset_bitasset_data_object &bad)
 
void cancel_bid (const collateral_bid_object &bid, bool create_virtual_op=true)
 
void execute_bid (const collateral_bid_object &bid, share_type debt_covered, share_type collateral_from_fund, const price_feed &current_feed)
 
bool apply_order_before_hardfork_625 (const limit_order_object &new_order_object)
 Process a new limit order through the markets. More...
 
bool apply_order (const limit_order_object &new_order_object)
 
asset calculate_market_fee (const asset_object &trade_asset, const asset &trade_amount, const bool &is_maker) const
 Calculate the market fee that is to be taken. More...
 
asset pay_market_fees (const account_object *seller, const asset_object &recv_asset, const asset &receives, const bool &is_maker, const optional< asset > &calculated_market_fees={})
 
asset pay_force_settle_fees (const asset_object &collecting_asset, const asset &collat_receives)
 
std::deque< precomputable_transaction_popped_tx
 
processed_transaction validate_transaction (const signed_transaction &trx)
 
generic_operation_result process_tickets ()
 
void update_bitasset_current_feed (const asset_bitasset_data_object &bitasset, bool skip_median_update=false)
 
void notify_applied_block (const signed_block &block)
 
void notify_on_pending_transaction (const signed_transaction &tx)
 
void notify_changed_objects ()
 

Additional Inherited Members

- Static Public Member Functions inherited from graphene::db::object_database
template<typename T >
static const T & cast (const object &obj)
 
template<typename T >
static T & cast (object &obj)
 
- Static Public Attributes inherited from graphene::db::object_database
static constexpr uint8_t _index_size = 255
 

Detailed Description

tracks the blockchain state in an extensible manner

Definition at line 70 of file database.hpp.

Member Enumeration Documentation

◆ match_result_type

Enumerator
none_filled 
only_taker_filled 
only_maker_filled 
both_filled 

Definition at line 417 of file database.hpp.

◆ validation_steps

Enumerator
skip_nothing 
skip_witness_signature 

used while reindexing

skip_transaction_signatures 

used by non-witness nodes

skip_transaction_dupe_check 

used while reindexing

skip_block_size_check 

used when applying locally generated transactions

skip_tapos_check 

used while reindexing – note this skips expiration check too

skip_merkle_check 

used while reindexing

skip_assert_evaluation 

used while reindexing

skip_undo_history_check 

used while reindexing

skip_witness_schedule_check 

used while reindexing

Definition at line 77 of file database.hpp.

Constructor & Destructor Documentation

◆ database()

graphene::chain::database::database ( )

Definition at line 44 of file db_management.cpp.

◆ ~database()

graphene::chain::database::~database ( )
override

Definition at line 50 of file db_management.cpp.

Member Function Documentation

◆ _push_transaction()

processed_transaction graphene::chain::database::_push_transaction ( const precomputable_transaction trx)

Definition at line 282 of file db_block.cpp.

◆ add_checkpoints()

void graphene::chain::database::add_checkpoints ( const flat_map< uint32_t, block_id_type > &  checkpts)

Definition at line 858 of file db_block.cpp.

◆ adjust_balance()

void graphene::chain::database::adjust_balance ( account_id_type  account,
asset  delta 
)

Adjust a particular account's balance in a given asset by a delta.

Parameters
accountID of account whose balance should be adjusted
deltaAsset ID and amount to adjust balance by

Definition at line 54 of file db_balance.cpp.

◆ apply_block()

void graphene::chain::database::apply_block ( const signed_block next_block,
uint32_t  skip = skip_nothing 
)

Definition at line 573 of file db_block.cpp.

◆ apply_debug_updates()

void graphene::chain::database::apply_debug_updates ( )

Definition at line 187 of file db_debug.cpp.

◆ apply_force_settlement()

void graphene::chain::database::apply_force_settlement ( const force_settlement_object new_settlement,
const asset_bitasset_data_object bitasset,
const asset_object asset_obj 
)

Process a new force-settlement request.

Parameters
new_settlementThe new force-settlement request
bitassetThe bitasset data object
asset_objThe asset object

Since the core-2481 hard fork, this function is called after a new force-settlement object is created to check if there are margin calls to be matched instantly.

Definition at line 943 of file db_market.cpp.

◆ apply_operation()

operation_result graphene::chain::database::apply_operation ( transaction_evaluation_state eval_state,
const operation op,
bool  is_virtual = true 
)

Definition at line 784 of file db_block.cpp.

◆ apply_order()

bool graphene::chain::database::apply_order ( const limit_order_object new_order_object)

Definition at line 741 of file db_market.cpp.

◆ apply_order_before_hardfork_625()

bool graphene::chain::database::apply_order_before_hardfork_625 ( const limit_order_object new_order_object)

Process a new limit order through the markets.

Parameters
new_order_objectThe new order to process
Returns
true if order was completely filled; false otherwise

This function takes a new limit order, and runs the markets attempting to match it with existing orders already on the books.

Definition at line 672 of file db_market.cpp.

◆ apply_transaction()

processed_transaction graphene::chain::database::apply_transaction ( const signed_transaction trx,
uint32_t  skip = skip_nothing 
)
Note
if a processed_transaction is passed in, it is cast into signed_transaction here. It also means that the operation_results field is ignored by consensus, although it is a part of block data.

Definition at line 688 of file db_block.cpp.

◆ before_last_checkpoint()

bool graphene::chain::database::before_last_checkpoint ( ) const

Definition at line 864 of file db_block.cpp.

◆ calculate_market_fee()

asset graphene::chain::database::calculate_market_fee ( const asset_object trade_asset,
const asset trade_amount,
const bool &  is_maker 
) const

Calculate the market fee that is to be taken.

Parameters
trade_assetthe asset (passed in to avoid a lookup)
trade_amountthe quantity that the fee calculation is based upon
is_makerTRUE if this is the fee for a maker, FALSE if taker

Definition at line 2557 of file db_market.cpp.

◆ cancel_bid()

void graphene::chain::database::cancel_bid ( const collateral_bid_object bid,
bool  create_virtual_op = true 
)

Definition at line 477 of file db_market.cpp.

◆ cancel_limit_order()

void graphene::chain::database::cancel_limit_order ( const limit_order_object order,
bool  create_virtual_op = true,
bool  skip_cancel_fee = false 
)

Definition at line 533 of file db_market.cpp.

◆ cancel_settle_order()

void graphene::chain::database::cancel_settle_order ( const force_settlement_object order)

Definition at line 524 of file db_market.cpp.

◆ check_call_orders()

bool graphene::chain::database::check_call_orders ( const asset_object mia,
bool  enable_black_swan = true,
bool  for_new_limit_order = false,
const asset_bitasset_data_object bitasset_ptr = nullptr,
bool  mute_exceptions = false,
bool  skip_matching_settle_orders = false 
)

Starting with the least collateralized orders, fill them if their call price is above the max(lowest bid,call_limit).

This method will return true if it filled a short or limit

Parameters
mia- the market issued asset that should be called.
enable_black_swan- when adjusting collateral, triggering a black swan is invalid and will throw if enable_black_swan is not set to true.
for_new_limit_order- true if this function is called when matching call orders with a new limit order. (Only relevent before hardfork 625. apply_order_before_hardfork_625() is only function that calls this with for_new_limit_order true.)
bitasset_ptr- an optional pointer to the bitasset_data object of the asset
mute_exceptions- whether to mute exceptions in a special case
skip_matching_settle_orders- whether to skip matching call orders with force settlements
Returns
true if a margin call was executed.

Definition at line 2079 of file db_market.cpp.

◆ check_settled_debt_order()

void graphene::chain::database::check_settled_debt_order ( const asset_bitasset_data_object bitasset)

Match the settled debt order of the specified asset as taker with other orders on the opposite side of the order book.

Parameters
bitassetThe bitasset data object

Since the core-2591 hard fork, this function is called after processed all call orders in check_call_orders().

Definition at line 2504 of file db_market.cpp.

◆ clear_pending()

void graphene::chain::database::clear_pending ( )

Definition at line 541 of file db_block.cpp.

◆ close()

void graphene::chain::database::close ( bool  rewind = true)

Definition at line 230 of file db_management.cpp.

◆ current_fee_schedule()

const fee_schedule & graphene::chain::database::current_fee_schedule ( ) const

Definition at line 62 of file db_getter.cpp.

◆ debug_dump()

void graphene::chain::database::debug_dump ( )

This method dumps the state of the blockchain in a semi-human readable form for the purpose of tracking down funds and mismatches in currency allocation

Definition at line 41 of file db_debug.cpp.

◆ debug_update()

void graphene::chain::database::debug_update ( const fc::variant_object update)

Definition at line 197 of file db_debug.cpp.

◆ deposit_cashback()

void graphene::chain::database::deposit_cashback ( const account_object acct,
share_type  amount,
bool  require_vesting = true 
)

helper to handle cashback rewards

Definition at line 202 of file db_balance.cpp.

◆ deposit_lazy_vesting()

optional< vesting_balance_id_type > graphene::chain::database::deposit_lazy_vesting ( const optional< vesting_balance_id_type > &  ovbid,
share_type  amount,
uint32_t  req_vesting_seconds,
vesting_balance_type  balance_type,
account_id_type  req_owner,
bool  require_vesting 
)

Helper to make lazy deposit to CDD VBO.

If the given optional VBID is not valid(), or it does not have a CDD vesting policy, or the owner / vesting_seconds of the policy does not match the parameter, then credit amount to newly created VBID and return it.

Otherwise, credit amount to ovbid.

Returns
ID of newly created VBO, but only if VBO was created.

Definition at line 156 of file db_balance.cpp.

◆ deposit_market_fee_vesting_balance()

void graphene::chain::database::deposit_market_fee_vesting_balance ( const account_id_type &  account_id,
const asset delta 
)

Definition at line 127 of file db_balance.cpp.

◆ deposit_witness_pay()

void graphene::chain::database::deposit_witness_pay ( const witness_object wit,
share_type  amount 
)

helper to handle witness pay

Definition at line 249 of file db_balance.cpp.

◆ enable_standby_votes_tracking()

void graphene::chain::database::enable_standby_votes_tracking ( bool  enable)
inline

Enable or disable tracking of votes of standby witnesses and committee members.

Definition at line 846 of file database.hpp.

◆ execute_bid()

void graphene::chain::database::execute_bid ( const collateral_bid_object bid,
share_type  debt_covered,
share_type  collateral_from_fund,
const price_feed current_feed 
)

Definition at line 492 of file db_market.cpp.

◆ fetch_block_by_id()

optional< signed_block > graphene::chain::database::fetch_block_by_id ( const block_id_type id) const

Definition at line 68 of file db_block.cpp.

◆ fetch_block_by_number()

optional< signed_block > graphene::chain::database::fetch_block_by_number ( uint32_t  num) const

Definition at line 76 of file db_block.cpp.

◆ find_least_collateralized_short()

const call_order_object * graphene::chain::database::find_least_collateralized_short ( const asset_bitasset_data_object bitasset,
bool  force_by_collateral_index 
) const

Find the call order with the least collateral ratio

Parameters
bitassetThe bitasset object
force_by_collateral_indexWhether to forcefully search via the by_collateral index
Returns
nullptr if not found, pointer to the call order if found

Definition at line 161 of file db_getter.cpp.

◆ find_settled_debt_order()

const limit_order_object * graphene::chain::database::find_settled_debt_order ( const asset_id_type &  a) const

Find the limit order which is the individual settlement fund of the specified asset

Parameters
aID of the asset
Returns
nullptr if not found, pointer to the limit order if found

Definition at line 152 of file db_getter.cpp.

◆ generate_block()

signed_block graphene::chain::database::generate_block ( const fc::time_point_sec  when,
witness_id_type  witness_id,
const fc::ecc::private_key block_signing_private_key,
uint32_t  skip 
)

Definition at line 382 of file db_block.cpp.

◆ get_account_stats_by_owner()

const account_statistics_object & graphene::chain::database::get_account_stats_by_owner ( account_id_type  owner) const

Definition at line 142 of file db_getter.cpp.

◆ get_applied_operations()

const vector< optional< operation_history_object > > & graphene::chain::database::get_applied_operations ( ) const

Definition at line 566 of file db_block.cpp.

◆ get_balance() [1/2]

asset graphene::chain::database::get_balance ( account_id_type  owner,
asset_id_type  asset_id 
) const

Retrieve a particular account's balance in a given asset.

Parameters
ownerAccount whose balance should be retrieved
asset_idID of the asset to get balance in
Returns
owner's balance in asset

Definition at line 35 of file db_balance.cpp.

◆ get_balance() [2/2]

asset graphene::chain::database::get_balance ( const account_object owner,
const asset_object asset_obj 
) const

This is an overloaded method.

Definition at line 44 of file db_balance.cpp.

◆ get_block_id_for_num()

block_id_type graphene::chain::database::get_block_id_for_num ( uint32_t  block_num) const

Definition at line 63 of file db_block.cpp.

◆ get_block_ids_on_fork()

std::vector< block_id_type > graphene::chain::database::get_block_ids_on_fork ( block_id_type  head_of_fork) const

Definition at line 93 of file db_block.cpp.

◆ get_chain_id()

const chain_id_type & graphene::chain::database::get_chain_id ( ) const

Definition at line 87 of file db_getter.cpp.

◆ get_chain_properties()

const chain_property_object & graphene::chain::database::get_chain_properties ( ) const

Definition at line 52 of file db_getter.cpp.

◆ get_checkpoints()

const flat_map<uint32_t,block_id_type> graphene::chain::database::get_checkpoints ( ) const
inline

Definition at line 571 of file database.hpp.

◆ get_core_asset()

const asset_object & graphene::chain::database::get_core_asset ( ) const

Definition at line 37 of file db_getter.cpp.

◆ get_core_dynamic_data()

const asset_dynamic_data_object & graphene::chain::database::get_core_dynamic_data ( ) const

Definition at line 42 of file db_getter.cpp.

◆ get_dynamic_global_properties()

const dynamic_global_property_object & graphene::chain::database::get_dynamic_global_properties ( ) const

Definition at line 57 of file db_getter.cpp.

◆ get_global_properties()

const global_property_object & graphene::chain::database::get_global_properties ( ) const

Definition at line 47 of file db_getter.cpp.

◆ get_market_fee_vesting_balance()

asset graphene::chain::database::get_market_fee_vesting_balance ( const account_id_type &  account_id,
const asset_id_type &  asset_id 
)

Retrieve a particular account's market fee vesting balance in a given asset.

Parameters
account_idAccount whose balance should be retrieved
asset_idID of the asset to get balance in
Returns
owner's balance in asset

Definition at line 114 of file db_balance.cpp.

◆ get_node_properties()

const node_property_object & graphene::chain::database::get_node_properties ( ) const

Definition at line 92 of file db_getter.cpp.

◆ get_recent_transaction()

const signed_transaction & graphene::chain::database::get_recent_transaction ( const transaction_id_type trx_id) const

Definition at line 85 of file db_block.cpp.

◆ get_scheduled_witness()

witness_id_type graphene::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 GRAPHENE_NULL_WITNESS

Definition at line 36 of file db_witness_schedule.cpp.

◆ get_slot_at_time()

uint32_t graphene::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 74 of file db_witness_schedule.cpp.

◆ get_slot_time()

fc::time_point_sec graphene::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 44 of file db_witness_schedule.cpp.

◆ get_viable_custom_authorities()

vector< authority > graphene::chain::database::get_viable_custom_authorities ( account_id_type  account,
const operation op,
rejected_predicate_map rejected_authorities = nullptr 
) const

Get a list of custom authorities which can validate the provided operation for the provided account.

Parameters
accountThe account whose authority is required
opThe operation requring the specified account's authority
rejected_authorities[Optional] A pointer to a map that should be populated with the custom authorities which were valid, but rejected because the operation did not comply with the restrictions
Returns
A vector of authorities which can be used to authorize op in place of account

Definition at line 102 of file db_getter.cpp.

◆ get_witness_schedule_object()

const witness_schedule_object & graphene::chain::database::get_witness_schedule_object ( ) const

Definition at line 147 of file db_getter.cpp.

◆ globally_settle_asset()

void graphene::chain::database::globally_settle_asset ( const asset_object mia,
const price settlement_price,
bool  check_margin_calls = false 
)

Globally settle bitasset at settle_price, let margin calls pay a premium and margin call fee if check_margin_calls is true (in this case others would be closed not at settle_price but at a price better for their owners).

All margin positions are force closed at the swan price Collateral received goes into a force-settlement fund No new margin positions can be created for this asset Force settlement happens without delay at the swan price, deducting from force-settlement fund

Definition at line 221 of file db_market.cpp.

◆ head_block_id()

block_id_type graphene::chain::database::head_block_id ( ) const

Definition at line 77 of file db_getter.cpp.

◆ head_block_num()

uint32_t graphene::chain::database::head_block_num ( ) const

Definition at line 72 of file db_getter.cpp.

◆ head_block_time()

time_point_sec graphene::chain::database::head_block_time ( ) const

Definition at line 67 of file db_getter.cpp.

◆ head_block_witness()

witness_id_type graphene::chain::database::head_block_witness ( ) const

◆ initialize_indexes()

void graphene::chain::database::initialize_indexes ( )

Reset the object graph in-memory.

db_init.cpp ////////////////////

Definition at line 154 of file db_init.cpp.

◆ is_known_block()

bool graphene::chain::database::is_known_block ( const block_id_type id) const
Returns
true if the block is in our fork DB or saved to disk as part of the official chain, otherwise return false

Definition at line 48 of file db_block.cpp.

◆ is_known_transaction()

bool graphene::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 57 of file db_block.cpp.

◆ last_non_undoable_block_num()

uint32_t graphene::chain::database::last_non_undoable_block_num ( ) const

Definition at line 130 of file db_getter.cpp.

◆ node_properties()

node_property_object & graphene::chain::database::node_properties ( )

Definition at line 97 of file db_getter.cpp.

◆ notify_applied_block()

void graphene::chain::database::notify_applied_block ( const signed_block block)
protected

Definition at line 582 of file db_notify.cpp.

◆ notify_changed_objects()

void graphene::chain::database::notify_changed_objects ( )
protected

Definition at line 592 of file db_notify.cpp.

◆ notify_on_pending_transaction()

void graphene::chain::database::notify_on_pending_transaction ( const signed_transaction tx)
protected

Definition at line 587 of file db_notify.cpp.

◆ open()

void graphene::chain::database::open ( const fc::path data_dir,
std::function< genesis_state_type()>  genesis_loader,
const std::string &  db_version 
)

Open a database, creating a new one if necessary.

Opens a database in the specified directory. If no initialized database is found, genesis_loader is called and its return value is used as the genesis state when initializing the new database

genesis_loader will not be called if an existing database is found.

Parameters
data_dirPath to open or create database in
genesis_loaderA callable object which returns the genesis state to initialize new databases on
db_versiona version string that changes when the internal database format and/or logic is modified

Definition at line 176 of file db_management.cpp.

◆ pay_force_settle_fees()

asset graphene::chain::database::pay_force_settle_fees ( const asset_object collecting_asset,
const asset collat_receives 
)

Definition at line 2702 of file db_market.cpp.

◆ pay_market_fees()

asset graphene::chain::database::pay_market_fees ( const account_object seller,
const asset_object recv_asset,
const asset receives,
const bool &  is_maker,
const optional< asset > &  calculated_market_fees = {} 
)

Definition at line 2592 of file db_market.cpp.

◆ pop_block()

void graphene::chain::database::pop_block ( )

Removes the most recent block from the database and undoes any changes it made.

Definition at line 523 of file db_block.cpp.

◆ pop_undo()

void graphene::chain::database::pop_undo ( )
inlineprotected

Definition at line 692 of file database.hpp.

◆ precompute_parallel() [1/2]

fc::future< void > graphene::chain::database::precompute_parallel ( const precomputable_transaction trx) const

Precomputes digests, signatures and operation validations. "Expensive" computations may be done in a parallel thread.

Parameters
trxthe transaction to preprocess
Returns
a future that will resolve to the input transaction with precomputations applied

Definition at line 926 of file db_block.cpp.

◆ precompute_parallel() [2/2]

fc::future< void > graphene::chain::database::precompute_parallel ( const signed_block block,
const uint32_t  skip = skip_nothing 
) const

Precomputes digests, signatures and operation validations depending on skip flags. "Expensive" computations may be done in a parallel thread.

Parameters
blockthe block to preprocess
skipindicates which computations can be skipped
Returns
a future that will resolve to the input block with precomputations applied

Definition at line 888 of file db_block.cpp.

◆ process_tickets()

generic_operation_result graphene::chain::database::process_tickets ( )

Definition at line 652 of file db_update.cpp.

◆ push_applied_operation()

uint32_t graphene::chain::database::push_applied_operation ( const operation op,
bool  is_virtual = true 
)

This method is used to track appied 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 is cleared after applying each block and calling the block observers which may want to index these operations.

Parameters
opThe operation to push
is_virtualWhether the operation is a virtual operation
Returns
the op_id which can be used to set the result after it has finished being applied.

Definition at line 548 of file db_block.cpp.

◆ push_block()

bool graphene::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.

Returns
true if we switched forks as a result of this push.

Definition at line 118 of file db_block.cpp.

◆ push_proposal()

processed_transaction graphene::chain::database::push_proposal ( const proposal_object proposal)
Exceptions
fc::exceptionif the proposed transaction fails to apply.

Definition at line 336 of file db_block.cpp.

◆ push_transaction()

processed_transaction graphene::chain::database::push_transaction ( const precomputable_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 270 of file db_block.cpp.

◆ reindex()

void graphene::chain::database::reindex ( fc::path  data_dir)

Rebuild object graph from block history and open detabase.

Parameters
data_dirthe path to store the database

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 55 of file db_management.cpp.

◆ revive_bitasset()

void graphene::chain::database::revive_bitasset ( const asset_object bitasset,
const asset_bitasset_data_object bad 
)

Definition at line 422 of file db_market.cpp.

◆ set_applied_operation_result()

void graphene::chain::database::set_applied_operation_result ( uint32_t  op_id,
const operation_result r 
)

Definition at line 555 of file db_block.cpp.

◆ to_pretty_string()

string graphene::chain::database::to_pretty_string ( const asset a) const

Definition at line 49 of file db_balance.cpp.

◆ update_bitasset_current_feed()

void graphene::chain::database::update_bitasset_current_feed ( const asset_bitasset_data_object bitasset,
bool  skip_median_update = false 
)

Derive asset_bitasset_data_object::current_feed from other data in the database

Parameters
bitassetThe bitasset object
skip_median_updateWhether to skip updating asset_bitasset_data_object::median_feed

Definition at line 270 of file db_update.cpp.

◆ validate_transaction()

processed_transaction graphene::chain::database::validate_transaction ( const signed_transaction trx)

This method validates transactions without adding it to the pending state.

Returns
true if the transaction would validate

Definition at line 307 of file db_block.cpp.

◆ wipe()

void graphene::chain::database::wipe ( const fc::path data_dir,
bool  include_blocks 
)

wipe Delete database from disk, and potentially the raw chain as well.

Parameters
data_dirthe path to store the database
include_blocksIf 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 165 of file db_management.cpp.

◆ witness_participation_rate()

uint32_t graphene::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 98 of file db_witness_schedule.cpp.

Member Data Documentation

◆ _current_block_num

uint32_t graphene::chain::database::_current_block_num = 0

Definition at line 800 of file database.hpp.

◆ _current_block_time

fc::time_point_sec graphene::chain::database::_current_block_time

Definition at line 799 of file database.hpp.

◆ _popped_tx

std::deque< precomputable_transaction > graphene::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 660 of file database.hpp.

◆ applied_block

fc::signal<void(const signed_block&)> graphene::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 624 of file database.hpp.

◆ changed_objects

fc::signal<void(const vector<object_id_type>&, const flat_set<account_id_type>&)> graphene::chain::database::changed_objects

Emitted After a block has been applied and committed. The callback should not yield and should execute quickly.

Definition at line 642 of file database.hpp.

◆ new_objects

fc::signal<void(const vector<object_id_type>&, const flat_set<account_id_type>&)> graphene::chain::database::new_objects

Emitted After a block has been applied and committed. The callback should not yield and should execute quickly.

Definition at line 636 of file database.hpp.

◆ on_pending_transaction

fc::signal<void(const signed_transaction&)> graphene::chain::database::on_pending_transaction

This signal is emitted any time a new transaction is added to the pending block state.

Definition at line 630 of file database.hpp.

◆ removed_objects

fc::signal<void(const vector<object_id_type>&, const vector<const object*>&, const flat_set<account_id_type>&)> graphene::chain::database::removed_objects

this signal is emitted any time an object is removed and contains a pointer to the last value of every object that was removed.

Definition at line 648 of file database.hpp.


The documentation for this class was generated from the following files: