@@ -6,7 +6,7 @@ use bitcoin::blockdata::block::Block;
66use bitcoin:: hash_types:: BlockHash ;
77use bitcoin:: network:: constants:: Network ;
88
9- use std:: ops:: DerefMut ;
9+ use std:: ops:: Deref ;
1010
1111/// The `Poll` trait defines behavior for polling block sources for a chain tip and retrieving
1212/// related chain data. It serves as an adapter for `BlockSource`.
@@ -17,15 +17,15 @@ use std::ops::DerefMut;
1717/// [`ChainPoller`]: ../struct.ChainPoller.html
1818pub trait Poll {
1919 /// Returns a chain tip in terms of its relationship to the provided chain tip.
20- fn poll_chain_tip < ' a > ( & ' a mut self , best_known_chain_tip : ValidatedBlockHeader ) ->
20+ fn poll_chain_tip < ' a > ( & ' a self , best_known_chain_tip : ValidatedBlockHeader ) ->
2121 AsyncBlockSourceResult < ' a , ChainTip > ;
2222
2323 /// Returns the header that preceded the given header in the chain.
24- fn look_up_previous_header < ' a > ( & ' a mut self , header : & ' a ValidatedBlockHeader ) ->
24+ fn look_up_previous_header < ' a > ( & ' a self , header : & ' a ValidatedBlockHeader ) ->
2525 AsyncBlockSourceResult < ' a , ValidatedBlockHeader > ;
2626
2727 /// Returns the block associated with the given header.
28- fn fetch_block < ' a > ( & ' a mut self , header : & ' a ValidatedBlockHeader ) ->
28+ fn fetch_block < ' a > ( & ' a self , header : & ' a ValidatedBlockHeader ) ->
2929 AsyncBlockSourceResult < ' a , ValidatedBlock > ;
3030}
3131
@@ -170,12 +170,12 @@ mod sealed {
170170///
171171/// Other `Poll` implementations should be built using `ChainPoller` as it provides the simplest way
172172/// of validating chain data and checking consistency.
173- pub struct ChainPoller < B : DerefMut < Target =T > + Sized , T : BlockSource > {
173+ pub struct ChainPoller < B : Deref < Target =T > + Sized , T : BlockSource > {
174174 block_source : B ,
175175 network : Network ,
176176}
177177
178- impl < B : DerefMut < Target =T > + Sized , T : BlockSource > ChainPoller < B , T > {
178+ impl < B : Deref < Target =T > + Sized , T : BlockSource > ChainPoller < B , T > {
179179 /// Creates a new poller for the given block source.
180180 ///
181181 /// If the `network` parameter is mainnet, then the difficulty between blocks is checked for
@@ -185,8 +185,8 @@ impl<B: DerefMut<Target=T> + Sized, T: BlockSource> ChainPoller<B, T> {
185185 }
186186}
187187
188- impl < B : DerefMut < Target =T > + Sized + Send + Sync , T : BlockSource > Poll for ChainPoller < B , T > {
189- fn poll_chain_tip < ' a > ( & ' a mut self , best_known_chain_tip : ValidatedBlockHeader ) ->
188+ impl < B : Deref < Target =T > + Sized + Send + Sync , T : BlockSource > Poll for ChainPoller < B , T > {
189+ fn poll_chain_tip < ' a > ( & ' a self , best_known_chain_tip : ValidatedBlockHeader ) ->
190190 AsyncBlockSourceResult < ' a , ChainTip >
191191 {
192192 Box :: pin ( async move {
@@ -206,7 +206,7 @@ impl<B: DerefMut<Target=T> + Sized + Send + Sync, T: BlockSource> Poll for Chain
206206 } )
207207 }
208208
209- fn look_up_previous_header < ' a > ( & ' a mut self , header : & ' a ValidatedBlockHeader ) ->
209+ fn look_up_previous_header < ' a > ( & ' a self , header : & ' a ValidatedBlockHeader ) ->
210210 AsyncBlockSourceResult < ' a , ValidatedBlockHeader >
211211 {
212212 Box :: pin ( async move {
@@ -225,7 +225,7 @@ impl<B: DerefMut<Target=T> + Sized + Send + Sync, T: BlockSource> Poll for Chain
225225 } )
226226 }
227227
228- fn fetch_block < ' a > ( & ' a mut self , header : & ' a ValidatedBlockHeader ) ->
228+ fn fetch_block < ' a > ( & ' a self , header : & ' a ValidatedBlockHeader ) ->
229229 AsyncBlockSourceResult < ' a , ValidatedBlock >
230230 {
231231 Box :: pin ( async move {
@@ -249,7 +249,7 @@ mod tests {
249249 let best_known_chain_tip = chain. tip ( ) ;
250250 chain. disconnect_tip ( ) ;
251251
252- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
252+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
253253 match poller. poll_chain_tip ( best_known_chain_tip) . await {
254254 Err ( e) => {
255255 assert_eq ! ( e. kind( ) , BlockSourceErrorKind :: Transient ) ;
@@ -261,10 +261,10 @@ mod tests {
261261
262262 #[ tokio:: test]
263263 async fn poll_chain_without_headers ( ) {
264- let mut chain = Blockchain :: default ( ) . with_height ( 1 ) . without_headers ( ) ;
264+ let chain = Blockchain :: default ( ) . with_height ( 1 ) . without_headers ( ) ;
265265 let best_known_chain_tip = chain. at_height ( 0 ) ;
266266
267- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
267+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
268268 match poller. poll_chain_tip ( best_known_chain_tip) . await {
269269 Err ( e) => {
270270 assert_eq ! ( e. kind( ) , BlockSourceErrorKind :: Persistent ) ;
@@ -283,7 +283,7 @@ mod tests {
283283 chain. blocks . last_mut ( ) . unwrap ( ) . header . bits =
284284 BlockHeader :: compact_target_from_u256 ( & Uint256 :: from_be_bytes ( [ 0 ; 32 ] ) ) ;
285285
286- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
286+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
287287 match poller. poll_chain_tip ( best_known_chain_tip) . await {
288288 Err ( e) => {
289289 assert_eq ! ( e. kind( ) , BlockSourceErrorKind :: Persistent ) ;
@@ -295,10 +295,10 @@ mod tests {
295295
296296 #[ tokio:: test]
297297 async fn poll_chain_with_malformed_headers ( ) {
298- let mut chain = Blockchain :: default ( ) . with_height ( 1 ) . malformed_headers ( ) ;
298+ let chain = Blockchain :: default ( ) . with_height ( 1 ) . malformed_headers ( ) ;
299299 let best_known_chain_tip = chain. at_height ( 0 ) ;
300300
301- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
301+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
302302 match poller. poll_chain_tip ( best_known_chain_tip) . await {
303303 Err ( e) => {
304304 assert_eq ! ( e. kind( ) , BlockSourceErrorKind :: Persistent ) ;
@@ -310,10 +310,10 @@ mod tests {
310310
311311 #[ tokio:: test]
312312 async fn poll_chain_with_common_tip ( ) {
313- let mut chain = Blockchain :: default ( ) . with_height ( 0 ) ;
313+ let chain = Blockchain :: default ( ) . with_height ( 0 ) ;
314314 let best_known_chain_tip = chain. tip ( ) ;
315315
316- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
316+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
317317 match poller. poll_chain_tip ( best_known_chain_tip) . await {
318318 Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
319319 Ok ( tip) => assert_eq ! ( tip, ChainTip :: Common ) ,
@@ -330,7 +330,7 @@ mod tests {
330330 let worse_chain_tip = chain. tip ( ) ;
331331 assert_eq ! ( best_known_chain_tip. chainwork, worse_chain_tip. chainwork) ;
332332
333- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
333+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
334334 match poller. poll_chain_tip ( best_known_chain_tip) . await {
335335 Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
336336 Ok ( tip) => assert_eq ! ( tip, ChainTip :: Worse ( worse_chain_tip) ) ,
@@ -345,7 +345,7 @@ mod tests {
345345 chain. disconnect_tip ( ) ;
346346 let worse_chain_tip = chain. tip ( ) ;
347347
348- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
348+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
349349 match poller. poll_chain_tip ( best_known_chain_tip) . await {
350350 Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
351351 Ok ( tip) => assert_eq ! ( tip, ChainTip :: Worse ( worse_chain_tip) ) ,
@@ -354,12 +354,12 @@ mod tests {
354354
355355 #[ tokio:: test]
356356 async fn poll_chain_with_better_tip ( ) {
357- let mut chain = Blockchain :: default ( ) . with_height ( 1 ) ;
357+ let chain = Blockchain :: default ( ) . with_height ( 1 ) ;
358358 let best_known_chain_tip = chain. at_height ( 0 ) ;
359359
360360 let better_chain_tip = chain. tip ( ) ;
361361
362- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
362+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
363363 match poller. poll_chain_tip ( best_known_chain_tip) . await {
364364 Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
365365 Ok ( tip) => assert_eq ! ( tip, ChainTip :: Better ( better_chain_tip) ) ,
0 commit comments