Scorum
Public Member Functions | Public Attributes | List of all members
scorum::app::detail::application_impl Class Reference
Inheritance diagram for scorum::app::detail::application_impl:

Public Member Functions

void reset_p2p_node (const fc::path &data_dir)
 
std::vector< fc::ip::endpoint > resolve_string_to_ip_endpoints (const std::string &endpoint_string)
 
void reset_websocket_server ()
 
void reset_websocket_tls_server ()
 
void on_connection (const fc::http::websocket_connection_ptr &c)
 
 application_impl (application *self, std::shared_ptr< chain::database > chain_db)
 
 ~application_impl ()
 
void register_builtin_apis ()
 
void compute_genesis_state (scorum::chain::genesis_state_type &genesis_state)
 
void startup ()
 
optional< api_access_infoget_api_access_info (const std::string &username) const
 
void set_api_access_info (const std::string &username, api_access_info &&permissions)
 
void register_api_factory (const std::string &name, std::function< fc::api_ptr(const api_context &)> factory)
 
fc::api_ptr create_api_by_name (const api_context &ctx)
 
virtual bool has_item (const graphene::net::item_id &id) override
 
virtual bool handle_block (const graphene::net::block_message &blk_msg, bool sync_mode, std::vector< fc::uint160_t > &contained_transaction_message_ids) override
 allows the application to validate an item prior to broadcasting to peers. More...
 
virtual void handle_transaction (const graphene::net::trx_message &transaction_message) override
 
virtual void handle_message (const message &message_to_process) override
 
bool is_included_block (const block_id_type &block_id)
 
virtual std::vector< item_hash_t > get_block_ids (const std::vector< item_hash_t > &blockchain_synopsis, uint32_t &remaining_item_count, uint32_t limit) override
 
virtual message get_item (const item_id &id) override
 
virtual chain_id_type get_chain_id () const override
 
virtual std::vector< item_hash_t > get_blockchain_synopsis (const item_hash_t &reference_point, uint32_t number_of_blocks_after_reference_point) override
 
virtual void sync_status (uint32_t item_type, uint32_t item_count) override
 
virtual void connection_count_changed (uint32_t c) override
 
virtual uint32_t get_block_number (const item_hash_t &block_id) override
 
virtual fc::time_point_sec get_block_time (const item_hash_t &block_id) override
 
virtual fc::time_point_sec get_blockchain_now () override
 
virtual item_hash_t get_head_block_id () const override
 
virtual uint32_t estimate_last_known_fork_from_git_revision_timestamp (uint32_t unix_timestamp) const override
 
virtual void error_encountered (const std::string &message, const fc::oexception &error) override
 
void get_max_block_age (int32_t &result)
 
void shutdown ()
 
template<typename API >
fc::api< API > create_write_node_api (const std::string &api_name)
 

Public Attributes

fc::optional< fc::temp_file > _lock_file
 
bool _is_block_producer = false
 
bool _force_validate = false
 
application_self
 
fc::path _data_dir
 
fc::path _shared_dir
 
const bpo::variables_map * _options = nullptr
 
api_access _apiaccess
 
std::shared_ptr< scorum::chain::database_chain_db
 
std::shared_ptr< graphene::net::node > _p2p_network
 
std::shared_ptr< fc::http::websocket_server > _websocket_server
 
std::shared_ptr< fc::http::websocket_tls_server > _websocket_tls_server
 
const plugin_names_type _plugins_locked_in_readonly_mode = { "witness", "debug_node" }
 
plugins_type _plugins_available
 
plugins_type _plugins_enabled
 
flat_map< std::string, std::function< fc::api_ptr(const api_context &)> > _api_factories_by_name
 
std::vector< std::string > _public_apis
 
int32_t _max_block_age = -1
 
uint64_t _shared_file_size
 
bool _running
 
uint32_t allow_future_time = 5
 

Detailed Description

Definition at line 108 of file application.cpp.

Constructor & Destructor Documentation

◆ application_impl()

scorum::app::detail::application_impl::application_impl ( application self,
std::shared_ptr< chain::database chain_db 
)
inline

Definition at line 282 of file application.cpp.

◆ ~application_impl()

scorum::app::detail::application_impl::~application_impl ( )
inline

Definition at line 288 of file application.cpp.

Member Function Documentation

◆ compute_genesis_state()

void scorum::app::detail::application_impl::compute_genesis_state ( scorum::chain::genesis_state_type genesis_state)
inline

Definition at line 303 of file application.cpp.

