Skip to content

Conversation

@MegaRedHand
Copy link
Collaborator

@MegaRedHand MegaRedHand commented Jan 30, 2026

Summary

Implements support for responding to incoming BlocksByRoot requests from peers, enabling ethlambda to serve blocks it has stored.

Key changes:

  • Storage architecture: Split block storage into separate Blocks and BlockSignatures tables for efficient reconstruction

    • New BlockSignaturesWithAttestation type stores signatures + proposer attestation
    • New insert_signed_block() / get_signed_block() methods for round-trip persistence
    • Enables serving full SignedBlockWithAttestation to peers on request
  • Protocol handling: Implemented handle_blocks_by_root_request() to respond with blocks from storage

    • Looks up requested block root in storage
    • Returns success response with block data if found
    • Drops channel (timeout) if block unavailable
    • Limitation: Currently handles only first root in request (multi-block support TODO)
  • Response type improvements: Refactored response structure for better error handling

    • Changed Response to enum with Success/Error variants
    • Added ResourceUnavailable response code for missing blocks
    • Implemented From<u8> / Into<u8> traits for ResponseCode (idiomatic conversions)
    • Graceful handling of unknown response codes
  • Development tooling: Added test-pr-devnet skill for testing branches in multi-client devnet

Test plan

  • Cargo fmt + lint pass
  • All tests passing
  • Test in multi-client devnet with .claude/skills/test-pr-devnet/scripts/test-branch.sh

@github-actions
Copy link

Kimi AI Code Review

### General Feedback

The PR introduces changes to support incoming block requests, which is a crucial feature for a P2P network in a blockchain context. The changes are spread across several files, indicating a comprehensive approach to the feature implementation. Here are my specific comments and suggestions:

Code Correctness and Potential Bugs

  1. Missing Error Handling: In handle_blocks_by_root_request, if server.store.get_signed_block(root) fails, it silently drops the channel without sending a response. This might lead to peers timing out unnecessarily. Consider sending an error response instead.

    • Line: 116-117
  2. Single Block Limitation: The comment mentions that the current implementation only handles the first root in a request. This should be addressed to fully support the protocol.

    • Line: 111

Security Vulnerabilities

  1. Data Validation: Ensure that all incoming data, especially from peers, is validated before processing. This includes checking the validity of block signatures and attestations.
    • Files Affected: store.rs, handlers.rs

Performance Implications

  1. Batch Operations: The use of batch operations in insert_signed_block is good for performance, but ensure that the batch size does not exceed the database's limits or cause memory issues.
    • Line: 325-334

Rust Best Practices and Idiomatic Patterns

  1. Use of expect: The use of expect for error handling is acceptable in this context, but consider using more explicit error handling in a production environment to handle potential database errors gracefully.

    • Files Affected: store.rs
  2. Avoiding Cloning: The approach to avoid cloning large signature data by taking ownership is good. This reduces memory overhead and improves performance.

    • Line: 320-334

Memory Safety and Proper Error Handling

  1. Error Propagation: In handle_blocks_by_root_request, errors in sending the response are logged but not propagated or handled further. Consider how these errors should be managed to ensure the stability of the network.
    • Line: 128

Code Readability and Maintainability

  1. Documentation: The comments explaining the limitations and TODO items are helpful for maintainability. Ensure that these are updated as the implementation progresses.

    • Files Affected: handlers.rs
  2. Naming Conventions: The naming of the new structs and functions is consistent with Rust conventions, which improves readability.

Consensus-Layer Considerations

  1. Fork Choice Correctness: The changes do not directly affect fork choice, but ensure that the new block storage mechanism does not introduce any inconsistencies in the fork choice logic.

  2. Attestation Processing: The changes introduce a new way to store and retrieve blocks with attestations. Ensure that this does not affect the attestation processing and validation logic.

Overall, the PR is a good start towards implementing block request handling. However, it needs further work to handle multiple blocks per request and to improve error handling and data validation.


Automated review by Kimi (Moonshot AI)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review by ChatGPT

store.insert_signed_block(block_root, signed_block.clone());
store.insert_state(block_root, post_state);

// Process block body attestations and their signatures

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Comments

General Comments

  1. Functionality & Code Correctness:
    • The updated PR replaces the line: store.insert_block(block_root, block.clone()); with store.insert_signed_block(block_root, signed_block.clone());. Make sure that this change is intentional and appropriate for your consensus logic. If signed_block is needed instead of block, verify that all dependent components will handle this correctly.

Specific Checks

  1. Memory Safety:

    • Cloning is used in both the old and new lines (block.clone() and signed_block.clone()). Check if the clone is necessary or if you can transfer ownership of these objects instead, to prevent unnecessary memory allocation and potential performance overhead.
  2. Error Handling:

    • Ensure that store.insert_signed_block() properly handles and propagates errors. Check for any potential panic or unwrap operations that might compromise system stability.
  3. Rust Best Practices and Idiomatic Patterns:

    • Consider using pattern matching or the ? operator for error handling to maintain cleaner and more idiomatic Rust code. Ensure that error types and error conversions are explicit and provide meaningful messages.
  4. Consensus-Layer Considerations:

    • Fork Choice: Ensure that the fork choice rule (like LMD GHOST) is not adversely affected by this change, especially if any logic depends on the type of block stored.
    • Attestation Processing: Check that the attestations related to signed_block (if any) are processed correctly with this change.
    • State Transitions: Since you mention storing the post_state, verify that this state is consistent with signed_block. This change should align with any state transition logic (like process_slots and process_block).
  5. Performance Considerations:

    • Evaluate the impact of substituting the storage with signed_block. Specifically, determine if the additional information or structure within signed_block affects performance, especially in terms of storage operations and retrievals.
  6. Code Readability and Maintainability:

    • Ensure that the naming around signed_block clearly conveys its purpose compared to block. Also, confirm that associated comments and documentation are updated to reflect this change.

In conclusion, this code change requires further attention to ensure correctness, performance, and consistency with the consensus-layer operations. Addressing the comments above will help increase confidence in the integration of this change.

}
}

