Pulse: Make active snodes info public, disambiguate next_block_template

- Make active snods info public for Pulse to query the list to allow
  Pulse quorums to be generated outside of the Service Node List.
This commit is contained in:
Doyle 2020-07-15 16:05:15 +10:00
parent 2894296556
commit a6e1f82f7a
12 changed files with 23 additions and 13 deletions

View File

@ -123,7 +123,7 @@ namespace cryptonote
extra_nonce = m_extra_messages[m_config.current_extra_message_index];
}
if(!m_phandler->get_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce))
if(!m_phandler->get_next_block_template(bl, m_mine_address, di, height, expected_reward, extra_nonce))
{
LOG_ERROR("Failed to get_block_template(), stopping mining");
return false;

View File

@ -50,7 +50,7 @@ namespace cryptonote
struct i_miner_handler
{
virtual bool handle_block_found(block& b, block_verification_context &bvc) = 0;
virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce) = 0;
virtual bool get_next_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce) = 0;
protected:
~i_miner_handler(){};
};
@ -84,7 +84,6 @@ namespace cryptonote
void do_print_hashrate(bool do_hr);
uint64_t get_block_reward() const { return m_block_reward; }
#if defined(LOKI_ENABLE_INTEGRATION_TEST_HOOKS)
std::atomic<bool> m_debug_mine_singular_block;
bool debug_mine_singular_block(const account_public_address& adr)
{
@ -93,7 +92,6 @@ namespace cryptonote
while(is_mining()) { }
return result;
}
#endif
private:
bool worker_thread(bool slow_mining = false);

View File

@ -1685,7 +1685,7 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
return false;
}
//------------------------------------------------------------------
bool Blockchain::create_block_template(block& b, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce)
bool Blockchain::create_next_block_template(block& b, const account_public_address& miner_address, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce)
{
return create_block_template(b, NULL, miner_address, diffic, height, expected_reward, ex_nonce);
}

View File

@ -355,7 +355,7 @@ namespace cryptonote
*
* @return true if block template filled in successfully, else false
*/
bool create_block_template(block& b, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce);
bool create_next_block_template(block& b, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce);
bool create_block_template(block& b, const crypto::hash *from_block, const account_public_address& miner_address, difficulty_type& di, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce);
/**

View File

@ -1914,9 +1914,9 @@ namespace cryptonote
m_quorum_cop.set_votes_relayed(votes);
}
//-----------------------------------------------------------------------------------------------
bool core::get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce)
bool core::get_next_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce)
{
return m_blockchain_storage.create_block_template(b, adr, diffic, height, expected_reward, ex_nonce);
return m_blockchain_storage.create_next_block_template(b, adr, diffic, height, expected_reward, ex_nonce);
}
//-----------------------------------------------------------------------------------------------
bool core::get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce)

View File

@ -359,7 +359,7 @@ namespace cryptonote
*
* @note see Blockchain::create_block_template
*/
virtual bool get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce);
virtual bool get_next_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce);
virtual bool get_block_template(block& b, const crypto::hash *prev_block, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, uint64_t& expected_reward, const blobdata& ex_nonce);
/**

View File

@ -1684,7 +1684,7 @@ namespace service_nodes
if (hf_version >= cryptonote::network_version_16)
{
quorum pulse_quorum = generate_pulse_quorum(nettype, db, height + 1, winner_pubkey, hf_version, active_service_nodes_infos(), block.pulse.round);
if (pulse_quorum.workers.size() == 1 && pulse_quorum.validators.size() == PULSE_QUORUM_NUM_VALIDATORS)
if (verify_pulse_quorum_sizes(pulse_quorum))
{
// NOTE: Send candidate to the back of the list
for (size_t quorum_index = 0 ; quorum_index < pulse_quorum.validators.size(); quorum_index++)

View File

@ -423,6 +423,10 @@ namespace service_nodes
}
}
std::vector<pubkey_and_sninfo> active_service_nodes_infos() const {
return m_state.active_service_nodes_infos();
}
void set_my_service_node_keys(const service_node_keys *keys);
void set_quorum_history_storage(uint64_t hist_size); // 0 = none (default), 1 = unlimited, N = # of blocks
bool store();

View File

@ -6,7 +6,7 @@
namespace service_nodes {
constexpr size_t PULSE_QUORUM_ENTROPY_LAG = 21; // How many blocks back from the tip of the Blockchain to source entropy for the Pulse quorums.
constexpr size_t PULSE_QUORUM_NUM_VALIDATORS = 11;
constexpr size_t PULSE_QUORUM_NUM_VALIDATORS = 0;
constexpr size_t PULSE_QUORUM_SIZE = PULSE_QUORUM_NUM_VALIDATORS + 1 /*Leader*/;
constexpr size_t pulse_min_service_nodes(cryptonote::network_type nettype)
@ -24,7 +24,7 @@ namespace service_nodes {
return result;
}
constexpr size_t PULSE_BLOCK_REQUIRED_SIGNATURES = 7; // A block must have exactly N signatures to be considered properly
constexpr size_t PULSE_BLOCK_REQUIRED_SIGNATURES = 0; // A block must have exactly N signatures to be considered properly
static_assert(PULSE_QUORUM_NUM_VALIDATORS >= PULSE_BLOCK_REQUIRED_SIGNATURES);
static_assert(PULSE_QUORUM_ENTROPY_LAG >= PULSE_QUORUM_SIZE, "We need to pull atleast PULSE_QUORUM_SIZE number of blocks from the Blockchain, we can't if the amount of blocks to go back from the tip of the Blockchain is less than the blocks we need.");

View File

@ -340,6 +340,12 @@ namespace service_nodes
return true;
}
bool verify_pulse_quorum_sizes(service_nodes::quorum const &quorum)
{
bool result = quorum.workers.size() == 1 && quorum.validators.size() == PULSE_QUORUM_NUM_VALIDATORS;
return result;
}
bool verify_checkpoint(uint8_t hf_version, cryptonote::checkpoint_t const &checkpoint, service_nodes::quorum const &quorum)
{
if (checkpoint.type == cryptonote::checkpoint_type::service_node)

View File

@ -111,9 +111,11 @@ namespace service_nodes
bool verify_vote_age (const quorum_vote_t& vote, uint64_t latest_height, cryptonote::vote_verification_context &vvc);
bool verify_vote_signature (uint8_t hf_version, const quorum_vote_t& vote, cryptonote::vote_verification_context &vvc, const service_nodes::quorum &quorum);
bool verify_quorum_signatures (service_nodes::quorum const &quorum, service_nodes::quorum_type type, uint8_t hf_version, uint64_t height, crypto::hash const &hash, std::vector<quorum_signature> const &signatures, std::any const &context);
bool verify_pulse_quorum_sizes (service_nodes::quorum const &quorum);
crypto::signature make_signature_from_vote (quorum_vote_t const &vote, const service_node_keys &keys);
crypto::signature make_signature_from_tx_state_change(cryptonote::tx_extra_service_node_state_change const &state_change, const service_node_keys &keys);
struct pool_vote_entry
{
quorum_vote_t vote;

View File

@ -809,7 +809,7 @@ bool loki_core_test_deregister_preferred::generate(std::vector<test_event_entry>
uint64_t height;
uint64_t expected_reward;
cryptonote::blobdata extra_nonce;
c.get_block_template(full_blk, miner.get_keys().m_account_address, diffic, height, expected_reward, extra_nonce);
c.get_next_block_template(full_blk, miner.get_keys().m_account_address, diffic, height, expected_reward, extra_nonce);
}
map_hash2tx_t mtx;