mirror of
https://github.com/monero-project/monero.git
synced 2025-08-16 19:40:29 -04:00
Improve cryptonote (block and tx) binary read performance
This commit is contained in:
parent
0a1ddc2eff
commit
08e4497c6e
29 changed files with 229 additions and 230 deletions
|
@ -211,9 +211,7 @@ namespace cryptonote
|
|||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_from_blob(const blobdata_ref& tx_blob, transaction& tx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << tx_blob;
|
||||
binary_archive<false> ba(ss);
|
||||
binary_archive<false> ba{epee::strspan<std::uint8_t>(tx_blob)};
|
||||
bool r = ::serialization::serialize(ba, tx);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
|
||||
CHECK_AND_ASSERT_MES(expand_transaction_1(tx, false), false, "Failed to expand transaction data");
|
||||
|
@ -224,9 +222,7 @@ namespace cryptonote
|
|||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_base_from_blob(const blobdata_ref& tx_blob, transaction& tx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << tx_blob;
|
||||
binary_archive<false> ba(ss);
|
||||
binary_archive<false> ba{epee::strspan<std::uint8_t>(tx_blob)};
|
||||
bool r = tx.serialize_base(ba);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
|
||||
CHECK_AND_ASSERT_MES(expand_transaction_1(tx, true), false, "Failed to expand transaction data");
|
||||
|
@ -236,9 +232,7 @@ namespace cryptonote
|
|||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_prefix_from_blob(const blobdata_ref& tx_blob, transaction_prefix& tx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << tx_blob;
|
||||
binary_archive<false> ba(ss);
|
||||
binary_archive<false> ba{epee::strspan<std::uint8_t>(tx_blob)};
|
||||
bool r = ::serialization::serialize_noeof(ba, tx);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction prefix from blob");
|
||||
return true;
|
||||
|
@ -246,9 +240,7 @@ namespace cryptonote
|
|||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_tx_from_blob(const blobdata_ref& tx_blob, transaction& tx, crypto::hash& tx_hash)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << tx_blob;
|
||||
binary_archive<false> ba(ss);
|
||||
binary_archive<false> ba{epee::strspan<std::uint8_t>(tx_blob)};
|
||||
bool r = ::serialization::serialize(ba, tx);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
|
||||
CHECK_AND_ASSERT_MES(expand_transaction_1(tx, false), false, "Failed to expand transaction data");
|
||||
|
@ -532,22 +524,15 @@ namespace cryptonote
|
|||
if(tx_extra.empty())
|
||||
return true;
|
||||
|
||||
std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size());
|
||||
std::istringstream iss(extra_str);
|
||||
binary_archive<false> ar(iss);
|
||||
binary_archive<false> ar{epee::to_span(tx_extra)};
|
||||
|
||||
bool eof = false;
|
||||
while (!eof)
|
||||
do
|
||||
{
|
||||
tx_extra_field field;
|
||||
bool r = ::do_serialize(ar, field);
|
||||
CHECK_AND_NO_ASSERT_MES_L1(r, false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
|
||||
tx_extra_fields.push_back(field);
|
||||
|
||||
std::ios_base::iostate state = iss.rdstate();
|
||||
eof = (EOF == iss.peek());
|
||||
iss.clear(state);
|
||||
}
|
||||
} while (!ar.eof());
|
||||
CHECK_AND_NO_ASSERT_MES_L1(::serialization::check_stream_state(ar), false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
|
||||
|
||||
return true;
|
||||
|
@ -578,13 +563,10 @@ namespace cryptonote
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size());
|
||||
std::istringstream iss(extra_str);
|
||||
binary_archive<false> ar(iss);
|
||||
binary_archive<false> ar{epee::to_span(tx_extra)};
|
||||
|
||||
bool eof = false;
|
||||
size_t processed = 0;
|
||||
while (!eof)
|
||||
do
|
||||
{
|
||||
tx_extra_field field;
|
||||
bool r = ::do_serialize(ar, field);
|
||||
|
@ -596,12 +578,8 @@ namespace cryptonote
|
|||
break;
|
||||
}
|
||||
tx_extra_fields.push_back(field);
|
||||
processed = iss.tellg();
|
||||
|
||||
std::ios_base::iostate state = iss.rdstate();
|
||||
eof = (EOF == iss.peek());
|
||||
iss.clear(state);
|
||||
}
|
||||
processed = ar.getpos();
|
||||
} while (!ar.eof());
|
||||
if (!::serialization::check_stream_state(ar))
|
||||
{
|
||||
MWARNING("failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
|
||||
|
@ -752,24 +730,18 @@ namespace cryptonote
|
|||
if (tx_extra.empty())
|
||||
return true;
|
||||
std::string extra_str(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size());
|
||||
std::istringstream iss(extra_str);
|
||||
binary_archive<false> ar(iss);
|
||||
binary_archive<false> ar{epee::strspan<std::uint8_t>(extra_str)};
|
||||
std::ostringstream oss;
|
||||
binary_archive<true> newar(oss);
|
||||
|
||||
bool eof = false;
|
||||
while (!eof)
|
||||
do
|
||||
{
|
||||
tx_extra_field field;
|
||||
bool r = ::do_serialize(ar, field);
|
||||
CHECK_AND_NO_ASSERT_MES_L1(r, false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
|
||||
if (field.type() != type)
|
||||
::do_serialize(newar, field);
|
||||
|
||||
std::ios_base::iostate state = iss.rdstate();
|
||||
eof = (EOF == iss.peek());
|
||||
iss.clear(state);
|
||||
}
|
||||
} while (!ar.eof());
|
||||
CHECK_AND_NO_ASSERT_MES_L1(::serialization::check_stream_state(ar), false, "failed to deserialize extra field. extra = " << string_tools::buff_to_hex_nodelimer(std::string(reinterpret_cast<const char*>(tx_extra.data()), tx_extra.size())));
|
||||
tx_extra.clear();
|
||||
std::string s = oss.str();
|
||||
|
@ -1357,9 +1329,7 @@ namespace cryptonote
|
|||
//---------------------------------------------------------------
|
||||
bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b, crypto::hash *block_hash)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << b_blob;
|
||||
binary_archive<false> ba(ss);
|
||||
binary_archive<false> ba{epee::strspan<std::uint8_t>(b_blob)};
|
||||
bool r = ::serialization::serialize(ba, b);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to parse block from blob");
|
||||
b.invalidate_hashes();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue