From 198f557d38da3212fed1f12c0113bf2c4633ff44 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 22 Sep 2015 20:35:19 +0100 Subject: blockchain: use different hard fork settings for testnet and mainnet --- src/cryptonote_core/blockchain.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/cryptonote_core/blockchain.cpp') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 65d07dcf7..c6e9b7684 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -73,7 +73,7 @@ static const struct { uint8_t version; uint64_t height; time_t time; -} hard_forks[] = { +} mainnet_hard_forks[] = { // version 1 from the start of the blockchain { 1, 1, 1341378000 }, @@ -81,6 +81,15 @@ static const struct { { 2, 1009827, 1442763710 }, }; +static const struct { + uint8_t version; + uint64_t height; + time_t time; +} testnet_hard_forks[] = { + // version 1 from the start of the blockchain + { 1, 1, 1341378000 }, +}; + //------------------------------------------------------------------ Blockchain::Blockchain(tx_memory_pool& tx_pool) : m_db(), m_tx_pool(tx_pool), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), @@ -288,8 +297,15 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet) m_db = db; m_hardfork = new HardFork(*db); - for (size_t n = 0; n < sizeof(hard_forks) / sizeof(hard_forks[0]); ++n) - m_hardfork->add(hard_forks[n].version, hard_forks[n].height, hard_forks[n].time); + if (testnet) { + for (size_t n = 0; n < sizeof(testnet_hard_forks) / sizeof(testnet_hard_forks[0]); ++n) + m_hardfork->add(testnet_hard_forks[n].version, testnet_hard_forks[n].height, testnet_hard_forks[n].time); + } + else + { + for (size_t n = 0; n < sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]); ++n) + m_hardfork->add(mainnet_hard_forks[n].version, mainnet_hard_forks[n].height, mainnet_hard_forks[n].time); + } m_hardfork->init(); // if the blockchain is new, add the genesis block -- cgit v1.2.3 From 4bbf944df083689aac23a35f78da0147852f54af Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 22 Sep 2015 20:43:19 +0100 Subject: blockchain: on hardfork 2, allow miners to claim less money than allowed So they can avoid dust if they so wish --- src/cryptonote_core/blockchain.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/cryptonote_core/blockchain.cpp') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index c6e9b7684..14ee36911 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -963,10 +963,14 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl LOG_PRINT_L1("coinbase transaction spend too much money (" << print_money(money_in_use) << "). Block reward is " << print_money(base_reward + fee) << "(" << print_money(base_reward) << "+" << print_money(fee) << ")"); return false; } - if(base_reward + fee != money_in_use) + // From hard fork 2, we allow a miner to claim less block reward than is allowed, in case a miner wants less dust + if (m_hardfork->get_current_version() < 2) { - LOG_PRINT_L1("coinbase transaction doesn't use full amount of block reward: spent: " << money_in_use << ", block reward " << base_reward + fee << "(" << base_reward << "+" << fee << ")"); - return false; + if(base_reward + fee != money_in_use) + { + LOG_PRINT_L1("coinbase transaction doesn't use full amount of block reward: spent: " << money_in_use << ", block reward " << base_reward + fee << "(" << base_reward << "+" << fee << ")"); + return false; + } } return true; } -- cgit v1.2.3 From 0a7421b60716051359f821b2540073ad27c141d3 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 26 Sep 2015 16:22:57 +0100 Subject: hardfork: rescan speedup Add a block height before which version 1 is assumed Use DB transactions --- src/cryptonote_core/blockchain.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/cryptonote_core/blockchain.cpp') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 14ee36911..ab420b046 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -80,6 +80,7 @@ static const struct { // version 2 can start from block 1009827, setup on the 20th of september { 2, 1009827, 1442763710 }, }; +static const uint64_t mainnet_hard_fork_version_1_till = 750000; static const struct { uint8_t version; @@ -89,6 +90,7 @@ static const struct { // version 1 from the start of the blockchain { 1, 1, 1341378000 }, }; +static const uint64_t testnet_hard_fork_version_1_till = 540000; //------------------------------------------------------------------ Blockchain::Blockchain(tx_memory_pool& tx_pool) : @@ -296,13 +298,14 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet) m_db = db; - m_hardfork = new HardFork(*db); if (testnet) { + m_hardfork = new HardFork(*db, 1, testnet_hard_fork_version_1_till); for (size_t n = 0; n < sizeof(testnet_hard_forks) / sizeof(testnet_hard_forks[0]); ++n) m_hardfork->add(testnet_hard_forks[n].version, testnet_hard_forks[n].height, testnet_hard_forks[n].time); } else { + m_hardfork = new HardFork(*db, 1, mainnet_hard_fork_version_1_till); for (size_t n = 0; n < sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]); ++n) m_hardfork->add(mainnet_hard_forks[n].version, mainnet_hard_forks[n].height, mainnet_hard_forks[n].time); } -- cgit v1.2.3 From 33affd2d17b8b207ef50331b21e4dad08c97146d Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sat, 26 Sep 2015 17:57:01 +0100 Subject: blockchain: on hardfork 2, require mixin 2 at least if possible --- src/cryptonote_core/blockchain.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/cryptonote_core/blockchain.cpp') 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::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); + 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()) { -- cgit v1.2.3