◆ connection_count_changed()

virtual void scorum::app::detail::application_impl::connection_count_changed ( uint32_t  c)
inlineoverridevirtual

Call any time the number of connected peers changes.

Definition at line 989 of file application.cpp.

◆ create_api_by_name()

fc::api_ptr scorum::app::detail::application_impl::create_api_by_name ( const api_context ctx)
inline

Definition at line 510 of file application.cpp.

◆ create_write_node_api()

template<typename API >
fc::api<API> scorum::app::detail::application_impl::create_write_node_api ( const std::string &  api_name)
inline

Definition at line 1066 of file application.cpp.

◆ error_encountered()

virtual void scorum::app::detail::application_impl::error_encountered ( const std::string &  message,
const fc::oexception &  error 
)
inlineoverridevirtual

Definition at line 1039 of file application.cpp.

◆ estimate_last_known_fork_from_git_revision_timestamp()

virtual uint32_t scorum::app::detail::application_impl::estimate_last_known_fork_from_git_revision_timestamp ( uint32_t  unix_timestamp) const
inlineoverridevirtual

Definition at line 1034 of file application.cpp.

◆ get_api_access_info()

optional<api_access_info> scorum::app::detail::application_impl::get_api_access_info ( const std::string &  username) const
inline

Definition at line 485 of file application.cpp.

◆ get_block_ids()

virtual std::vector<item_hash_t> scorum::app::detail::application_impl::get_block_ids ( const std::vector< item_hash_t > &  blockchain_synopsis,
uint32_t &  remaining_item_count,
uint32_t  limit 
)
inlineoverridevirtual

Assuming all data elements are ordered in some way, this method should return up to limit ids that occur after the last ID in synopsis that we recognize.

On return, remaining_item_count will be set to the number of items in our blockchain after the last item returned in the result, or 0 if the result contains the last item in the blockchain

Definition at line 673 of file application.cpp.

◆ get_block_number()

virtual uint32_t scorum::app::detail::application_impl::get_block_number ( const item_hash_t &  block_id)
inlineoverridevirtual

Definition at line 994 of file application.cpp.

◆ get_block_time()

virtual fc::time_point_sec scorum::app::detail::application_impl::get_block_time ( const item_hash_t &  block_id)
inlineoverridevirtual

Returns the time a block was produced (if block_id = 0, returns genesis time). If we don't know about the block, returns time_point_sec::min()

Definition at line 1007 of file application.cpp.

◆ get_blockchain_now()

virtual fc::time_point_sec scorum::app::detail::application_impl::get_blockchain_now ( )
inlineoverridevirtual

returns fc::time_point::now();

Definition at line 1024 of file application.cpp.

◆ get_blockchain_synopsis()

virtual std::vector<item_hash_t> scorum::app::detail::application_impl::get_blockchain_synopsis ( const item_hash_t &  reference_point,
uint32_t  number_of_blocks_after_reference_point 
)
inlineoverridevirtual

Returns a synopsis of the blockchain used for syncing. This consists of a list of block hashes at intervals exponentially increasing towards the genesis block. When syncing to a peer, the peer uses this data to determine if we're on the same fork as they are, and if not, what blocks they need to send us to get us on their fork.

In the over-simplified case, this is a straighforward synopsis of our current preferred blockchain; when we first connect up to a peer, this is what we will be sending. It looks like this: If the blockchain is empty, it will return the empty list. If the blockchain has one block, it will return a list containing just that block. If it contains more than one block: the first element in the list will be the hash of the highest numbered block that we cannot undo the second element will be the hash of an item at the half way point in the undoable segment of the blockchain the third will be ~3/4 of the way through the undoable segment of the block chain the fourth will be at ~7/8... &c. the last item in the list will be the hash of the most recent block on our preferred chain so if the blockchain had 26 blocks labeled a - z, the synopsis would be: a n u x z the idea being that by sending a small (<30) number of block ids, we can summarize a huge blockchain. The block ids are more dense near the end of the chain where because we are more likely to be almost in sync when we first connect, and forks are likely to be short. If the peer we're syncing with in our example is on a fork that started at block 'v', then they will reply to our synopsis with a list of all blocks starting from block 'u', the last block they know that we had in common.

In the real code, there are several complications.

First, as an optimization, we don't usually send a synopsis of the entire blockchain, we send a synopsis of only the segment of the blockchain that we have undo data for. If their fork doesn't build off of something in our undo history, we would be unable to switch, so there's no reason to fetch the blocks.

