void debug_node_plugin::on_applied_block( const chain::signed_block& b ) { if( !_debug_updates.empty() ) apply_debug_updates(); if( _json_object_stream ) { (*_json_object_stream) << "{\"bn\":" << fc::to_string( b.block_num() ) << "}\n"; } }
/** * Every time a block is produced, this method is called. This method will iterate through all * mining accounts specified by commandline and for which the private key is known. The first * account that isn't already scheduled in the mining queue is selected to mine for the * BLOCK_INTERVAL minus 1 second. If a POW is solved or a a new block comes in then the * worker will stop early. * * Work is farmed out to N threads in parallel based upon the value specified on the command line. * * The miner assumes that the next block will be produced on time and that network propagation * will take at least 1 second. This 1 second consists of the time it took to receive the block * and how long it will take to broadcast the work. In other words, we assume 0.5s broadcast times * and therefore do not even attempt work that cannot be delivered on time. */ void witness_plugin::on_applied_block( const chain::signed_block& b ) { try { if( !_mining_threads || _miners.size() == 0 ) return; chain::database& db = database(); const auto& dgp = db.get_dynamic_global_properties(); double hps = (_total_hashes*1000000)/(fc::time_point::now()-_hash_start_time).count(); int64_t bits = (dgp.num_pow_witnesses/4) + 4; fc::uint128 hashes = fc::uint128(1) << bits; hashes *= 1000000; hps += 1; hashes /= int64_t(hps*1000000); auto seconds = hashes.to_uint64(); //double seconds = hashes/hps; auto minutes = uint64_t(seconds / 60.0); if( _total_hashes > 0 ) ilog( "hash rate: ${x} hps target: ${t} queue: ${l} estimated time to produce: ${m} minutes", ("x",uint64_t(hps)) ("t",bits) ("m", minutes ) ("l",dgp.num_pow_witnesses) ); _head_block_num = b.block_num(); /// save these variables to be captured by worker lambda for( const auto& miner : _miners ) { const auto* w = db.find_witness( miner.first ); if( !w || w->pow_worker == 0 ) { auto miner_pub_key = miner.second; //a.active.key_auths.begin()->first; auto priv_key_itr = _private_keys.find(miner_pub_key); if( priv_key_itr == _private_keys.end() ) { continue; /// skipping miner for lack of private key } auto miner_priv_key = priv_key_itr->second; start_mining( miner_pub_key, priv_key_itr->second, miner.first, b ); break; } else { // ilog( "Skipping miner ${m} because it is already scheduled to produce a block", ("m",miner) ); } } // for miner in miners } catch ( const fc::exception& e ) { ilog( "exception thrown while attempting to mine" ); } }