Skip to content

Commit

Permalink
Attempt to fix 'invalid signature' error
Browse files Browse the repository at this point in the history
- '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
  • Loading branch information
who-biz committed Oct 26, 2019
1 parent 0a9fb5c commit e15fecc
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 54 deletions.
8 changes: 4 additions & 4 deletions src/cryptonote_protocol/cryptonote_protocol_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,15 @@ namespace cryptonote
struct request
{
int sig_count;
std::list<blobdata> ptx_strings;
blobdata ptx_string;
blobdata tx_blob;
crypto::hash tx_hash;
std::string payment_id;
std::vector<int> signers_index;

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)
Expand All @@ -333,15 +333,15 @@ namespace cryptonote
struct request
{
int sig_count;
std::list<blobdata> ptx_strings;
blobdata ptx_string;
blobdata tx_blob;
crypto::hash tx_hash;
std::string payment_id;
std::vector<int> signers_index;

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)
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_protocol/cryptonote_protocol_handler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 12 additions & 12 deletions src/komodo_notary_server/notarization_tx_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ std::vector<wallet2::pending_tx> get_cached_ptx()
return ptx;
}

std::pair<std::list<std::string>, std::string> get_cached_peer_ptx_pair()
std::pair<std::string, std::string> get_cached_peer_ptx_pair()
{
std::pair<std::list<std::string>,std::string> cache_entry;
std::pair<std::string,std::string> cache_entry;
if (!peer_ptx_cache.empty())
cache_entry = peer_ptx_cache.back();
return cache_entry;
}
}

std::vector<wallet2::pending_tx> get_cached_peer_ptx()
{
std::pair<std::list<std::string>,std::string> cache_entry;
std::pair<std::string,std::string> cache_entry;
if (!peer_ptx_cache.empty())
cache_entry = peer_ptx_cache.back();
std::list<std::string> ptx_list = cache_entry.first;
std::string ptx_list = cache_entry.first;
std::string signers_index_str = cache_entry.second;
std::vector<wallet2::pending_tx> ptx_vec;
if (!ptx_list.empty()) {
Expand Down Expand Up @@ -96,11 +96,11 @@ bool add_ptx_to_cache(std::vector<wallet2::pending_tx> const& ptx)
}
*/

bool add_peer_ptx_to_cache(std::list<std::string>& 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::list<std::string>,std::string> cache_entry;
cache_entry = std::make_pair(ptx_strings, signers_index_str);
if (ptx_strings.empty()) {
std::pair<std::string,std::string> 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 {
Expand All @@ -114,7 +114,7 @@ bool add_peer_ptx_to_cache(std::list<std::string>& 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<std::string> ptx_strings = arg.ptx_strings;
std::string ptx_string = arg.ptx_string;
int const sig_count = arg.sig_count;
std::vector<int> signers_index = arg.signers_index;
std::string signers_index_s;
Expand All @@ -129,12 +129,12 @@ bool req_ntz_sig_to_cache(cryptonote::NOTIFY_REQUEST_NTZ_SIG::request& arg, std:
int tmp = cryptonote::get_index<int>(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()
Expand Down
4 changes: 2 additions & 2 deletions src/komodo_notary_server/notarization_tx_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ std::vector<tools::wallet2::pending_tx> get_cached_ptx();
bool add_ptx_to_cache(std::vector<tools::wallet2::pending_tx> const& ptx);
size_t get_ntz_cache_count();
std::vector<tools::wallet2::pending_tx> get_cached_peer_ptx();
std::pair<std::list<std::string>,std::string> get_cached_peer_ptx_pair();
bool add_peer_ptx_to_cache(std::list<std::string>& ptx, std::string const& signers_index);
std::pair<std::string,std::string> 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();

Expand Down
2 changes: 1 addition & 1 deletion src/komodo_notary_server/notarization_tx_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
namespace tools {

std::list<std::vector<wallet2::pending_tx>> ntz_ptx_cache;
std::vector<std::pair<std::list<std::string>,std::string>> peer_ptx_cache;
std::vector<std::pair<std::string,std::string>> peer_ptx_cache;

}
61 changes: 36 additions & 25 deletions src/komodo_notary_server/notary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::list<std::string>,std::string> cache_entry = get_cached_peer_ptx_pair();
request.recv_blob = cache_entry.first;
std::pair<std::string,std::string> 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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}

Expand All @@ -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)
{
Expand All @@ -1223,16 +1233,12 @@ namespace tools
return false;
}

std::list<std::string> recv_blobs;
std::list<std::string> 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) {
Expand All @@ -1253,6 +1259,7 @@ namespace tools
for (const auto& each : ntzpool_txs) {
pool_indexes.push_back(each.signers_index);
}

std::vector<int> signers_index;
std::list<int> best_index;
for (int i = 0; i < 13; i++) {
Expand All @@ -1269,14 +1276,13 @@ namespace tools
}

std::vector<tools::wallet2::pending_tx> 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;
Expand Down Expand Up @@ -1450,11 +1456,16 @@ namespace tools

const std::vector<int> 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;
Expand Down
6 changes: 4 additions & 2 deletions src/komodo_notary_server/notary_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,15 @@ namespace notary_rpc
{
struct request
{
std::list<std::string> 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)
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/core_rpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/rpc/core_rpc_server_commands_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -970,14 +970,14 @@ namespace cryptonote
struct request
{
int sig_count;
std::list<std::string> 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)
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4922,13 +4922,13 @@ void wallet2::get_ntzpool_tx(std::vector<pending_tx>& ptx_vector)

}
//----------------------------------------------------------------------------------------------------
void wallet2::request_ntz_sig(std::list<std::string> const& ptx_string, std::vector<pending_tx> ptxs, const int& sigs_count, const std::string& payment_id, std::vector<int> const & signers_index)
void wallet2::request_ntz_sig(std::string const& ptx_string, std::vector<pending_tx> ptxs, const int& sigs_count, const std::string& payment_id, std::vector<int> 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<std::string> tx_blobs;
for (const auto& each : ptxs) {
blobdata blob = tx_to_blob(each.tx);
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ namespace tools
uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx, bool bulletproof);

void commit_tx(pending_tx& ptx_vector);
void request_ntz_sig(std::list<std::string> const& ptx_string, std::vector<pending_tx> ptxs, int const& sigs_count, std::string const& payment_id, std::vector<int> const& sig_index);
void request_ntz_sig(std::string const& ptx_string, std::vector<pending_tx> ptxs, int const& sigs_count, std::string const& payment_id, std::vector<int> const& sig_index);
void get_ntzpool_tx(std::vector<pending_tx>& ptx_vector);
void get_ntzpool_txs_and_keys(std::vector<cryptonote::ntz_tx_info>& txs, std::vector<cryptonote::spent_key_image_info>& spent_key_images);
void commit_tx(std::vector<pending_tx>& ptx_vector);
Expand Down

0 comments on commit e15fecc

Please sign in to comment.