BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
Public Member Functions | Public Attributes | Friends | List of all members
graphene::app::detail::application_impl Class Reference

#include <application_impl.hxx>

Inheritance diagram for graphene::app::detail::application_impl:
graphene::net::node_delegate

Public Member Functions

void reset_p2p_node (const fc::path &data_dir)
 
void new_connection (const fc::http::websocket_connection_ptr &c)
 
void reset_websocket_server ()
 
void reset_websocket_tls_server ()
 
 application_impl (application &self)
 
virtual ~application_impl ()
 
void set_block_production (bool producing_blocks)
 
void set_api_limit ()
 
void initialize (const fc::path &data_dir, std::shared_ptr< boost::program_options::variables_map > options)
 
void startup ()
 
fc::optional< api_access_infoget_api_access_info (const string &username) const
 
void set_api_access_info (const string &username, api_access_info &&permissions)
 
bool has_item (const net::item_id &id) override
 
bool handle_block (const graphene::net::block_message &blk_msg, bool sync_mode, std::vector< graphene::net::message_hash_type > &contained_transaction_msg_ids) override
 allows the application to validate an item prior to broadcasting to peers. More...
 
void handle_transaction (const graphene::net::trx_message &transaction_message) override
 Called when a new transaction comes in from the network. More...
 
void handle_message (const graphene::net::message &message_to_process) override
 Called when a new message comes in from the network other than a block or a transaction. Currently there are no other possible messages, so this should never be called. More...
 
bool is_included_block (const graphene::chain::block_id_type &block_id)
 
std::vector< graphene::net::item_hash_tget_block_ids (const std::vector< graphene::net::item_hash_t > &blockchain_synopsis, uint32_t &remaining_item_count, uint32_t limit) override
 
graphene::net::message get_item (const graphene::net::item_id &id) override
 
graphene::chain::chain_id_type get_chain_id () const override
 
std::vector< graphene::net::item_hash_tget_blockchain_synopsis (const graphene::net::item_hash_t &reference_point, uint32_t number_of_blocks_after_reference_point) override
 
void sync_status (uint32_t item_type, uint32_t item_count) override
 
void connection_count_changed (uint32_t c) override
 
uint32_t get_block_number (const graphene::net::item_hash_t &block_id) override
 
fc::time_point_sec get_block_time (const graphene::net::item_hash_t &block_id) override
 
graphene::net::item_hash_t get_head_block_id () const override
 
uint32_t estimate_last_known_fork_from_git_revision_timestamp (uint32_t unix_timestamp) const override
 
void error_encountered (const std::string &message, const fc::oexception &error) override
 
uint8_t get_current_block_interval_in_seconds () const override
 
void add_available_plugin (std::shared_ptr< abstract_plugin > p)
 Add an available plugin. More...
 
void enable_plugin (const string &name)
 Enables a plugin. More...
 
bool is_plugin_enabled (const string &name) const
 Returns whether a plugin is enabled. More...
 
- Public Member Functions inherited from graphene::net::node_delegate
virtual ~node_delegate ()=default
 
virtual bool handle_block (const graphene::net::block_message &blk_msg, bool sync_mode, std::vector< message_hash_type > &contained_transaction_msg_ids)=0
 Called when a new block comes in from the network. More...
 
virtual std::vector< item_hash_tget_block_ids (const std::vector< item_hash_t > &blockchain_synopsis, uint32_t &remaining_item_count, uint32_t limit=2000)=0
 

Public Attributes

fc::optional< fc::temp_file_lock_file
 
bool _is_block_producer = false
 
bool _force_validate = false
 
application_options _app_options
 

Friends

class graphene::app::application
 

Detailed Description

Definition at line 15 of file application_impl.hxx.

Constructor & Destructor Documentation

◆ application_impl()

graphene::app::detail::application_impl::application_impl ( application self)
inlineexplicit

Definition at line 31 of file application_impl.hxx.

◆ ~application_impl()

graphene::app::detail::application_impl::~application_impl ( )
virtual

Definition at line 117 of file application.cpp.

Member Function Documentation

◆ add_available_plugin()

void graphene::app::detail::application_impl::add_available_plugin ( std::shared_ptr< abstract_plugin p)

Add an available plugin.

Definition at line 1147 of file application.cpp.

◆ connection_count_changed()

void graphene::app::detail::application_impl::connection_count_changed ( uint32_t  c)
overridevirtual

Call any time the number of connected peers changes.

Implements graphene::net::node_delegate.

Definition at line 1036 of file application.cpp.

◆ enable_plugin()

void graphene::app::detail::application_impl::enable_plugin ( const string &  name)

Enables a plugin.

Definition at line 1111 of file application.cpp.

◆ error_encountered()

void graphene::app::detail::application_impl::error_encountered ( const std::string &  message,
const fc::oexception error 
)
overridevirtual

Implements graphene::net::node_delegate.

Definition at line 1067 of file application.cpp.

◆ estimate_last_known_fork_from_git_revision_timestamp()

uint32_t graphene::app::detail::application_impl::estimate_last_known_fork_from_git_revision_timestamp ( uint32_t  unix_timestamp) const
overridevirtual

Implements graphene::net::node_delegate.

Definition at line 1062 of file application.cpp.

◆ get_api_access_info()

optional< api_access_info > graphene::app::detail::application_impl::get_api_access_info ( const string &  username) const

Definition at line 614 of file application.cpp.

◆ get_block_ids()

std::vector< item_hash_t > graphene::app::detail::application_impl::get_block_ids ( const std::vector< graphene::net::item_hash_t > &  blockchain_synopsis,
uint32_t &  remaining_item_count,
uint32_t  limit 
)
override

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 771 of file application.cpp.

◆ get_block_number()

uint32_t graphene::app::detail::application_impl::get_block_number ( const graphene::net::item_hash_t block_id)
overridevirtual

Implements graphene::net::node_delegate.

Definition at line 1041 of file application.cpp.

◆ get_block_time()

fc::time_point_sec graphene::app::detail::application_impl::get_block_time ( const graphene::net::item_hash_t block_id)
overridevirtual

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()

Implements graphene::net::node_delegate.

Definition at line 1050 of file application.cpp.

◆ get_blockchain_synopsis()

std::vector< item_hash_t > graphene::app::detail::application_impl::get_blockchain_synopsis ( const graphene::net::item_hash_t reference_point,
uint32_t  number_of_blocks_after_reference_point 
)
overridevirtual

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.

Implements graphene::net::node_delegate.

Definition at line 901 of file application.cpp.

◆ get_chain_id()

chain_id_type graphene::app::detail::application_impl::get_chain_id ( ) const
overridevirtual

Implements graphene::net::node_delegate.

Definition at line 838 of file application.cpp.

◆ get_current_block_interval_in_seconds()

uint8_t graphene::app::detail::application_impl::get_current_block_interval_in_seconds ( ) const
overridevirtual

Implements graphene::net::node_delegate.

Definition at line 1072 of file application.cpp.

◆ get_head_block_id()

item_hash_t graphene::app::detail::application_impl::get_head_block_id ( ) const
overridevirtual

Implements graphene::net::node_delegate.

Definition at line 1057 of file application.cpp.

◆ get_item()

message graphene::app::detail::application_impl::get_item ( const graphene::net::item_id id)
overridevirtual

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

Implements graphene::net::node_delegate.

Definition at line 822 of file application.cpp.

◆ handle_block()

bool graphene::app::detail::application_impl::handle_block ( const graphene::net::block_message blk_msg,
bool  sync_mode,
std::vector< graphene::net::message_hash_type > &  contained_transaction_msg_ids 
)
override

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

Parameters
blk_msgthe message which contains the block
sync_modetrue if the message was fetched through the sync process, false during normal operation
contained_transaction_msg_idscontainer for the transactions to write back into
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 660 of file application.cpp.

◆ handle_message()

void graphene::app::detail::application_impl::handle_message ( const graphene::net::message message_to_process)
overridevirtual

Called when a new message comes in from the network other than a block or a transaction. Currently there are no other possible messages, so this should never be called.

Exceptions
exceptionif error validating the item, otherwise the item is safe to broadcast on.

Implements graphene::net::node_delegate.

Definition at line 749 of file application.cpp.

◆ handle_transaction()

void graphene::app::detail::application_impl::handle_transaction ( const graphene::net::trx_message trx_msg)
overridevirtual

Called when a new transaction comes in from the network.

Exceptions
exceptionif error validating the item, otherwise the item is safe to broadcast on.

Implements graphene::net::node_delegate.

Definition at line 733 of file application.cpp.

◆ has_item()

bool graphene::app::detail::application_impl::has_item ( const net::item_id id)
overridevirtual

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

Implements graphene::net::node_delegate.

Definition at line 640 of file application.cpp.

◆ initialize()

void graphene::app::detail::application_impl::initialize ( const fc::path data_dir,
std::shared_ptr< boost::program_options::variables_map >  options 
)

Definition at line 264 of file application.cpp.

◆ is_included_block()

bool graphene::app::detail::application_impl::is_included_block ( const graphene::chain::block_id_type block_id)

Definition at line 755 of file application.cpp.

◆ is_plugin_enabled()

bool graphene::app::detail::application_impl::is_plugin_enabled ( const string &  name) const

Returns whether a plugin is enabled.

Definition at line 632 of file application.cpp.

◆ new_connection()

void graphene::app::detail::application_impl::new_connection ( const fc::http::websocket_connection_ptr c)

Definition at line 188 of file application.cpp.

◆ reset_p2p_node()

void graphene::app::detail::application_impl::reset_p2p_node ( const fc::path data_dir)

Definition at line 122 of file application.cpp.

◆ reset_websocket_server()

void graphene::app::detail::application_impl::reset_websocket_server ( )

Definition at line 222 of file application.cpp.

◆ reset_websocket_tls_server()

void graphene::app::detail::application_impl::reset_websocket_tls_server ( )

Definition at line 239 of file application.cpp.

◆ set_api_access_info()

void graphene::app::detail::application_impl::set_api_access_info ( const string &  username,
api_access_info &&  permissions 
)

Definition at line 627 of file application.cpp.

◆ set_api_limit()

void graphene::app::detail::application_impl::set_api_limit ( )

Definition at line 328 of file application.cpp.

◆ set_block_production()

void graphene::app::detail::application_impl::set_block_production ( bool  producing_blocks)

Definition at line 1152 of file application.cpp.

◆ startup()

void graphene::app::detail::application_impl::startup ( )

Definition at line 597 of file application.cpp.

◆ sync_status()

void graphene::app::detail::application_impl::sync_status ( uint32_t  item_type,
uint32_t  item_count 
)
overridevirtual

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

Implements graphene::net::node_delegate.

Definition at line 1028 of file application.cpp.

Friends And Related Function Documentation

◆ graphene::app::application

friend class graphene::app::application
friend

Definition at line 209 of file application_impl.hxx.

Member Data Documentation

◆ _app_options

application_options graphene::app::detail::application_impl::_app_options

Definition at line 21 of file application_impl.hxx.

◆ _force_validate

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

Definition at line 20 of file application_impl.hxx.

◆ _is_block_producer

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

Definition at line 19 of file application_impl.hxx.

◆ _lock_file

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

Definition at line 18 of file application_impl.hxx.


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