Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hyle-team/zano
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptozoidberg committed Sep 5, 2019
2 parents 734b726 + d8f3a7f commit a1bee7d
Show file tree
Hide file tree
Showing 44 changed files with 11,141 additions and 7,521 deletions.
17 changes: 17 additions & 0 deletions contrib/epee/include/serialization/keyvalue_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ namespace epee
epee::string_tools::hex_to_pod(a, res);
return res;
}

//basic helpers for blob-to-hex serialization

inline std::string transform_binbuf_to_hexstr(const std::string& a)
{
return epee::string_tools::buff_to_hex_nodelimer(a);
}

inline std::string transform_hexstr_to_binbuff(const std::string& a)
{
std::string res;
if (!epee::string_tools::parse_hexstr_to_binbuff(a, res))
{
CHECK_AND_ASSERT_THROW_MES(false, "Failed to parse hex string:" << a);
}
return res;
}
//-------------------------------------------------------------------------------------------------------------------


Expand Down
5 changes: 4 additions & 1 deletion contrib/epee/include/serialization/keyvalue_serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public: \
#define KV_SERIALIZE_POD_AS_HEX_STRING_N(varialble, val_name) \
KV_SERIALIZE_CUSTOM_N(varialble, std::string, epee::transform_t_pod_to_str<decltype(varialble)>, epee::transform_str_to_t_pod<decltype(varialble)>, val_name)


#define KV_SERIALIZE_BLOB_AS_HEX_STRING_N(varialble, val_name) \
KV_SERIALIZE_CUSTOM_N(varialble, std::string, epee::transform_binbuf_to_hexstr, epee::transform_hexstr_to_binbuff, val_name)


#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(varialble, val_name) \
Expand All @@ -99,6 +100,8 @@ public: \
#define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(varialble) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(varialble, #varialble)
#define KV_SERIALIZE_CUSTOM(varialble, stored_type, from_v_to_stored, from_stored_to_v) KV_SERIALIZE_CUSTOM_N(varialble, stored_type, from_v_to_stored, from_stored_to_v, #varialble)
#define KV_SERIALIZE_POD_AS_HEX_STRING(varialble) KV_SERIALIZE_POD_AS_HEX_STRING_N(varialble, #varialble)
#define KV_SERIALIZE_BLOB_AS_HEX_STRING(varialble) KV_SERIALIZE_BLOB_AS_HEX_STRING_N(varialble, #varialble)



#define KV_CHAIN_MAP(variable_obj) epee::namespace_accessor<decltype(this_ref.variable_obj)>::template serialize_map<is_store>(this_ref.variable_obj, stg, hparent_section);
Expand Down
1 change: 1 addition & 0 deletions src/common/command_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ namespace command_line
const arg_descriptor<bool> arg_disable_upnp = { "disable-upnp", "Disable UPnP (enhances local network privacy)", false, true };

const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync = { "disable-stop-if-time-out-of-sync", "Do not stop the daemon if serious time synchronization problem is detected", false, true };
const arg_descriptor<bool> arg_disable_stop_on_low_free_space = { "disable-stop-on-low-free-space", "Do not stop the daemon if free space at data dir is critically low", false, true };
}
1 change: 1 addition & 0 deletions src/common/command_line.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,5 @@ namespace command_line
extern const arg_descriptor<bool> arg_show_rpc_autodoc;
extern const arg_descriptor<bool> arg_disable_upnp;
extern const arg_descriptor<bool> arg_disable_stop_if_time_out_of_sync;
extern const arg_descriptor<bool> arg_disable_stop_on_low_free_space;
}
50 changes: 50 additions & 0 deletions src/connectivity_tool/conn_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace
const command_line::arg_descriptor<int64_t> arg_set_peer_log_level = { "set-peer-log-level", "Set log level for remote peer", 0, true };
const command_line::arg_descriptor<std::string> arg_download_peer_log = { "download-peer-log", "Download log from remote peer <starting_offset>[,<count>]", "", true };
const command_line::arg_descriptor<bool> arg_do_consloe_log = { "do-console-log", "Tool generates debug console output(debug purposes)", "", true };
const command_line::arg_descriptor<std::string> arg_generate_integrated_address = { "generate-integrated-address", "Tool create integrated address from simple address and payment_id", "", true };
}

