Skip to content

Commit

Permalink
Merge pull request #114 from victor-tucci/prevent-unlocks-small-holdings
Browse files Browse the repository at this point in the history
Daemon validation for restrict unlock for the small contributor
  • Loading branch information
sanada08 authored Aug 24, 2023
2 parents 093fa4c + 2b96d2f commit aea19a6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
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 @@ -723,13 +723,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

0 comments on commit aea19a6

Please sign in to comment.