diff --git a/silkworm/db/snapshots/body_snapshot.hpp b/silkworm/db/snapshots/body_snapshot.hpp index bec0a0a591..f2a1e43cec 100644 --- a/silkworm/db/snapshots/body_snapshot.hpp +++ b/silkworm/db/snapshots/body_snapshot.hpp @@ -27,16 +27,16 @@ namespace silkworm::snapshots { void decode_word_into_body(ByteView word, BlockBodyForStorage& body); -struct BodySnapshotWordSerializer : public SnapshotWordSerializer { +struct BodySnapshotWordDeserializer : public SnapshotWordDeserializer { BlockBodyForStorage value; - ~BodySnapshotWordSerializer() override = default; + ~BodySnapshotWordDeserializer() override = default; void decode_word(ByteView word) override { decode_word_into_body(word, value); } }; -struct BodySnapshotReader : public SnapshotReader {}; +struct BodySnapshotReader : public SnapshotReader {}; } // namespace silkworm::snapshots diff --git a/silkworm/db/snapshots/header_snapshot.hpp b/silkworm/db/snapshots/header_snapshot.hpp index b3295d8d60..6412f7cbce 100644 --- a/silkworm/db/snapshots/header_snapshot.hpp +++ b/silkworm/db/snapshots/header_snapshot.hpp @@ -27,10 +27,10 @@ namespace silkworm::snapshots { void decode_word_into_header(ByteView word, BlockHeader& header); void check_sanity_of_header_with_metadata(const BlockHeader& header, BlockNum block_from, BlockNum block_to); -struct HeaderSnapshotWordSerializer : public SnapshotWordSerializer { +struct HeaderSnapshotWordDeserializer : public SnapshotWordDeserializer { BlockHeader value; - ~HeaderSnapshotWordSerializer() override = default; + ~HeaderSnapshotWordDeserializer() override = default; void decode_word(ByteView word) override { decode_word_into_header(word, value); @@ -41,6 +41,6 @@ struct HeaderSnapshotWordSerializer : public SnapshotWordSerializer { } }; -struct HeaderSnapshotReader : public SnapshotReader {}; +struct HeaderSnapshotReader : public SnapshotReader {}; } // namespace silkworm::snapshots diff --git a/silkworm/db/snapshots/snapshot_reader.cpp b/silkworm/db/snapshots/snapshot_reader.cpp index ab541da51f..e3f7af1d40 100644 --- a/silkworm/db/snapshots/snapshot_reader.cpp +++ b/silkworm/db/snapshots/snapshot_reader.cpp @@ -51,27 +51,27 @@ Snapshot::Iterator& Snapshot::Iterator::operator++() { ++it_; if (has_next) { - serializer_->decode_word(*it_); - serializer_->check_sanity_with_metadata(path_.block_from(), path_.block_to()); + deserializer_->decode_word(*it_); + deserializer_->check_sanity_with_metadata(path_.block_from(), path_.block_to()); } else { - serializer_.reset(); + deserializer_.reset(); } return *this; } bool operator==(const Snapshot::Iterator& lhs, const Snapshot::Iterator& rhs) { - return (lhs.serializer_ == rhs.serializer_) && - (!lhs.serializer_ || (lhs.it_ == rhs.it_)); + return (lhs.deserializer_ == rhs.deserializer_) && + (!lhs.deserializer_ || (lhs.it_ == rhs.it_)); } -Snapshot::Iterator Snapshot::begin(std::shared_ptr serializer) const { +Snapshot::Iterator Snapshot::begin(std::shared_ptr deserializer) const { auto it = decoder_.begin(); if (it == decoder_.end()) { return end(); } - serializer->decode_word(*it); - serializer->check_sanity_with_metadata(path_.block_from(), path_.block_to()); - return Snapshot::Iterator{std::move(it), std::move(serializer), path()}; + deserializer->decode_word(*it); + deserializer->check_sanity_with_metadata(path_.block_from(), path_.block_to()); + return Snapshot::Iterator{std::move(it), std::move(deserializer), path()}; } Snapshot::Iterator Snapshot::end() const { @@ -82,18 +82,18 @@ seg::Decompressor::Iterator Snapshot::seek_decoder(uint64_t offset, std::optiona return decoder_.seek(offset, hash_prefix ? ByteView{hash_prefix->bytes, 1} : ByteView{}); } -Snapshot::Iterator Snapshot::seek(uint64_t offset, std::optional hash_prefix, std::shared_ptr serializer) const { +Snapshot::Iterator Snapshot::seek(uint64_t offset, std::optional hash_prefix, std::shared_ptr deserializer) const { auto it = seek_decoder(offset, hash_prefix); if (it == decoder_.end()) { return end(); } try { - serializer->decode_word(*it); + deserializer->decode_word(*it); } catch (...) { return end(); } - serializer->check_sanity_with_metadata(path_.block_from(), path_.block_to()); - return Snapshot::Iterator{std::move(it), std::move(serializer), path()}; + deserializer->check_sanity_with_metadata(path_.block_from(), path_.block_to()); + return Snapshot::Iterator{std::move(it), std::move(deserializer), path()}; } void Snapshot::close() { diff --git a/silkworm/db/snapshots/snapshot_reader.hpp b/silkworm/db/snapshots/snapshot_reader.hpp index 25b2afe572..0aa2058fa4 100644 --- a/silkworm/db/snapshots/snapshot_reader.hpp +++ b/silkworm/db/snapshots/snapshot_reader.hpp @@ -45,7 +45,7 @@ class Snapshot { public: class Iterator { public: - using value_type = std::shared_ptr; + using value_type = std::shared_ptr; using iterator_category = std::input_iterator_tag; using difference_type = std::ptrdiff_t; using pointer = const value_type*; @@ -53,12 +53,12 @@ class Snapshot { Iterator( seg::Decompressor::Iterator it, - std::shared_ptr serializer, + std::shared_ptr deserializer, SnapshotPath path) - : it_(std::move(it)), serializer_(std::move(serializer)), path_(std::move(path)) {} + : it_(std::move(it)), deserializer_(std::move(deserializer)), path_(std::move(path)) {} - reference operator*() const { return serializer_; } - pointer operator->() const { return &serializer_; } + reference operator*() const { return deserializer_; } + pointer operator->() const { return &deserializer_; } Iterator operator++(int) { return std::exchange(*this, ++Iterator{*this}); } Iterator& operator++(); @@ -68,7 +68,7 @@ class Snapshot { private: seg::Decompressor::Iterator it_; - std::shared_ptr serializer_; + std::shared_ptr deserializer_; SnapshotPath path_; }; @@ -98,10 +98,10 @@ class Snapshot { void reopen_segment(); void close(); - Iterator begin(std::shared_ptr serializer) const; + Iterator begin(std::shared_ptr deserializer) const; Iterator end() const; - Iterator seek(uint64_t offset, std::optional hash_prefix, std::shared_ptr serializer) const; + Iterator seek(uint64_t offset, std::optional hash_prefix, std::shared_ptr deserializer) const; private: seg::Decompressor::Iterator seek_decoder(uint64_t offset, std::optional hash_prefix) const; @@ -112,12 +112,12 @@ class Snapshot { seg::Decompressor decoder_; }; -template +template class SnapshotReader { public: class Iterator { public: - using value_type = decltype(TWordSerializer::value); + using value_type = decltype(TWordDeserializer::value); using iterator_category = std::input_iterator_tag; using difference_type = std::ptrdiff_t; using pointer = const value_type*; @@ -140,9 +140,9 @@ class SnapshotReader { private: value_type& value() const { - SnapshotWordSerializer& base_serializer = **it_; - // dynamic_cast is safe because TWordSerializer was used when creating the Iterator - auto& s = dynamic_cast(base_serializer); + SnapshotWordDeserializer& base_deserializer = **it_; + // dynamic_cast is safe because TWordDeserializer was used when creating the Iterator + auto& s = dynamic_cast(base_deserializer); return s.value; } @@ -154,7 +154,7 @@ class SnapshotReader { SnapshotReader(const Snapshot& snapshot) : snapshot_(snapshot) {} Iterator begin() const { - return Iterator{snapshot_.begin(std::make_shared())}; + return Iterator{snapshot_.begin(std::make_shared())}; } Iterator end() const { @@ -162,7 +162,7 @@ class SnapshotReader { } Iterator seek(uint64_t offset, std::optional hash_prefix = std::nullopt) const { - return Iterator{snapshot_.seek(offset, hash_prefix, std::make_shared())}; + return Iterator{snapshot_.seek(offset, hash_prefix, std::make_shared())}; } std::optional seek_one(uint64_t offset, std::optional hash_prefix = std::nullopt) const { diff --git a/silkworm/db/snapshots/snapshot_word_serializer.hpp b/silkworm/db/snapshots/snapshot_word_serializer.hpp index e06f77df18..5cecd26295 100644 --- a/silkworm/db/snapshots/snapshot_word_serializer.hpp +++ b/silkworm/db/snapshots/snapshot_word_serializer.hpp @@ -21,8 +21,8 @@ namespace silkworm::snapshots { -struct SnapshotWordSerializer { - virtual ~SnapshotWordSerializer() = default; +struct SnapshotWordDeserializer { + virtual ~SnapshotWordDeserializer() = default; virtual void decode_word(ByteView word) = 0; virtual void check_sanity_with_metadata(BlockNum /*block_from*/, BlockNum /*block_to*/) {} }; diff --git a/silkworm/db/snapshots/txn_snapshot.hpp b/silkworm/db/snapshots/txn_snapshot.hpp index 0594eee6fe..3599cd5fe2 100644 --- a/silkworm/db/snapshots/txn_snapshot.hpp +++ b/silkworm/db/snapshots/txn_snapshot.hpp @@ -21,9 +21,9 @@ namespace silkworm::snapshots { -struct TransactionSnapshotReader : public SnapshotReader {}; +struct TransactionSnapshotReader : public SnapshotReader {}; template -struct TransactionSnapshotPayloadRlpReader : public SnapshotReader> {}; +struct TransactionSnapshotPayloadRlpReader : public SnapshotReader> {}; } // namespace silkworm::snapshots diff --git a/silkworm/db/snapshots/txn_snapshot_word_serializer.hpp b/silkworm/db/snapshots/txn_snapshot_word_serializer.hpp index e57675fcfd..69ab160dba 100644 --- a/silkworm/db/snapshots/txn_snapshot_word_serializer.hpp +++ b/silkworm/db/snapshots/txn_snapshot_word_serializer.hpp @@ -41,10 +41,10 @@ Hash tx_buffer_hash(ByteView tx_buffer, uint64_t tx_id); //! Decode transaction from snapshot word. Format is: tx_hash_1byte + sender_address_20byte + tx_rlp_bytes void decode_word_into_tx(ByteView word, Transaction& tx); -struct TransactionSnapshotWordSerializer : public SnapshotWordSerializer { +struct TransactionSnapshotWordDeserializer : public SnapshotWordDeserializer { Transaction value; - ~TransactionSnapshotWordSerializer() override = default; + ~TransactionSnapshotWordDeserializer() override = default; void decode_word(ByteView word) override { decode_word_into_tx(word, value); @@ -52,10 +52,10 @@ struct TransactionSnapshotWordSerializer : public SnapshotWordSerializer { }; template -struct TransactionSnapshotWordPayloadRlpSerializer : public SnapshotWordSerializer { +struct TransactionSnapshotWordPayloadRlpDeserializer : public SnapshotWordDeserializer { TBytes value; - ~TransactionSnapshotWordPayloadRlpSerializer() override = default; + ~TransactionSnapshotWordPayloadRlpDeserializer() override = default; void decode_word(ByteView word) override { auto data = slice_tx_data(word);