typedef COMMAND_REQUEST_STAT_INFO_T<t_currency_protocol_handler<core>::stat_info> COMMAND_REQUEST_STAT_INFO;
Expand Down Expand Up @@ -1035,6 +1036,48 @@ bool handle_download_peer_log(po::variables_map& vm)

return true;
}


bool handle_generate_integrated_address(po::variables_map& vm)
{
std::string add_and_payment_id = command_line::get_arg(vm, arg_generate_integrated_address);

std::string::size_type off = add_and_payment_id.find(':');
if (off == std::string::npos)
{
std::cout << "ERROR: wrong syntax, delimiter symbol (':') not found " << ENDL;
return false;
}

std::string address = add_and_payment_id.substr(0, off);
std::string payment_id = add_and_payment_id.substr(off+1, add_and_payment_id.length());
std::string payment_id_bin;
if (!epee::string_tools::parse_hexstr_to_binbuff(payment_id, payment_id_bin))
{
payment_id_bin = payment_id;
}

if (address.empty() || payment_id_bin.empty())
{
std::cout << "ERROR: wrong syntax, address or paymentd_id not set" << ENDL;
return false;
}

account_public_address acc_addr = AUTO_VAL_INIT(acc_addr);
bool r = currency::get_account_address_from_str(acc_addr, address);
if (!r)
{
std::cout << "ERROR: wrong syntax, address is wrong: " << address << ENDL;
return false;
}

std::string integrated_addr = currency::get_account_address_and_payment_id_as_str(acc_addr, payment_id_bin);


std::cout << "Integrated address: " << integrated_addr << ENDL;

return true;
}
//---------------------------------------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
Expand Down Expand Up @@ -1076,6 +1119,9 @@ int main(int argc, char* argv[])
command_line::add_arg(desc_params, arg_set_peer_log_level);
command_line::add_arg(desc_params, arg_download_peer_log);
command_line::add_arg(desc_params, arg_do_consloe_log);
command_line::add_arg(desc_params, arg_generate_integrated_address);



po::options_description desc_all;
desc_all.add(desc_general).add(desc_params);
Expand Down Expand Up @@ -1144,6 +1190,10 @@ int main(int argc, char* argv[])
{
return handle_download_peer_log(vm) ? EXIT_SUCCESS : EXIT_FAILURE;
}
else if (command_line::has_arg(vm, arg_generate_integrated_address))
{
return handle_generate_integrated_address(vm) ? EXIT_SUCCESS : EXIT_FAILURE;
}
else
{
std::cerr << "Not enough arguments." << ENDL;
Expand Down
140 changes: 136 additions & 4 deletions src/currency_core/blockchain_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,60 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro
if(!m_db_blocks.back()->bl.timestamp)
timestamp_diff = m_core_runtime_config.get_core_time() - 1341378000;

m_db.begin_transaction();
set_lost_tx_unmixable();
m_db.commit_transaction();

LOG_PRINT_GREEN("Blockchain initialized. (v:" << m_db_storage_major_compatibility_version << ") last block: " << m_db_blocks.size() - 1 << ENDL
<< "genesis: " << get_block_hash(m_db_blocks[0]->bl) << ENDL
<< "last block: " << m_db_blocks.size() - 1 << ", " << misc_utils::get_time_interval_string(timestamp_diff) << " time ago" << ENDL
<< "current pos difficulty: " << get_next_diff_conditional(true) << ENDL
<< "current pow difficulty: " << get_next_diff_conditional(false) << ENDL
<< "total transactions: " << m_db_transactions.size(),
LOG_LEVEL_0);


return true;
}

