Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daemon validation for restrict unlock for the small contributor #114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cryptonote_core/master_node_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,12 @@ namespace master_nodes
return false;
}

master_node_info master_node_list::state_t::get_master_node_details(crypto::public_key mnode_key)
{
auto it = master_nodes_infos.find(mnode_key);
return *it->second;
}

bool is_registration_tx(cryptonote::network_type nettype, uint8_t hf_version, const cryptonote::transaction& tx, uint64_t block_timestamp, uint64_t block_height, uint32_t index, crypto::public_key& key, master_node_info& info)
{
contributor_args_t contributor_args = {};
Expand Down
3 changes: 2 additions & 1 deletion src/cryptonote_core/master_node_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,14 @@ namespace master_nodes
bool process_key_image_unlock_tx(cryptonote::network_type nettype, uint64_t block_height, const cryptonote::transaction &tx,uint8_t version);
payout get_block_leader() const;
payout get_block_producer(uint8_t POS_round) const;
master_node_info get_master_node_details(crypto::public_key mnode_key);
};

// Can be set to true (via --dev-allow-local-ips) for debugging a new testnet on a local private network.
bool debug_allow_local_ips = false;
void record_timestamp_participation(crypto::public_key const &pubkey, bool participated);
void record_timesync_status(crypto::public_key const &pubkey, bool synced);

master_node_info get_master_node_details(crypto::public_key mnode_key){return m_state.get_master_node_details(mnode_key);}
private:
// Note(maxim): private methods don't have to be protected the mutex
bool m_rescanning = false; /* set to true when doing a rescan so we know not to reset proofs */
Expand Down
38 changes: 38 additions & 0 deletions src/cryptonote_core/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,44 @@ namespace cryptonote
return false;
}

if(tx.type == txtype::key_image_unlock)
{
if(hf_version >= cryptonote::network_version_18)
{
crypto::public_key mnode_key;
if (!cryptonote::get_master_node_pubkey_from_tx_extra(tx.extra, mnode_key))
return false;

cryptonote::tx_extra_tx_key_image_unlock unlock;
if (!cryptonote::get_field_from_tx_extra(tx.extra, unlock))
return false;

uint64_t block_height = m_blockchain.get_current_blockchain_height();
const master_nodes::master_node_info &node_info = m_blockchain.get_master_node_list().get_master_node_details(mnode_key);

for (const auto &contributor : node_info.contributors)
{
auto cit = std::find_if(contributor.locked_contributions.begin(),
contributor.locked_contributions.end(),
[&unlock](const master_nodes::master_node_info::contribution_t &contribution) {
return unlock.key_image == contribution.key_image;
});
if (cit != contributor.locked_contributions.end())
{
if (cit->amount < (master_nodes::SMALL_CONTRIBUTOR_THRESHOLD*COIN) && (block_height - node_info.registration_height) < master_nodes::SMALL_CONTRIBUTOR_UNLOCK_TIMER)
{
MWARNING("Unlock TX: small contributor trying to unlock node before "
<< std::to_string(master_nodes::SMALL_CONTRIBUTOR_UNLOCK_TIMER) <<" blocks from the registration height"
<< " for tx: "
<< get_transaction_hash(tx));
tvc.m_verifivation_failed = true;
return false;
}
}
}
}
}

if(!check_inputs_types_supported(tx))
{
tvc.m_verifivation_failed = true;
Expand Down