21 namespace blockchain_monitoring {
30 typedef std::chrono::high_resolution_clock Clock;
31 Clock::time_point _block_start_time = Clock::time_point::min();
32 Clock::duration _last_block_processing_duration = Clock::duration::zero();
36 _block_start_time = Clock::now();
41 if (_block_start_time != Clock::time_point::min())
43 _last_block_processing_duration = Clock::now() - _block_start_time;
44 _block_start_time = Clock::time_point::min();
57 return std::chrono::duration_cast<std::chrono::microseconds>(_last_block_processing_duration);
77 virtual void process_bucket_creation(
const bucket_object& bucket)
override
79 auto& db = _self.database();
84 virtual void process_block(
const bucket_object& bucket,
const signed_block& b)
override;
86 virtual void process_pre_operation(
const bucket_object& bucket,
const operation_notification& o)
override;
88 virtual void process_post_operation(
const bucket_object& bucket,
const operation_notification& o)
override;
90 template <
typename TSourceId>
91 void collect_withdraw_stats(
const bucket_object& bucket,
const asset& vesting_shares,
const TSourceId& source_id);
143 if (comment.parent_author.length())
150 if (comment.parent_author.length())
161 const auto& cv_idx = _db.get_index<comment_vote_index>().indices().get<by_comment_voter>();
163 const auto& voter = _db.account_service().get_account(op.
voter);
164 const auto itr = cv_idx.find(boost::make_tuple(comment.id, voter.id));
166 if (itr->num_changes)
168 if (comment.parent_author.size())
175 if (comment.parent_author.size())
224 const auto& account = _db.account_service().get_account(op.
from_account);
226 collect_withdraw_stats(account.id, account.scorumpower);
231 const auto& dev_pool = _db.dev_pool_service().get();
233 collect_withdraw_stats(dev_pool.id, dev_pool.sp_balance);
279 if (withdraw_scorumpower_service.is_exists(source_id))
281 const auto& wvo = withdraw_scorumpower_service.get(source_id);
282 vesting_withdraw_rate = wvo.vesting_withdraw_rate;
310 uint32_t trx_size = 0;
315 trx_size += fc::raw::pack_size(trx);
318 db.modify(bucket, [&](bucket_object& bo) {
320 bo.transactions += num_trx;
321 bo.bandwidth += trx_size;
325 void blockchain_monitoring_plugin_impl::process_pre_operation(
const bucket_object& bucket,
326 const operation_notification& note)
328 auto& db = _self.database();
332 auto comment = db.obtain_service<dbs_comment>().get(op.
author, op.
permlink);
334 db.modify(bucket, [&](bucket_object& b) {
335 if (comment.parent_author.length())
338 b.root_comments_deleted++;
342 collect_withdraw_stats(bucket, op.scorumpower, db.account_service().get_account(op.account).id);
346 collect_withdraw_stats(bucket, proposal_op.
vesting_shares, db.dev_pool_service().get().id);
351 void blockchain_monitoring_plugin_impl::process_post_operation(
const bucket_object& bucket,
352 const operation_notification& o)
354 auto& db = _self.database();
358 db.modify(bucket, [&](bucket_object& b) { b.operations++; });
360 o.op.visit(operation_process(db, bucket));
363 template <
typename TSourceId>
364 void blockchain_monitoring_plugin_impl::collect_withdraw_stats(
const bucket_object& bucket,
365 const asset& vesting_shares,
366 const TSourceId& source_id)
368 auto& db = _self.database();
371 if (vesting_shares.
amount > 0 && new_vesting_withdrawal_rate == 0)
372 new_vesting_withdrawal_rate = 1;
374 const auto& withdraw_scorumpower_service = db.obtain_service<chain::dbs_withdraw_scorumpower>();
378 if (withdraw_scorumpower_service.is_exists(source_id))
380 const auto& wvo = withdraw_scorumpower_service.get(source_id);
381 vesting_withdraw_rate = wvo.vesting_withdraw_rate;
384 db.modify(bucket, [&](bucket_object& b) {
385 if (vesting_withdraw_rate.amount > 0)
386 b.modified_vesting_withdrawal_requests++;
388 b.new_vesting_withdrawal_requests++;
390 b.vesting_withdraw_rate_delta += new_vesting_withdrawal_rate - vesting_withdraw_rate.amount;
398 , _my(new detail::blockchain_monitoring_plugin_impl(*this))
407 boost::program_options::options_description& cfg)
410 "chain-stats-bucket-size",
411 boost::program_options::value<std::string>()->default_value(
"[60,3600,21600,86400,604800,2592000]"),
412 "Track blockchain statistics by grouping orders into buckets of equal size measured in seconds specified as a "
413 "JSON array of numbers")(
414 "chain-stats-history-per-bucket", boost::program_options::value<uint32_t>()->default_value(100),
415 "How far back in time to track history for each bucket size, measured in the number of buckets (default: 100)");
423 if (options.count(
"chain-stats-bucket-size"))
425 const std::string& buckets = options[
"chain-stats-bucket-size"].as<std::string>();
426 _my->_tracked_buckets = fc::json::from_string(buckets).as<flat_set<uint32_t>>();
428 if (options.count(
"chain-stats-history-per-bucket"))
429 _my->_maximum_history_per_bucket_size = options[
"chain-stats-history-per-bucket"].as<uint32_t>();
431 ilog(
"chain-stats-bucket-size: ${b}", (
"b", _my->_tracked_buckets));
432 ilog(
"chain-stats-history-per-bucket: ${h}", (
"h", _my->_maximum_history_per_bucket_size));
436 FC_CAPTURE_AND_RETHROW()
449 return _my->_tracked_buckets;
454 return _my->_maximum_history_per_bucket_size;
459 return std::chrono::duration_cast<std::chrono::microseconds>(_my->_timer.get_last_block_duration()).count();
SCORUM_DEFINE_PLUGIN(blockchain_monitoring, scorum::blockchain_monitoring::blockchain_monitoring_plugin)
#define API_BLOCKCHAIN_STATISTICS
void register_api_factory(const std::string &name, std::function< fc::api_ptr(const api_context &)> factory)
application & app() const
virtual void plugin_initialize(const boost::program_options::variables_map &options) override
Perform early startup routines and register plugin indexes, callbacks, etc.
uint32_t get_last_block_duration_microseconds() const
uint32_t get_max_history_per_bucket() const
blockchain_monitoring_plugin(application *app)
const flat_set< uint32_t > & get_tracked_buckets() const
virtual void plugin_startup() override
Begin normal runtime operations.
virtual void plugin_set_program_options(boost::program_options::options_description &cli, boost::program_options::options_description &cfg) override
Fill in command line parameters used by the plugin.
virtual ~blockchain_monitoring_plugin()
blockchain_monitoring_plugin_impl(blockchain_monitoring_plugin &plugin)
virtual ~blockchain_monitoring_plugin_impl()
void operator()(const vote_operation &op) const
void operator()(const transfer_to_scorumpower_operation &op) const
void operator()(const acc_to_devpool_vesting_withdraw_operation &op) const
void operator()(const proposal_virtual_operation &op) const
void operator()(const devpool_finished_vesting_withdraw_operation &) const
void operator()(const witness_miss_block_operation &op) const
void operator()(const curation_reward_operation &op) const
void operator()(const account_create_by_committee_operation &op) const
void operator()(const devpool_to_devpool_vesting_withdraw_operation &op) const
void operator()(const transfer_operation &op) const
void operator()(const account_create_with_delegation_operation &op) const
void operator()(const author_reward_operation &op) const
void operator()(const T &) const
void operator()(const account_create_operation &op) const
void operator()(const devpool_to_acc_vesting_withdraw_operation &op) const
operation_process(chain::database &db, const bucket_object &b)
void collect_withdraw_stats(const TSourceId &source_id, const asset &source_sp) const
void operator()(const acc_finished_vesting_withdraw_operation &op) const
void operator()(const comment_operation &op) const
void operator()(const acc_to_acc_vesting_withdraw_operation &op) const
void collect_withdraw_stats(const asset &withdrawn) const
std::chrono::microseconds get_last_block_duration() const
perfomance_timer(chain::database &db)
tracks the blockchain state in an extensible manner
time_point_sec head_block_time() const
fc::signal< void(const signed_block &)> applied_block
fc::signal< void(const signed_block &)> pre_applied_block
ConcreteService & obtain_service() const
#define SCORUM_VESTING_WITHDRAW_INTERVALS
bool is_virtual_operation(const operation &op)
#define API_NODE_MONITORING
uint32_t transfers
Account/devpool to account transfers.
share_type vesting_withdraw_rate_delta
uint32_t changed_reply_votes
Changed votes on replies.
share_type scorumpower_paid_to_authors
Amount of SP paid to authors.
uint32_t reply_edits
Edits to replies.
uint32_t root_comment_edits
Edits to root comments.
uint32_t vesting_withdrawals_processed
Number of vesting withdrawals.
uint32_t transfers_to_scorumpower
Transfers of SCR into SP.
uint32_t replies
Replies to comments.
uint32_t new_root_votes
New votes on root comments.
uint32_t free_accounts_created
Accounts created with fee.
uint32_t new_reply_votes
New votes on replies.
uint32_t blocks
Blocks produced.
uint32_t finished_vesting_withdrawals
Processed vesting withdrawals that are now finished.
share_type scr_paid_to_curators
Amount of SCR paid to curators.
uint32_t paid_accounts_created
Accounts created with fee.
share_type scorumpower_withdrawn
Amount of SP withdrawn to SCR.
uint32_t root_comments
Top level root comments.
share_type scorumpower_transferred
Amount of SP transferred to another account.
share_type scorum_transferred
SCR transferred from account to account.
share_type scorum_transferred_to_scorumpower
Amount of SCR vested.
share_type scorumpower_paid_to_curators
Amount of SP paid to curators.
share_type scr_paid_to_authors
Amount of SCR paid to authors.
uint32_t changed_root_votes
Changed votes on root comments.
uint32_t payouts
Number of comment payouts.
fc::shared_map< uint32_t, account_name_type > missed_blocks
map missed block to witness which missed
account_name_type from_account
Creates new account by registration committee.
Creates new account with delegation.
asset_symbol_type symbol() const
asset reward
all reward for comment author (with from_children_payout)
protocol::proposal_operation proposal_op
std::vector< signed_transaction > transactions
Transfers SCR from one account to another.
asset amount
The amount of asset to transfer from from to to.