@@ -16,19 +16,19 @@ impl<'b, B: DerefMut<Target=dyn BlockSource + 'b> + Sized + Sync + Send> ChainPo
16
16
}
17
17
18
18
impl < ' b , B : DerefMut < Target =dyn BlockSource + ' b > + Sized + Sync + Send > Poll for ChainPoller < ' b , B > {
19
- fn poll_chain_tip < ' a > ( & ' a mut self , best_chain_tip : ValidatedBlockHeader ) ->
19
+ fn poll_chain_tip < ' a > ( & ' a mut self , best_known_chain_tip : ValidatedBlockHeader ) ->
20
20
AsyncBlockSourceResult < ' a , ChainTip >
21
21
{
22
22
Box :: pin ( async move {
23
23
let ( block_hash, height) = self . block_source . get_best_block ( ) . await ?;
24
- if block_hash == best_chain_tip . header . block_hash ( ) {
24
+ if block_hash == best_known_chain_tip . header . block_hash ( ) {
25
25
return Ok ( ChainTip :: Common ) ;
26
26
}
27
27
28
28
let chain_tip = self . block_source
29
29
. get_header ( & block_hash, height) . await ?
30
30
. validate ( block_hash) ?;
31
- if chain_tip. chainwork > best_chain_tip . chainwork {
31
+ if chain_tip. chainwork > best_known_chain_tip . chainwork {
32
32
Ok ( ChainTip :: Better ( chain_tip) )
33
33
} else {
34
34
Ok ( ChainTip :: Worse ( chain_tip) )
@@ -97,11 +97,11 @@ impl<'b, B: DerefMut<Target=dyn BlockSource + 'b> + Sized + Sync + Send> ChainMu
97
97
}
98
98
99
99
impl < ' b , B : ' b + DerefMut < Target =dyn BlockSource + ' b > + Sized + Sync + Send > Poll for ChainMultiplexer < ' b , B > {
100
- fn poll_chain_tip < ' a > ( & ' a mut self , best_chain_tip : ValidatedBlockHeader ) ->
100
+ fn poll_chain_tip < ' a > ( & ' a mut self , best_known_chain_tip : ValidatedBlockHeader ) ->
101
101
AsyncBlockSourceResult < ' a , ChainTip >
102
102
{
103
103
Box :: pin ( async move {
104
- let mut heaviest_chain_tip = best_chain_tip ;
104
+ let mut heaviest_chain_tip = best_known_chain_tip ;
105
105
let mut best_result = Err ( BlockSourceError :: Persistent ) ;
106
106
for ( i, ( poller, error) ) in self . block_sources . iter_mut ( ) . enumerate ( ) {
107
107
if let BlockSourceError :: Persistent = error {
@@ -181,11 +181,11 @@ mod tests {
181
181
#[ tokio:: test]
182
182
async fn poll_empty_chain ( ) {
183
183
let mut chain = Blockchain :: default ( ) . with_height ( 0 ) ;
184
- let best_chain_tip = chain. tip ( ) ;
184
+ let best_known_chain_tip = chain. tip ( ) ;
185
185
chain. disconnect_tip ( ) ;
186
186
187
187
let mut poller = ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Bitcoin ) ;
188
- match poller. poll_chain_tip ( best_chain_tip ) . await {
188
+ match poller. poll_chain_tip ( best_known_chain_tip ) . await {
189
189
Err ( e) => assert_eq ! ( e, BlockSourceError :: Transient ) ,
190
190
Ok ( _) => panic ! ( "Expected error" ) ,
191
191
}
@@ -194,10 +194,10 @@ mod tests {
194
194
#[ tokio:: test]
195
195
async fn poll_chain_without_headers ( ) {
196
196
let mut chain = Blockchain :: default ( ) . with_height ( 1 ) . without_headers ( ) ;
197
- let best_chain_tip = chain. at_height ( 0 ) ;
197
+ let best_known_chain_tip = chain. at_height ( 0 ) ;
198
198
199
199
let mut poller = ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Bitcoin ) ;
200
- match poller. poll_chain_tip ( best_chain_tip ) . await {
200
+ match poller. poll_chain_tip ( best_known_chain_tip ) . await {
201
201
Err ( e) => assert_eq ! ( e, BlockSourceError :: Persistent ) ,
202
202
Ok ( _) => panic ! ( "Expected error" ) ,
203
203
}
@@ -206,14 +206,14 @@ mod tests {
206
206
#[ tokio:: test]
207
207
async fn poll_chain_with_invalid_pow ( ) {
208
208
let mut chain = Blockchain :: default ( ) . with_height ( 1 ) ;
209
- let best_chain_tip = chain. at_height ( 0 ) ;
209
+ let best_known_chain_tip = chain. at_height ( 0 ) ;
210
210
211
211
// Invalidate the tip by changing its target.
212
212
chain. blocks . last_mut ( ) . unwrap ( ) . header . bits =
213
213
BlockHeader :: compact_target_from_u256 ( & Uint256 :: from_be_bytes ( [ 0 ; 32 ] ) ) ;
214
214
215
215
let mut poller = ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Bitcoin ) ;
216
- match poller. poll_chain_tip ( best_chain_tip ) . await {
216
+ match poller. poll_chain_tip ( best_known_chain_tip ) . await {
217
217
Err ( e) => assert_eq ! ( e, BlockSourceError :: Persistent ) ,
218
218
Ok ( _) => panic ! ( "Expected error" ) ,
219
219
}
@@ -222,10 +222,10 @@ mod tests {
222
222
#[ tokio:: test]
223
223
async fn poll_chain_with_malformed_headers ( ) {
224
224
let mut chain = Blockchain :: default ( ) . with_height ( 1 ) . malformed_headers ( ) ;
225
- let best_chain_tip = chain. at_height ( 0 ) ;
225
+ let best_known_chain_tip = chain. at_height ( 0 ) ;
226
226
227
227
let mut poller = ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Bitcoin ) ;
228
- match poller. poll_chain_tip ( best_chain_tip ) . await {
228
+ match poller. poll_chain_tip ( best_known_chain_tip ) . await {
229
229
Err ( e) => assert_eq ! ( e, BlockSourceError :: Persistent ) ,
230
230
Ok ( _) => panic ! ( "Expected error" ) ,
231
231
}
@@ -234,10 +234,10 @@ mod tests {
234
234
#[ tokio:: test]
235
235
async fn poll_chain_with_common_tip ( ) {
236
236
let mut chain = Blockchain :: default ( ) . with_height ( 0 ) ;
237
- let best_chain_tip = chain. tip ( ) ;
237
+ let best_known_chain_tip = chain. tip ( ) ;
238
238
239
239
let mut poller = ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Bitcoin ) ;
240
- match poller. poll_chain_tip ( best_chain_tip ) . await {
240
+ match poller. poll_chain_tip ( best_known_chain_tip ) . await {
241
241
Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
242
242
Ok ( tip) => assert_eq ! ( tip, ChainTip :: Common ) ,
243
243
}
@@ -246,18 +246,18 @@ mod tests {
246
246
#[ tokio:: test]
247
247
async fn poll_chain_with_uncommon_tip_but_equal_chainwork ( ) {
248
248
let mut chain = Blockchain :: default ( ) . with_height ( 1 ) ;
249
- let best_chain_tip = chain. tip ( ) ;
249
+ let best_known_chain_tip = chain. tip ( ) ;
250
250
251
251
// Change the nonce to get a different block hash with the same chainwork.
252
252
chain. blocks . last_mut ( ) . unwrap ( ) . header . nonce += 1 ;
253
253
254
254
let worse_chain_tip = chain. tip ( ) ;
255
255
let worse_chain_tip_hash = worse_chain_tip. header . block_hash ( ) ;
256
256
let worse_chain_tip = worse_chain_tip. validate ( worse_chain_tip_hash) . unwrap ( ) ;
257
- assert_eq ! ( best_chain_tip . chainwork, worse_chain_tip. chainwork) ;
257
+ assert_eq ! ( best_known_chain_tip . chainwork, worse_chain_tip. chainwork) ;
258
258
259
259
let mut poller = ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Bitcoin ) ;
260
- match poller. poll_chain_tip ( best_chain_tip ) . await {
260
+ match poller. poll_chain_tip ( best_known_chain_tip ) . await {
261
261
Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
262
262
Ok ( tip) => assert_eq ! ( tip, ChainTip :: Worse ( worse_chain_tip) ) ,
263
263
}
@@ -266,15 +266,15 @@ mod tests {
266
266
#[ tokio:: test]
267
267
async fn poll_chain_with_worse_tip ( ) {
268
268
let mut chain = Blockchain :: default ( ) . with_height ( 1 ) ;
269
- let best_chain_tip = chain. tip ( ) ;
269
+ let best_known_chain_tip = chain. tip ( ) ;
270
270
chain. disconnect_tip ( ) ;
271
271
272
272
let worse_chain_tip = chain. tip ( ) ;
273
273
let worse_chain_tip_hash = worse_chain_tip. header . block_hash ( ) ;
274
274
let worse_chain_tip = worse_chain_tip. validate ( worse_chain_tip_hash) . unwrap ( ) ;
275
275
276
276
let mut poller = ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Bitcoin ) ;
277
- match poller. poll_chain_tip ( best_chain_tip ) . await {
277
+ match poller. poll_chain_tip ( best_known_chain_tip ) . await {
278
278
Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
279
279
Ok ( tip) => assert_eq ! ( tip, ChainTip :: Worse ( worse_chain_tip) ) ,
280
280
}
@@ -283,16 +283,16 @@ mod tests {
283
283
#[ tokio:: test]
284
284
async fn poll_chain_with_better_tip ( ) {
285
285
let mut chain = Blockchain :: default ( ) . with_height ( 1 ) ;
286
- let worse_chain_tip = chain. at_height ( 0 ) ;
286
+ let best_known_chain_tip = chain. at_height ( 0 ) ;
287
287
288
- let best_chain_tip = chain. tip ( ) ;
289
- let best_chain_tip_hash = best_chain_tip . header . block_hash ( ) ;
290
- let best_chain_tip = best_chain_tip . validate ( best_chain_tip_hash ) . unwrap ( ) ;
288
+ let better_chain_tip = chain. tip ( ) ;
289
+ let better_chain_tip_hash = better_chain_tip . header . block_hash ( ) ;
290
+ let better_chain_tip = better_chain_tip . validate ( better_chain_tip_hash ) . unwrap ( ) ;
291
291
292
292
let mut poller = ChainPoller :: new ( & mut chain as & mut dyn BlockSource , Network :: Bitcoin ) ;
293
- match poller. poll_chain_tip ( worse_chain_tip ) . await {
293
+ match poller. poll_chain_tip ( best_known_chain_tip ) . await {
294
294
Err ( e) => panic ! ( "Unexpected error: {:?}" , e) ,
295
- Ok ( tip) => assert_eq ! ( tip, ChainTip :: Better ( best_chain_tip ) ) ,
295
+ Ok ( tip) => assert_eq ! ( tip, ChainTip :: Better ( better_chain_tip ) ) ,
296
296
}
297
297
}
298
298
}
0 commit comments