Skip to content

Commit

Permalink
add test code
Browse files Browse the repository at this point in the history
  • Loading branch information
jackzhhuang committed Sep 27, 2024
1 parent 2d3745e commit 07de3ce
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
20 changes: 20 additions & 0 deletions chain/mock/src/mock_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,26 @@ impl MockChain {
.create_block(template, self.net.time_service().as_ref())
}

pub fn produce_block_by_params(
&mut self,
parent_header: BlockHeader,
tips: Vec<HashValue>,
pruning_point: HashValue,
) -> Result<Block> {
let (template, _) = self.head.create_block_template_by_header(
*self.miner.address(),
parent_header,
vec![],
vec![],
None,
tips,
pruning_point,
)?;
self.head
.consensus()
.create_block(template, self.net.time_service().as_ref())
}

pub fn produce_block_by_tips(
&mut self,
parent_header: BlockHeader,
Expand Down
4 changes: 2 additions & 2 deletions chain/src/verifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ impl BasicDagVerifier {
),
)
})?,
"Invalid block: parent {} might not exist.",
parent_hash
"Invalid block: parent {:?} is not the descendant of pruning point: {:?}",
parent_hash, new_block_header.pruning_point()
);
Ok::<(), ConnectBlockError>(())
})?;
Expand Down
24 changes: 19 additions & 5 deletions chain/tests/test_prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,29 @@ fn test_block_chain_prune() -> anyhow::Result<()> {
.collect::<HashSet<_>>(),
HashSet::from_iter(vec![block_blue_6.id(), block_blue_6_1.id()])
);

let tips = mock_chain.head().get_dag_state()?.tips;
assert_eq!(
mock_chain
.head()
.get_dag_state()?
.tips
tips.iter().cloned().collect::<HashSet<_>>(),
HashSet::from_iter(vec![block_blue_7.id()])
);

let failure_block = mock_chain.produce_block_by_params(
block_blue_7.header().clone(),
vec![block_red_4.id(), block_blue_7.id()],
block_blue_7.header().pruning_point(),
)?;
assert_eq!(
failure_block
.header()
.parents_hash()
.into_iter()
.collect::<HashSet<_>>(),
HashSet::from_iter(vec![block_blue_7.id()])
HashSet::from_iter(vec![block_red_4.id(), block_blue_7.id()])
);
let result = mock_chain.apply(failure_block);
debug!("apply failure block result: {:?}", result);
assert!(result.is_err());

Ok(())
}
14 changes: 1 addition & 13 deletions kube/manifest/starcoin-halley.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
starcoin/node-pool: seed-pool
containers:
- name: starcoin
image: starcoin/starcoin:dag-master
image: starcoin/starcoin:pruning-point
imagePullPolicy: Always
command:
- bash
Expand Down Expand Up @@ -68,18 +68,6 @@ spec:
timeoutSeconds: 2
failureThreshold: 3
successThreshold: 1
readinessProbe:
exec:
command:
- sh
- -c
- >-
/starcoin/starcoin -n halley -d /sc-data node sync status|grep Synchronized
initialDelaySeconds: 10
periodSeconds: 5
timeoutSeconds: 2
failureThreshold: 3
successThreshold: 1
volumeClaimTemplates:
- metadata:
name: starcoin-volume
Expand Down
7 changes: 5 additions & 2 deletions sync/src/tasks/block_sync_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,11 @@ where
.find_absent_ancestor(vec![block_header.clone()])
.await?;

if count == 0
|| block_header.number() % 1000 == 0
if count == 0 {
return anyhow::Ok(ParallelSign::Continue);
}

if block_header.number() % 1000 == 0
|| block_header.number() >= self.target.target_id.number()
{
let parallel_execute = DagBlockSender::new(
Expand Down

0 comments on commit 07de3ce

Please sign in to comment.