-
Notifications
You must be signed in to change notification settings - Fork 289
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
Synchronize optimization into parallel processing, and replace the calculation of ghost data with validation methods during synchronization to improve efficiency #4192
Changes from 31 commits
ee7104f
85b9b45
2d672b4
e575d6d
959995e
8e1744a
03f8b8d
b9e34d0
689a478
b086d13
1fa8f94
4f26278
cb4abfe
bcac3fa
ccfe95d
4e50d66
30ecb99
a2f64bc
763f1d3
be34e3b
4299894
8437fe8
ef84a9b
d1edfb7
532d9b6
d46c9ad
7d535d6
58fa314
03981e3
c5a4093
6d27f2c
96df6fc
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 |
---|---|---|
|
@@ -7,6 +7,7 @@ use starcoin_chain_api::{ | |
verify_block, ChainReader, ConnectBlockError, VerifiedBlock, VerifyBlockField, | ||
}; | ||
use starcoin_consensus::{Consensus, ConsensusVerifyError}; | ||
use starcoin_dag::types::ghostdata::GhostdagData; | ||
use starcoin_logger::prelude::debug; | ||
use starcoin_open_block::AddressFilter; | ||
use starcoin_types::block::{Block, BlockHeader, ALLOWED_FUTURE_BLOCKTIME}; | ||
|
@@ -76,13 +77,16 @@ pub trait BlockVerifier { | |
StaticVerifier::verify_body_hash(&new_block)?; | ||
watch(CHAIN_WATCH_NAME, "n13"); | ||
//verify uncles | ||
Self::verify_uncles( | ||
let ghostdata = Self::verify_uncles( | ||
current_chain, | ||
new_block.uncles().unwrap_or_default(), | ||
new_block_header, | ||
)?; | ||
watch(CHAIN_WATCH_NAME, "n14"); | ||
Ok(VerifiedBlock(new_block)) | ||
Ok(VerifiedBlock { | ||
block: new_block, | ||
ghostdata, | ||
}) | ||
Comment on lines
+80
to
+89
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. Refactor suggestion: Consider handling the case where The method |
||
} | ||
|
||
fn verify_blacklisted_txns(new_block: &Block) -> Result<()> { | ||
|
@@ -101,7 +105,7 @@ pub trait BlockVerifier { | |
current_chain: &R, | ||
uncles: &[BlockHeader], | ||
header: &BlockHeader, | ||
) -> Result<()> | ||
) -> Result<Option<GhostdagData>> | ||
where | ||
R: ChainReader, | ||
{ | ||
|
@@ -118,7 +122,7 @@ pub trait BlockVerifier { | |
} | ||
|
||
if uncles.is_empty() { | ||
return Ok(()); | ||
return Ok(None); | ||
} | ||
verify_block!( | ||
VerifyBlockField::Uncle, | ||
|
@@ -163,7 +167,7 @@ pub trait BlockVerifier { | |
Self::verify_header(&uncle_branch, uncle)?; | ||
uncle_ids.insert(uncle_id); | ||
} | ||
Ok(()) | ||
Ok(None) | ||
} | ||
|
||
fn can_be_uncle<R>(current_chain: &R, block_header: &BlockHeader) -> Result<bool> | ||
|
@@ -318,25 +322,27 @@ impl BlockVerifier for NoneVerifier { | |
where | ||
R: ChainReader, | ||
{ | ||
Ok(VerifiedBlock(new_block)) | ||
Ok(VerifiedBlock { | ||
block: new_block, | ||
ghostdata: None, | ||
}) | ||
} | ||
|
||
fn verify_uncles<R>( | ||
_current_chain: &R, | ||
_uncles: &[BlockHeader], | ||
_header: &BlockHeader, | ||
) -> Result<()> | ||
) -> Result<Option<GhostdagData>> | ||
where | ||
R: ChainReader, | ||
{ | ||
Ok(()) | ||
Ok(None) | ||
} | ||
} | ||
|
||
//TODO: Implement it. | ||
pub struct DagVerifier; | ||
impl BlockVerifier for DagVerifier { | ||
fn verify_header<R>(current_chain: &R, new_block_header: &BlockHeader) -> Result<()> | ||
struct BasicDagVerifier; | ||
impl BasicDagVerifier { | ||
pub fn verify_header<R>(current_chain: &R, new_block_header: &BlockHeader) -> Result<()> | ||
where | ||
R: ChainReader, | ||
{ | ||
|
@@ -380,50 +386,60 @@ impl BlockVerifier for DagVerifier { | |
ConsensusVerifier::verify_header(current_chain, new_block_header) | ||
} | ||
|
||
fn verify_blue_blocks<R>( | ||
current_chain: &R, | ||
uncles: &[BlockHeader], | ||
header: &BlockHeader, | ||
) -> Result<GhostdagData> | ||
where | ||
R: ChainReader, | ||
{ | ||
current_chain.verify_and_ghostdata(uncles, header) | ||
} | ||
} | ||
//TODO: Implement it. | ||
pub struct DagVerifier; | ||
impl BlockVerifier for DagVerifier { | ||
fn verify_header<R>(current_chain: &R, new_block_header: &BlockHeader) -> Result<()> | ||
where | ||
R: ChainReader, | ||
{ | ||
BasicDagVerifier::verify_header(current_chain, new_block_header) | ||
} | ||
|
||
fn verify_uncles<R>( | ||
_current_chain: &R, | ||
_uncles: &[BlockHeader], | ||
_header: &BlockHeader, | ||
) -> Result<()> | ||
) -> Result<Option<GhostdagData>> | ||
where | ||
R: ChainReader, | ||
{ | ||
// let mut uncle_ids = HashSet::new(); | ||
// for uncle in uncles { | ||
// let uncle_id = uncle.id(); | ||
// verify_block!( | ||
// VerifyBlockField::Uncle, | ||
// !uncle_ids.contains(&uncle.id()), | ||
// "repeat uncle {:?} in current block {:?}", | ||
// uncle_id, | ||
// header.id() | ||
// ); | ||
|
||
// if !header.is_dag() { | ||
// verify_block!( | ||
// VerifyBlockField::Uncle, | ||
// uncle.number() < header.number() , | ||
// "uncle block number bigger than or equal to current block ,uncle block number is {} , current block number is {}", uncle.number(), header.number() | ||
// ); | ||
// } | ||
|
||
// verify_block!( | ||
// VerifyBlockField::Uncle, | ||
// current_chain.get_block_info(Some(uncle_id))?.is_some(), | ||
// "Invalid block: uncle {} does not exist", | ||
// uncle_id | ||
// ); | ||
|
||
// debug!( | ||
// "verify_uncle header number {} hash {:?} uncle number {} hash {:?}", | ||
// header.number(), | ||
// header.id(), | ||
// uncle.number(), | ||
// uncle.id() | ||
// ); | ||
// uncle_ids.insert(uncle_id); | ||
// } | ||
Ok(None) | ||
} | ||
} | ||
|
||
Ok(()) | ||
pub struct DagVerifierWithGhostData; | ||
impl BlockVerifier for DagVerifierWithGhostData { | ||
fn verify_header<R>(current_chain: &R, new_block_header: &BlockHeader) -> Result<()> | ||
where | ||
R: ChainReader, | ||
{ | ||
BasicDagVerifier::verify_header(current_chain, new_block_header) | ||
} | ||
|
||
fn verify_uncles<R>( | ||
current_chain: &R, | ||
uncles: &[BlockHeader], | ||
header: &BlockHeader, | ||
) -> Result<Option<GhostdagData>> | ||
where | ||
R: ChainReader, | ||
{ | ||
Ok(Some(BasicDagVerifier::verify_blue_blocks( | ||
current_chain, | ||
uncles, | ||
header, | ||
)?)) | ||
} | ||
} |
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.
New method for verifying blocks with ghost data.
The addition of
verify_and_ghostdata
method is a significant enhancement that allows for the verification of blocks along with their ghost data. This method directly supports the PR's objectives by integrating ghost data handling into the block verification process, which is expected to improve the integrity and efficiency of block synchronization.Consider adding detailed documentation for this method to explain its parameters, expected behavior, and any potential side effects or exceptions it might handle.
Would you like me to help draft the documentation for this new method?