From e15fecc13c2e7dc71e18a6d39e0ab266eb21b029 Mon Sep 17 00:00:00 2001 From: who-biz <37732338+who-biz@users.noreply.github.com> Date: Sat, 26 Oct 2019 16:46:34 -0400 Subject: [PATCH] Attempt to fix 'invalid signature' error - 'invalid signature' is a misleading error... not happening in tx signatures, but portable storage signature in boost it appears. - this commit assumes we are running into an error because of std::list type, and attempts to fix by removing --- .../cryptonote_protocol_defs.h | 8 +-- .../cryptonote_protocol_handler.inl | 4 +- .../notarization_tx_cache.cpp | 24 ++++---- .../notarization_tx_cache.h | 4 +- .../notarization_tx_container.h | 2 +- src/komodo_notary_server/notary_server.cpp | 61 +++++++++++-------- .../notary_server_commands_defs.h | 6 +- src/rpc/core_rpc_server.cpp | 2 +- src/rpc/core_rpc_server_commands_defs.h | 4 +- src/wallet/wallet2.cpp | 4 +- src/wallet/wallet2.h | 2 +- 11 files changed, 67 insertions(+), 54 deletions(-) diff --git a/src/cryptonote_protocol/cryptonote_protocol_defs.h b/src/cryptonote_protocol/cryptonote_protocol_defs.h index f25994c1..664829e5 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_defs.h +++ b/src/cryptonote_protocol/cryptonote_protocol_defs.h @@ -307,7 +307,7 @@ namespace cryptonote struct request { int sig_count; - std::list ptx_strings; + blobdata ptx_string; blobdata tx_blob; crypto::hash tx_hash; std::string payment_id; @@ -315,7 +315,7 @@ namespace cryptonote BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(sig_count) - KV_SERIALIZE(ptx_strings) + KV_SERIALIZE(ptx_string) KV_SERIALIZE(tx_blob) KV_SERIALIZE_VAL_POD_AS_BLOB(tx_hash) KV_SERIALIZE(payment_id) @@ -333,7 +333,7 @@ namespace cryptonote struct request { int sig_count; - std::list ptx_strings; + blobdata ptx_string; blobdata tx_blob; crypto::hash tx_hash; std::string payment_id; @@ -341,7 +341,7 @@ namespace cryptonote BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(sig_count) - KV_SERIALIZE(ptx_strings) + KV_SERIALIZE(ptx_string) KV_SERIALIZE(tx_blob) KV_SERIALIZE_VAL_POD_AS_BLOB(tx_hash) KV_SERIALIZE(payment_id) diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index ef54804d..05a1303a 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -890,7 +890,7 @@ namespace cryptonote return 1; } } - ag.ptx_strings = arg.ptx_strings; + ag.ptx_string = arg.ptx_string; ag.tx_hash = arg.tx_hash; ag.sig_count = arg.sig_count; ag.payment_id = arg.payment_id; @@ -938,7 +938,7 @@ namespace cryptonote return 1; } - ag.ptx_strings = arg.ptx_strings; + ag.ptx_string = arg.ptx_string; ag.tx_hash = arg.tx_hash; ag.sig_count = arg.sig_count; ag.payment_id = arg.payment_id; diff --git a/src/komodo_notary_server/notarization_tx_cache.cpp b/src/komodo_notary_server/notarization_tx_cache.cpp index eeb22b84..31a7a388 100644 --- a/src/komodo_notary_server/notarization_tx_cache.cpp +++ b/src/komodo_notary_server/notarization_tx_cache.cpp @@ -42,20 +42,20 @@ std::vector get_cached_ptx() return ptx; } -std::pair, std::string> get_cached_peer_ptx_pair() +std::pair get_cached_peer_ptx_pair() { - std::pair,std::string> cache_entry; + std::pair cache_entry; if (!peer_ptx_cache.empty()) cache_entry = peer_ptx_cache.back(); return cache_entry; -} +} std::vector get_cached_peer_ptx() { - std::pair,std::string> cache_entry; + std::pair cache_entry; if (!peer_ptx_cache.empty()) cache_entry = peer_ptx_cache.back(); - std::list ptx_list = cache_entry.first; + std::string ptx_list = cache_entry.first; std::string signers_index_str = cache_entry.second; std::vector ptx_vec; if (!ptx_list.empty()) { @@ -96,11 +96,11 @@ bool add_ptx_to_cache(std::vector const& ptx) } */ -bool add_peer_ptx_to_cache(std::list& ptx_strings, std::string const& signers_index_str) +bool add_peer_ptx_to_cache(std::string& ptx_string, std::string const& signers_index_str) { - std::pair,std::string> cache_entry; - cache_entry = std::make_pair(ptx_strings, signers_index_str); - if (ptx_strings.empty()) { + std::pair cache_entry; + cache_entry = std::make_pair(ptx_string, signers_index_str); + if (ptx_string.empty()) { MERROR("Error: attempted to add empty ptx string to cache!"); return false; } else { @@ -114,7 +114,7 @@ bool add_peer_ptx_to_cache(std::list& ptx_strings, std::string cons } bool req_ntz_sig_to_cache(cryptonote::NOTIFY_REQUEST_NTZ_SIG::request& arg, std::string const& signers_index_str) { - std::list ptx_strings = arg.ptx_strings; + std::string ptx_string = arg.ptx_string; int const sig_count = arg.sig_count; std::vector signers_index = arg.signers_index; std::string signers_index_s; @@ -129,12 +129,12 @@ bool req_ntz_sig_to_cache(cryptonote::NOTIFY_REQUEST_NTZ_SIG::request& arg, std: int tmp = cryptonote::get_index(i, arg.signers_index); if ((tmp < 10) && (tmp != neg)) { each_ind = "0" + std::to_string(tmp); - } else { + } else { each_ind = std::to_string(tmp); } signers_index_s += each_ind; } - return add_peer_ptx_to_cache(ptx_strings, signers_index_str); + return add_peer_ptx_to_cache(ptx_string, signers_index_str); } size_t get_ntz_cache_count() diff --git a/src/komodo_notary_server/notarization_tx_cache.h b/src/komodo_notary_server/notarization_tx_cache.h index ac54b5a5..ad146173 100644 --- a/src/komodo_notary_server/notarization_tx_cache.h +++ b/src/komodo_notary_server/notarization_tx_cache.h @@ -34,8 +34,8 @@ std::vector get_cached_ptx(); bool add_ptx_to_cache(std::vector const& ptx); size_t get_ntz_cache_count(); std::vector get_cached_peer_ptx(); -std::pair,std::string> get_cached_peer_ptx_pair(); -bool add_peer_ptx_to_cache(std::list& ptx, std::string const& signers_index); +std::pair get_cached_peer_ptx_pair(); +bool add_peer_ptx_to_cache(std::string& ptx, std::string const& signers_index); bool req_ntz_sig_to_cache(cryptonote::NOTIFY_REQUEST_NTZ_SIG::request& req, std::string const& signers_index); size_t get_peer_ptx_cache_count(); diff --git a/src/komodo_notary_server/notarization_tx_container.h b/src/komodo_notary_server/notarization_tx_container.h index 12a27f33..c975dbc5 100644 --- a/src/komodo_notary_server/notarization_tx_container.h +++ b/src/komodo_notary_server/notarization_tx_container.h @@ -31,6 +31,6 @@ namespace tools { std::list> ntz_ptx_cache; -std::vector,std::string>> peer_ptx_cache; +std::vector> peer_ptx_cache; } diff --git a/src/komodo_notary_server/notary_server.cpp b/src/komodo_notary_server/notary_server.cpp index 0208456f..5668de5b 100644 --- a/src/komodo_notary_server/notary_server.cpp +++ b/src/komodo_notary_server/notary_server.cpp @@ -162,13 +162,13 @@ namespace tools { //TODO: clean this conditional up, and below it... looking ugly bool last = on_create_ntz_transfer(req, res, e); if (last) - ++num_calls; - } + ++num_calls; + } if ((get_peer_ptx_cache_count() >= 1) && (get_ntz_cache_count() >= 2) && (m_wallet->get_ntzpool_count(true) >= 1)) { notary_rpc::COMMAND_RPC_APPEND_NTZ_SIG::request request; - std::pair,std::string> cache_entry = get_cached_peer_ptx_pair(); - request.recv_blob = cache_entry.first; + std::pair cache_entry = get_cached_peer_ptx_pair(); + request.ptx_blob = cache_entry.first; request.signers_index = cache_entry.second; notary_rpc::COMMAND_RPC_APPEND_NTZ_SIG::response response; epee::json_rpc::error err; @@ -181,8 +181,8 @@ namespace tools } return true; }, 20000); - - m_net_server.add_idle_handler([this](){ + + m_net_server.add_idle_handler([this](){ if (m_stop.load(std::memory_order_relaxed)) { send_stop_signal(); @@ -1173,7 +1173,12 @@ namespace tools bool fill_res = fill_response(ptx_vector, true, res.tx_key_list, res.amount_list, res.fee_list, res.multisig_txset, false, res.tx_hash_list, true, res.tx_blob_list, true, res.tx_metadata_list, er); if (fill_res) { - m_wallet->request_ntz_sig(res.tx_metadata_list, ptx_vector, sig_count, payment_id, si_const); + std::string tx_metadata; + for (const auto& each : res.tx_metadata_list) { + tx_metadata = each; + break; + } + m_wallet->request_ntz_sig(tx_metadata, ptx_vector, sig_count, payment_id, si_const); MWARNING("Signatures < 13: [request_ntz_sig] sent with sig_count: " << std::to_string(sig_count) << ", signers_index = " << index_vec << ", and payment id: " << payment_id); } @@ -1190,16 +1195,21 @@ namespace tools bool fill_res = fill_response(ptx_vector, true, res.tx_key_list, res.amount_list, res.fee_list, res.multisig_txset, false, res.tx_hash_list, true, res.tx_blob_list, true, res.tx_metadata_list, er); if (fill_res) { - m_wallet->request_ntz_sig(res.tx_metadata_list, ptx_vector, sig_count, payment_id, si_const); - MWARNING("Signatures < 13: [request_ntz_sig] sent with sig_count: " << std::to_string(sig_count) << ", signers_index = " << index_vec << ", and payment id: " << payment_id); - } + std::string tx_metadata; + for (const auto& each : res.tx_metadata_list) { + tx_metadata = each; + break; + } + m_wallet->request_ntz_sig(tx_metadata, ptx_vector, sig_count, payment_id, si_const); + MWARNING("Signatures < 13: [request_ntz_sig] sent with sig_count: " << std::to_string(sig_count) << ", signers_index = " << index_vec << ", and payment id: " << payment_id); + } return fill_res; } else { return true; } - } + } } catch (const std::exception& e) { @@ -1223,16 +1233,12 @@ namespace tools return false; } - std::list recv_blobs; - std::list hex_blobs = req.recv_blob; - for (const auto& each : hex_blobs) { - std::string tmp; - if (!epee::string_tools::parse_hexstr_to_binbuff(each, tmp)) { - MERROR("Failed to parse recv_blob from hexstr!"); + std::string tx_blob; + std::string ptx_blob; + std::string hex_blob = req.tx_blob; + if (!epee::string_tools::parse_hexstr_to_binbuff(hex_blob, tx_blob)) { + MERROR("Failed to parse ptx_blob from hexstr!"); return false; - } else { - recv_blobs.push_back(tmp); - } } uint16_t pool_count = m_wallet->get_ntzpool_count(true); if (pool_count < 1) { @@ -1253,6 +1259,7 @@ namespace tools for (const auto& each : ntzpool_txs) { pool_indexes.push_back(each.signers_index); } + std::vector signers_index; std::list best_index; for (int i = 0; i < 13; i++) { @@ -1269,14 +1276,13 @@ namespace tools } std::vector recv_ptx_vec; - for (const auto& recv_blob : recv_blobs) { wallet2::pending_tx pen_tx; std::stringstream iss; - iss << recv_blob; + iss << ptx_blob; boost::archive::portable_binary_iarchive ar(iss); ar >> pen_tx; recv_ptx_vec.push_back(pen_tx); - } + for (const auto& recv_ptx : recv_ptx_vec) { int sig_count = req.sig_count; @@ -1450,11 +1456,16 @@ namespace tools const std::vector si_const = signers_index; ptx_vector.push_back(recv_ptx); - + bool fill_res = fill_response(ptx_vector, true, res.tx_key_list, res.amount_list, res.fee_list, res.multisig_txset, ready_to_send, res.tx_hash_list, true, res.tx_blob_list, true, res.tx_metadata_list, er); if (fill_res) { - m_wallet->request_ntz_sig(res.tx_metadata_list, ptx_vector, sig_count, payment_id, si_const); + std::string tx_metadata; + for (const auto& each : res.tx_metadata_list) { + tx_metadata = each; + break; + } + m_wallet->request_ntz_sig(tx_metadata, ptx_vector, sig_count, payment_id, si_const); MWARNING("Signatures < 13: [request_ntz_sig] sent with sig_count: " << std::to_string(sig_count) << ", signers_index = " << index_vec << ", and payment id: " << payment_id); } return fill_res; diff --git a/src/komodo_notary_server/notary_server_commands_defs.h b/src/komodo_notary_server/notary_server_commands_defs.h index cbc1502a..75814b9e 100644 --- a/src/komodo_notary_server/notary_server_commands_defs.h +++ b/src/komodo_notary_server/notary_server_commands_defs.h @@ -546,13 +546,15 @@ namespace notary_rpc { struct request { - std::list recv_blob; + std::string tx_blob; + std::string ptx_blob; int sig_count; std::string signers_index; std::string payment_id; BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(recv_blob) + KV_SERIALIZE(tx_blob) + KV_SERIALIZE(ptx_blob) KV_SERIALIZE(sig_count) KV_SERIALIZE(signers_index) KV_SERIALIZE(payment_id) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index a6660421..7ec32766 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -1185,7 +1185,7 @@ namespace cryptonote if ((req.sig_count < 13) && (req.sig_count > 0)) { NOTIFY_REQUEST_NTZ_SIG::request r; - r.ptx_strings = req.ptx_strings; + r.ptx_string = req.ptx_string; r.tx_blob = req.tx_blob; r.sig_count = req.sig_count; r.payment_id = req.payment_id; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 69308d5a..75f07224 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -970,14 +970,14 @@ namespace cryptonote struct request { int sig_count; - std::list ptx_strings; + std::string ptx_string; std::string tx_blob; std::string payment_id; std::string signers_index/* = "-1-1-1-1-1-1-1-1-1-1-1-1-1"*/; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(sig_count) - KV_SERIALIZE(ptx_strings) + KV_SERIALIZE(ptx_string) KV_SERIALIZE(tx_blob) KV_SERIALIZE(payment_id) KV_SERIALIZE(signers_index) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 18202ca4..29571164 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -4922,13 +4922,13 @@ void wallet2::get_ntzpool_tx(std::vector& ptx_vector) } //---------------------------------------------------------------------------------------------------- -void wallet2::request_ntz_sig(std::list const& ptx_string, std::vector ptxs, const int& sigs_count, const std::string& payment_id, std::vector const & signers_index) +void wallet2::request_ntz_sig(std::string const& ptx_string, std::vector ptxs, const int& sigs_count, const std::string& payment_id, std::vector const & signers_index) { using namespace cryptonote; // Normal submit COMMAND_RPC_REQUEST_NTZ_SIG::request request = AUTO_VAL_INIT(request); request.sig_count = sigs_count; - request.ptx_strings = ptx_string; + request.ptx_string = ptx_string; std::vector tx_blobs; for (const auto& each : ptxs) { blobdata blob = tx_to_blob(each.tx); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 1c812a40..1d5e2b2e 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -677,7 +677,7 @@ namespace tools uint64_t unlock_time, uint64_t fee, const std::vector& extra, cryptonote::transaction& tx, pending_tx &ptx, bool bulletproof); void commit_tx(pending_tx& ptx_vector); - void request_ntz_sig(std::list const& ptx_string, std::vector ptxs, int const& sigs_count, std::string const& payment_id, std::vector const& sig_index); + void request_ntz_sig(std::string const& ptx_string, std::vector ptxs, int const& sigs_count, std::string const& payment_id, std::vector const& sig_index); void get_ntzpool_tx(std::vector& ptx_vector); void get_ntzpool_txs_and_keys(std::vector& txs, std::vector& spent_key_images); void commit_tx(std::vector& ptx_vector);