@@ -6,7 +6,7 @@ use bitcoin::blockdata::block::Block;
6
6
use bitcoin:: hash_types:: BlockHash ;
7
7
use bitcoin:: network:: constants:: Network ;
8
8
9
- use std:: ops:: DerefMut ;
9
+ use std:: ops:: Deref ;
10
10
11
11
/// The `Poll` trait defines behavior for polling block sources for a chain tip and retrieving
12
12
/// related chain data. It serves as an adapter for `BlockSource`.
@@ -17,15 +17,15 @@ use std::ops::DerefMut;
17
17
/// [`ChainPoller`]: ../struct.ChainPoller.html
18
18
pub trait Poll {
19
19
/// 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 ) ->
21
21
AsyncBlockSourceResult < ' a , ChainTip > ;
22
22
23
23
/// 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 ) ->
25
25
AsyncBlockSourceResult < ' a , ValidatedBlockHeader > ;
26
26
27
27
/// 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 ) ->
29
29
AsyncBlockSourceResult < ' a , ValidatedBlock > ;
30
30
}
31
31
@@ -170,12 +170,12 @@ mod sealed {
170
170
///
171
171
/// Other `Poll` implementations should be built using `ChainPoller` as it provides the simplest way
172
172
/// 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 > {
174
174
block_source : B ,
175
175
network : Network ,
176
176
}
177
177
178
- impl < B : DerefMut < Target =T > + Sized , T : BlockSource > ChainPoller < B , T > {
178
+ impl < B : Deref < Target =T > + Sized , T : BlockSource > ChainPoller < B , T > {
179
179
/// Creates a new poller for the given block source.
180
180
///
181
181
/// 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> {
185
185
}
186
186
}
187
187
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 ) ->
190
190
AsyncBlockSourceResult < ' a , ChainTip >
191
191
{
192
192
Box :: pin ( async move {
@@ -206,7 +206,7 @@ impl<B: DerefMut<Target=T> + Sized + Send + Sync, T: BlockSource> Poll for Chain
206
206
} )
207
207
}
208
208
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 ) ->
210
210
AsyncBlockSourceResult < ' a , ValidatedBlockHeader >
211
211
{
212
212
Box :: pin ( async move {
@@ -225,7 +225,7 @@ impl<B: DerefMut<Target=T> + Sized + Send + Sync, T: BlockSource> Poll for Chain
225
225
} )
226
226
}
227
227
228
- fn fetch_block < ' a > ( & ' a mut self , header : & ' a ValidatedBlockHeader ) ->
228
+ fn fetch_block < ' a > ( & ' a self , header : & ' a ValidatedBlockHeader ) ->
229
229
AsyncBlockSourceResult < ' a , ValidatedBlock >
230
230
{
231
231
Box :: pin ( async move {
@@ -249,7 +249,7 @@ mod tests {
249
249
let best_known_chain_tip = chain. tip ( ) ;
250
250
chain. disconnect_tip ( ) ;
251
251
252
- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
252
+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
253
253
match poller. poll_chain_tip ( best_known_chain_tip) . await {
254
254
Err ( e) => {
255
255
assert_eq ! ( e. kind( ) , BlockSourceErrorKind :: Transient ) ;
@@ -261,10 +261,10 @@ mod tests {
261
261
262
262
#[ tokio:: test]
263
263
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 ( ) ;
265
265
let best_known_chain_tip = chain. at_height ( 0 ) ;
266
266
267
- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
267
+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
268
268
match poller. poll_chain_tip ( best_known_chain_tip) . await {
269
269
Err ( e) => {
270
270
assert_eq ! ( e. kind( ) , BlockSourceErrorKind :: Persistent ) ;
@@ -283,7 +283,7 @@ mod tests {
283
283
chain. blocks . last_mut ( ) . unwrap ( ) . header . bits =
284
284
BlockHeader :: compact_target_from_u256 ( & Uint256 :: from_be_bytes ( [ 0 ; 32 ] ) ) ;
285
285
286
- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
286
+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
287
287
match poller. poll_chain_tip ( best_known_chain_tip) . await {
288
288
Err ( e) => {
289
289
assert_eq ! ( e. kind( ) , BlockSourceErrorKind :: Persistent ) ;
@@ -295,10 +295,10 @@ mod tests {
295
295
296
296
#[ tokio:: test]
297
297
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 ( ) ;
299
299
let best_known_chain_tip = chain. at_height ( 0 ) ;
300
300
301
- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
301
+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
302
302
match poller. poll_chain_tip ( best_known_chain_tip) . await {
303
303
Err ( e) => {
304
304
assert_eq ! ( e. kind( ) , BlockSourceErrorKind :: Persistent ) ;
@@ -310,10 +310,10 @@ mod tests {
310
310
311
311
#[ tokio:: test]
312
312
async fn poll_chain_with_common_tip ( ) {
313
- let mut chain = Blockchain :: default ( ) . with_height ( 0 ) ;
313
+ let chain = Blockchain :: default ( ) . with_height ( 0 ) ;
314
314
let best_known_chain_tip = chain. tip ( ) ;
315
315
316
- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
316
+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
317
317
match poller. poll_chain_tip ( best_known_chain_tip) . await {
318
318
Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
319
319
Ok ( tip) => assert_eq ! ( tip, ChainTip :: Common ) ,
@@ -330,7 +330,7 @@ mod tests {
330
330
let worse_chain_tip = chain. tip ( ) ;
331
331
assert_eq ! ( best_known_chain_tip. chainwork, worse_chain_tip. chainwork) ;
332
332
333
- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
333
+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
334
334
match poller. poll_chain_tip ( best_known_chain_tip) . await {
335
335
Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
336
336
Ok ( tip) => assert_eq ! ( tip, ChainTip :: Worse ( worse_chain_tip) ) ,
@@ -345,7 +345,7 @@ mod tests {
345
345
chain. disconnect_tip ( ) ;
346
346
let worse_chain_tip = chain. tip ( ) ;
347
347
348
- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
348
+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
349
349
match poller. poll_chain_tip ( best_known_chain_tip) . await {
350
350
Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
351
351
Ok ( tip) => assert_eq ! ( tip, ChainTip :: Worse ( worse_chain_tip) ) ,
@@ -354,12 +354,12 @@ mod tests {
354
354
355
355
#[ tokio:: test]
356
356
async fn poll_chain_with_better_tip ( ) {
357
- let mut chain = Blockchain :: default ( ) . with_height ( 1 ) ;
357
+ let chain = Blockchain :: default ( ) . with_height ( 1 ) ;
358
358
let best_known_chain_tip = chain. at_height ( 0 ) ;
359
359
360
360
let better_chain_tip = chain. tip ( ) ;
361
361
362
- let mut poller = ChainPoller :: new ( & mut chain, Network :: Bitcoin ) ;
362
+ let poller = ChainPoller :: new ( & chain, Network :: Bitcoin ) ;
363
363
match poller. poll_chain_tip ( best_known_chain_tip) . await {
364
364
Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
365
365
Ok ( tip) => assert_eq ! ( tip, ChainTip :: Better ( better_chain_tip) ) ,
0 commit comments