aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-01-29 15:09:17 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-01-29 17:21:11 +0000
commit3b1d7e03fcc1caa8898ced33e127f6ba09d66df8 (patch)
treedbec9bdbe5dc27b3c420433b99750ef036827489 /src/cryptonote_core
parentMerge pull request #626 (diff)
downloadmonero-3b1d7e03fcc1caa8898ced33e127f6ba09d66df8.tar.xz
Fix V1/V2 use of hard fork related parameters
Some of it uses hardcoded height, which will need some thinking for next (voted upon) fork.
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp19
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp10
-rw-r--r--src/cryptonote_core/cryptonote_basic_impl.cpp6
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp7
-rw-r--r--src/cryptonote_core/tx_pool.cpp50
-rw-r--r--src/cryptonote_core/tx_pool.h5
6 files changed, 65 insertions, 32 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 40e8609b8..b27927c0a 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -478,12 +478,18 @@ block Blockchain::pop_block_from_blockchain()
if (!is_coinbase(tx))
{
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
+
+ // This is not quite correct, as we really want to add the txes
+ // to the pool based on the version determined after all blocks
+ // are popped.
+ uint8_t version = get_current_hard_fork_version();
+
// We assume that if they were in a block, the transactions are already
// known to the network as a whole. However, if we had mined that block,
// that might not be always true. Unlikely though, and always relaying
// these again might cause a spike of traffic as many nodes re-relay
// all the transactions in a popped block when a reorg happens.
- bool r = m_tx_pool.add_tx(tx, tvc, true, true);
+ bool r = m_tx_pool.add_tx(tx, tvc, true, true, version);
if (!r)
{
LOG_ERROR("Error returning transaction to tx_pool");
@@ -702,7 +708,7 @@ difficulty_type Blockchain::get_difficulty_for_next_block()
m_timestamps = timestamps;
m_difficulties = difficulties;
}
- size_t target = get_current_hard_fork_version() < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET;
+ size_t target = get_current_hard_fork_version() < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET_V2;
return next_difficulty(timestamps, difficulties, target);
}
//------------------------------------------------------------------
@@ -900,7 +906,7 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std:
}
// FIXME: This will fail if fork activation heights are subject to voting
- size_t target = get_ideal_hard_fork_version(bei.height) < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET;
+ size_t target = get_ideal_hard_fork_version(bei.height) < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET_V2;
// calculate the difficulty target for the block and return it
return next_difficulty(timestamps, cumulative_difficulties, target);
@@ -2239,7 +2245,7 @@ bool Blockchain::is_tx_spendtime_unlocked(uint64_t unlock_time) const
{
//interpret as time
uint64_t current_time = static_cast<uint64_t>(time(NULL));
- if(current_time + (get_current_hard_fork_version() < 2 ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS) >= unlock_time)
+ if(current_time + (get_current_hard_fork_version() < 2 ? CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V1 : CRYPTONOTE_LOCKED_TX_ALLOWED_DELTA_SECONDS_V2) >= unlock_time)
return true;
else
return false;
@@ -2364,6 +2370,7 @@ bool Blockchain::check_block_timestamp(const block& b) const
//------------------------------------------------------------------
void Blockchain::return_tx_to_pool(const std::vector<transaction> &txs)
{
+ uint8_t version = get_current_hard_fork_version();
for (auto& tx : txs)
{
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
@@ -2372,7 +2379,7 @@ void Blockchain::return_tx_to_pool(const std::vector<transaction> &txs)
// that might not be always true. Unlikely though, and always relaying
// these again might cause a spike of traffic as many nodes re-relay
// all the transactions in a popped block when a reorg happens.
- if (!m_tx_pool.add_tx(tx, tvc, true, true))
+ if (!m_tx_pool.add_tx(tx, tvc, true, true, version))
{
LOG_PRINT_L0("Failed to return taken transaction with hash: " << get_transaction_hash(tx) << " to tx_pool");
}
@@ -2698,7 +2705,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
//------------------------------------------------------------------
bool Blockchain::update_next_cumulative_size_limit()
{
- uint64_t full_reward_zone = get_current_hard_fork_version() < 2 ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 : CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE;
+ uint64_t full_reward_zone = get_current_hard_fork_version() < 2 ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 : CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2;
LOG_PRINT_L3("Blockchain::" << __func__);
std::vector<size_t> sz;
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index 3034cf3f7..f656f938b 100644
--- a/src/cryptonote_core/blockchain_storage.cpp
+++ b/src/cryptonote_core/blockchain_storage.cpp
@@ -301,7 +301,7 @@ bool blockchain_storage::purge_transaction_from_blockchain(const crypto::hash& t
if(!is_coinbase(tx))
{
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- bool r = m_tx_pool->add_tx(tx, tvc, true, true);
+ bool r = m_tx_pool->add_tx(tx, tvc, true, true, 1);
CHECK_AND_ASSERT_MES(r, false, "purge_block_data_from_blockchain: failed to add transaction to transaction pool");
}
@@ -1699,7 +1699,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
{
LOG_PRINT_L1("Block with id: " << id << "has at least one transaction (id: " << tx_id << ") with wrong inputs.");
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- bool add_res = m_tx_pool->add_tx(tx, tvc, true, relayed);
+ bool add_res = m_tx_pool->add_tx(tx, tvc, true, relayed, 1);
CHECK_AND_ASSERT_MES2(add_res, "handle_block_to_main_chain: failed to add transaction back to transaction pool");
purge_block_data_from_blockchain(bl, tx_processed_count);
add_block_as_invalid(bl, id);
@@ -1712,7 +1712,7 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
{
LOG_PRINT_L1("Block with id: " << id << " failed to add transaction to blockchain storage");
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
- bool add_res = m_tx_pool->add_tx(tx, tvc, true, relayed);
+ bool add_res = m_tx_pool->add_tx(tx, tvc, true, relayed, 1);
CHECK_AND_ASSERT_MES2(add_res, "handle_block_to_main_chain: failed to add transaction back to transaction pool");
purge_block_data_from_blockchain(bl, tx_processed_count);
bvc.m_verifivation_failed = true;
@@ -1787,8 +1787,8 @@ bool blockchain_storage::update_next_comulative_size_limit()
get_last_n_blocks_sizes(sz, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
uint64_t median = epee::misc_utils::median(sz);
- if(median <= CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE)
- median = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE;
+ if(median <= CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1)
+ median = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1;
m_current_block_cumul_sz_limit = median*2;
return true;
diff --git a/src/cryptonote_core/cryptonote_basic_impl.cpp b/src/cryptonote_core/cryptonote_basic_impl.cpp
index da14d772b..74f44e2af 100644
--- a/src/cryptonote_core/cryptonote_basic_impl.cpp
+++ b/src/cryptonote_core/cryptonote_basic_impl.cpp
@@ -74,8 +74,8 @@ namespace cryptonote {
}
//-----------------------------------------------------------------------------------------------
bool get_block_reward(size_t median_size, size_t current_block_size, uint64_t already_generated_coins, uint64_t &reward, uint8_t version) {
- static_assert(DIFFICULTY_TARGET%60==0&&DIFFICULTY_TARGET_V1%60==0,"difficulty targets must be a multiple of 60");
- const int target = version < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET;
+ static_assert(DIFFICULTY_TARGET_V2%60==0&&DIFFICULTY_TARGET_V1%60==0,"difficulty targets must be a multiple of 60");
+ const int target = version < 2 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET_V2;
const int target_minutes = target / 60;
const int emission_speed_factor = EMISSION_SPEED_FACTOR_PER_MINUTE - (target_minutes-1);
@@ -85,7 +85,7 @@ namespace cryptonote {
base_reward = FINAL_SUBSIDY_PER_MINUTE*target_minutes;
}
- uint64_t full_reward_zone = version < 2 ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 : CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE;
+ uint64_t full_reward_zone = version < 2 ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 : CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2;
//make it soft
if (median_size < full_reward_zone) {
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 608abea19..ac0be5a07 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -358,6 +358,10 @@ namespace cryptonote
r = m_blockchain_storage.init(db, m_testnet, m_fakechain);
+ // now that we have a valid m_blockchain_storage, we can clean out any
+ // transactions in the pool that do not conform to the current fork
+ m_mempool.validate(m_blockchain_storage.get_current_hard_fork_version());
+
bool show_time_stats = command_line::get_arg(vm, command_line::arg_show_time_stats) != 0;
m_blockchain_storage.set_show_time_stats(show_time_stats);
#else
@@ -607,7 +611,8 @@ namespace cryptonote
return true;
}
- return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block, relayed);
+ uint8_t version = m_blockchain_storage.get_current_hard_fork_version();
+ return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block, relayed, version);
}
//-----------------------------------------------------------------------------------------------
bool core::relay_txpool_transactions()
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 1be44172d..2c607fa88 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -54,7 +54,8 @@ namespace cryptonote
{
namespace
{
- size_t const TRANSACTION_SIZE_LIMIT = (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
+ size_t const TRANSACTION_SIZE_LIMIT_V1 = (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
+ size_t const TRANSACTION_SIZE_LIMIT_V2 = (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
time_t const MIN_RELAY_TIME = (60 * 5); // only start re-relaying transactions after that many seconds
time_t const MAX_RELAY_TIME = (60 * 60 * 4); // at most that many seconds between resends
@@ -81,7 +82,7 @@ namespace cryptonote
}
#endif
//---------------------------------------------------------------------------------
- bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed)
+ bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool relayed, uint8_t version)
{
@@ -118,9 +119,10 @@ namespace cryptonote
return false;
}
- if (!kept_by_block && blob_size >= TRANSACTION_SIZE_LIMIT)
+ size_t tx_size_limit = (version < 2 ? TRANSACTION_SIZE_LIMIT_V1 : TRANSACTION_SIZE_LIMIT_V2);
+ if (!kept_by_block && blob_size >= tx_size_limit)
{
- LOG_PRINT_L1("transaction is too big: " << blob_size << " bytes, maximum size: " << TRANSACTION_SIZE_LIMIT);
+ LOG_PRINT_L1("transaction is too big: " << blob_size << " bytes, maximum size: " << tx_size_limit);
tvc.m_verifivation_failed = true;
return false;
}
@@ -217,12 +219,12 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------------------------
- bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed)
+ bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, uint8_t version)
{
crypto::hash h = null_hash;
size_t blob_size = 0;
get_transaction_hash(tx, h, blob_size);
- return add_tx(tx, h, blob_size, tvc, keeped_by_block, relayed);
+ return add_tx(tx, h, blob_size, tvc, keeped_by_block, relayed, version);
}
//---------------------------------------------------------------------------------
bool tx_memory_pool::remove_transaction_keyimages(const transaction& tx)
@@ -607,6 +609,33 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------------------------
+ size_t tx_memory_pool::validate(uint8_t version)
+ {
+ size_t n_removed = 0;
+ size_t tx_size_limit = (version < 2 ? TRANSACTION_SIZE_LIMIT_V1 : TRANSACTION_SIZE_LIMIT_V2);
+ for (auto it = m_transactions.begin(); it != m_transactions.end(); ) {
+ if (it->second.blob_size >= tx_size_limit) {
+ LOG_PRINT_L1("Transaction " << get_transaction_hash(it->second.tx) << " is too big (" << it->second.blob_size << " bytes), removing it from pool");
+ remove_transaction_keyimages(it->second.tx);
+ auto sorted_it = find_tx_in_sorted_container(it->first);
+ if (sorted_it == m_txs_by_fee.end())
+ {
+ LOG_PRINT_L1("Removing tx " << it->first << " from tx pool, but it was not found in the sorted txs container!");
+ }
+ else
+ {
+ m_txs_by_fee.erase(sorted_it);
+ }
+ auto pit = it++;
+ m_transactions.erase(pit);
+ ++n_removed;
+ continue;
+ }
+ it++;
+ }
+ return n_removed;
+ }
+ //---------------------------------------------------------------------------------
bool tx_memory_pool::init(const std::string& config_folder)
{
CRITICAL_REGION_LOCAL(m_transactions_lock);
@@ -629,15 +658,6 @@ namespace cryptonote
m_spent_key_images.clear();
}
- for (auto it = m_transactions.begin(); it != m_transactions.end(); ) {
- if (it->second.blob_size >= TRANSACTION_SIZE_LIMIT) {
- LOG_PRINT_L1("Transaction " << get_transaction_hash(it->second.tx) << " is too big (" << it->second.blob_size << " bytes), removing it from pool");
- remove_transaction_keyimages(it->second.tx);
- m_transactions.erase(it);
- }
- it++;
- }
-
// no need to store queue of sorted transactions, as it's easy to generate.
for (const auto& tx : m_transactions)
{
diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h
index 5a3af1262..3832ccb64 100644
--- a/src/cryptonote_core/tx_pool.h
+++ b/src/cryptonote_core/tx_pool.h
@@ -81,8 +81,8 @@ namespace cryptonote
#else
tx_memory_pool(blockchain_storage& bchs);
#endif
- bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed);
- bool add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed);
+ bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block, bool relayed, uint8_t version);
+ bool add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, uint8_t version);
//gets tx and remove it from pool
bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee, bool &relayed);
@@ -105,6 +105,7 @@ namespace cryptonote
void set_relayed(const std::list<std::pair<crypto::hash, cryptonote::transaction>>& txs);
size_t get_transactions_count() const;
std::string print_pool(bool short_format) const;
+ size_t validate(uint8_t version);
/*bool flush_pool(const std::strig& folder);
bool inflate_pool(const std::strig& folder);*/