-
Notifications
You must be signed in to change notification settings - Fork 258
Red transaction process #4424
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
base: dag-master
Are you sure you want to change the base?
Red transaction process #4424
Conversation
WalkthroughThis pull request integrates the handling of red blocks across several modules without altering the primary functionality. It adds a new Changes
Sequence Diagram(s)Block Template Creation with Red Block ProcessingsequenceDiagram
participant M as Miner
participant CT as CreateBlockTemplate
participant GD as GhostData Provider
participant TP as TxPoolSyncService
M->>CT: Request block template
CT->>GD: Retrieve ghostdata (blue & red blocks)
GD-->>CT: Return ghostdata (mergeset blues & reds)
CT->>TP: Process transactions from red blocks
TP-->>CT: Return processed red block transactions
CT-->>M: Return block template with blue and red block info
Block Depth Information RetrievalsequenceDiagram
participant Client as Caller
participant BDM as BlockDepthManagerT
participant DS as DepthStore
Client->>BDM: get_block_depth_info(hash)
BDM->>DS: Retrieve block depth info for hash
DS-->>BDM: Return Option<BlockDepthInfo> or error
BDM-->>Client: Return block depth information (or handle error)
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (3)
🔇 Additional comments (1)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 2
🧹 Nitpick comments (6)
flexidag/tests/tests.rs (2)
1452-1452
: Variable name typo in method call.There's a typo in the variable name (
merge_dapth_info
instead ofmerge_depth_info
).-let merge_dapth_info = dag.generate_the_block_depth(pruning_point, &ghostdata, merge_depth)?; +let merge_depth_info = dag.generate_the_block_depth(pruning_point, &ghostdata, merge_depth)?;
1457-1457
: Same typo in variable reference.The same typo appears here when accessing the field.
-assert_eq!(fork, merge_dapth_info.merge_depth_root); +assert_eq!(fork, merge_depth_info.merge_depth_root);miner/src/create_block_template/mod.rs (2)
226-235
: Consider using more specific error messages for red blocks.The error message "uncle block header not found" is the same for both blue and red blocks. Consider using more specific error messages to differentiate between them for easier debugging.
- op_block_header.ok_or_else(|| format_err!("uncle block header not found.")) + op_block_header.ok_or_else(|| format_err!("red block header not found."))
289-289
: Consider updating log messages to include red blocks information.The existing log message on line 241 only mentions uncles (blue blocks) but doesn't include information about red blocks being processed. Consider updating the log message to include the count of red blocks and transactions from them.
info!( - "[CreateBlockTemplate] previous_header: {:?}, block_gas_limit: {}, max_txns: {}, txn len: {}, uncles len: {}, timestamp: {}", + "[CreateBlockTemplate] previous_header: {:?}, block_gas_limit: {}, max_txns: {}, txn len: {}, uncles len: {}, red blocks len: {}, red txns len: {}, timestamp: {}", previous_header, block_gas_limit, max_txns, txns.len(), uncles.len(), + red_blocks.len(), + red_transactions.len(), now_millis, );flexidag/src/blockdag.rs (2)
26-26
: Rename or remove theOk
import.Importing
Ok
fromanyhow
may shadow the standard usage of theOk
enum variant. Consider removing it to avoid confusion, unless it’s explicitly required.- use anyhow::{bail, ensure, format_err, Ok}; + use anyhow::{bail, ensure, format_err};
811-846
: Review generate_the_block_depth control flow.• The early return at lines 820-824 neatly handles the
merge_depth_root == zero
case, but leads to a double-return structure.
• After the insertion intoblock_depth_info_store
, the function logs root and finality, then returns the same data.
Consider storing theBlockDepthInfo
in a variable once and returning it at the end to simplify.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (11)
chain/mock/src/mock_chain.rs
(1 hunks)chain/src/chain.rs
(1 hunks)flexidag/src/block_depth/block_depth_info.rs
(3 hunks)flexidag/src/blockdag.rs
(6 hunks)flexidag/src/consensusdb/consensus_block_depth.rs
(1 hunks)flexidag/src/consensusdb/db.rs
(1 hunks)flexidag/tests/tests.rs
(8 hunks)miner/src/create_block_template/mod.rs
(5 hunks)sync/src/block_connector/block_connector_service.rs
(3 hunks)sync/src/block_connector/mod.rs
(1 hunks)sync/src/block_connector/write_block_chain.rs
(0 hunks)
💤 Files with no reviewable changes (1)
- sync/src/block_connector/write_block_chain.rs
🔇 Additional comments (26)
flexidag/src/consensusdb/db.rs (1)
26-26
: Improved encapsulation by restricting access to thedb
fieldThe visibility of the
db
field has been changed frompub
topub(crate)
, restricting access to only within the same crate. This is a good practice that better encapsulates the internal implementation details.chain/src/chain.rs (3)
317-318
: LGTM: Added placeholder for new red_blocks fieldAdding the placeholder for the new
red_blocks
field in the destructured assignment properly aligns with the changes in theMineNewDagBlockInfo
struct.
320-321
: LGTM: Correctly extracting red blocks from ghostdataThe code properly extracts the red blocks from
ghostdata.mergeset_reds
similar to how blue blocks are handled, ensuring consistency in the implementation.
325-326
: LGTM: Adding the red_blocks field to MineNewDagBlockInfo constructionThe
red_blocks
field is correctly integrated into theMineNewDagBlockInfo
struct construction, completing the implementation of red blocks tracking alongside blue blocks.flexidag/src/consensusdb/consensus_block_depth.rs (1)
84-91
: Improved error handling for KeyNotFound scenarioThe error handling has been refined to distinguish between
KeyNotFound
errors and other types of errors. This is a good improvement as it prevents unnecessary warning logs for expected scenarios where a key is simply not found.chain/mock/src/mock_chain.rs (1)
287-288
: LGTM: Added red_blocks field support in produce_block_for_pruningThe
red_blocks
field has been added to the destructured assignment fromcalc_mergeset_and_tips
with a wildcard pattern_
since its value is not needed in this context. This change properly aligns with the updatedMineNewDagBlockInfo
struct definition.sync/src/block_connector/mod.rs (2)
59-59
: The field name change improves clarity.Renaming
blues_hash
toblue_blocks_hash
makes the field's purpose more explicit and maintains consistency with the newred_blocks_hash
field.
65-65
: New field added to support red blocks processing.The addition of
red_blocks_hash
field complements the blue blocks tracking and enables the system to process both types of blocks. This field appears to be part of a broader implementation of red block handling across the codebase.flexidag/src/block_depth/block_depth_info.rs (3)
7-7
: Updated import to include BlockDepthInfoReader.This import change supports the implementation of the new
get_block_depth_info
method in theBlockDepthManagerT
struct.
60-62
: Good encapsulation with new public method.Adding this public method centralizes access to block depth information through the
BlockDepthManagerT
interface rather than requiring direct access to thedepth_store
. This improves the API design and makes the code more maintainable.
88-88
: Code refactored to use the new method.The implementation now uses the newly added
get_block_depth_info
method instead of directly accessing the depth store, which is more consistent and better encapsulated.flexidag/tests/tests.rs (4)
1028-1028
: Updated to handle new red_blocks field.The test has been updated to accommodate the new
red_blocks
field fromcalc_mergeset_and_tips
, ensuring tests remain compatible with the implementation changes.
1059-1059
: Consistent handling of red_blocks in another test case.This change maintains consistency with the previous test update, ensuring all test code properly handles the new red_blocks field.
1405-1407
: Method call updated to reflect API changes.The code now uses
generate_the_block_depth
instead of what appears to have been renamed fromcheck_bounded_merge_depth
, and appropriately accesses themerge_depth_root
field from the returnedBlockDepthInfo
struct.
1509-1569
: Good addition of test for ancestor relationship verification.This new test thoroughly validates the
check_ancestor_of
andcheck_ancestor_of_chain
functionality by creating a DAG with a clear ancestor hierarchy and verifying the expected relationships. This improves test coverage for an important component of the system.miner/src/create_block_template/mod.rs (4)
27-27
: Added HashSet import for transaction deduplication.This import supports the new functionality to deduplicate transactions from red blocks.
160-160
: Expanded trait constraint for better functionality.Adding the
TxPoolSyncService
constraint enables the use of methods likeadd_txns
on the transaction provider, supporting the integration of red block transactions.
187-187
: Variable naming improved for clarity and new field handled.Renamed
blues_hash
toblue_blocks_hash
for clarity and added destructuring of the newred_blocks_hash
field to support red blocks processing.Also applies to: 193-193
282-289
: Good implementation of transaction deduplication from red blocks.Using a HashSet to collect and deduplicate transactions from red blocks before adding them to the transaction pool is an efficient approach. This ensures that identical transactions aren't processed multiple times.
sync/src/block_connector/block_connector_service.rs (4)
429-429
: Add new field to track red blocks.This extends the
MineNewDagBlockInfo
destructuring to includered_blocks
. Ensure all internal uses ofMineNewDagBlockInfo
handle the new field and that it’s correctly populated from upstream.Would you like a search script to ensure the
red_blocks
property is fully utilized across the codebase?
469-470
: Ensure consistency of ghostdata mergeset references.Assigning
blue_blocks
frommergeset_blues
andred_blocks
frommergeset_reds
aligns with the new red/blue block distinction. Confirm that any logic handling these vectors matches this intended purpose (e.g., verifying that red blocks are truly red rather than leftover references).
507-507
: Expose red blocks in MinerResponse.The
red_blocks_hash
field inMinerResponse
helps external consumers handle or track red blocks. Confirm that downstream logic uses this field correctly, for example, in the miner or block verification steps.
466-466
:❓ Verification inconclusive
Check dag.ghostdata error handling.
Be sure that
tips
is never empty and can reliably provide valid ghost data. Iftips
is empty, this call may produce undesired behavior or errors.
🏁 Script executed:
#!/bin/bash # Verify safe usage of dag.ghostdata calls rg -A 3 "dag\.ghostdata\(.*\)"Length of output: 5176
Ensure Non-Empty
tips
for Reliable ghostdata ExecutionPlease verify that the
tips
vector passed todag.ghostdata(&tips)?
insync/src/block_connector/block_connector_service.rs
is always non-empty. Our grep output shows that in other parts of the codebase (and notably in tests), ghostdata is consistently called with non-empty identifiers. However, be sure that upstream validations guarantee that an emptytips
list never reaches this call, or introduce an explicit check/assertion to handle that case gracefully.flexidag/src/blockdag.rs (3)
59-59
: Add red_blocks to MineNewDagBlockInfo.This public field tracks “red blocks” for DAG-based consensus. Confirm that any associated logic, such as mergeset computations, properly initiates and updates the
red_blocks
vector.
769-772
: Invoke block depth generation conditionally.When
pruning_point
is zero, the code sets it togenesis_id
; otherwise, it callsgenerate_the_block_depth
. Ensure skipping depth generation for the genesis scenario is intended, or consider clarifying with an inline comment.
848-880
: Validate bounded merge depth on red blocks.Ensuring each red block is either under the merge depth root or “kosherized” by a blue block prevents protocol violations. This approach of lazily loading kosherizing blues is sound, though note performance overhead if many red blocks exist.
Benchmark for 0e931ddClick to view benchmark
|
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Other information
Summary by CodeRabbit
New Features
Tests
Refactor