Skip to content

Commit 9d36b29

Browse files
committed
Remove unnecessary match expressions
1 parent 4a0a9b1 commit 9d36b29

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

lightning-block-sync/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,9 @@ async fn sync_chain_monitor<CL: ChainListener + Sized, P: Poll>(new_header: Vali
363363

364364
for event in events.drain(..).rev() {
365365
if let ForkStep::ConnectBlock(header) = event {
366-
let block = match chain_poller.fetch_block(&header).await {
367-
Err(e) => return Err((e, new_tip)),
368-
Ok(b) => b,
369-
};
366+
let block = chain_poller
367+
.fetch_block(&header).await
368+
.or_else(|e| Err((e, new_tip)))?;
370369
debug_assert_eq!(block.block_hash, header.block_hash);
371370
println!("Connecting block {}", header.block_hash.to_hex());
372371
chain_notifier.block_connected(&block, header.height);

lightning-block-sync/src/poller.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,18 @@ impl<'b, B: DerefMut<Target=dyn BlockSource + 'b> + Sized + Sync + Send> Poll fo
2020
AsyncBlockSourceResult<'a, ChainTip>
2121
{
2222
Box::pin(async move {
23-
match self.block_source.get_best_block().await {
24-
Err(e) => Err(e),
25-
Ok((block_hash, height)) => {
26-
if block_hash == best_chain_tip.header.block_hash() {
27-
return Ok(ChainTip::Common);
28-
}
29-
30-
let chain_tip = self.block_source
31-
.get_header(&block_hash, height).await?
32-
.validate(block_hash)?;
33-
if chain_tip.chainwork > best_chain_tip.chainwork {
34-
Ok(ChainTip::Better(chain_tip))
35-
} else {
36-
Ok(ChainTip::Worse(chain_tip))
37-
}
38-
},
23+
let (block_hash, height) = self.block_source.get_best_block().await?;
24+
if block_hash == best_chain_tip.header.block_hash() {
25+
return Ok(ChainTip::Common);
26+
}
27+
28+
let chain_tip = self.block_source
29+
.get_header(&block_hash, height).await?
30+
.validate(block_hash)?;
31+
if chain_tip.chainwork > best_chain_tip.chainwork {
32+
Ok(ChainTip::Better(chain_tip))
33+
} else {
34+
Ok(ChainTip::Worse(chain_tip))
3935
}
4036
})
4137
}

0 commit comments

Comments
 (0)