Merge pull request #63 from mikezackles/bytecoin_for_merge

Misc fixes from bytecoin
This commit is contained in:
mikezackles 2014-07-17 19:23:49 -04:00
commit 905b67bc79
16 changed files with 53 additions and 61 deletions

View file

@ -110,7 +110,7 @@ namespace tools
void encode_block(const char* block, size_t size, char* res) void encode_block(const char* block, size_t size, char* res)
{ {
assert(1 <= size && size <= sizeof(full_block_size)); assert(1 <= size && size <= full_block_size);
uint64_t num = uint_8be_to_64(reinterpret_cast<const uint8_t*>(block), size); uint64_t num = uint_8be_to_64(reinterpret_cast<const uint8_t*>(block), size);
int i = static_cast<int>(encoded_block_sizes[size]) - 1; int i = static_cast<int>(encoded_block_sizes[size]) - 1;

View file

@ -350,7 +350,6 @@ void cn_slow_hash(const void *data, size_t length, char *hash)
RDATA_ALIGN16 uint64_t a[2]; RDATA_ALIGN16 uint64_t a[2];
RDATA_ALIGN16 uint64_t b[2]; RDATA_ALIGN16 uint64_t b[2];
RDATA_ALIGN16 uint64_t c[2]; RDATA_ALIGN16 uint64_t c[2];
RDATA_ALIGN16 uint8_t aes_key[AES_KEY_SIZE];
union cn_slow_hash_state state; union cn_slow_hash_state state;
__m128i _a, _b, _c; __m128i _a, _b, _c;
uint64_t hi, lo; uint64_t hi, lo;

View file

@ -23,8 +23,6 @@
#include "crypto/hash.h" #include "crypto/hash.h"
//#include "serialization/json_archive.h" //#include "serialization/json_archive.h"
using namespace std;
using namespace epee;
using namespace cryptonote; using namespace cryptonote;
DISABLE_VS_WARNINGS(4267) DISABLE_VS_WARNINGS(4267)
@ -85,14 +83,14 @@ bool blockchain_storage::init(const std::string& config_folder)
uint64_t timestamp_diff = time(NULL) - m_blocks.back().bl.timestamp; uint64_t timestamp_diff = time(NULL) - m_blocks.back().bl.timestamp;
if(!m_blocks.back().bl.timestamp) if(!m_blocks.back().bl.timestamp)
timestamp_diff = time(NULL) - 1341378000; 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; return true;
} }
//------------------------------------------------------------------ //------------------------------------------------------------------
bool blockchain_storage::store_blockchain() bool blockchain_storage::store_blockchain()
{ {
m_is_blockchain_storing = true; 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..."); LOG_PRINT_L0("Storing blockchain...");
if (!tools::create_directories_if_necessary(m_config_folder)) if (!tools::create_directories_if_necessary(m_config_folder))
@ -517,8 +515,7 @@ bool blockchain_storage::validate_miner_transaction(const block& b, size_t cumul
std::vector<size_t> last_blocks_sizes; std::vector<size_t> last_blocks_sizes;
get_last_n_blocks_sizes(last_blocks_sizes, CRYPTONOTE_REWARD_BLOCKS_WINDOW); 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"); LOG_PRINT_L0("block size " << cumulative_block_size << " is bigger than allowed for this blockchain");
return false; return false;
} }
@ -707,7 +704,7 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto::
uint64_t block_height = get_block_height(b); uint64_t block_height = get_block_height(b);
if(0 == block_height) 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; bvc.m_verifivation_failed = true;
return false; return false;
} }
@ -791,7 +788,7 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto::
if(!prevalidate_miner_transaction(b, bei.height)) 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."); << " (as alternative) have wrong miner transaction.");
bvc.m_verifivation_failed = true; bvc.m_verifivation_failed = true;
return false; return false;
@ -1104,7 +1101,7 @@ void blockchain_storage::print_blockchain_outs(const std::string& file)
ss << "\t" << vals[i].first << ": " << vals[i].second << ENDL; 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); LOG_PRINT_L0("Current outputs index writen to file: " << file);
}else }else
@ -1352,7 +1349,7 @@ bool blockchain_storage::check_tx_inputs(const transaction& tx, const crypto::ha
if(have_tx_keyimg_as_spent(in_to_key.k_image)) 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; return false;
} }
@ -1651,7 +1648,7 @@ bool blockchain_storage::update_next_comulative_size_limit()
std::vector<size_t> sz; std::vector<size_t> sz;
get_last_n_blocks_sizes(sz, CRYPTONOTE_REWARD_BLOCKS_WINDOW); 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) if(median <= CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE)
median = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE; median = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE;

