mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
compressor: use a prevector in compressed script serialization
Use a prevector for stack allocation instead of heap allocation during script compression and decompression. These functions were doing millions of unnecessary heap allocations during IBD. We introduce a CompressedScript type alias for this prevector. It is size 33 as that is the maximum size of a compressed script. Fix the DecompressScript header to match the variable name from compressor.cpp Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -36,7 +36,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
if (!script_opt) return;
|
||||
const CScript script{*script_opt};
|
||||
|
||||
std::vector<unsigned char> compressed;
|
||||
CompressedScript compressed;
|
||||
if (CompressScript(script, compressed)) {
|
||||
const unsigned int size = compressed[0];
|
||||
compressed.erase(compressed.begin());
|
||||
@@ -94,10 +94,12 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
|
||||
{
|
||||
const std::vector<uint8_t> bytes = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
CompressedScript compressed_script;
|
||||
compressed_script.assign(bytes.begin(), bytes.end());
|
||||
// DecompressScript(..., ..., bytes) is not guaranteed to be defined if the bytes vector is too short
|
||||
if (bytes.size() >= 32) {
|
||||
if (compressed_script.size() >= 32) {
|
||||
CScript decompressed_script;
|
||||
DecompressScript(decompressed_script, fuzzed_data_provider.ConsumeIntegral<unsigned int>(), bytes);
|
||||
DecompressScript(decompressed_script, fuzzed_data_provider.ConsumeIntegral<unsigned int>(), compressed_script);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user