diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-09-26 17:57:01 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-09-27 22:46:53 +0100 |
commit | 33affd2d17b8b207ef50331b21e4dad08c97146d (patch) | |
tree | 9ffc05f5954bcac91147205d9f7c43fc779564ca | |
parent | hardfork: make the voting window a week (diff) | |
download | monero-33affd2d17b8b207ef50331b21e4dad08c97146d.tar.xz |
blockchain: on hardfork 2, require mixin 2 at least if possible
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index ab420b046..3d96f6f5d 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1998,6 +1998,43 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc return true; } + // from hard fork 2, we require mixin at least 2 unless one output cannot mix with 2 others + // if one output cannot mix with 2 others, we accept at most 1 output that can mix + if (m_hardfork->get_current_version() >= 2) + { + size_t n_unmixable = 0, n_mixable = 0; + size_t mixin = std::numeric_limits<size_t>::max(); + for (const auto& txin : tx.vin) + { + // non txin_to_key inputs will be rejected below + if (txin.type() == typeid(txin_to_key)) + { + const txin_to_key& in_to_key = boost::get<txin_to_key>(txin); + uint64_t n_outputs = m_db->get_num_outputs(in_to_key.amount); + // n_outputs includes the output we're considering + if (n_outputs <= 2) + ++n_unmixable; + else + ++n_mixable; + if (in_to_key.key_offsets.size() - 1 < mixin) + mixin = in_to_key.key_offsets.size() - 1; + } + } + if (mixin < 2) + { + if (n_unmixable == 0) + { + LOG_PRINT_L1("Tx " << get_transaction_hash(tx) << " has too low mixin (" << mixin << "), and no unmixable inputs"); + return false; + } + if (n_mixable > 1) + { + LOG_PRINT_L1("Tx " << get_transaction_hash(tx) << " has too low mixin (" << mixin << "), and more than one mixable input with unmixable inputs"); + return false; + } + } + } + auto it = m_check_txin_table.find(tx_prefix_hash); if(it == m_check_txin_table.end()) { |