mirror of
https://github.com/jwinterm/aeon.git
synced 2026-11-13 08:33:54 +01:00
version-1.10
This commit is contained in:
@@ -1,6 +1,32 @@
|
||||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
// Copyright (c) 2014, AEON, The Monero Project
|
||||
//
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification, are
|
||||
// permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
// conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
// of conditions and the following disclaimer in the documentation and/or other
|
||||
// materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
||||
// used to endorse or promote products derived from this software without specific
|
||||
// prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
@@ -23,8 +49,6 @@
|
||||
#include "crypto/hash.h"
|
||||
//#include "serialization/json_archive.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace epee;
|
||||
using namespace cryptonote;
|
||||
|
||||
DISABLE_VS_WARNINGS(4267)
|
||||
@@ -85,14 +109,14 @@ bool blockchain_storage::init(const std::string& config_folder)
|
||||
uint64_t timestamp_diff = time(NULL) - m_blocks.back().bl.timestamp;
|
||||
if(!m_blocks.back().bl.timestamp)
|
||||
timestamp_diff = time(NULL) - 1341378000;
|
||||
LOG_PRINT_GREEN("Blockchain initialized. last block: " << m_blocks.size()-1 << ", " << misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block(), LOG_LEVEL_0);
|
||||
LOG_PRINT_GREEN("Blockchain initialized. last block: " << m_blocks.size() - 1 << ", " << epee::misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block(), LOG_LEVEL_0);
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::store_blockchain()
|
||||
{
|
||||
m_is_blockchain_storing = true;
|
||||
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([&](){m_is_blockchain_storing=false;});
|
||||
epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){m_is_blockchain_storing=false;});
|
||||
|
||||
LOG_PRINT_L0("Storing blockchain...");
|
||||
if (!tools::create_directories_if_necessary(m_config_folder))
|
||||
@@ -517,8 +541,7 @@ bool blockchain_storage::validate_miner_transaction(const block& b, size_t cumul
|
||||
|
||||
std::vector<size_t> last_blocks_sizes;
|
||||
get_last_n_blocks_sizes(last_blocks_sizes, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
|
||||
if(!get_block_reward(misc_utils::median(last_blocks_sizes), cumulative_block_size, already_generated_coins, base_reward))
|
||||
{
|
||||
if (!get_block_reward(epee::misc_utils::median(last_blocks_sizes), cumulative_block_size, already_generated_coins, base_reward)) {
|
||||
LOG_PRINT_L0("block size " << cumulative_block_size << " is bigger than allowed for this blockchain");
|
||||
return false;
|
||||
}
|
||||
@@ -707,7 +730,7 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto::
|
||||
uint64_t block_height = get_block_height(b);
|
||||
if(0 == block_height)
|
||||
{
|
||||
LOG_ERROR("Block with id: " << string_tools::pod_to_hex(id) << " (as alternative) have wrong miner transaction");
|
||||
LOG_ERROR("Block with id: " << epee::string_tools::pod_to_hex(id) << " (as alternative) have wrong miner transaction");
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
}
|
||||
@@ -791,7 +814,7 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto::
|
||||
|
||||
if(!prevalidate_miner_transaction(b, bei.height))
|
||||
{
|
||||
LOG_PRINT_RED_L0("Block with id: " << string_tools::pod_to_hex(id)
|
||||
LOG_PRINT_RED_L0("Block with id: " << epee::string_tools::pod_to_hex(id)
|
||||
<< " (as alternative) have wrong miner transaction.");
|
||||
bvc.m_verifivation_failed = true;
|
||||
return false;
|
||||
@@ -1104,7 +1127,7 @@ void blockchain_storage::print_blockchain_outs(const std::string& file)
|
||||
ss << "\t" << vals[i].first << ": " << vals[i].second << ENDL;
|
||||
}
|
||||
}
|
||||
if(file_io_utils::save_string_to_file(file, ss.str()))
|
||||
if(epee::file_io_utils::save_string_to_file(file, ss.str()))
|
||||
{
|
||||
LOG_PRINT_L0("Current outputs index writen to file: " << file);
|
||||
}else
|
||||
@@ -1126,11 +1149,15 @@ bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count)
|
||||
bool blockchain_storage::find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::list<std::pair<block, std::list<transaction> > >& blocks, uint64_t& total_height, uint64_t& start_height, size_t max_count)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_blockchain_lock);
|
||||
if(!find_blockchain_supplement(qblock_ids, start_height))
|
||||
return false;
|
||||
if(req_start_block > 0) {
|
||||
start_height = req_start_block;
|
||||
} else {
|
||||
if(!find_blockchain_supplement(qblock_ids, start_height))
|
||||
return false;
|
||||
}
|
||||
|
||||
total_height = get_current_blockchain_height();
|
||||
size_t count = 0;
|
||||
@@ -1352,7 +1379,7 @@ bool blockchain_storage::check_tx_inputs(const transaction& tx, const crypto::ha
|
||||
|
||||
if(have_tx_keyimg_as_spent(in_to_key.k_image))
|
||||
{
|
||||
LOG_PRINT_L1("Key image already spent in blockchain: " << string_tools::pod_to_hex(in_to_key.k_image));
|
||||
LOG_PRINT_L1("Key image already spent in blockchain: " << epee::string_tools::pod_to_hex(in_to_key.k_image));
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1651,7 +1678,7 @@ bool blockchain_storage::update_next_comulative_size_limit()
|
||||
std::vector<size_t> sz;
|
||||
get_last_n_blocks_sizes(sz, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
|
||||
|
||||
uint64_t median = misc_utils::median(sz);
|
||||
uint64_t median = epee::misc_utils::median(sz);
|
||||
if(median <= CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE)
|
||||
median = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user