diff --git a/src/cryptonote_basic/cryptonote_format_utils.cpp b/src/cryptonote_basic/cryptonote_format_utils.cpp index 9ca625a14..dad319533 100644 --- a/src/cryptonote_basic/cryptonote_format_utils.cpp +++ b/src/cryptonote_basic/cryptonote_format_utils.cpp @@ -1158,64 +1158,64 @@ namespace cryptonote //--------------------------------------------------------------- bool add_graft_tx_extra_to_extra(transaction &tx, const supernode::GraftTxExtra &graft_extra) { - return add_graft_tx_extra_to_extra(tx.extra, graft_extra); + return add_graft_tx_extra_to_extra(tx.extra, graft_extra); } //--------------------------------------------------------------- bool add_graft_tx_extra_to_extra(std::vector& extra, const supernode::GraftTxExtra &graft_extra) { - std::string blob; - ::serialization::dump_binary(const_cast(graft_extra), blob); - tx_extra_graft_extra container; - container.data = blob; - blob.clear(); - ::serialization::dump_binary(container, blob); - extra.push_back(TX_EXTRA_GRAFT_EXTRA_TAG); - std::copy(blob.begin(), blob.end(), std::back_inserter(extra)); - return true; + std::string blob; + ::serialization::dump_binary(const_cast(graft_extra), blob); + tx_extra_graft_extra container; + container.data = blob; + blob.clear(); + ::serialization::dump_binary(container, blob); + extra.push_back(TX_EXTRA_GRAFT_EXTRA_TAG); + std::copy(blob.begin(), blob.end(), std::back_inserter(extra)); + return true; } //--------------------------------------------------------------- bool get_graft_tx_extra_from_extra(const transaction &tx, supernode::GraftTxExtra &graft_tx_extra) { - std::vector tx_extra_fields; - parse_tx_extra(tx.extra, tx_extra_fields); - tx_extra_graft_extra graft_extra; - if(!find_tx_extra_field_by_type(tx_extra_fields, graft_extra)) - return false; - return ::serialization::parse_binary(graft_extra.data, graft_tx_extra); + std::vector tx_extra_fields; + parse_tx_extra(tx.extra, tx_extra_fields); + tx_extra_graft_extra graft_extra; + if(!find_tx_extra_field_by_type(tx_extra_fields, graft_extra)) + return false; + return ::serialization::parse_binary(graft_extra.data, graft_tx_extra); } namespace { - struct GraftStakeTxExtra - { - std::string supernode_public_id; - cryptonote::account_public_address supernode_public_address; - crypto::signature supernode_signature; - - GraftStakeTxExtra() = default; - - GraftStakeTxExtra(const std::string &supernode_public_id, - const cryptonote::account_public_address& supernode_public_address, - const crypto::signature &supernode_signature) : - supernode_public_id(supernode_public_id), - supernode_public_address(supernode_public_address), - supernode_signature(supernode_signature) - {} - - bool operator ==(const GraftStakeTxExtra &rhs) const { - return supernode_public_id == rhs.supernode_public_id && - !memcmp(&supernode_public_address.m_view_public_key.data[0], &rhs.supernode_public_address.m_view_public_key.data[0], - sizeof(supernode_public_address.m_view_public_key.data)) && - !memcmp(&supernode_signature.c.data[0], &rhs.supernode_signature.c.data[0], sizeof(supernode_signature.c.data)) && - !memcmp(&supernode_signature.r.data[0], &rhs.supernode_signature.r.data[0], sizeof(supernode_signature.r.data)); - } + struct GraftStakeTxExtra + { + std::string supernode_public_id; + cryptonote::account_public_address supernode_public_address; + crypto::signature supernode_signature; + + GraftStakeTxExtra() = default; + + GraftStakeTxExtra(const std::string &supernode_public_id, + const cryptonote::account_public_address& supernode_public_address, + const crypto::signature &supernode_signature) : + supernode_public_id(supernode_public_id), + supernode_public_address(supernode_public_address), + supernode_signature(supernode_signature) + {} + + bool operator ==(const GraftStakeTxExtra &rhs) const { + return supernode_public_id == rhs.supernode_public_id && + !memcmp(&supernode_public_address.m_view_public_key.data[0], &rhs.supernode_public_address.m_view_public_key.data[0], + sizeof(supernode_public_address.m_view_public_key.data)) && + !memcmp(&supernode_signature.c.data[0], &rhs.supernode_signature.c.data[0], sizeof(supernode_signature.c.data)) && + !memcmp(&supernode_signature.r.data[0], &rhs.supernode_signature.r.data[0], sizeof(supernode_signature.r.data)); + } - BEGIN_SERIALIZE_OBJECT() - FIELD(supernode_public_id) - FIELD(supernode_public_address) - FIELD(supernode_signature) - END_SERIALIZE() - }; + BEGIN_SERIALIZE_OBJECT() + FIELD(supernode_public_id) + FIELD(supernode_public_address) + FIELD(supernode_signature) + END_SERIALIZE() + }; } bool add_graft_stake_tx_extra_to_extra @@ -1224,16 +1224,16 @@ namespace cryptonote const cryptonote::account_public_address &supernode_public_address, const crypto::signature &supernode_signature) { - GraftStakeTxExtra tx_extra(supernode_public_id, supernode_public_address, supernode_signature); - std::string blob; - ::serialization::dump_binary(tx_extra, blob); - tx_extra_graft_stake_tx container; - container.data = blob; - blob.clear(); - ::serialization::dump_binary(container, blob); - extra.push_back(TX_EXTRA_GRAFT_STAKE_TX_TAG); - std::copy(blob.begin(), blob.end(), std::back_inserter(extra)); - return true; + GraftStakeTxExtra tx_extra(supernode_public_id, supernode_public_address, supernode_signature); + std::string blob; + ::serialization::dump_binary(tx_extra, blob); + tx_extra_graft_stake_tx container; + container.data = blob; + blob.clear(); + ::serialization::dump_binary(container, blob); + extra.push_back(TX_EXTRA_GRAFT_STAKE_TX_TAG); + std::copy(blob.begin(), blob.end(), std::back_inserter(extra)); + return true; } bool add_graft_rta_header_to_extra(std::vector &extra, const rta_header &rta_header) @@ -1261,13 +1261,13 @@ namespace cryptonote bool add_graft_tx_secret_key_to_extra(std::vector &extra, const crypto::secret_key& secret_key) { - tx_extra_graft_tx_secret_key container; - container.secret_key = secret_key; - std::string blob; - ::serialization::dump_binary(container, blob); - extra.push_back(TX_EXTRA_GRAFT_TX_SECRET_KEY_TAG); - std::copy(blob.begin(), blob.end(), std::back_inserter(extra)); - return true; + tx_extra_graft_tx_secret_key container; + container.secret_key = secret_key; + std::string blob; + ::serialization::dump_binary(container, blob); + extra.push_back(TX_EXTRA_GRAFT_TX_SECRET_KEY_TAG); + std::copy(blob.begin(), blob.end(), std::back_inserter(extra)); + return true; } bool get_graft_stake_tx_extra_from_extra @@ -1277,30 +1277,30 @@ namespace cryptonote crypto::signature &supernode_signature, crypto::secret_key &tx_secret_key) { - std::vector tx_extra_fields; - parse_tx_extra(tx.extra, tx_extra_fields); + std::vector tx_extra_fields; + parse_tx_extra(tx.extra, tx_extra_fields); - tx_extra_graft_stake_tx stake_tx_extra; + tx_extra_graft_stake_tx stake_tx_extra; - if(!find_tx_extra_field_by_type(tx_extra_fields, stake_tx_extra)) - return false; + if(!find_tx_extra_field_by_type(tx_extra_fields, stake_tx_extra)) + return false; - GraftStakeTxExtra stake_tx; + GraftStakeTxExtra stake_tx; - if (!::serialization::parse_binary(stake_tx_extra.data, stake_tx)) - return false; + if (!::serialization::parse_binary(stake_tx_extra.data, stake_tx)) + return false; - tx_extra_graft_tx_secret_key stake_tx_secret_key_extra; + tx_extra_graft_tx_secret_key stake_tx_secret_key_extra; - if(!find_tx_extra_field_by_type(tx_extra_fields, stake_tx_secret_key_extra)) - return false; + if(!find_tx_extra_field_by_type(tx_extra_fields, stake_tx_secret_key_extra)) + return false; - supernode_public_id = stake_tx.supernode_public_id; - supernode_public_address = stake_tx.supernode_public_address; - supernode_signature = stake_tx.supernode_signature; - tx_secret_key = stake_tx_secret_key_extra.secret_key; + supernode_public_id = stake_tx.supernode_public_id; + supernode_public_address = stake_tx.supernode_public_address; + supernode_signature = stake_tx.supernode_signature; + tx_secret_key = stake_tx_secret_key_extra.secret_key; - return true; + return true; } bool add_graft_rta_signatures_to_extra2(std::vector &extra, const std::vector &rta_signatures) @@ -1328,15 +1328,15 @@ namespace cryptonote bool graft_get_disqualification(const transaction &tx, tx_extra_graft_disqualification& disq) { - if(tx.version != 123) - return false; - if(!tx.vin.empty() || !tx.vout.empty() || tx.rct_signatures.txnFee !=0) - return false; - std::vector tx_extra_fields; - parse_tx_extra(tx.extra, tx_extra_fields); - if(!find_tx_extra_field_by_type(tx_extra_fields, disq)) - return false; - return true; + if(tx.version != 123) + return false; + if(!tx.vin.empty() || !tx.vout.empty() || tx.rct_signatures.txnFee !=0) + return false; + std::vector tx_extra_fields; + parse_tx_extra(tx.extra, tx_extra_fields); + if(!find_tx_extra_field_by_type(tx_extra_fields, disq)) + return false; + return true; } bool graft_is_disqualification(const transaction &tx) diff --git a/src/cryptonote_basic/tx_extra.h b/src/cryptonote_basic/tx_extra.h index 3a9d01e61..465417251 100644 --- a/src/cryptonote_basic/tx_extra.h +++ b/src/cryptonote_basic/tx_extra.h @@ -244,27 +244,27 @@ namespace cryptonote struct tx_extra_graft_disqualification { - struct disqualification_item - { - uint64_t block_height; - crypto::hash block_hash; - crypto::public_key id; - BEGIN_SERIALIZE() - FIELD(block_height) - FIELD(block_hash) - FIELD(id) - END_SERIALIZE() - }; - - struct signer_item - { - crypto::public_key signer_id; - crypto::signature sign; - BEGIN_SERIALIZE() - FIELD(signer_id) - FIELD(sign) - END_SERIALIZE() - }; + struct disqualification_item + { + uint64_t block_height; + crypto::hash block_hash; + crypto::public_key id; + BEGIN_SERIALIZE() + FIELD(block_height) + FIELD(block_hash) + FIELD(id) + END_SERIALIZE() + }; + + struct signer_item + { + crypto::public_key signer_id; + crypto::signature sign; + BEGIN_SERIALIZE() + FIELD(signer_id) + FIELD(sign) + END_SERIALIZE() + }; disqualification_item item; std::vector signers; diff --git a/src/cryptonote_core/stake_transaction_processor.cpp b/src/cryptonote_core/stake_transaction_processor.cpp index 6fa8fc71b..fe0620762 100644 --- a/src/cryptonote_core/stake_transaction_processor.cpp +++ b/src/cryptonote_core/stake_transaction_processor.cpp @@ -155,32 +155,32 @@ using Ids = std::vector; std::array, TIERS> makeBBLindexes(const Tiers& bbl_tiers) { - std::array, TIERS> res; - for(size_t t=0; tTI{ return std::make_pair(t, idx++); } ); - } - return res; + std::array, TIERS> res; + for(size_t t=0; tTI{ return std::make_pair(t, idx++); } ); + } + return res; } Ids fromIndexes(const Tiers& bbl_tiers, const std::vector& idxs) { - Ids res; - res.reserve(idxs.size()); - for(auto& ti : idxs) - { - auto& t = ti.first; - auto& i = ti.second; - auto& supernode_public_id = bbl_tiers[t][i].supernode_public_id; - crypto::public_key id; - bool ok = epee::string_tools::hex_to_pod(supernode_public_id, id); - assert(ok); - res.emplace_back(std::move(id)); - } - return res; + Ids res; + res.reserve(idxs.size()); + for(auto& ti : idxs) + { + auto& t = ti.first; + auto& i = ti.second; + auto& supernode_public_id = bbl_tiers[t][i].supernode_public_id; + crypto::public_key id; + bool ok = epee::string_tools::hex_to_pod(supernode_public_id, id); + assert(ok); + res.emplace_back(std::move(id)); + } + return res; } } //namespace @@ -227,37 +227,37 @@ void StakeTransactionProcessor::process_block_stake_transaction(uint64_t block_i tx_extra_graft_disqualification disq_extra; if(graft_check_disqualification(tx, &disq_extra)) { - MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash); - continue; + MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash); + continue; } if(block_index <= disq_extra.item.block_height) { - MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash - << "; invalid block_height " << disq_extra.item.block_height << " current " << block_index); - continue; + MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash + << "; invalid block_height " << disq_extra.item.block_height << " current " << block_index); + continue; } crypto::hash b_hash = m_blockchain.get_block_id_by_height(disq_extra.item.block_height); if(b_hash != disq_extra.item.block_hash) { - MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash - << "; invalid block_hash "); - continue; + MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash + << "; invalid block_hash "); + continue; } //get BBL size_t depth = m_blockchain_based_list->block_height() - disq_extra.item.block_height; if(m_blockchain_based_list->history_depth() <= depth) { - MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash - << "; out of history "); - continue; + MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash + << "; out of history "); + continue; } if(disq_extra.signers.size() < graft::generator::REQUIRED_BBQS_VOTES) { - MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash - << "; lack of signers "); - continue; + MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash + << "; lack of signers "); + continue; } auto& tiers = m_blockchain_based_list->tiers(depth); @@ -270,23 +270,23 @@ void StakeTransactionProcessor::process_block_stake_transaction(uint64_t block_i if(std::none_of(qcl.begin(), qcl.end(), [&disq_extra](crypto::public_key& v)->bool { return v == disq_extra.item.id; } )) { - std::string id_str; - epee::string_tools::pod_to_hex(disq_extra.item.id); - MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash - << "; disqualified id " << id_str << " is not in QCL"); - continue; + std::string id_str; + epee::string_tools::pod_to_hex(disq_extra.item.id); + MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash + << "; disqualified id " << id_str << " is not in QCL"); + continue; } for(auto& si : disq_extra.signers) { - if(std::none_of(bbqs.begin(), bbqs.end(), [&si](crypto::public_key& v)->bool { return v == si.signer_id; } )) - { - std::string id_str; - epee::string_tools::pod_to_hex(si.signer_id); - MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash - << "; signer id " << id_str << " is not in BBQS"); - continue; - } + if(std::none_of(bbqs.begin(), bbqs.end(), [&si](crypto::public_key& v)->bool { return v == si.signer_id; } )) + { + std::string id_str; + epee::string_tools::pod_to_hex(si.signer_id); + MWARNING("Ignore invalid disqualification transaction at block #" << block_index << ", tx_hash=" << tx_hash + << "; signer id " << id_str << " is not in BBQS"); + continue; + } } disqualification disq; diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 3403767f9..e25493d8c 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -192,12 +192,12 @@ namespace cryptonote bool is_rta_tx = tx.type == transaction::tx_type_rta; if(is_disqualification_tx) { - if(!graft_check_disqualification(tx)) - { - MERROR("Invalid disqualification transaction with id " << id); - tvc.m_verifivation_failed = true; - return false; - } + if(!graft_check_disqualification(tx)) + { + MERROR("Invalid disqualification transaction with id " << id); + tvc.m_verifivation_failed = true; + return false; + } } else if (is_rta_tx) { cryptonote::rta_header rta_hdr;