diff --git a/include/metaverse/bitcoin/constants.hpp b/include/metaverse/bitcoin/constants.hpp index 164e02042..130cb7dec 100644 --- a/include/metaverse/bitcoin/constants.hpp +++ b/include/metaverse/bitcoin/constants.hpp @@ -49,6 +49,7 @@ BC_CONSTEXPR uint8_t byte_bits = 8; // Consensus constants. extern uint32_t coinbase_maturity; +BC_CONSTEXPR uint64_t transaction_maturity = 3; BC_CONSTEXPR uint32_t max_input_sequence = max_uint32; BC_CONSTEXPR uint32_t total_reward = 100000000; diff --git a/src/lib/blockchain/block_chain_impl.cpp b/src/lib/blockchain/block_chain_impl.cpp index ce4c68e4b..a894eb6a8 100644 --- a/src/lib/blockchain/block_chain_impl.cpp +++ b/src/lib/blockchain/block_chain_impl.cpp @@ -3330,6 +3330,14 @@ bool block_chain_impl::is_utxo_spendable(const chain::transaction& tx, uint32_t return false; } + if (transaction_maturity > calc_number_of_blocks(tx_height, latest_height)){ + log::debug(LOG_BLOCKCHAIN) << "transaction is not mature" << + " transaction hash =" << encode_hash(tx.hash()) << + " tx_height=" << tx_height << + " latest_height=" << latest_height; + return false; + } + const auto output = tx.outputs[index]; if (chain::operation::is_pay_key_hash_with_lock_height_pattern(output.script.operations)) { diff --git a/src/lib/consensus/miner.cpp b/src/lib/consensus/miner.cpp index f1ed45473..19846ff54 100644 --- a/src/lib/consensus/miner.cpp +++ b/src/lib/consensus/miner.cpp @@ -115,11 +115,19 @@ bool miner::get_input_etp(const chain::transaction& tx, const std::vectoroutputs[input.previous_output.index]); } else { -#ifdef MVS_DEBUG - log::debug(LOG_HEADER) << "previous transaction not ready: " << encode_hash(hash); -#endif + log::warning(LOG_HEADER) << encode_hash(tx.hash())<< " previous transaction not ready: " << encode_hash(hash); return false; } } @@ -191,9 +197,7 @@ bool miner::get_transaction( // check fees if (fee < min_tx_fee || !blockchain::validate_transaction::check_special_fees(setting_.use_testnet_rules, tx, fee)) { -#ifdef MVS_DEBUG - log::debug(LOG_HEADER) << "check fees failed, delete_tx " << encode_hash(hash); -#endif + log::warning(LOG_HEADER) << "check fees failed, pool delete_tx " << encode_hash(hash); i = transactions.erase(i); // delete it from pool if not enough fee node_.pool().delete_tx(hash); @@ -205,9 +209,7 @@ bool miner::get_transaction( // check double spending for (const auto& input : tx.inputs) { if (node_.chain_impl().get_spends_output(input.previous_output)) { -#ifdef MVS_DEBUG - log::debug(LOG_HEADER) << "check double spending failed, delete_tx " << encode_hash(hash); -#endif + log::warning(LOG_HEADER) << "check double spending failed, pool delete_tx " << encode_hash(hash); i = transactions.erase(i); node_.pool().delete_tx(hash); transaction_is_ok = false;