async fn handle_blocks_by_root_response(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Comments

Code Correctness

  • Line 104-105: The code currently processes only the first block root from the request, which may lead to limited functionality as the protocol allows handling multiple roots. Consider implementing a mechanism to iterate over all given roots and respond to each.

Security Vulnerabilities

  • Potential Denial-of-Service: Handling requests that involve multiple roots (up to 1024) sequentially should be monitored to prevent any potential DoS scenarios. Consider adding rate limits or checks to prevent abuse.

Performance Implications

  • Processing only the first root is an underutilization of bandwidth and does not leverage batching benefits. Implementing full request handling will improve efficiency.

Rust Best Practices

  • Error Handling: The current pattern for handling errors in the send_response method (Line 117) uses logging but does not handle potential subsequent impacts. Consider implementing a retry mechanism or incrementing a failure metric if appropriate.

Memory Safety and Error Handling

  • Ensure that any extracted parts (like the option in Line 104) are checked and managed to handle all potential outcomes (e.g., none case with a verbose error log).

Code Readability and Maintainability

  • Clearly comment your code when using match arms as done. While this is useful as a TODO, planning structure facilitates future maintenance.

Consensus-layer Considerations

  • Fork Choice Rule: Not directly implicated in this snippet, ensure any changes to block handling do not negatively impact fork-choice.
  • Attestation Processing: Any blocks processed should ensure attestations are correctly handled and verified when fully implementing blocks-by-root request handling.

The code is not ready to merge as it lacks the full implementation for processing blocks by root requests as outlined above.

Table::BlockSignatures,
Table::States,
Table::LatestKnownAttestations,
Table::LatestNewAttestations,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Correctness and Potential Bugs

  • The new variant BlockSignatures added to the Table enum should be thoroughly tested for its integration with existing code. Make sure that wherever Table::Blocks is used to perform operations related to block storage, any operations around signatures should use Table::BlockSignatures if necessary.

Security Vulnerabilities

  • Ensure that the handling of BlockSignatures especially with potentially high volumes requires robust validation checks. Mismanagement in signature handling could lead to verification failures or exploit scenarios.

Performance Implications

  • The addition of the BlockSignatures variant to the enum increases the potential memory footprint of storage maps. Consider this if BlockSignatures become large in size.

Rust Best Practices and Idiomatic Patterns

  • Verify if the BlockSignatures carries any specific types or if it requires type-specific implementations elsewhere which might need further changes or generic typing.

Memory Safety and Proper Error Handling

  • It is crucial for operations that involve variants like BlockSignatures to have proper error handling mechanisms to avoid panics or unwarranted execution paths in consensus-critical code.

Code Readability and Maintainability

  • Make sure any other components relying on the structure of ALL_TABLES is updated accordingly to recognize BlockSignatures.

Consensus-layer Considerations

  • Ensure that BlockSignatures is integrated into the correct fork choice, attestation processing, justification, and finalization logic as intended.

Overall, ensure comprehensive tests are added wherever the new BlockSignatures variant might impact functionality. There is a need for cautious exploration on how this integrates with existing consensus-related functionality.

Table::BlockSignatures => "block_signatures",
Table::States => "states",
Table::LatestKnownAttestations => "latest_known_attestations",
Table::LatestNewAttestations => "latest_new_attestations",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Correctness and Potential Bugs

  • The change merely adds block_signatures to the cf_name function mapping, indicating an adjustment that likely corresponds to a new table in the database. Ensure that all related logic for handling this new table is implemented elsewhere in the codebase, especially where it's initialized or used.

Security Vulnerabilities

  • No immediate security vulnerabilities in the provided diff, but confirm the new BlockSignatures table adheres to security best practices involving access control and data integrity checks.

Performance Implications

  • Adding a new element to an enum and handling it in function matching should not have a significant impact on performance. Ensure database interactions with the new table are efficient and that appropriate indices or caching mechanisms are in place.

Rust Best Practices and Idiomatic Patterns

  • Code seems to follow Rust's idiomatic pattern for pattern matching. Ensure other parts of codebase that use this function are updated accordingly if necessary.

Memory Safety and Proper Error Handling

  • This small change does not introduce memory safety issues, but verify any database interactions related to BlockSignatures are error-handled appropriately, especially in potentially asynchronous contexts.

Code Readability and Maintainability

  • The addition is straightforward and maintains readability. Ensure documentation and other areas of the codebase are updated to reflect this new addition.

Consensus-layer Considerations

  • A thorough review beyond the provided diff is necessary to ensure the BlockSignatures integration does not disrupt fork choice, attestation processing, justification, finalization logic, or state transitions.

Additional Considerations

  • Ensure SSZ encoding/decoding logic accounts for any new data types introduced with the BlockSignatures table, and XMSS signature processing adapts as needed to any structural changes in data.

In summary, the change looks minor, but the implications across the system need thorough review before merging. Verify the new table is fully supported and consistent across the system and that there's adequate test coverage for this new functionality. Consider the provided diff as part of a more extensive feature implementation rather than isolated.


// ============ States ============

/// Iterate over all (root, state) pairs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are some observations regarding the proposed changes:

Code Correctness and Potential Bugs

  • Error Handling: The code frequently uses expect with descriptive error messages for error handling. In production code, especially in a consensus client, this is risky. Consider using proper error-handling mechanisms, such as Result and match statements, to gracefully handle errors and potentially logging them instead of panicking.

Security Vulnerabilities

  • Unchecked Assumptions: The use of expect indicates an assumption that operations will succeed without exception. For blockchain contexts, failure to handle unexpected behavior could be exploited, especially if assumptions are incorrect.

Performance Implications

  • Batch Operations: The use of batch operations (put_batch) is a good practice for performance, minimizing the number of writes. However, there is no error recovery strategy after expect. Consider implementing retry logic or rollback mechanisms to improve robustness in concurrent environments.

Rust Best Practices and Idiomatic Patterns

  • Cloning Avoidance: The code avoids unnecessary cloning, which is a commendable practice in Rust to minimize memory overhead.

Memory Safety and Proper Error Handling

  • Error Propagation: As previously mentioned, relying on expect may lead to unexpected panic if certain assumptions fail. Replace it with error propagation using ? and return Result types where appropriate.

Code Readability and Maintainability

  • Destructuring: The destructuring of SignedBlockWithAttestation is clear and improves readability.
  • Comments: Descriptive comments explaining the function's purpose contribute to understanding but refrain from inline comments that just restate code (

Consensus-layer Considerations

  • SSZ Encoding/Decoding: It's important to handle any potential decoding errors, especially since invalid or malformed data could compromise consensus state.
  • Safety Checks: Verify that the decoded SSZ objects meet all required invariants in the context of consensus logic.

Overall, while the code structure and approach look promising, there are several critical changes required, especially concerning error handling and recovery, to ensure robustness in a sensitive blockchain context. Until these are addressed, the PR is not ready for merge.

@github-actions
Copy link

Kimi AI Code Review

### Review

This PR introduces support for incoming block requests in the ethlambda Ethereum consensus client. The changes are extensive and involve multiple components of the system. Here's a detailed review:

Code Correctness and Potential Bugs

  1. Ownership for Large Structures: The PR correctly identifies the need to avoid cloning large data structures like signatures to save memory and processing time. This is a good practice in Rust.

    • Suggested Change: Ensure that all call sites of insert_signed_block and similar functions are aware of the ownership transfer and handle cloning if necessary.
  2. Formatting Patterns: The PR introduces a pattern for extracting long arguments into variables to improve code readability.

    • Suggested Change: Apply this pattern consistently throughout the codebase to improve readability.
  3. Storage Architecture: The PR correctly distinguishes between the genesis block and other blocks in terms of signature storage.

    • Suggested Change: Add comments explaining why the genesis block is handled differently.

Security Vulnerabilities

  1. Error Handling: The PR introduces error handling for non-success responses in the req/resp protocol.

    • Suggested Change: Ensure that all error cases are properly logged and handled to prevent potential security issues.
  2. SSZ Encoding/Decoding: The PR uses SSZ encoding and decoding for block and error message handling.

    • Suggested Change: Verify that the SSZ encoding and decoding logic is correct and secure against malformed data attacks.

Performance Implications

  1. Batch Operations: The PR uses batch operations for database writes, which is more efficient than individual writes.

    • Suggested Change: Monitor the performance impact of batch operations and adjust batch sizes if necessary.
  2. Asynchronous Operations: The PR uses asynchronous I/O operations for network communication.

    • Suggested Change: Ensure that the asynchronous operations do not introduce unnecessary latency or complexity.

Rust Best Practices and Idiomatic Patterns

  1. Error Handling: The PR uses Rust's Result and Error types for error handling.

    • Suggested Change: Consider using custom error types for more descriptive error messages.
  2. Type Safety: The PR uses Rust's type system to ensure safety and correctness.

    • Suggested Change: Add more type annotations to increase code clarity and safety.

Memory Safety and Proper Error Handling

  1. Memory Management: The PR correctly manages memory by avoiding unnecessary cloning of large data structures.

    • Suggested Change: Review memory usage patterns and optimize if necessary.
  2. Error Propagation: The PR propagates errors correctly through the system.

    • Suggested Change: Ensure that all error paths are handled consistently and do not lead to panics or undefined behavior.

Code Readability and Maintainability

  1. Documentation: The PR includes comments and documentation for new code.

    • Suggested Change: Add more detailed documentation for complex logic and edge cases.
  2. Code Structure: The PR organizes code into modules and functions effectively.

    • Suggested Change: Consider further modularization to improve maintainability.

Consensus-Layer Considerations

  1. Fork Choice Correctness: The PR does not directly affect fork choice logic.

    • Suggested Change: Verify that the new block request handling does not introduce any consensus issues.
  2. Attestation Processing: The PR does not directly affect attestation processing.

    • Suggested Change: Ensure that attestation processing remains consistent with the new block request handling.

Overall, the PR is well-structured and addresses a critical feature for the Ethereum consensus client. However, it is essential to thoroughly test the new functionality, especially around error handling and edge cases, to ensure the system's robustness and security.


Automated review by Kimi (Moonshot AI)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review by ChatGPT


### State Root Computation
- Always computed via `tree_hash_root()` after full state transition
- Must match proposer's pre-computed `block.state_root`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Feedback

Code Correctness and Potential Bugs:

  1. Line 84-85: In the consume_signed_block function, ensure that all necessary validations are performed on the SignedBlockWithAttestation. There should be checks not just for structure but also for any state requirements.

  2. Line 88: Be cautious with .clone(), even if it makes the cost explicit. Consider using Arc or other smart pointers for better efficiency with large data structures if applicable.

Security Vulnerabilities (Blockchain Code Considerations):

  1. If XMSS is involved in the SignedBlockWithAttestation, ensure signature verifications are resistant to replay and other cryptographic attacks.

  2. Ensure that the handling of block and state transitions adequately checks for illegal state manipulation.

Performance Implications:

  1. Avoid unnecessary cloning of large data structures. Rust’s borrowing and ownership principles should be leveraged more effectively.

Rust Best Practices and Idiomatic Patterns:

  1. Line 93-96: The example about the formatting pattern is a great suggestion. Ensure that this approach is used consistently across the codebase.

  2. Statements should avoid relying too heavily on expect without considering other error handling strategies such as Result unwrapping chains that provide error context.

Memory Safety and Proper Error Handling:

  1. Instead of using .expect(), consider error propagation where applicable to provide more balanced error feedback.

Code Readability and Maintainability:

  1. The new sections in the Markdown do improve maintainability; continuing this pattern across other modules would enhance readability.

Consensus-layer Considerations:

  1. Fork choice correctness relies heavily on maintaining a consistent state basis (LMD GHOST / 3SF-mini). Ensure that the functions managing these aspects are thoroughly tested.

  2. Validate attestation processing logic aligns with Ethereum Consensus specifications, considering edge cases.

  3. Justification and finalization logic must ensure that any "attack edge" cases are covered where invalid states might be justified accidentally.

Conclusion:

The PR has introduced some valuable code patterns, but there are concerns regarding potential performance issues and the safety of error handling which should be addressed before merging. Please ensure rigorous testing and validation especially around security-sensitive operations and maintain code allocation efficiency.

super::messages::ResponsePayload::Status(status) => status.as_ssz_bytes(),
super::messages::ResponsePayload::BlocksByRoot(response) => response.as_ssz_bytes(),
};
let encoded = match &payload {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Correctness and Potential Bugs

  1. Line 12: The change from ResponseResult to ResponseCode seems to impact the response handling logic. Ensure that all relevant code dealing with response results has been updated appropriately.
  2. Lines 91 & 101: The modification from Response::new to Response::success or Response::error improves readability as it clearly differentiates between success and error responses.

Security Vulnerabilities

  1. Ensure that throughout, all SSZ encoding and decoding processes properly validate input sizes and constraints to prevent buffer overflows or unintended behaviors.

Performance Implications

  1. Line 126: The match statement optimization streamlines success and error handling by segregating them, which is fine from a performance standpoint given the structured response type.

Rust Best Practices and Idiomatic Patterns

  1. The use of the io::Error::new for error propagation is appropriate and idiomatic within the context of async/await patterns.

Memory Safety and Proper Error Handling

  1. Memory handling with from_ssz_bytes appears correct, assuming from_ssz_bytes performs necessary validations.
  2. Ensure potential io::Error via unwrap_or_else or ? operator have sufficient context or are converted into higher-level errors for easier debugging.

Code Readability and Maintainability

  1. Line 116: The restructuring of error and success code dispatching improves code readability, making clear distinctions between response types.

Consensus-layer Considerations

  • Fork Choice and Attestation: The PR does not seem to touch critical components directly related to fork choice or attestation, so review remains limited in these areas.
  • State Transition Functions: No direct review points found related to process_slots and process_block in this PR.

In conclusion, while minor issues and oversight needs addressing (mainly around ensuring all code paths have updated response handling), overall changes seem to improve code maintainability and readability.

) {
warn!(%peer, %root, ?err, "Failed to send BlocksByRoot response");
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Correctness and Potential Bugs

  • The refactoring from ResponseResult to Response with Response::Success and Response::Error improves clarity. However, ensure that every part of the codebase that interacts with this enum is updated to avoid runtime errors.

Security Vulnerabilities

  • Ensure that all warnings, especially those involving peer-related errors like warn!(%peer, ?code, %error_str, "Received error response"), are not leaking sensitive information about the state of requests or server logic that could be exploited.

Performance Implications

  • The use of pattern matching on enums (e.g., Response::Success { payload }) is efficient and idiomatic in Rust; no immediate performance concerns.

Rust Best Practices and Idiomatic Patterns

  • Prefer unwrap_or_else or map_err over unwrap() for converting results to avoid potential panics in production code. In send_response().unwrap();, consider handling the error more gracefully.

Memory Safety and Proper Error Handling

  • Check any instances where strings are being converted from byte representations (e.g., String::from_utf8_lossy(&message)) for potential invalid sequences and handle them appropriately.

Code Readability and Maintainability

  • The refactoring improved readability by simplifying error handling. However, consider documenting the rationale behind switching to separate Response::Success and Response::Error responses, which aids new developers in understanding the changes.
  • Consider renaming error variables in catch blocks (e.g., let error_str = String::from_utf8_lossy(&message);) to make it clear that they are intended to capture specific error information, e.g., error_message.

Consensus-Layer Considerations

  • Ensure fork choice algorithms such as LMD GHOST or 3SF-mini are not affected by these changes. Test the integration thoroughly as these are susceptible to subtle bugs.
  • Double-check that attestation processing is properly integrated with the new error handling logic, as mismatches could lead to incorrect state transition assumptions.
  • Review that justification and finalization logic handle any new enum patterns properly without missing finality conditions.

Additional Recommendations

  • Ensure comprehensive testing, especially where the response structs have changed. Automated tests should cover all branches of Response::Success and Response::Error to ensure robustness against various response scenarios.

Overall, the PR introduces a beneficial refactoring but requires careful consideration in terms of error handling and rigorous testing across the consensus logic components to maintain correctness in the consensus layer.


/// Convert to the wire format byte representation.
pub fn to_u8(self) -> u8 {
self as u8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Correctness and Potential Bugs

  • The refactoring from ResponseResult to ResponseCode is well-intentioned but introduces no functional changes that require additional scrutiny for correctness beyond renamed variants.

Security Vulnerabilities

  • It's crucial to ensure that the Response handling is consistent with protocol specifications, especially where error code logic is concerned. Ensure that errors are handled safely without leaking potentially sensitive information.

Performance Implications

  • The use of #[allow(clippy::large_enum_variant)] for the Response enum indicates potential for large memory usage when dealing with multiple instances of Response. However, since blockchain consensus layers typically optimize for correctness and security, this may not be directly problematic unless there are high volumes of data being managed concurrently.

Rust Best Practices and Idiomatic Patterns

  • The overall use of enums rather than structs for success and error cases is idiomatic in Rust and aligns well with the language's pattern matching features.
  • Consider using Result type directly for the Response, which would be more idiomatic, unless there's a specific requirement for the custom enum.

Memory Safety and Proper Error Handling

  • The changes do not introduce any memory safety issues directly. Rust’s borrowing and ownership rules should largely prevent typical memory safety issues if adhered to.

Code Readability and Maintainability

  • The refactoring improves clarity by separating success and error cases more explicitly with respective function constructors success and error.
  • Consider documenting each field in ResponsePayload for clarity, especially complex ones like BlocksByRoot as it involves potentially large and nested data structures.

Consensus-layer Considerations

  • Ensure that any changes to Response handling are compatible with the fork choice rule implementations, particularly for LMD GHOST processing. Clarity in error messaging can aid in maintaining sync.
  • For attestation processing, ensure that error handling is rigorous as bad attestation can lead to state inconsistencies.

SSZ Encoding/Decoding Correctness

  • Ensure that the SSZ encoding/decoding for the remaining fields in ResponsePayload is correctly implemented to prevent issues in client communication.

Overall, while the changes are constructive and refine the code, attention should be paid to how ResponseCode and Response are integrated into the broader consensus logic to ensure correctness, especially regarding error management.

ResponseResult, STATUS_PROTOCOL_V1, Status,
BLOCKS_BY_ROOT_PROTOCOL_V1, BlocksByRootRequest, Request, Response, ResponseCode,
ResponsePayload, STATUS_PROTOCOL_V1, Status, error_message,
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General Overview

The pull request involves a subtle change in a public export section – an update from ResponseResult to ResponseCode. This kind of change seems superficial but can have broader implications if this code is part of a shared library interface.

Code Correctness and Potential Bugs

  • Line 6: Ensure that ResponseCode is the intended replacement for ResponseResult. Verify that the logic for handling responses throughout the code base is compatible with this change. This involves ensuring that all usages of ResponseResult have been audited and appropriately refactored.

Security Vulnerabilities

  • No direct security vulnerabilities are evident from this code diff. However, changing types in blockchain code requires a careful audit of all dependent components for logical consistency, especially around network response handling.

Performance Implications

  • There are no apparent performance implications from this change alone. However, if ResponseCode has a different underlying structure than ResponseResult, it could affect performance based on its use in protocol processing logic.

Rust Best Practices and Idiomatic Patterns

  • Exporting items at the module level is a common practice in Rust, but care must be taken to ensure the exposed API's stability unless pre-1.0 development is expected.

Memory Safety and Proper Error Handling

  • Ensure ResponseCode and ResponseResult have similar memory footprint and error handling capabilities. Proper Rust practices should seamlessly handle this with ownership, lifetimes, and borrowing rules, but verifying these aspects is crucial here.

Code Readability and Maintainability

  • The change is minor in terms of code size but can impact readability if ResponseCode and ResponseResult are not adequately documented. Ensure that accompanying documentation reflects the rationale for this change.

Consensus-layer Considerations

  • Ensure the codebase's fork choice, attestation processing, and other consensus components correctly reflect any API changes involving ResponseCode. This particular change might not directly impact these areas, but indirect dependencies should be audited.

Further Recommendations

  • Audit Usage: Review across the entire codebase to ensure all previous ResponseResult references are accurately replaced.
  • Documentation: Update relevant documentation to specify why this change is necessary at this time.
  • Testing: Conduct regression tests specifically focusing on networking although this change seems minor to ensure communication protocols handle each type correctly.

Based on this, the PR requires further review and potentially more context verification before it being safe to merge.

@github-actions
Copy link

Kimi AI Code Review

This PR introduces support for incoming block requests, which is a crucial feature for a consensus client. I will review the changes focusing on code correctness, security, performance, Rust best practices, memory safety, error handling, and maintainability.

Code Correctness and Potential Bugs

  1. store.rs: The changes in store.rs correctly implement the storage logic for blocks and their signatures. The use of separate tables for blocks and block signatures is a good design choice to handle the genesis block's special case.

    • insert_signed_block and get_signed_block functions correctly handle the storage and retrieval of signed blocks. The use of clone() in on_block is justified to avoid cloning large signature data.

    • insert_block function is also correctly implemented.

  2. block.rs: The introduction of BlockSignaturesWithAttestation and its associated methods is correct. The from_signed_block and to_signed_block methods ensure that large signature data is not cloned unnecessarily.

  3. req_resp/codec.rs: The changes in the codec implementation correctly handle the new response codes and error messages. The use of ResponseCode and ErrorMessage types ensures type safety and clarity.

  4. req_resp/handlers.rs: The changes in the request/response handlers correctly implement the logic for handling incoming block requests. The use of Response::success and Response::error methods is appropriate.

Security Vulnerabilities

The changes do not introduce any obvious security vulnerabilities. The handling of error responses and the separation of block and signature storage help maintain the integrity of the consensus process.

Performance Implications

  1. Ownership and Cloning: The use of ownership to avoid cloning large signature data is a good performance optimization. However, it's essential to ensure that this does not lead to unexpected behavior or memory safety issues.

  2. Error Handling: The use of expect for error handling in the storage operations is acceptable for now, but it would be better to propagate errors to the caller in a production setting.

Rust Best Practices and Idiomatic Patterns

  1. Error Handling: As mentioned earlier, using expect for error handling is not ideal for production code. Consider using Result and propagating errors to the caller.

  2. Documentation: The changes are well-documented, which is good for maintainability and understanding the code.

Memory Safety and Proper Error Handling

The changes appear to be memory-safe, and the use of expect is justified in this context. However, as mentioned earlier, using Result for error handling would be more idiomatic.

Code Readability and Maintainability

  1. Naming Conventions: The naming conventions used in the code are consistent and clear.

  2. Code Structure: The code structure is well-organized, with logical separation of concerns.

Consensus-Layer Considerations

  1. Fork Choice Correctness: The changes do not directly affect fork choice logic, but the introduction of block request handling is essential for a complete consensus client.

  2. Attestation Processing: The changes do not affect attestation processing directly.

  3. State Transition Functions: The changes do not directly affect state transition functions.

  4. XMSS Signature Verification: The changes do not affect XMSS signature verification.

  5. SSZ Encoding/Decoding Correctness: The changes correctly use SSZ encoding and decoding for block and signature data.

Overall, the PR is well-implemented and addresses an important feature for the consensus client. The changes are correct, secure, and follow Rust best practices. The code is well-documented and maintainable. The only suggestion for improvement is to consider using Result for error handling in a production setting.


Automated review by Kimi (Moonshot AI)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review by ChatGPT

return Err(io::Error::new(
io::ErrorKind::InvalidData,
format!("invalid result code: {}", result),
));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Correctness and Potential Bugs

  1. Line 65: The change from ResponseCode::from_u8(result_byte) to ResponseCode::from(result_byte) indicates the use of the From trait. Ensure that ResponseCode properly implements the From<u8> trait and handles invalid byte conversions, returning a meaningful error or a default value.

  2. Line 135, 146: Similarly, the changes from to_u8() to into() implies the Into trait is used. Verify that Into<u8> is correctly implemented for ResponseCode to properly handle edge cases.

Security Vulnerabilities

  • Ensure that the error handling mechanisms in decode_payload and other asynchronous operations prevent any form of denial-of-service from malformed or malicious payloads. Implement necessary bounds or checks if they are not currently performed.

Performance Implications

  • Using From and Into traits introduces minimal performance overhead, but any associated functions should be examined for potential inefficiencies or logical flaws.
  • IO operations such as read_exact and write_all involve I/O operations, which can be a bottleneck; ensure these are non-blocking as expected and optimize if necessary.

Rust Best Practices and Idiomatic Patterns

  • Traits Usage: The use of From and Into traits appear idiomatic in Rust. Ensure comprehensive testing and implementation covers all use cases.

Memory Safety and Proper Error Handling

  • Memory safety is likely preserved given Rust's guarantees, but validate all conversions and ensure ResponsePayload is managed correctly without potential overflows or underflows in SSZ encoding.

Code Readability and Maintainability

  • Traits and Conversion: Changes improve code readability by using Rust's idiomatic trait system (From/Into). Make sure comments or documentation specify why conversions are employed, aiding maintainability.

Consensus-layer Considerations

  • No details provided on fork choice, attestation processing, or other consensus logic appear. Ensure other parts handle validation, justification, and finalization correctly.

Overall, fixes are good, but ensure the appropriate implementations and error handling mechanisms are robustly tested.

/// Request was malformed or violated protocol rules.
pub const INVALID_REQUEST: Self = Self(1);
/// Server encountered an internal error processing the request.
pub const SERVER_ERROR: Self = Self(2);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Correctness and Potential Bugs

  • The removal of the from_u8 function in favor of implementing From<u8> changes the way unknown codes are mapped. The previous implementation specified how to handle unknown ranges distinctly as either SERVER_ERROR or INVALID_REQUEST. The new From<u8> simply wraps the integer in a ResponseCode, potentially deferring the specification of behavior until later code execution, which could lead to errors or undefined behavior.

Security Vulnerabilities

  • The From<u8> implementation does not enforce handling rules for unknown codes immediately, which could lead to security implications if misused or overlooked in later parts of the system.

Performance Implications

  • The changes should not notably impact performance, as mapping a byte to a constant is a minimal operation.

Rust Best Practices and Idiomatic Patterns

  • Implementing From<u8> is idiomatic; however, you should ensure additional functions enforce any specific logic essential for validating input eagerly.
  • The use of pattern guards in the fmt::Debug implementation to handle distinct ranges is clear and appropriate.

Memory Safety and Proper Error Handling

  • No issues with memory safety were identified. However, the design now requires consumers to enforce correct mappings after constructing a ResponseCode with From<u8>, which could introduce error handling challenges elsewhere.

Code Readability and Maintainability

  • While implementation of standard conversion traits (From) is idiomatic in Rust, the loss of the detailed handling logic in from_u8 is a regression in terms of self-documenting code. Consider retaining logic or documenting expected usage patterns where ResponseCode is invoked via From.

Additional Notes on Consensus-Layer Considerations

  • This code solely addresses ResponseCode handling, which is a foundational element but should integrate seamlessly with other consensus-layer operations (such as fork choice, attestation validation, etc.). Ensure correct mappings relevant to consensus logic elsewhere.

Recommendation

  • Reintroduce and retain specific handling logic for unknown response codes eagerly, potentially through helper functions, to ensure expected behavior is consistently enforced without relying on debugging output alone. Consider revisiting state management and consensus rules where ResponseCode usage appears.

@github-actions
Copy link

Kimi AI Code Review

This PR introduces support for incoming block requests in the `ethlambda` Ethereum consensus client. The changes are extensive and touch multiple components of the system, including the storage layer, networking layer, and data types. Here's a detailed review:

Code Correctness and Potential Bugs

  1. Block Signature Storage: The PR introduces a new BlockSignaturesWithAttestation struct to store block signatures separately from the block itself. This is a good design decision to avoid storing large signature data twice, especially for the genesis block which has no signatures. However, ensure that the logic in store.insert_signed_block correctly handles the separation of block and signature data (lines 296-325 in store.rs).

  2. Response Handling: The new response handling logic in req_resp/handlers.rs correctly differentiates between success and error responses. However, the current implementation only handles the first root in a BlocksByRootRequest (lines 84-97 in handlers.rs). Consider implementing support for multiple blocks per request as specified by the protocol.

Security Vulnerabilities

  1. Error Handling: The PR introduces error responses with a custom error message. Ensure that these messages do not leak sensitive information about the internal state of the node. The current implementation truncates messages to 256 bytes, which is a good practice to avoid buffer overflows (lines 98-111 in messages.rs).

  2. Signature Verification: The PR does not include changes to the signature verification logic. Ensure that the existing logic correctly verifies signatures for incoming blocks, as this is a critical security consideration for blockchain consensus.

Performance Implications

  1. Separate Storage for Signatures: Storing block signatures separately can improve performance by reducing the amount of data written to disk for each block. This is especially beneficial for nodes with limited storage capacity.

  2. Batch Operations: The use of batch operations in the storage layer can improve performance by reducing the number of disk I/O operations. Ensure that the batch operations are correctly implemented and do not introduce any race conditions or data inconsistencies (lines 128-136 in store.rs).

Rust Best Practices and Idiomatic Patterns

  1. Trait Implementations: The PR includes idiomatic trait implementations for converting between ResponseCode and u8. This is a good practice that enables the use of .into() for more readable code (lines 81-96 in CLAUDE.md).

  2. Ownership for Large Structures: The PR correctly takes ownership of large structures like SignedBlockWithAttestation to avoid unnecessary cloning. This is an important optimization for performance and memory usage (lines 97-112 in CLAUDE.md).

Memory Safety and Proper Error Handling

  1. Error Propagation: The PR uses .expect() for error handling in several places. While this is acceptable for internal operations, consider using a more robust error handling strategy for external interactions, such as network requests, to avoid panics and ensure the node remains responsive.

  2. SSZ Encoding/Decoding: The PR relies on SSZ encoding and decoding for block and signature data. Ensure that the encoding and decoding logic is correct and does not introduce any memory safety issues.

Code Readability and Maintainability

  1. Documentation: The PR includes documentation for new patterns and idioms in CLAUDE.md. This is a good practice that helps maintain code readability and maintainability.

  2. Modular Code: The changes are well-organized into modular components, such as separate files for request/response handling and storage operations. This makes the code easier to understand and maintain.

Overall, the PR is well-written and introduces important new functionality for handling incoming block requests. However, ensure that the implementation correctly handles multiple blocks per request and that the error handling strategy is robust enough for external interactions.


Automated review by Kimi (Moonshot AI)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review by ChatGPT


### Ownership for Large Structures
```rust
// Prefer taking ownership to avoid cloning large data (signatures ~3KB)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Correctness and Potential Bugs

  • Fork Choice: Ensure the fork choice rule LMD GHOST is accurately implemented. Verify that the logic for selecting the head of the chain aligns with the latest specifications and that any changes maintain the intended behavior. Without reviewing specific lines, ensure that the use of metrics for scoring is correctly implemented and that it reflects recent changes in the protocol.
  • State Transition Functions: Double-check that process_slots and process_block handle all edge cases. Specifically, ensure that the order and correctness of applying block and slot transitions meet specifications.

Security Vulnerabilities

  • Input Validation: Ensure that all inputs, especially those involved in consensus logic and state transitions, are thoroughly validated to prevent malformed data from causing unexpected behavior.
  • Signature Verification: XMSS in Rust must be handled correctly regarding memory. Ensure that XMSS signature verification and aggregation are secure and efficient, using well-vetted cryptography libraries.

Performance Implications

  • While trait implementations using From/Into are idiomatic, they should also be evaluated in context to ensure that conversion does not become a performance bottleneck, especially in consensus-critical paths.

Rust Best Practices & Idiomatic Patterns

  • Trait Implementations: The use of From/Into traits throughout the codebase is a good practice. Ensure consistency in their usage across different modules.
  • Check for unnecessary clones or places where borrowing could be used instead to improve performance.

Memory Safety and Proper Error Handling

  • Ensure error handling within process_slots and process_block functions is thorough to prevent state corruption. Prefer using Result and Option for error handling and returning actionable context when errors occur.

Code Readability and Maintainability

  • Ensure that comments and documentation are comprehensive and clear, especially in complex logic sections like fork choice and state transitions.

SSZ Encoding/Decoding Correctness

  • Double-check that SSZ encoding/decoding is implemented correctly as per the Ethereum consensus specifications to avoid any serialization/deserialization bugs, which are critical for interoperability and security.

Overall, the inclusion of idiomatic Rust practices like trait implementations is positive, but thorough reviews and tests are essential given the critical nature of consensus code in blockchain applications. Address the specific issues highlighted, ensuring comprehensive testing especially in fork choice and state transition logic. Consider adding more detailed code snippets in your request to perform a more line-specific review.

@MegaRedHand MegaRedHand force-pushed the support-block-requests branch from 2d1cee2 to cdd6894 Compare January 30, 2026 21:07
@MegaRedHand MegaRedHand marked this pull request as ready for review January 30, 2026 21:07
@github-actions
Copy link

🤖 Kimi Code Review

Review Summary

This PR introduces comprehensive devnet testing infrastructure and implements proper BlocksByRoot request/response handling. The changes are well-structured and follow Rust best practices. Here are my findings:

Well Implemented

  • Devnet testing scripts are robust with proper error handling and cleanup
  • Storage separation for blocks and signatures is architecturally sound
  • Response code handling follows Ethereum consensus specs correctly
  • Error handling is comprehensive with proper SSZ encoding

⚠️ Issues Found

1. Critical: Missing Genesis Block Handling (storage/src/store.rs:344-348)

The get_signed_block function will return None for genesis blocks since they have no signatures table entry. This breaks BlocksByRoot responses for genesis.

Fix:

pub fn get_signed_block(&self, root: &H256) -> Option<SignedBlockWithAttestation> {
    let view = self.backend.begin_read().expect("read view");
    let key = root.as_ssz_bytes();

    let block_bytes = view.get(Table::Blocks, &key).expect("get")?;
    
    // Handle genesis case - no signatures
    if let Some(sig_bytes) = view.get(Table::BlockSignatures, &key).expect("get") {
        let block = Block::from_ssz_bytes(&block_bytes).expect("valid block");
        let signatures = BlockSignaturesWithAttestation::from_ssz_bytes(&sig_bytes)
            .expect("valid signatures");
        Some(signatures.to_signed_block(block))
    } else {
        // Genesis block - create empty signatures
        let block = Block::from_ssz_bytes(&block_bytes).expect("valid block");
        Some(SignedBlockWithAttestation {
            message: BlockWithAttestation {
                block,
                proposer_attestation: Attestation::default(), // or proper genesis attestation
            },
            signature: BlockSignatures::default(),
        })
    }
}

2. Error Message Truncation (net/p2p/src/req_resp/messages.rs:124-127)

The error message truncation doesn't indicate when truncation occurs, which could hide important debugging info.

Fix:

pub fn error_message(msg: impl AsRef<str>) -> ErrorMessage {
    let bytes = msg.as_ref().as_bytes();
    if bytes.len() > 256 {
        warn!("Error message truncated: {} -> 256 bytes", bytes.len());
        let mut vec = bytes[..256].to_vec();
        // Ensure valid UTF-8 boundary
        while vec.last().map(|&b| b & 0x80 != 0).unwrap_or(false) {
            vec.pop();
        }
        ErrorMessage::new(vec).expect("error message fits")
    } else {
        ErrorMessage::new(bytes.to_vec()).expect("error message fits")
    }
}

3. BlocksByRoot Request Limitation (net/p2p/src/req_resp/handlers.rs:111-117)

The TODO comment is accurate - only handling the first root violates the spec which allows up to 1024 blocks.

Fix:

// For now, handle single block to avoid breaking changes
// TODO: Implement chunked responses for multiple blocks
if request.roots.len() > 1 {
    debug!(%peer, count = request.roots.len(), "Multi-block request not yet supported");
}

🔍 Minor Improvements

  1. Path handling in test scripts should use realpath for robustness
  2. Resource cleanup in test scripts could use trap for guaranteed cleanup
  3. Metrics collection in devnet scripts would help with performance analysis

🎯 Security Considerations

  • ✅ No apparent security vulnerabilities in the changes
  • ✅ Proper input validation for SSZ decoding
  • ✅ Resource limits enforced (256-byte error messages, 1024 block roots)

📊 Performance Impact

  • Storage: Additional table adds ~3KB per block (signatures + attestation)
  • Network: Error responses now properly formatted instead of dropped connections
  • Testing: Devnet scripts add ~2-3 minutes to CI but provide critical validation

The PR is ready to merge after addressing the genesis block handling issue.


Automated review by Kimi (Moonshot AI) · custom prompt

@github-actions
Copy link

🤖 Codex Code Review

Found a few correctness/protocol issues in the P2P req/resp changes. These affect interoperability and block sync.

Findings

  • Compile error / wrong accessor: request.first() is called on BlocksByRootRequest, but no such method exists. This should be request.roots.first() or add a helper. crates/net/p2p/src/req_resp/handlers.rs:113
  • Protocol violation on empty request: when roots is empty you return without responding. Peers will hang until timeout and may treat us as misbehaving. Send INVALID_REQUEST with an error message. crates/net/p2p/src/req_resp/handlers.rs:113-115
  • Multi-root handling incomplete: you only respond to the first root, but the protocol expects one response per requested root (or reject if you only support 1). This can break sync with clients that batch requests. Either enforce len == 1 and return INVALID_REQUEST otherwise, or implement chunked responses. crates/net/p2p/src/req_resp/handlers.rs:111-126
  • Error responses don’t clear pending fetches: Response::Error is logged but doesn’t update pending_requests/request_id_map. If a peer returns RESOURCE_UNAVAILABLE, the fetch can remain stuck without retry. Consider treating error responses as fetch failures and retrying with another peer (or removing pending). crates/net/p2p/src/req_resp/handlers.rs:44-47 (and compare with success cleanup at crates/net/p2p/src/req_resp/handlers.rs:157-160)
  • get_signed_block can’t serve genesis: it returns None if signatures are missing, and genesis has no signatures. A peer requesting genesis via BlocksByRoot will get RESOURCE_UNAVAILABLE even though the block exists. Consider special-casing genesis (return block with empty signatures if valid) or storing a signatures entry for genesis. crates/storage/src/store.rs:342-357 and crates/net/p2p/src/req_resp/handlers.rs:118-139

Consensus-layer scope

  • No changes touching fork choice, attestation processing, justification/finalization, or state transition logic. Those areas look unaffected by this PR.

I didn’t run tests. If you want, I can add a small unit test for empty/multi-root BlocksByRoot request handling or update the protocol handling to be spec-compliant.


Automated review by OpenAI Codex · custom prompt

@claude
Copy link

claude bot commented Jan 30, 2026

Code Review: PR #68 - Support Incoming Block Requests

Overview

This PR implements BlocksByRoot request handling, allowing ethlambda to serve blocks to peers. The implementation adds a new storage architecture with separate tables for blocks and signatures, plus proper error handling for the req/resp protocol.


✅ Strengths

  1. Ownership-based API design - Excellent use of move semantics to avoid cloning 3KB signatures
  2. Clean separation of concerns - Block vs BlockSignatures tables handles genesis edge case elegantly
  3. Proper error response handling - ResponseCode implementation follows protocol spec
  4. Type-safe From/Into traits - Idiomatic Rust pattern for ResponseCode conversions

🔴 Critical Issues

1. Data Integrity Risk: Non-atomic dual-table writes (store.rs:327-339)

insert_signed_block writes to two tables but lacks proper atomicity guarantees. If commit fails partially, blocks become unretrievable since get_signed_block() returns None if either table is missing data.

Fix: Chain put_batch calls or add explicit transaction handling.

2. Consensus-critical: Missing block validation (handlers.rs:118-143)

When serving BlocksByRoot responses, the code doesn't verify that the stored block's tree_hash_root matches the requested root. If storage is corrupted, you'll send incorrect data to peers.

Fix: Add root validation before sending response.


⚠️ Security Concerns

3. UTF-8 truncation bug (messages.rs:114-124)

error_message() truncates at byte 256 without checking UTF-8 boundaries, potentially splitting multi-byte characters.

Fix: Use s.floor_char_boundary(256) to truncate strings properly.


🟡 Design Issues

4. Incomplete protocol implementation (handlers.rs:111-116)

Only handles first root in BlocksByRoot requests (protocol allows up to 1024). Silent truncation may confuse peers.

Recommendation: Return INVALID_REQUEST for multi-root requests or document limitation clearly.

5. Response enum size imbalance (messages.rs:17)

Large enum variant (3KB SignedBlock vs 256B ErrorMessage) wastes stack space.

Fix: Box the large variant.


🔵 Code Quality Issues

  1. Silent failure on empty request (handlers.rs:113-116) - Drops channel without response, causing peer timeout. Should send INVALID_REQUEST error.

  2. Missing ShortRoot in logs (handlers.rs:121) - Should use ShortRoot formatting per project standards.


✅ Pre-merge Checklist


📊 Overall Assessment

Architecture: ✅ Solid design with good separation of concerns

Correctness: ⚠️ Two critical bugs need fixing before merge

Security: ⚠️ UTF-8 truncation issue should be fixed

Recommendation: Request changes - Fix critical issues #1 and #2, then ready to merge.


Automated review by Claude (Anthropic) · custom prompt

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 30, 2026

Greptile Overview

Greptile Summary

This PR implements support for responding to incoming BlocksByRoot requests from peers, completing the request/response protocol for block synchronization.

Key Changes

  • Request Handling: Implements handle_blocks_by_root_request() to look up blocks from storage and send responses
  • Error Handling: Refactored Response from struct to enum with Success and Error variants, adding proper error codes (INVALID_REQUEST, SERVER_ERROR, RESOURCE_UNAVAILABLE)
  • Storage Architecture: Separated block storage into two tables - Blocks for block data and BlockSignatures for signature data, enabling uniform storage for both genesis (no signatures) and regular blocks
  • Backward Compatibility: Added from_ssz_bytes_compat() method to support both old (transparent list) and new (container) formats for BlocksByRootRequest

Limitations

  • Currently only responds with the first requested block root, even though the protocol supports up to 1024 roots per request (noted in TODO comment)
  • Genesis blocks cannot be served via get_signed_block() since they lack signatures in the BlockSignatures table

Confidence Score: 2/5

  • This PR has a critical compilation error that will prevent the code from building
  • The code contains a method call request.first() on line 113 of handlers.rs, but BlocksByRootRequest doesn't have a first() method - it should be request.roots.first(). This is a syntax error that will cause compilation to fail. Additionally, the genesis block retrieval limitation could cause runtime issues if peers request the genesis block.
  • Pay close attention to crates/net/p2p/src/req_resp/handlers.rs (line 113 syntax error) and crates/storage/src/store.rs (genesis block handling)

Important Files Changed

Filename Overview
crates/net/p2p/src/req_resp/handlers.rs Added BlocksByRoot request handling with storage lookup and error responses
crates/net/p2p/src/req_resp/messages.rs Refactored Response to enum with Success/Error variants, added ResponseCode handling
crates/net/p2p/src/req_resp/codec.rs Updated codec to handle error responses with proper SSZ encoding/decoding
crates/storage/src/store.rs Added separate storage for block signatures and methods to store/retrieve signed blocks
crates/common/types/src/block.rs Added BlockSignaturesWithAttestation type for separate storage of block signatures

Sequence Diagram

sequenceDiagram
    participant Peer as Remote Peer
    participant Handler as Request Handler
    participant Store as Storage Layer
    participant Codec as Response Codec
    
    Note over Peer,Codec: Incoming BlocksByRoot Request Flow
    
    Peer->>Handler: BlocksByRoot Request (roots list)
    Handler->>Handler: Extract first root from request
    Handler->>Store: get_signed_block(root)
    
    alt Block Found
        Store->>Store: Read from Blocks table
        Store->>Store: Read from BlockSignatures table
        Store->>Handler: Return SignedBlockWithAttestation
        Handler->>Codec: Response::success(BlocksByRoot(block))
        Codec->>Codec: Write success code (0)
        Codec->>Codec: SSZ-encode block
        Codec->>Peer: Send response with block data
    else Block Not Found
        Store->>Handler: Return None
        Handler->>Codec: Response::error(RESOURCE_UNAVAILABLE)
        Codec->>Codec: Write error code (3)
        Codec->>Codec: SSZ-encode error message
        Codec->>Peer: Send error response
    end
    
    Note over Peer,Codec: Storage Architecture
    Note over Store: Blocks table: H256 -> Block
    Note over Store: BlockSignatures table: H256 -> BlockSignaturesWithAttestation
    Note over Store: Genesis blocks have no signatures entry
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

MegaRedHand and others added 2 commits January 30, 2026 18:14
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@MegaRedHand MegaRedHand merged commit b0cc64a into main Jan 30, 2026
2 checks passed
@MegaRedHand MegaRedHand deleted the support-block-requests branch January 30, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants