-
Notifications
You must be signed in to change notification settings - Fork 290
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
Fix bug: no store the sync dag block #4259
base: dag-master
Are you sure you want to change the base?
Changes from 6 commits
a6403bc
c173559
48c9bac
c8b259a
1a6c851
264a5d6
3b2a145
197bc4f
adfcb23
e06797d
86ee296
8250159
573bc89
e3dca70
248b7fb
e4eff6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ use super::util::Refs; | |
use crate::consensusdb::schemadb::{GhostdagStoreReader, HeaderStoreReader, RelationsStoreReader}; | ||
use crate::reachability::reachability_service::ReachabilityService; | ||
use crate::types::{ghostdata::GhostdagData, ordering::*}; | ||
use anyhow::{bail, ensure, Context, Result}; | ||
use anyhow::{ensure, Context, Result}; | ||
use parking_lot::RwLock; | ||
use starcoin_crypto::HashValue as Hash; | ||
use starcoin_logger::prelude::*; | ||
|
@@ -171,7 +171,7 @@ impl< | |
Ok(new_block_data) | ||
} | ||
|
||
pub(crate) fn verify_and_ghostdata( | ||
pub(crate) fn _verify_and_ghostdata( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Remove underscore prefix from verify_and_ghostdata method The underscore prefix is inconsistent with the method's usage pattern. The evidence shows:
The underscore prefix suggests internal use, but this is clearly a public-facing API method. Remove the underscore to match its actual visibility and usage pattern. 🔗 Analysis chainClarify method visibility intention The underscore prefix suggests this method is intended for internal/private use, but it's still marked as Let's check if this method is still being used by other modules: Consider either:
🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for any remaining calls to verify_and_ghostdata
rg "verify_and_ghostdata" --type rust
Length of output: 536 Script: #!/bin/bash
# Let's check the implementation of verify_and_ghostdata in blockdag.rs to understand the relationship
rg -A 10 "verify_and_ghostdata" flexidag/src/blockdag.rs
# Also check the trait implementation in chain/src/chain.rs
rg -A 10 "verify_and_ghostdata" chain/src/chain.rs
Length of output: 1804 Script: #!/bin/bash
# Let's check the implementation in ghostdag/protocol.rs to understand the full context
rg -A 20 "_verify_and_ghostdata" flexidag/src/ghostdag/protocol.rs
# Also check if there are any direct usages of the underscore version
rg "_verify_and_ghostdata" --type rust
Length of output: 1085 |
||
&self, | ||
blue_blocks: &[BlockHeader], | ||
header: &BlockHeader, | ||
|
@@ -221,12 +221,8 @@ impl< | |
.map(|header| header.id()) | ||
.collect::<HashSet<_>>() | ||
{ | ||
if header.number() < 10000000 { | ||
// no bail before 10000000 | ||
warn!("The data of blue set is not equal when executing the block: {:?}, for {:?}, checking data: {:?}", header.id(), blue_blocks.iter().map(|header| header.id()).collect::<Vec<_>>(), new_block_data.mergeset_blues); | ||
} else { | ||
bail!("The data of blue set is not equal when executing the block: {:?}, for {:?}, checking data: {:?}", header.id(), blue_blocks.iter().map(|header| header.id()).collect::<Vec<_>>(), new_block_data.mergeset_blues); | ||
} | ||
warn!("The data of blue set is not equal when executing the block: {:?}, for {:?}, checking data: {:?}", header.id(), blue_blocks.iter().map(|header| header.id()).collect::<Vec<_>>(), new_block_data.mergeset_blues); | ||
return self.ghostdag(&header.parents_hash()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error handling and logging. The current implementation has several issues:
Consider this alternative implementation: - warn!("The data of blue set is not equal when executing the block: {:?}, for {:?}, checking data: {:?}", header.id(), blue_blocks.iter().map(|header| header.id()).collect::<Vec<_>>(), new_block_data.mergeset_blues);
- return self.ghostdag(&header.parents_hash());
+ let expected_blues: HashSet<_> = blue_blocks.iter().map(|header| header.id()).collect();
+ let actual_blues: HashSet<_> = new_block_data.mergeset_blues.iter().skip(1).cloned().collect();
+ let missing_blues: Vec<_> = expected_blues.difference(&actual_blues).collect();
+ let extra_blues: Vec<_> = actual_blues.difference(&expected_blues).collect();
+
+ warn!(
+ "Blue set mismatch for block {:?}:\nMissing blues: {:?}\nUnexpected blues: {:?}",
+ header.id(),
+ missing_blues,
+ extra_blues
+ );
+
+ return Err(anyhow::anyhow!(
+ "Blue set verification failed for block {:?}",
+ header.id()
+ )); This change:
|
||
} | ||
|
||
let blue_score = self | ||
|
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.
Fix potential panic and improve performance.
The current implementation has several issues:
skip(1)
could panic ifmergeset_blues
is emptyConsider this improved implementation:
📝 Committable suggestion