-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
snapshots: index builder refactorings #1922
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
90de1de
ByteView
battlmonstr a1611ab
make_key
battlmonstr f6fd0d4
IndexDescriptor
battlmonstr 1544e4c
separate TransactionToBlockIndex
battlmonstr e07876a
IndexKeyFactory interface instead of std::function
battlmonstr 2f60c79
TxsAndBodiesQuery
battlmonstr 21f1212
IndexInputDataQuery
battlmonstr aa5bc0e
rename IndexBuilder, TransactionIndex1
battlmonstr f43d0ff
avoid get_os_temporary_path in tests
battlmonstr ffd147c
pass bodies_segment_region to indexes
battlmonstr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2024 The Silkworm Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "body_index.hpp" | ||
|
||
#include <silkworm/db/snapshots/seg/common/varint.hpp> | ||
|
||
namespace silkworm::snapshots { | ||
|
||
Bytes BodyIndex::KeyFactory::make(ByteView /*key_data*/, uint64_t i) { | ||
Bytes uint64_buffer; | ||
seg::varint::encode(uint64_buffer, i); | ||
return uint64_buffer; | ||
} | ||
|
||
} // namespace silkworm::snapshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024 The Silkworm Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
#include <optional> | ||
|
||
#include <silkworm/core/common/bytes.hpp> | ||
#include <silkworm/infra/common/memory_mapped_file.hpp> | ||
|
||
#include "index_builder.hpp" | ||
#include "path.hpp" | ||
|
||
namespace silkworm::snapshots { | ||
|
||
class BodyIndex { | ||
public: | ||
static IndexBuilder make(SnapshotPath segment_path, std::optional<MemoryMappedRegion> segment_region = std::nullopt) { | ||
auto descriptor = make_descriptor(segment_path); | ||
auto query = std::make_unique<DecompressorIndexInputDataQuery>(std::move(segment_path), segment_region); | ||
return IndexBuilder{std::move(descriptor), std::move(query)}; | ||
} | ||
|
||
struct KeyFactory : IndexKeyFactory { | ||
~KeyFactory() override = default; | ||
Bytes make(ByteView key_data, uint64_t i) override; | ||
}; | ||
|
||
private: | ||
static IndexDescriptor make_descriptor(const SnapshotPath& segment_path) { | ||
return { | ||
.index_file = segment_path.index_file(), | ||
.key_factory = std::make_unique<KeyFactory>(), | ||
.base_data_id = segment_path.block_from(), | ||
}; | ||
} | ||
}; | ||
|
||
} // namespace silkworm::snapshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright 2024 The Silkworm Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#include "header_index.hpp" | ||
|
||
#include <silkworm/core/common/util.hpp> | ||
#include <silkworm/infra/common/ensure.hpp> | ||
|
||
namespace silkworm::snapshots { | ||
|
||
Bytes HeaderIndex::KeyFactory::make(ByteView key_data, uint64_t i) { | ||
auto word = key_data; | ||
ensure(!word.empty(), [&]() { return "HeaderIndex: word empty i=" + std::to_string(i); }); | ||
const uint8_t first_hash_byte{word[0]}; | ||
const ByteView rlp_encoded_header{word.data() + 1, word.size() - 1}; | ||
const ethash::hash256 hash = keccak256(rlp_encoded_header); | ||
ensure(hash.bytes[0] == first_hash_byte, | ||
[&]() { return "HeaderIndex: invalid prefix=" + to_hex(first_hash_byte) + " hash=" + to_hex(hash.bytes); }); | ||
return Bytes{ByteView{hash.bytes}}; | ||
} | ||
|
||
} // namespace silkworm::snapshots |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024 The Silkworm Authors | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
#include <optional> | ||
|
||
#include <silkworm/core/common/bytes.hpp> | ||
#include <silkworm/infra/common/memory_mapped_file.hpp> | ||
|
||
#include "index_builder.hpp" | ||
#include "path.hpp" | ||
|
||
namespace silkworm::snapshots { | ||
|
||
class HeaderIndex { | ||
public: | ||
static IndexBuilder make(SnapshotPath segment_path, std::optional<MemoryMappedRegion> segment_region = std::nullopt) { | ||
auto descriptor = make_descriptor(segment_path); | ||
auto query = std::make_unique<DecompressorIndexInputDataQuery>(std::move(segment_path), segment_region); | ||
return IndexBuilder{std::move(descriptor), std::move(query)}; | ||
} | ||
|
||
struct KeyFactory : IndexKeyFactory { | ||
~KeyFactory() override = default; | ||
Bytes make(ByteView key_data, uint64_t i) override; | ||
}; | ||
|
||
private: | ||
static IndexDescriptor make_descriptor(const SnapshotPath& segment_path) { | ||
return { | ||
.index_file = segment_path.index_file(), | ||
.key_factory = std::make_unique<KeyFactory>(), | ||
.base_data_id = segment_path.block_from(), | ||
}; | ||
} | ||
}; | ||
|
||
} // namespace silkworm::snapshots |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could merge these two lines into just one:
looking exactly similar to the
HeaderIndex
andBodyIndex
above, either by refactoring or overloading the currentTransactionIndex::make
. Next PR is fine