Second, when a peer replies to our initial synopsis and gives us a list of the blocks they think we are missing, they only send a chunk of a few thousand blocks at once. After we get those block ids, we need to request more blocks by sending another synopsis (we can't just say "send me the next 2000 ids" because they may have switched forks themselves and they don't track what they've sent us). For faster performance, we want to get a fairly long list of block ids first, then start downloading the blocks. The peer doesn't handle these follow-up block id requests any different from the initial request; it treats the synopsis we send as our blockchain and bases its response entirely off that. So to get the response we want (the next chunk of block ids following the last one they sent us, or, failing that, the shortest fork off of the last list of block ids they sent), we need to construct a synopsis as if our blockchain was made up of:

  1. the blocks in our block chain up to the fork point (if there is a fork) or the head block (if no fork)
  2. the blocks we've already pushed from their fork (if there's a fork)
  3. the block ids they've previously sent us Segment 3 is handled in the p2p code, it just tells us the number of blocks it has (in number_of_blocks_after_reference_point) so we can leave space in the synopsis for them. We're responsible for constructing the synopsis of Segments 1 and 2 from our active blockchain and fork database. The reference_point parameter is the last block from that peer that has been successfully pushed to the blockchain, so that tells us whether the peer is on a fork or on the main chain.

Definition at line 829 of file application.cpp.

◆ get_chain_id()

virtual chain_id_type scorum::app::detail::application_impl::get_chain_id ( ) const
inlineoverridevirtual

Definition at line 766 of file application.cpp.

◆ get_head_block_id()

virtual item_hash_t scorum::app::detail::application_impl::get_head_block_id ( ) const
inlineoverridevirtual

Definition at line 1029 of file application.cpp.

◆ get_item()

virtual message scorum::app::detail::application_impl::get_item ( const item_id &  id)
inlineoverridevirtual

Given the hash of the requested data, fetch the body.

Definition at line 742 of file application.cpp.

◆ get_max_block_age()

void scorum::app::detail::application_impl::get_max_block_age ( int32_t &  result)
inline

Definition at line 1044 of file application.cpp.

◆ handle_block()

virtual bool scorum::app::detail::application_impl::handle_block ( const graphene::net::block_message &  blk_msg,
bool  sync_mode,
std::vector< fc::uint160_t > &  contained_transaction_message_ids 
)
inlineoverridevirtual

allows the application to validate an item prior to broadcasting to peers.

Parameters
sync_modetrue if the message was fetched through the sync process, false during normal operation
Returns
true if this message caused the blockchain to switch forks, false if it did not
Exceptions
exceptionif error validating the item, otherwise the item is safe to broadcast on.

Definition at line 556 of file application.cpp.

◆ handle_message()

virtual void scorum::app::detail::application_impl::handle_message ( const message &  message_to_process)
inlineoverridevirtual

Definition at line 649 of file application.cpp.

◆ handle_transaction()

virtual void scorum::app::detail::application_impl::handle_transaction ( const graphene::net::trx_message &  transaction_message)
inlineoverridevirtual

Definition at line 637 of file application.cpp.

◆ has_item()

virtual bool scorum::app::detail::application_impl::has_item ( const graphene::net::item_id &  id)
inlineoverridevirtual

If delegate has the item, the network has no need to fetch it.

Definition at line 524 of file application.cpp.

◆ is_included_block()

bool scorum::app::detail::application_impl::is_included_block ( const block_id_type block_id)
inline

Definition at line 655 of file application.cpp.

◆ on_connection()

void scorum::app::detail::application_impl::on_connection ( const fc::http::websocket_connection_ptr &  c)
inline

Definition at line 262 of file application.cpp.

◆ register_api_factory()

void scorum::app::detail::application_impl::register_api_factory ( const std::string &  name,
std::function< fc::api_ptr(const api_context &)>  factory 
)
inline

Definition at line 505 of file application.cpp.

◆ register_builtin_apis()

void scorum::app::detail::application_impl::register_builtin_apis ( )
inline

Definition at line 292 of file application.cpp.

◆ reset_p2p_node()

void scorum::app::detail::application_impl::reset_p2p_node ( const fc::path &  data_dir)
inline

Definition at line 115 of file application.cpp.

◆ reset_websocket_server()

void scorum::app::detail::application_impl::reset_websocket_server ( )
inline

Definition at line 209 of file application.cpp.

◆ reset_websocket_tls_server()

