MCPcopy Create free account
hub / github.com/Achain-Dev/Achain / delegate_loop

Method delegate_loop

src/Chain/libraries/client/Client.cpp:640–708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

638 return _wallet->delete_account(account_name);
639 }
640 void ClientImpl::delegate_loop() {
641 if (!_wallet->is_open() || _wallet->is_locked())
642 return;
643
644 vector<WalletAccountEntry> enabled_delegates = _wallet->get_my_delegates(enabled_delegate_status);
645
646 if (enabled_delegates.empty())
647 return;
648
649 const auto now = blockchain::now();
650 ilog("Starting delegate loop at time: ${t}", ("t", now));
651 _chain_db->_verify_transaction_signatures = true;
652
653 if (_delegate_loop_first_run) {
654 set_target_connections(ALP_NET_DELEGATE_DESIRED_CONNECTIONS);
655 _delegate_loop_first_run = false;
656 }
657
658 _chain_db->generating_block = false;
659 const auto next_block_time = _wallet->get_next_producible_block_timestamp(enabled_delegates);
660
661 if (next_block_time.valid()) {
662 _wallet->_generating_block = true;
663 _chain_db->generating_block = true;
664 ilog("Producing block at time: ${t}", ("t", *next_block_time));
665
666 if (*next_block_time <= now) {
667 try {
668 _delegate_config.validate();
669 FC_ASSERT(network_get_connection_count() >= _delegate_config.network_min_connection_count,
670 "Client must have ${count} connections before you may produce blocks!",
671 ("count", _delegate_config.network_min_connection_count));
672 FC_ASSERT(_wallet->is_unlocked(), "Wallet must be unlocked to produce blocks!");
673 FC_ASSERT((now - *next_block_time) < fc::seconds(ALP_BLOCKCHAIN_BLOCK_INTERVAL_SEC),
674 "You missed your slot at time: ${t}!", ("t", *next_block_time));
675 FullBlock next_block = _chain_db->generate_block(*next_block_time, _delegate_config);
676 _wallet->sign_block(next_block);
677 on_new_block(next_block, next_block.id(), false);
678 _p2p_node->broadcast(BlockMessage(next_block));
679 ilog("Produced block #${n}!", ("n", next_block.block_num));
680
681 } catch (const fc::canceled_exception&) {
682 throw;
683
684 } catch (const fc::exception& e) {
685 _exception_db.store(e);
686 }
687 }
688 }
689
690 uint32_t slot_number = blockchain::get_slot_number(now);
691 time_point_sec next_slot_time = blockchain::get_slot_start_time(slot_number + 1);
692 ilog("Rescheduling delegate loop for time: ${t}", ("t", next_slot_time));
693 time_point scheduled_time = next_slot_time;
694
695 if (blockchain::ntp_time().valid())
696 scheduled_time -= blockchain::ntp_error();
697

Callers

nothing calls this directly

Calls 15

nowFunction · 0.85
BlockMessageClass · 0.85
get_slot_numberFunction · 0.85
get_slot_start_timeFunction · 0.85
ntp_timeFunction · 0.85
ntp_errorFunction · 0.85
scheduleFunction · 0.85
get_my_delegatesMethod · 0.80
is_unlockedMethod · 0.80
secondsFunction · 0.50
is_openMethod · 0.45
is_lockedMethod · 0.45

Tested by

no test coverage detected