Skip to content

Commit 7af1dbe

Browse files
committed
Reuse ChainPoller in ChainMultiplexer
1 parent 6ab4b24 commit 7af1dbe

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

lightning-block-sync/src/poller.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -145,29 +145,9 @@ impl<'b, B: 'b + DerefMut<Target=dyn BlockSource + 'b> + Sized + Sync + Send> Po
145145
continue;
146146
}
147147

148-
let result = match block_source.get_best_block().await {
149-
Err(e) => Err(e),
150-
Ok((block_hash, height)) => {
151-
if block_hash == heaviest_chain_tip.header.block_hash() {
152-
Ok(ChainTip::Common)
153-
} else {
154-
match block_source.get_header(&block_hash, height).await {
155-
Err(e) => Err(e),
156-
Ok(chain_tip) => {
157-
crate::stateless_check_header(&chain_tip.header)?;
158-
if chain_tip.header.block_hash() != block_hash {
159-
Err(BlockSourceError::Persistent)
160-
} else if chain_tip.chainwork <= heaviest_chain_tip.chainwork {
161-
Ok(ChainTip::Worse(block_hash, chain_tip))
162-
} else {
163-
Ok(ChainTip::Better(block_hash, chain_tip))
164-
}
165-
},
166-
}
167-
}
168-
},
169-
};
170-
148+
let mut poller = ChainPoller::new(&mut **block_source as &mut dyn BlockSource);
149+
let result = poller.poll_chain_tip(heaviest_chain_tip).await
150+
.map(|(chain_tip, _)| chain_tip);
171151
match result {
172152
Err(BlockSourceError::Persistent) => {
173153
*error = BlockSourceError::Persistent;

0 commit comments

Comments
 (0)