void scorum::app::detail::application_impl::reset_websocket_tls_server ( )
inline

Definition at line 231 of file application.cpp.

◆ resolve_string_to_ip_endpoints()

std::vector<fc::ip::endpoint> scorum::app::detail::application_impl::resolve_string_to_ip_endpoints ( const std::string &  endpoint_string)
inline

Definition at line 181 of file application.cpp.

◆ set_api_access_info()

void scorum::app::detail::application_impl::set_api_access_info ( const std::string &  username,
api_access_info &&  permissions 
)
inline

Definition at line 500 of file application.cpp.

◆ shutdown()

void scorum::app::detail::application_impl::shutdown ( )
inline

Definition at line 1050 of file application.cpp.

◆ startup()

void scorum::app::detail::application_impl::startup ( )
inline

Definition at line 324 of file application.cpp.

◆ sync_status()

virtual void scorum::app::detail::application_impl::sync_status ( uint32_t  item_type,
uint32_t  item_count 
)
inlineoverridevirtual

Call this after the call to handle_message succeeds.

Parameters
item_typethe type of the item we're synchronizing, will be the same as item passed to the sync_from() call
item_countthe number of items known to the node that haven't been sent to handle_item() yet. After item_count more calls to handle_item(), the node will be in sync

Definition at line 981 of file application.cpp.

Member Data Documentation

◆ _api_factories_by_name

flat_map<std::string, std::function<fc::api_ptr(const api_context&)> > scorum::app::detail::application_impl::_api_factories_by_name

Definition at line 1096 of file application.cpp.

◆ _apiaccess

api_access scorum::app::detail::application_impl::_apiaccess

Definition at line 1083 of file application.cpp.

◆ _chain_db

std::shared_ptr<scorum::chain::database> scorum::app::detail::application_impl::_chain_db

Definition at line 1085 of file application.cpp.

◆ _data_dir

fc::path scorum::app::detail::application_impl::_data_dir

Definition at line 1080 of file application.cpp.

◆ _force_validate

bool scorum::app::detail::application_impl::_force_validate = false

Definition at line 113 of file application.cpp.

◆ _is_block_producer

bool scorum::app::detail::application_impl::_is_block_producer = false

Definition at line 112 of file application.cpp.

◆ _lock_file

fc::optional<fc::temp_file> scorum::app::detail::application_impl::_lock_file

Definition at line 111 of file application.cpp.

◆ _max_block_age

int32_t scorum::app::detail::application_impl::_max_block_age = -1

Definition at line 1098 of file application.cpp.

◆ _options

const bpo::variables_map* scorum::app::detail::application_impl::_options = nullptr

Definition at line 1082 of file application.cpp.

◆ _p2p_network

std::shared_ptr<graphene::net::node> scorum::app::detail::application_impl::_p2p_network

Definition at line 1086 of file application.cpp.

◆ _plugins_available

plugins_type scorum::app::detail::application_impl::_plugins_available

Definition at line 1094 of file application.cpp.

◆ _plugins_enabled

plugins_type scorum::app::detail::application_impl::_plugins_enabled

Definition at line 1095 of file application.cpp.

◆ _plugins_locked_in_readonly_mode

const plugin_names_type scorum::app::detail::application_impl::_plugins_locked_in_readonly_mode = { "witness", "debug_node" }

Definition at line 1092 of file application.cpp.

◆ _public_apis

std::vector<std::string> scorum::app::detail::application_impl::_public_apis

Definition at line 1097 of file application.cpp.

◆ _running

bool scorum::app::detail::application_impl::_running

Definition at line 1101 of file application.cpp.

◆ _self

application* scorum::app::detail::application_impl::_self

Definition at line 1078 of file application.cpp.

◆ _shared_dir

fc::path scorum::app::detail::application_impl::_shared_dir

Definition at line 1081 of file application.cpp.

◆ _shared_file_size

uint64_t scorum::app::detail::application_impl::_shared_file_size

Definition at line 1099 of file application.cpp.

◆ _websocket_server

std::shared_ptr<fc::http::websocket_server> scorum::app::detail::application_impl::_websocket_server

Definition at line 1087 of file application.cpp.

◆ _websocket_tls_server

std::shared_ptr<fc::http::websocket_tls_server> scorum::app::detail::application_impl::_websocket_tls_server

Definition at line 1088 of file application.cpp.

◆ allow_future_time

uint32_t scorum::app::detail::application_impl::allow_future_time = 5

Definition at line 1103 of file application.cpp.


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