mirror of
https://github.com/monero-project/monero.git
synced 2025-08-04 06:14:15 -04:00
Merge pull request #7661
08e4497
Improve cryptonote (block and tx) binary read performance (Lee Clagett)
This commit is contained in:
commit
7499837a6f
29 changed files with 229 additions and 230 deletions
|
@ -648,11 +648,9 @@ public:
|
|||
bvc.m_verifivation_failed = true;
|
||||
|
||||
cryptonote::block blk;
|
||||
std::stringstream ss;
|
||||
ss << sr_block.data;
|
||||
binary_archive<false> ba(ss);
|
||||
binary_archive<false> ba{epee::strspan<std::uint8_t>(sr_block.data)};
|
||||
::serialization::serialize(ba, blk);
|
||||
if (!ss.good())
|
||||
if (!ba.good())
|
||||
{
|
||||
blk = cryptonote::block();
|
||||
}
|
||||
|
@ -671,11 +669,9 @@ public:
|
|||
bool tx_added = pool_size + 1 == m_c.get_pool_transactions_count();
|
||||
|
||||
cryptonote::transaction tx;
|
||||
std::stringstream ss;
|
||||
ss << sr_tx.data;
|
||||
binary_archive<false> ba(ss);
|
||||
binary_archive<false> ba{epee::strspan<std::uint8_t>(sr_tx.data)};
|
||||
::serialization::serialize(ba, tx);
|
||||
if (!ss.good())
|
||||
if (!ba.good())
|
||||
{
|
||||
tx = cryptonote::transaction();
|
||||
}
|
||||
|
|
|
@ -37,9 +37,7 @@ BEGIN_INIT_SIMPLE_FUZZER()
|
|||
END_INIT_SIMPLE_FUZZER()
|
||||
|
||||
BEGIN_SIMPLE_FUZZER()
|
||||
std::stringstream ss;
|
||||
ss << std::string((const char*)buf, len);
|
||||
binary_archive<false> ba(ss);
|
||||
binary_archive<false> ba{{buf, len}};
|
||||
rct::Bulletproof proof = AUTO_VAL_INIT(proof);
|
||||
::serialization::serialize(ba, proof);
|
||||
END_SIMPLE_FUZZER()
|
||||
|
|
|
@ -50,11 +50,8 @@ BEGIN_INIT_SIMPLE_FUZZER()
|
|||
END_INIT_SIMPLE_FUZZER()
|
||||
|
||||
BEGIN_SIMPLE_FUZZER()
|
||||
std::string s((const char*)buf, len);
|
||||
std::pair<uint64_t, std::vector<tools::wallet2::transfer_details>> outputs;
|
||||
std::stringstream iss;
|
||||
iss << s;
|
||||
binary_archive<false> ar(iss);
|
||||
binary_archive<false> ar{{buf, len}};
|
||||
::serialization::serialize(ar, outputs);
|
||||
size_t n_outputs = wallet->import_outputs(outputs);
|
||||
std::cout << boost::lexical_cast<std::string>(n_outputs) << " outputs imported" << std::endl;
|
||||
|
|
|
@ -50,11 +50,8 @@ BEGIN_INIT_SIMPLE_FUZZER()
|
|||
END_INIT_SIMPLE_FUZZER()
|
||||
|
||||
BEGIN_SIMPLE_FUZZER()
|
||||
std::string s((const char*)buf, len);
|
||||
tools::wallet2::unsigned_tx_set exported_txs;
|
||||
std::stringstream iss;
|
||||
iss << s;
|
||||
binary_archive<false> ar(iss);
|
||||
binary_archive<false> ar{{buf, len}};
|
||||
::serialization::serialize(ar, exported_txs);
|
||||
std::vector<tools::wallet2::pending_tx> ptx;
|
||||
bool success = wallet->sign_tx(exported_txs, "/tmp/cold-transaction-test-signed", ptx);
|
||||
|
|
|
@ -132,11 +132,10 @@ TEST(Serialization, BinaryArchiveInts) {
|
|||
ASSERT_EQ(8, oss.str().size());
|
||||
ASSERT_EQ(string("\0\0\0\0\xff\0\0\0", 8), oss.str());
|
||||
|
||||
istringstream iss(oss.str());
|
||||
binary_archive<false> iar(iss);
|
||||
binary_archive<false> iar{epee::strspan<std::uint8_t>(oss.str())};
|
||||
iar.serialize_int(x1);
|
||||
ASSERT_EQ(8, iss.tellg());
|
||||
ASSERT_TRUE(iss.good());
|
||||
ASSERT_EQ(8, iar.getpos());
|
||||
ASSERT_TRUE(iar.good());
|
||||
|
||||
ASSERT_EQ(x, x1);
|
||||
}
|
||||
|
@ -151,10 +150,9 @@ TEST(Serialization, BinaryArchiveVarInts) {
|
|||
ASSERT_EQ(6, oss.str().size());
|
||||
ASSERT_EQ(string("\x80\x80\x80\x80\xF0\x1F", 6), oss.str());
|
||||
|
||||
istringstream iss(oss.str());
|
||||
binary_archive<false> iar(iss);
|
||||
binary_archive<false> iar{epee::strspan<std::uint8_t>(oss.str())};
|
||||
iar.serialize_varint(x1);
|
||||
ASSERT_TRUE(iss.good());
|
||||
ASSERT_TRUE(iar.good());
|
||||
ASSERT_EQ(x, x1);
|
||||
}
|
||||
|
||||
|
|
|
@ -287,3 +287,73 @@ TEST(sort_tx_extra, invalid_suffix_partial)
|
|||
std::vector<uint8_t> expected(&expected_arr[0], &expected_arr[0] + sizeof(expected_arr));
|
||||
ASSERT_EQ(sorted, expected);
|
||||
}
|
||||
|
||||
TEST(remove_field_from_tx_extra, remove_first)
|
||||
{
|
||||
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
|
||||
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 2, 1, 42};
|
||||
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
|
||||
|
||||
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(2, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[1].type());
|
||||
|
||||
tx_extra_fields.clear();
|
||||
ASSERT_TRUE(cryptonote::remove_field_from_tx_extra(extra, typeid(cryptonote::tx_extra_pub_key)));
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(1, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[0].type());
|
||||
}
|
||||
|
||||
TEST(remove_field_from_tx_extra, remove_last)
|
||||
{
|
||||
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
|
||||
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 2, 1, 42};
|
||||
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
|
||||
|
||||
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(2, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[1].type());
|
||||
|
||||
tx_extra_fields.clear();
|
||||
ASSERT_TRUE(cryptonote::remove_field_from_tx_extra(extra, typeid(cryptonote::tx_extra_nonce)));
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(1, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
}
|
||||
|
||||
TEST(remove_field_from_tx_extra, remove_middle)
|
||||
{
|
||||
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
|
||||
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 2, 1, 42, 1, 30, 208, 98, 162, 133, 64, 85, 83, 112,
|
||||
91, 188, 89, 211, 24, 131, 39, 154, 22, 228, 80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230};
|
||||
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
|
||||
|
||||
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(3, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[1].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[2].type());
|
||||
|
||||
tx_extra_fields.clear();
|
||||
ASSERT_TRUE(cryptonote::remove_field_from_tx_extra(extra, typeid(cryptonote::tx_extra_nonce)));
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(2, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
}
|
||||
|
||||
TEST(remove_field_from_tx_extra, invalid_varint)
|
||||
{
|
||||
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
|
||||
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 2, 0x80, 0};
|
||||
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
|
||||
|
||||
ASSERT_FALSE(cryptonote::remove_field_from_tx_extra(extra, typeid(cryptonote::tx_extra_nonce)));
|
||||
ASSERT_EQ(sizeof(extra_arr), extra.size());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue