Skip to content

Commit 4b83f18

Browse files
committed
Rename best_chain_tip to best_known_chain_tip
1 parent 74e8d8d commit 4b83f18

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

lightning-block-sync/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub trait BlockSource : Sync + Send {
100100
/// related chain data. It serves as an adapter for `BlockSource`.
101101
pub trait Poll {
102102
/// Returns a chain tip in terms of its relationship to the provided chain tip.
103-
fn poll_chain_tip<'a>(&'a mut self, best_chain_tip: ValidatedBlockHeader) ->
103+
fn poll_chain_tip<'a>(&'a mut self, best_known_chain_tip: ValidatedBlockHeader) ->
104104
AsyncBlockSourceResult<'a, ChainTip>;
105105

106106
/// Returns the header that preceded the given header in the chain.

lightning-block-sync/src/poller.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ impl<'b, B: DerefMut<Target=dyn BlockSource + 'b> + Sized + Sync + Send> ChainPo
1616
}
1717

1818
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) ->
2020
AsyncBlockSourceResult<'a, ChainTip>
2121
{
2222
Box::pin(async move {
2323
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() {
2525
return Ok(ChainTip::Common);
2626
}
2727

2828
let chain_tip = self.block_source
2929
.get_header(&block_hash, height).await?
3030
.validate(block_hash)?;
31-
if chain_tip.chainwork > best_chain_tip.chainwork {
31+
if chain_tip.chainwork > best_known_chain_tip.chainwork {
3232
Ok(ChainTip::Better(chain_tip))
3333
} else {
3434
Ok(ChainTip::Worse(chain_tip))
@@ -97,11 +97,11 @@ impl<'b, B: DerefMut<Target=dyn BlockSource + 'b> + Sized + Sync + Send> ChainMu
9797
}
9898

9999
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) ->
101101
AsyncBlockSourceResult<'a, ChainTip>
102102
{
103103
Box::pin(async move {
104-
let mut heaviest_chain_tip = best_chain_tip;
104+
let mut heaviest_chain_tip = best_known_chain_tip;
105105
let mut best_result = Err(BlockSourceError::Persistent);
106106
for (i, (poller, error)) in self.block_sources.iter_mut().enumerate() {
107107
if let BlockSourceError::Persistent = error {
@@ -181,11 +181,11 @@ mod tests {
181181
#[tokio::test]
182182
async fn poll_empty_chain() {
183183
let mut chain = Blockchain::default().with_height(0);
184-
let best_chain_tip = chain.tip();
184+
let best_known_chain_tip = chain.tip();
185185
chain.disconnect_tip();
186186

187187
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 {
189189
Err(e) => assert_eq!(e, BlockSourceError::Transient),
190190
Ok(_) => panic!("Expected error"),
191191
}
@@ -194,10 +194,10 @@ mod tests {
194194
#[tokio::test]
195195
async fn poll_chain_without_headers() {
196196
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);
198198

199199
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 {
201201
Err(e) => assert_eq!(e, BlockSourceError::Persistent),
202202
Ok(_) => panic!("Expected error"),
203203
}
@@ -206,14 +206,14 @@ mod tests {
206206
#[tokio::test]
207207
async fn poll_chain_with_invalid_pow() {
208208
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);
210210

211211
// Invalidate the tip by changing its target.
212212
chain.blocks.last_mut().unwrap().header.bits =
213213
BlockHeader::compact_target_from_u256(&Uint256::from_be_bytes([0; 32]));
214214

215215
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 {
217217
Err(e) => assert_eq!(e, BlockSourceError::Persistent),
218218
Ok(_) => panic!("Expected error"),
219219
}
@@ -222,10 +222,10 @@ mod tests {
222222
#[tokio::test]
223223
async fn poll_chain_with_malformed_headers() {
224224
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);
226226

227227
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 {
229229
Err(e) => assert_eq!(e, BlockSourceError::Persistent),
230230
Ok(_) => panic!("Expected error"),
231231
}
@@ -234,10 +234,10 @@ mod tests {
234234
#[tokio::test]
235235
async fn poll_chain_with_common_tip() {
236236
let mut chain = Blockchain::default().with_height(0);
237-
let best_chain_tip = chain.tip();
237+
let best_known_chain_tip = chain.tip();
238238

239239
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 {
241241
Err(e) => panic!("Unexpected error: {:?}", e),
242242
Ok(tip) => assert_eq!(tip, ChainTip::Common),
243243
}
@@ -246,18 +246,18 @@ mod tests {
246246
#[tokio::test]
247247
async fn poll_chain_with_uncommon_tip_but_equal_chainwork() {
248248
let mut chain = Blockchain::default().with_height(1);
249-
let best_chain_tip = chain.tip();
249+
let best_known_chain_tip = chain.tip();
250250

251251
// Change the nonce to get a different block hash with the same chainwork.
252252
chain.blocks.last_mut().unwrap().header.nonce += 1;
253253

254254
let worse_chain_tip = chain.tip();
255255
let worse_chain_tip_hash = worse_chain_tip.header.block_hash();
256256
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);
258258

259259
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 {
261261
Err(e) => panic!("Unexpected error: {:?}", e),
262262
Ok(tip) => assert_eq!(tip, ChainTip::Worse(worse_chain_tip)),
263263
}
@@ -266,15 +266,15 @@ mod tests {
266266
#[tokio::test]
267267
async fn poll_chain_with_worse_tip() {
268268
let mut chain = Blockchain::default().with_height(1);
269-
let best_chain_tip = chain.tip();
269+
let best_known_chain_tip = chain.tip();
270270
chain.disconnect_tip();
271271

272272
let worse_chain_tip = chain.tip();
273273
let worse_chain_tip_hash = worse_chain_tip.header.block_hash();
274274
let worse_chain_tip = worse_chain_tip.validate(worse_chain_tip_hash).unwrap();
275275

276276
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 {
278278
Err(e) => panic!("Unexpected error: {:?}", e),
279279
Ok(tip) => assert_eq!(tip, ChainTip::Worse(worse_chain_tip)),
280280
}
@@ -283,16 +283,16 @@ mod tests {
283283
#[tokio::test]
284284
async fn poll_chain_with_better_tip() {
285285
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);
287287

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();
291291

292292
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 {
294294
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)),
296296
}
297297
}
298298
}

0 commit comments

Comments
 (0)