Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughThis PR centralizes DAG-driven chain switches by adding Changes
Sequence Diagram(s)sequenceDiagram
participant DAG as "DAG / EventBus"
participant SyncSvc as "Sync Block Connector\n(write_block_chain)"
participant ChainReader as "ChainReaderService\n(get_main_mut)"
participant BlockChain as "BlockChain\n(select_dag_state / switch_to_block)"
participant ChainState as "ChainStateService"
participant VMState as "VM / State DB"
DAG->>SyncSvc: NewDagBlock(msg with executed_block)
SyncSvc->>ChainReader: switch_header(executed_block.header())
ChainReader->>BlockChain: get_main_mut().select_dag_state(header)
Note over BlockChain: select_dag_state calls switch_to_block when needed
BlockChain->>VMState: rebuild accumulators & state DBs (in-place)
BlockChain-->>ChainReader: return (Result<()>)
alt header matches current head
ChainReader->>SyncSvc: apply_new_head_from_dag(executed_block)
SyncSvc-->>ChainReader: result
end
BlockChain->>ChainState: emit/update state root
ChainState-->>VMState: change_root(state_root)
Note: rectangles/styles use default participant styling; component interactions and in-place switching are shown. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a76a4576dd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| pub fn switch_header(&mut self, header: &BlockHeader) -> Result<BlockHeader> { | ||
| let new_branch = self.main.select_dag_state(header)?; // 1 | ||
| self.select_head(new_branch)?; | ||
| self.main.select_dag_state(header)?; | ||
| self.update_startup_info(&self.main.current_header())?; |
There was a problem hiding this comment.
Preserve head selection side effects in switch_header
switch_header now only mutates self.main via select_dag_state and immediately updates startup info, but it no longer calls select_head/do_new_head. That removes the total-difficulty check and, more importantly, skips reorg handling (txpool updates, metrics, and NewHeadBlock/NewBranch broadcasts). When a NewDagBlock arrives (handled in BlockConnectorService), the chain will silently switch to the selected block without notifying subscribers or updating the txpool, leaving downstream components out of sync after a head change or reorg.
Useful? React with 👍 / 👎.
a76a457 to
d386358
Compare
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
Refactor
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.