From aee65e0a6b4fdcfe64c976d8331e02ce5f5fb05c Mon Sep 17 00:00:00 2001 From: Jun Li <472780330@qq.com> Date: Thu, 20 Feb 2020 15:37:35 +0800 Subject: [PATCH 1/6] add transaction maturity Add the minimum number of blocks for transaction validation --- include/metaverse/bitcoin/constants.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/metaverse/bitcoin/constants.hpp b/include/metaverse/bitcoin/constants.hpp index 164e02042..256378e2d 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 uint32_t transaction_maturity = 3; BC_CONSTEXPR uint32_t max_input_sequence = max_uint32; BC_CONSTEXPR uint32_t total_reward = 100000000; From f7d33626db3106b345d135cb185769df8d7d39b3 Mon Sep 17 00:00:00 2001 From: Jun Li <472780330@qq.com> Date: Thu, 20 Feb 2020 15:43:49 +0800 Subject: [PATCH 2/6] Transaction adds block confirmation When selecting transaction input, the confirmation of the selected utxo block must not be less than transaction_maturity(3) --- src/lib/blockchain/block_chain_impl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/blockchain/block_chain_impl.cpp b/src/lib/blockchain/block_chain_impl.cpp index ce4c68e4b..1a54ab78c 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 maturity" << + " 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)) { From 21493083da7ae5b01fe45d2398ea01f8fd5d6e92 Mon Sep 17 00:00:00 2001 From: Jun Li <472780330@qq.com> Date: Thu, 20 Feb 2020 15:46:58 +0800 Subject: [PATCH 3/6] Update block_chain_impl.cpp --- src/lib/blockchain/block_chain_impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/blockchain/block_chain_impl.cpp b/src/lib/blockchain/block_chain_impl.cpp index 1a54ab78c..a894eb6a8 100644 --- a/src/lib/blockchain/block_chain_impl.cpp +++ b/src/lib/blockchain/block_chain_impl.cpp @@ -3331,7 +3331,7 @@ bool block_chain_impl::is_utxo_spendable(const chain::transaction& tx, uint32_t } if (transaction_maturity > calc_number_of_blocks(tx_height, latest_height)){ - log::debug(LOG_BLOCKCHAIN) << "transaction is maturity" << + log::debug(LOG_BLOCKCHAIN) << "transaction is not mature" << " transaction hash =" << encode_hash(tx.hash()) << " tx_height=" << tx_height << " latest_height=" << latest_height; From fe5b3cce2ef40fc6efbdc2d4f866915ed8e41c64 Mon Sep 17 00:00:00 2001 From: Jun Li <472780330@qq.com> Date: Thu, 20 Feb 2020 16:33:37 +0800 Subject: [PATCH 4/6] Update miner.cpp --- src/lib/consensus/miner.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/consensus/miner.cpp b/src/lib/consensus/miner.cpp index f1ed45473..3c94c0ba5 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; From e8d1b86a06bda6ada64e2e78c5c693c27487681a Mon Sep 17 00:00:00 2001 From: Jun Li <472780330@qq.com> Date: Thu, 20 Feb 2020 20:33:40 +0800 Subject: [PATCH 5/6] Update constants.hpp --- include/metaverse/bitcoin/constants.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/metaverse/bitcoin/constants.hpp b/include/metaverse/bitcoin/constants.hpp index 256378e2d..130cb7dec 100644 --- a/include/metaverse/bitcoin/constants.hpp +++ b/include/metaverse/bitcoin/constants.hpp @@ -49,7 +49,7 @@ BC_CONSTEXPR uint8_t byte_bits = 8; // Consensus constants. extern uint32_t coinbase_maturity; -BC_CONSTEXPR uint32_t transaction_maturity = 3; +BC_CONSTEXPR uint64_t transaction_maturity = 3; BC_CONSTEXPR uint32_t max_input_sequence = max_uint32; BC_CONSTEXPR uint32_t total_reward = 100000000; From 81235134fa3d752033057ae664a983e0e6bd77c0 Mon Sep 17 00:00:00 2001 From: Jun Li <472780330@qq.com> Date: Thu, 20 Feb 2020 20:34:50 +0800 Subject: [PATCH 6/6] Update miner.cpp --- src/lib/consensus/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/consensus/miner.cpp b/src/lib/consensus/miner.cpp index 3c94c0ba5..19846ff54 100644 --- a/src/lib/consensus/miner.cpp +++ b/src/lib/consensus/miner.cpp @@ -123,7 +123,7 @@ bool miner::get_input_etp(const chain::transaction& tx, const std::vector