View file

@ -81,24 +81,6 @@ namespace cryptonote
return m_blockchain_storage.get_transactions(txs_ids, txs, missed_txs); return m_blockchain_storage.get_transactions(txs_ids, txs, missed_txs);
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::get_transaction(const crypto::hash &h, transaction &tx)
{
std::vector<crypto::hash> ids;
ids.push_back(h);
std::list<transaction> ltx;
std::list<crypto::hash> missing;
if (m_blockchain_storage.get_transactions(ids, ltx, missing))
{
if (ltx.size() > 0)
{
tx = *ltx.begin();
return true;
}
}
return false;
}
//-----------------------------------------------------------------------------------------------
bool core::get_alternative_blocks(std::list<block>& blocks) bool core::get_alternative_blocks(std::list<block>& blocks)
{ {
return m_blockchain_storage.get_alternative_blocks(blocks); return m_blockchain_storage.get_alternative_blocks(blocks);
@ -284,10 +266,10 @@ namespace cryptonote
return m_blockchain_storage.get_total_transactions(); return m_blockchain_storage.get_total_transactions();
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::get_outs(uint64_t amount, std::list<crypto::public_key>& pkeys) //bool core::get_outs(uint64_t amount, std::list<crypto::public_key>& pkeys)
{ //{
return m_blockchain_storage.get_outs(amount, pkeys); // return m_blockchain_storage.get_outs(amount, pkeys);
} //}
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block) bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block)
{ {
@ -398,10 +380,10 @@ namespace cryptonote
{ {
m_miner.on_synchronized(); m_miner.on_synchronized();
} }
bool core::get_backward_blocks_sizes(uint64_t from_height, std::vector<size_t>& sizes, size_t count) //bool core::get_backward_blocks_sizes(uint64_t from_height, std::vector<size_t>& sizes, size_t count)
{ //{
return m_blockchain_storage.get_backward_blocks_sizes(from_height, sizes, count); // return m_blockchain_storage.get_backward_blocks_sizes(from_height, sizes, count);
} //}
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
bool core::add_new_block(const block& b, block_verification_context& bvc) bool core::add_new_block(const block& b, block_verification_context& bvc)
{ {
@ -418,7 +400,6 @@ namespace cryptonote
return false; return false;
} }
block b = AUTO_VAL_INIT(b); block b = AUTO_VAL_INIT(b);
if(!parse_and_validate_block_from_blob(block_blob, b)) if(!parse_and_validate_block_from_blob(block_blob, b))
{ {
@ -493,9 +474,9 @@ namespace cryptonote
return m_blockchain_storage.get_block_by_hash(h, blk); return m_blockchain_storage.get_block_by_hash(h, blk);
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
void core::get_all_known_block_ids(std::list<crypto::hash> &main, std::list<crypto::hash> &alt, std::list<crypto::hash> &invalid) { //void core::get_all_known_block_ids(std::list<crypto::hash> &main, std::list<crypto::hash> &alt, std::list<crypto::hash> &invalid) {
m_blockchain_storage.get_all_known_block_ids(main, alt, invalid); // m_blockchain_storage.get_all_known_block_ids(main, alt, invalid);
} //}
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------
std::string core::print_pool(bool short_format) std::string core::print_pool(bool short_format)
{ {

View file

@ -58,9 +58,8 @@ namespace cryptonote
} }
crypto::hash get_block_id_by_height(uint64_t height); crypto::hash get_block_id_by_height(uint64_t height);
bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<transaction>& txs, std::list<crypto::hash>& missed_txs); bool get_transactions(const std::vector<crypto::hash>& txs_ids, std::list<transaction>& txs, std::list<crypto::hash>& missed_txs);
bool get_transaction(const crypto::hash &h, transaction &tx);
bool get_block_by_hash(const crypto::hash &h, block &blk); bool get_block_by_hash(const crypto::hash &h, block &blk);
void get_all_known_block_ids(std::list<crypto::hash> &main, std::list<crypto::hash> &alt, std::list<crypto::hash> &invalid); //void get_all_known_block_ids(std::list<crypto::hash> &main, std::list<crypto::hash> &alt, std::list<crypto::hash> &invalid);
bool get_alternative_blocks(std::list<block>& blocks); bool get_alternative_blocks(std::list<block>& blocks);
size_t get_alternative_blocks_count(); size_t get_alternative_blocks_count();
@ -71,13 +70,13 @@ namespace cryptonote
bool get_pool_transactions(std::list<transaction>& txs); bool get_pool_transactions(std::list<transaction>& txs);
size_t get_pool_transactions_count(); size_t get_pool_transactions_count();
size_t get_blockchain_total_transactions(); size_t get_blockchain_total_transactions();
bool get_outs(uint64_t amount, std::list<crypto::public_key>& pkeys); //bool get_outs(uint64_t amount, std::list<crypto::public_key>& pkeys);
bool have_block(const crypto::hash& id); bool have_block(const crypto::hash& id);
bool get_short_chain_history(std::list<crypto::hash>& ids); bool get_short_chain_history(std::list<crypto::hash>& ids);
bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp); bool find_blockchain_supplement(const std::list<crypto::hash>& qblock_ids, NOTIFY_RESPONSE_CHAIN_ENTRY::request& resp);
bool 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 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 get_stat_info(core_stat_info& st_inf); bool get_stat_info(core_stat_info& st_inf);
bool get_backward_blocks_sizes(uint64_t from_height, std::vector<size_t>& sizes, size_t count); //bool get_backward_blocks_sizes(uint64_t from_height, std::vector<size_t>& sizes, size_t count);
bool get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<uint64_t>& indexs); bool get_tx_outputs_gindexs(const crypto::hash& tx_id, std::vector<uint64_t>& indexs);
crypto::hash get_tail_id(); crypto::hash get_tail_id();
bool get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res); bool get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res);