//------------------------------------------------------------------
bool blockchain_storage::set_lost_tx_unmixable_for_height(uint64_t height)
{
if (height == 75738)
return set_lost_tx_unmixable();
return true;
}
//------------------------------------------------------------------
bool blockchain_storage::set_lost_tx_unmixable()
{
if (m_db_blocks.size() > 75738)
{
crypto::hash tx_id_1 = epee::string_tools::parse_tpod_from_hex_string<crypto::hash>("c2a2229d614e7c026433efbcfdbd0be1f68d9b419220336df3e2c209f5d57314");
crypto::hash tx_id_2 = epee::string_tools::parse_tpod_from_hex_string<crypto::hash>("647f936c6ffbd136f5c95d9a90ad554bdb4c01541c6eb5755ad40b984d80da67");

auto tx_ptr_1 = m_db_transactions.find(tx_id_1);
CHECK_AND_ASSERT_MES(tx_ptr_1, false, "Internal error: filed to find lost tx");
transaction_chain_entry tx1_local_entry(*tx_ptr_1);
for (size_t i = 0; i != tx1_local_entry.m_spent_flags.size(); i++)
{
tx1_local_entry.m_spent_flags[i] = true;
}
m_db_transactions.set(tx_id_1, tx1_local_entry);

auto tx_ptr_2 = m_db_transactions.find(tx_id_2);
transaction_chain_entry tx2_local_entry(*tx_ptr_2);
CHECK_AND_ASSERT_MES(tx_ptr_1, false, "Internal error: filed to find lost tx");
for (size_t i = 0; i != tx2_local_entry.m_spent_flags.size(); i++)
{
tx2_local_entry.m_spent_flags[i] = true;
}
m_db_transactions.set(tx_id_2, tx2_local_entry);
}
return true;
}
//------------------------------------------------------------------
void blockchain_storage::patch_out_if_needed(txout_to_key& out, const crypto::hash& tx_id, uint64_t n) const
{
}
//------------------------------------------------------------------
void blockchain_storage::initialize_db_solo_options_values()
{
Expand Down Expand Up @@ -1578,7 +1621,19 @@ bool blockchain_storage::handle_alternative_block(const block& b, const crypto::
{
//block orphaned
bvc.m_marked_as_orphaned = true;
LOG_PRINT_RED_L0("Block recognized as orphaned and rejected, id = " << id << "," << ENDL << "parent id = " << b.prev_id << ENDL << "height = " << coinbase_height);

if (m_invalid_blocks.count(id) != 0)
{
LOG_PRINT_RED_L0("Block recognized as blacklisted and rejected, id = " << id << "," << ENDL << "parent id = " << b.prev_id << ENDL << "height = " << coinbase_height);
}
else if (m_invalid_blocks.count(b.prev_id) != 0)
{
LOG_PRINT_RED_L0("Block recognized as orphaned (parent " << b.prev_id << " is in blacklist) and rejected, id = " << id << "," << ENDL << "parent id = " << b.prev_id << ENDL << "height = " << coinbase_height);
}
else
{
LOG_PRINT_RED_L0("Block recognized as orphaned and rejected, id = " << id << "," << ENDL << "parent id = " << b.prev_id << ENDL << "height = " << coinbase_height);
}
}

CHECK_AND_ASSERT_MES(validate_blockchain_prev_links(), false, "EPIC FAIL!");
Expand Down Expand Up @@ -3406,8 +3461,7 @@ uint64_t blockchain_storage::tx_fee_median_for_height(uint64_t h)const
//------------------------------------------------------------------
bool blockchain_storage::validate_all_aliases_for_new_median_mode()
{

LOG_PRINT_L0("Started reinitialization of median fee...");
LOG_PRINT_L0("Started reinitialization of median fee...");
math_helper::once_a_time_seconds<10> log_idle;
uint64_t sz = m_db_blocks.size();
for (uint64_t i = 0; i != sz; i++)
Expand Down Expand Up @@ -3446,6 +3500,80 @@ bool blockchain_storage::validate_all_aliases_for_new_median_mode()
return true;
}
//------------------------------------------------------------------
bool blockchain_storage::print_tx_outputs_lookup(const crypto::hash& tx_id)const
{
CRITICAL_REGION_LOCAL(m_read_lock);
auto tx_ptr = m_db_transactions.find(tx_id);

if (!tx_ptr)
{
LOG_PRINT_RED_L0("Tx " << tx_id << " not found");
return true;
}

//amount -> index -> [{tx_id, rind_count}]
std::map<uint64_t, std::map<uint64_t, std::list<std::pair<crypto::hash,uint64_t > > > > usage_stat;
std::stringstream strm_tx;
CHECK_AND_ASSERT_MES(tx_ptr->tx.vout.size() == tx_ptr->m_global_output_indexes.size(), false, "Internal error: output size missmatch");
for (uint64_t i = 0; i!= tx_ptr->tx.vout.size();i++)
{
strm_tx << "[" << i << "]: " << print_money(tx_ptr->tx.vout[i].amount) << ENDL;
if (tx_ptr->tx.vout[i].target.type() != typeid(currency::txout_to_key))
continue;

usage_stat[tx_ptr->tx.vout[i].amount][tx_ptr->m_global_output_indexes[i]];

}

LOG_PRINT_L0("Lookup in all transactions....");
for (uint64_t i = 0; i != m_db_blocks.size(); i++)
{
auto block_ptr = m_db_blocks[i];
for (auto block_tx_id : block_ptr->bl.tx_hashes)
{
auto block_tx_ptr = m_db_transactions.find(block_tx_id);
for (auto txi_in : block_tx_ptr->tx.vin)
{
if(txi_in.type() != typeid(currency::txin_to_key))
continue;
currency::txin_to_key& txi_in_tokey = boost::get<currency::txin_to_key>(txi_in);
uint64_t amount = txi_in_tokey.amount;
auto amount_it = usage_stat.find(amount);
if(amount_it == usage_stat.end())
continue;

for (txout_v& off : txi_in_tokey.key_offsets)
{
if(off.type() != typeid(uint64_t))
continue;
uint64_t index = boost::get<uint64_t>(off);
auto index_it = amount_it->second.find(index);
if(index_it == amount_it->second.end())
continue;
index_it->second.push_back(std::pair<crypto::hash, uint64_t>(block_tx_id, txi_in_tokey.key_offsets.size()));
}
}
}
}

std::stringstream ss;
for (auto& amount : usage_stat)
{
for (auto& index : amount.second)
{
ss << "[" << print_money(amount.first) << ":" << index.first << "]" << ENDL ;
for (auto& list_entry : index.second)
{
ss << " " << list_entry.first << ": " << list_entry.second << ENDL;
}
}
}

LOG_PRINT_L0("Results: " << ENDL << strm_tx.str() << ENDL << ss.str());

return true;
}
//------------------------------------------------------------------
bool blockchain_storage::have_tx_keyimges_as_spent(const transaction &tx) const
{
// check all tx's inputs for being already spent
Expand Down Expand Up @@ -4547,6 +4675,10 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
powpos_str_entry << "PoW:\t" << proof_hash;
timestamp_str_entry << ", block ts: " << bei.bl.timestamp << " (diff: " << std::showpos << ts_diff << "s)";
}
//explanation of this code will be provided later with public announce
set_lost_tx_unmixable_for_height(bei.height);


LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED " << (is_pos_bl ? "[PoS]" : "[PoW]") << " Sq: " << sequence_factor
<< ENDL << "id:\t" << id << timestamp_str_entry.str()
<< ENDL << powpos_str_entry.str()
Expand Down
8 changes: 8 additions & 0 deletions src/currency_core/blockchain_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ namespace currency
void inspect_blocks_index() const;
bool rebuild_tx_fee_medians();
bool validate_all_aliases_for_new_median_mode();
bool print_tx_outputs_lookup(const crypto::hash& tx_id) const;
private:

//-------------- DB containers --------------
Expand Down Expand Up @@ -524,6 +525,9 @@ namespace currency
bool init_tx_fee_median();
bool update_tx_fee_median();
void initialize_db_solo_options_values();
bool set_lost_tx_unmixable();
bool set_lost_tx_unmixable_for_height(uint64_t height);
void patch_out_if_needed(txout_to_key& out, const crypto::hash& tx_id, uint64_t n)const ;
bool switch_to_alternative_blockchain(alt_chain_type& alt_chain);
void purge_alt_block_txs_hashs(const block& b);
void add_alt_block_txs_hashs(const block& b);
Expand Down Expand Up @@ -690,7 +694,11 @@ namespace currency
TIME_MEASURE_FINISH_PD(tx_check_inputs_loop_scan_outputkeys_loop_find_tx);

CHECKED_GET_SPECIFIC_VARIANT(tx_ptr->tx.vout[n].target, const txout_to_key, outtk, false);
//explanation of this code will be provided later with public announce
patch_out_if_needed(const_cast<txout_to_key&>(outtk), tx_id, n);



CHECK_AND_ASSERT_MES(tx_in_to_key.key_offsets.size() >= 1, false, "internal error: tx input has empty key_offsets"); // should never happen as input correctness must be handled by the caller
bool mixattr_ok = is_mixattr_applicable_for_fake_outs_counter(outtk.mix_attr, tx_in_to_key.key_offsets.size() - 1);
CHECK_AND_ASSERT_MES(mixattr_ok, false, "tx output #" << output_index << " violates mixin restrictions: mix_attr = " << static_cast<uint32_t>(outtk.mix_attr) << ", key_offsets.size = " << tx_in_to_key.key_offsets.size());
Expand Down
Loading

0 comments on commit a1bee7d

Please sign in to comment.