You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Enhanced BlockNumber struct by adding derive_more::Display and removing the manual implementation of Display.
Introduced a new redis module in the storage.
Added RedisPermanentStorage to the permanent storage options and included a new configuration option perm-storage-url.
Created a new module for Redis permanent storage and implemented RedisPermanentStorage with methods for block, transaction, account, and slot operations.
Added redis dependency to Cargo.toml.
Updated docker-compose.yaml to include Redis and Redis Commander services.
Changes walkthrough 📝
Relevant files
Enhancement
block_number.rs
Enhance `BlockNumber` struct with `derive_more::Display`
src/eth/primitives/block_number.rs
Added derive_more::Display to BlockNumber struct.
Removed manual implementation of Display for BlockNumber.
dinhani-cw
changed the title
feat: initial redis support (only for tests)
feat: initial redis support (only for debug purposes)
Jul 29, 2024
dinhani-cw
changed the title
feat: initial redis support (only for debug purposes)
feat: initial redis support (only for debug purposes) - part 1
Jul 29, 2024
Core Component Initialization The initialization of RedisPermanentStorage is not logged. Ensure that the initialization is logged with all relevant configurations for better traceability.
Error Handling The conn function uses log_and_err! macro for logging errors. Ensure that the original error is logged in a field called reason for consistency.
Dynamic Field Logging In multiple places, dynamic fields are being formatted into log messages. Instead, add these dynamic fields as tracing fields to ensure structured logging.
Unwrap Usage The new function uses unwrap when opening a Redis client. Use expect with a meaningful message instead to handle potential errors gracefully.
Improve type conversion clarity and safety in the read_mined_block_number method
The read_mined_block_number method currently converts the usize value directly into a BlockNumber. This can be improved by explicitly converting the usize to U64 before creating the BlockNumber for better clarity and type safety.
Why: This suggestion enhances type safety and clarity by explicitly converting usize to U64 before creating BlockNumber. It is a best practice that improves code reliability.
9
Enhancement
Simplify error handling in the conn method by using the ? operator
The conn method currently logs an error and returns it using log_and_err!. It would be more idiomatic to use the ? operator directly in the match statement to propagate the error, simplifying the code.
-match self.client.get_connection() {- Ok(conn) => Ok(conn),- Err(e) => log_and_err!(reason = e, "failed to get redis connection"),-}+self.client.get_connection().map_err(|e| log_and_err!(reason = e, "failed to get redis connection"))
Suggestion importance[1-10]: 8
Why: The suggestion simplifies the error handling logic, making the code more idiomatic and easier to read. It correctly addresses the existing code and provides a clear improvement.
8
Performance
Optimize the save_accounts method by using collect directly into a Vec
The save_accounts method can be optimized by using collect directly into a Vec instead of collect_vec, which is more idiomatic and avoids an unnecessary dependency on itertools.
-let redis_accounts = accounts+let redis_accounts: Vec<_> = accounts
.into_iter()
.map(|acc| {
let key = format!("account::{}", acc.address);
let value = to_json_string(&acc);
(key, value)
})
- .collect_vec();+ .collect();
Suggestion importance[1-10]: 8
Why: This suggestion removes an unnecessary dependency on itertools and makes the code more idiomatic by using collect directly into a Vec. It is a valid and useful optimization.
8
Optimize the save_block method by using extend instead of push in the loop
The save_block method can be optimized by using extend instead of push in the loop to add multiple elements to redis_values, which can improve performance slightly.
-for tx in &block.transactions {+redis_values.extend(block.transactions.iter().map(|tx| {
let tx_key = format!("tx::{}", tx.input.hash);
let tx_value = to_json_string(&tx);
- redis_values.push((tx_key, tx_value));-}+ (tx_key, tx_value)+}));
Suggestion importance[1-10]: 7
Why: The suggestion provides a minor performance improvement by using extend instead of push in the loop. It is contextually accurate and optimizes the code slightly.
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.
PR Type
Enhancement, Configuration changes
Description
BlockNumber
struct by addingderive_more::Display
and removing the manual implementation ofDisplay
.redis
module in the storage.RedisPermanentStorage
to the permanent storage options and included a new configuration optionperm-storage-url
.RedisPermanentStorage
with methods for block, transaction, account, and slot operations.redis
dependency toCargo.toml
.docker-compose.yaml
to include Redis and Redis Commander services.Changes walkthrough 📝
block_number.rs
Enhance `BlockNumber` struct with `derive_more::Display`
src/eth/primitives/block_number.rs
derive_more::Display
toBlockNumber
struct.Display
forBlockNumber
.mod.rs
Introduce Redis module in storage
src/eth/storage/mod.rs
redis
module.permanent_storage.rs
Add Redis support to permanent storage configuration
src/eth/storage/permanent_storage.rs
RedisPermanentStorage
to permanent storage options.perm-storage-url
configuration option.mod.rs
Create Redis permanent storage module
src/eth/storage/redis/mod.rs
redis_permanent.rs
Implement RedisPermanentStorage with necessary methods
src/eth/storage/redis/redis_permanent.rs
RedisPermanentStorage
with methods for block, transaction,account, and slot operations.
Cargo.toml
Add Redis dependency to Cargo.toml
Cargo.toml
redis
dependency.docker-compose.yaml
Add Redis services to docker-compose
docker-compose.yaml