View file

@ -595,7 +595,7 @@ namespace cryptonote
{ {
blobdata blob = t_serializable_object_to_blob(static_cast<block_header>(b)); blobdata blob = t_serializable_object_to_blob(static_cast<block_header>(b));
crypto::hash tree_root_hash = get_tx_tree_hash(b); crypto::hash tree_root_hash = get_tx_tree_hash(b);
blob.append((const char*)&tree_root_hash, sizeof(tree_root_hash )); blob.append(reinterpret_cast<const char*>(&tree_root_hash), sizeof(tree_root_hash));
blob.append(tools::get_varint_data(b.tx_hashes.size()+1)); blob.append(tools::get_varint_data(b.tx_hashes.size()+1));
return blob; return blob;
} }

View file

@ -85,7 +85,6 @@ namespace cryptonote
uint64_t get_outs_money_amount(const transaction& tx); uint64_t get_outs_money_amount(const transaction& tx);
bool check_inputs_types_supported(const transaction& tx); bool check_inputs_types_supported(const transaction& tx);
bool check_outs_valid(const transaction& tx); bool check_outs_valid(const transaction& tx);
blobdata get_block_hashing_blob(const block& b);
bool parse_amount(uint64_t& amount, const std::string& str_amount); bool parse_amount(uint64_t& amount, const std::string& str_amount);
bool check_money_overflow(const transaction& tx); bool check_money_overflow(const transaction& tx);

View file

