-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat: add TreeConfig #9833
Merged
fgimenez
merged 2 commits into
paradigmxyz:main
from
fgimenez:fgimenez/configurable-tree-settings
Jul 26, 2024
Merged
feat: add TreeConfig #9833
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,74 @@ | ||
//! Engine tree configuration. | ||
|
||
const DEFAULT_PERSISTENCE_THRESHOLD: u64 = 256; | ||
const DEFAULT_BLOCK_BUFFER_LIMIT: u32 = 256; | ||
const DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH: u32 = 256; | ||
|
||
/// The configuration of the engine tree. | ||
#[derive(Debug)] | ||
pub struct TreeConfig { | ||
/// Maximum number of blocks to be kept only in memory without triggering persistence. | ||
persistence_threshold: u64, | ||
/// Number of pending blocks that cannot be executed due to missing parent and | ||
/// are kept in cache. | ||
block_buffer_limit: u32, | ||
/// Number of invalid headers to keep in cache. | ||
max_invalid_header_cache_length: u32, | ||
} | ||
|
||
impl Default for TreeConfig { | ||
fn default() -> Self { | ||
Self { | ||
persistence_threshold: DEFAULT_PERSISTENCE_THRESHOLD, | ||
block_buffer_limit: DEFAULT_BLOCK_BUFFER_LIMIT, | ||
max_invalid_header_cache_length: DEFAULT_MAX_INVALID_HEADER_CACHE_LENGTH, | ||
} | ||
} | ||
} | ||
|
||
impl TreeConfig { | ||
/// Create engine tree configuration. | ||
pub const fn new( | ||
persistence_threshold: u64, | ||
block_buffer_limit: u32, | ||
max_invalid_header_cache_length: u32, | ||
) -> Self { | ||
Self { persistence_threshold, block_buffer_limit, max_invalid_header_cache_length } | ||
} | ||
|
||
/// Return the persistence threshold. | ||
pub const fn persistence_threshold(&self) -> u64 { | ||
self.persistence_threshold | ||
} | ||
|
||
/// Return the block buffer limit. | ||
pub const fn block_buffer_limit(&self) -> u32 { | ||
self.block_buffer_limit | ||
} | ||
|
||
/// Return the maximum invalid cache header length. | ||
pub const fn max_invalid_header_cache_length(&self) -> u32 { | ||
self.max_invalid_header_cache_length | ||
} | ||
|
||
/// Setter for persistence threshold. | ||
pub const fn with_persistence_threshold(mut self, persistence_threshold: u64) -> Self { | ||
self.persistence_threshold = persistence_threshold; | ||
self | ||
} | ||
|
||
/// Setter for block buffer limit. | ||
pub const fn with_block_buffer_limit(mut self, block_buffer_limit: u32) -> Self { | ||
self.block_buffer_limit = block_buffer_limit; | ||
self | ||
} | ||
|
||
/// Setter for maximum invalid header cache length. | ||
pub const fn with_max_invalid_header_cache_length( | ||
mut self, | ||
max_invalid_header_cache_length: u32, | ||
) -> Self { | ||
self.max_invalid_header_cache_length = max_invalid_header_cache_length; | ||
self | ||
} | ||
} |
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
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.
lets keep the constants but move to config