always make chain selection in process_new_ref
If the block landed onto the current tip branch is far away in the
future, this will cause the network to stall. To awaid that, we should
always send such blocks to a new branch.
fix
@@ -295,8 +295,18 @@ pub async fn process_new_ref(
candidate: Arc<Ref>,
) -> Result<(), Error> {
let candidate_hash = candidate.hash();
-
let tip_ref = tip.get_ref().await;
+
+ match chain_selection::compare_against(blockchain.storage(), &tip_ref, &candidate) {
+ ComparisonResult::PreferCurrent => {
+ info!(
+ logger,
+ "create new branch with tip {} | current-tip {}",
+ candidate.header().description(),
+ tip_ref.header().description(),
+ );
+ }
+ ComparisonResult::PreferCandidate => {
if tip_ref.hash() == candidate.block_parent_hash() {
info!(
logger,
@@ -313,16 +323,6 @@ pub async fn process_new_ref(
tip.update_ref(candidate).await;
} else {
- match chain_selection::compare_against(blockchain.storage(), &tip_ref, &candidate) {
- ComparisonResult::PreferCurrent => {
- info!(
- logger,
- "create new branch with tip {} | current-tip {}",
- candidate.header().description(),
- tip_ref.header().description(),
- );
- }
- ComparisonResult::PreferCandidate => {
info!(
logger,
"switching branch from {} to {}",
@@ -340,7 +340,7 @@ pub async fn process_new_ref(
tip.swap(branch).await;
}
}
- };
+ }
Ok(())
}