@ -130,7 +130,7 @@ namespace nodetool
if (!parse_peers_and_add_to_container(vm, arg_p2p_add_exclusive_node, m_exclusive_peers)) if (!parse_peers_and_add_to_container(vm, arg_p2p_add_exclusive_node, m_exclusive_peers))
return false; return false;
} }
else if (command_line::has_arg(vm, arg_p2p_add_priority_node)) if (command_line::has_arg(vm, arg_p2p_add_priority_node))
{ {
if (!parse_peers_and_add_to_container(vm, arg_p2p_add_priority_node, m_priority_peers)) if (!parse_peers_and_add_to_container(vm, arg_p2p_add_priority_node, m_priority_peers))
return false; return false;

View file

@ -115,8 +115,8 @@ namespace cryptonote
{ {
struct request struct request
{ {
std::list<uint64_t> amounts; std::vector<uint64_t> amounts;
uint64_t outs_count; uint64_t outs_count;
BEGIN_KV_SERIALIZE_MAP() BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(amounts) KV_SERIALIZE(amounts)
KV_SERIALIZE(outs_count) KV_SERIALIZE(outs_count)
@ -414,7 +414,11 @@ namespace cryptonote
struct COMMAND_RPC_GET_LAST_BLOCK_HEADER struct COMMAND_RPC_GET_LAST_BLOCK_HEADER
{ {
typedef std::list<std::string> request; struct request
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
struct response struct response
{ {

View file

@ -2,6 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <sstream> #include <sstream>
#include "binary_archive.h" #include "binary_archive.h"

View file

@ -2,6 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <vector> #include <vector>
#include "serialization.h" #include "serialization.h"

View file

@ -2,6 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#pragma once
#include <sstream> #include <sstream>
#include "json_archive.h" #include "json_archive.h"

View file

@ -16,6 +16,13 @@ namespace serialization
return ::do_serialize(ar, e); return ::do_serialize(ar, e);
} }
template <typename Archive>
bool serialize_vector_element(Archive& ar, uint32_t& e)
{
ar.serialize_varint(e);
return true;
}
template <typename Archive> template <typename Archive>
bool serialize_vector_element(Archive& ar, uint64_t& e) bool serialize_vector_element(Archive& ar, uint64_t& e)
{ {

View file

@ -499,9 +499,9 @@ bool simple_wallet::start_mining(const std::vector<std::string>& args)
} }
else if (1 == args.size()) else if (1 == args.size())
{ {
uint16_t num; uint16_t num = 1;
ok = string_tools::get_xtype_from_string(num, args[0]); ok = string_tools::get_xtype_from_string(num, args[0]);
ok &= (1 <= num && num <= max_mining_threads_count); ok = ok && (1 <= num && num <= max_mining_threads_count);
req.threads_count = num; req.threads_count = num;
} }
else else

View file

@ -203,7 +203,7 @@ namespace tools
struct refresh_error : public wallet_logic_error struct refresh_error : public wallet_logic_error
{ {
protected: protected:
refresh_error(std::string&& loc, const std::string& message) explicit refresh_error(std::string&& loc, const std::string& message)
: wallet_logic_error(std::move(loc), message) : wallet_logic_error(std::move(loc), message)
{ {
} }
@ -277,7 +277,7 @@ namespace tools
struct transfer_error : public wallet_logic_error struct transfer_error : public wallet_logic_error
{ {
protected: protected:
transfer_error(std::string&& loc, const std::string& message) explicit transfer_error(std::string&& loc, const std::string& message)
: wallet_logic_error(std::move(loc), message) : wallet_logic_error(std::move(loc), message)
{ {
} }
@ -287,7 +287,7 @@ namespace tools
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
struct not_enough_money : public transfer_error struct not_enough_money : public transfer_error
{ {
not_enough_money(std::string&& loc, uint64_t availbable, uint64_t tx_amount, uint64_t fee) explicit not_enough_money(std::string&& loc, uint64_t availbable, uint64_t tx_amount, uint64_t fee)
: transfer_error(std::move(loc), "not enough money") : transfer_error(std::move(loc), "not enough money")
, m_available(availbable) , m_available(availbable)
, m_tx_amount(tx_amount) , m_tx_amount(tx_amount)
@ -431,7 +431,7 @@ namespace tools
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
struct tx_sum_overflow : public transfer_error struct tx_sum_overflow : public transfer_error
{ {
tx_sum_overflow(std::string&& loc, const std::vector<cryptonote::tx_destination_entry>& destinations, uint64_t fee) explicit tx_sum_overflow(std::string&& loc, const std::vector<cryptonote::tx_destination_entry>& destinations, uint64_t fee)
: transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max())) : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits<uint64_t>::max()))
, m_destinations(destinations) , m_destinations(destinations)
, m_fee(fee) , m_fee(fee)
@ -507,7 +507,7 @@ namespace tools
} }
protected: protected:
wallet_rpc_error(std::string&& loc, const std::string& message, const std::string& request) explicit wallet_rpc_error(std::string&& loc, const std::string& message, const std::string& request)
: wallet_logic_error(std::move(loc), message) : wallet_logic_error(std::move(loc), message)
, m_request(request) , m_request(request)
{ {

View file

@ -80,7 +80,7 @@ inline void get(std::istream &input, std::vector<char> &res) {
} }
} }
#if !defined(_MSC_VER) #if !defined(_MSC_VER) || _MSC_VER >= 1800
template<typename T, typename... TT> template<typename T, typename... TT>
typename std::enable_if<(sizeof...(TT) > 0), void>::type typename std::enable_if<(sizeof...(TT) > 0), void>::type