Skip to content

Commit

Permalink
chain: Fix sync failed since verified and open block compact with meta
Browse files Browse the repository at this point in the history
  • Loading branch information
sanlee42 committed May 8, 2024
1 parent d533c1f commit 1fcd227
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
35 changes: 24 additions & 11 deletions chain/open-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,30 @@ impl OpenedBlock {
let chain_state =
ChainStateDB::new(storage.into_super_arc(), Some(previous_header.state_root()));
let chain_id = previous_header.chain_id();
let block_meta = BlockMetadata::new_with_parents(
previous_block_id,
block_timestamp,
author,
None,
uncles.len() as u64,
previous_header.number() + 1,
chain_id,
previous_header.gas_used(),
tips_hash.unwrap_or_default(),
);
let block_meta = if chain_id.is_proxima() {
BlockMetadata::new(
previous_block_id,
block_timestamp,
author,
None,
uncles.len() as u64,
previous_header.number() + 1,
chain_id,
previous_header.gas_used(),
)
} else {
BlockMetadata::new_with_parents(
previous_block_id,
block_timestamp,
author,
None,
uncles.len() as u64,
previous_header.number() + 1,
chain_id,
previous_header.gas_used(),
tips_hash.unwrap_or_default(),
)
};
let mut opened_block = Self {
previous_block_info: block_info,
block_meta,
Expand Down
29 changes: 10 additions & 19 deletions chain/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ pub trait BlockVerifier {
where
R: ChainReader,
{
if header.is_legacy() {
return Ok(());
}
let epoch = current_chain.epoch();
let is_legacy = header.is_legacy();

let switch_epoch = header.number() == epoch.end_block_number();
// epoch first block's uncles should empty.
Expand Down Expand Up @@ -147,21 +143,6 @@ pub trait BlockVerifier {
"invalid block: block {} can not be uncle.",
uncle_id
);

let valid_parents_hash = if is_legacy {
uncle.parents_hash().is_none()
} else {
uncle.parents_hash().unwrap_or_default().is_empty()
};

verify_block!(
VerifyBlockField::Uncle,
valid_parents_hash,
"uncle {} is not valid for a single-chain block, parents_hash len {}",
uncle.id(),
uncle.parents_hash().unwrap_or_default().len()
);

debug!(
"verify_uncle header number {} hash {:?} uncle number {} hash {:?}",
header.number(),
Expand Down Expand Up @@ -439,6 +420,16 @@ impl BlockVerifier for DagVerifier {
//TODO: Implement it.
pub struct DagBasicVerifier;
impl BlockVerifier for DagBasicVerifier {
fn verify_uncles<R>(
_current_chain: &R,
_uncles: &[BlockHeader],
_header: &BlockHeader,
) -> Result<()>
where
R: ChainReader,
{
Ok(())
}
fn verify_header<R>(current_chain: &R, new_block_header: &BlockHeader) -> Result<()>
where
R: ChainReader,
Expand Down

0 comments on commit 1fcd227

Please sign in to comment.