@@ -96,16 +96,6 @@ impl CheckPoint {
9696 . expect ( "must construct checkpoint" )
9797 }
9898
99- /// Convenience method to convert the [`CheckPoint`] into an [`Update`].
100- ///
101- /// For more information, refer to [`Update`].
102- pub fn into_update ( self , introduce_older_blocks : bool ) -> Update {
103- Update {
104- tip : self ,
105- introduce_older_blocks,
106- }
107- }
108-
10999 /// Puts another checkpoint onto the linked list representing the blockchain.
110100 ///
111101 /// Returns an `Err(self)` if the block you are pushing on is not at a greater height that the one you
@@ -251,31 +241,6 @@ impl IntoIterator for CheckPoint {
251241 }
252242}
253243
254- /// Used to update [`LocalChain`].
255- ///
256- /// This is used as input for [`LocalChain::apply_update`]. It contains the update's chain `tip` and
257- /// a flag `introduce_older_blocks` which signals whether this update intends to introduce missing
258- /// blocks to the original chain.
259- ///
260- /// Block-by-block syncing mechanisms would typically create updates that builds upon the previous
261- /// tip. In this case, `introduce_older_blocks` would be `false`.
262- ///
263- /// Script-pubkey based syncing mechanisms may not introduce transactions in a chronological order
264- /// so some updates require introducing older blocks (to anchor older transactions). For
265- /// script-pubkey based syncing, `introduce_older_blocks` would typically be `true`.
266- #[ derive( Debug , Clone , PartialEq ) ]
267- pub struct Update {
268- /// The update chain's new tip.
269- pub tip : CheckPoint ,
270-
271- /// Whether the update allows for introducing older blocks.
272- ///
273- /// Refer to [struct-level documentation] for more.
274- ///
275- /// [struct-level documentation]: Update
276- pub introduce_older_blocks : bool ,
277- }
278-
279244/// This is a local implementation of [`ChainOracle`].
280245#[ derive( Debug , Clone , PartialEq ) ]
281246pub struct LocalChain {
@@ -390,23 +355,16 @@ impl LocalChain {
390355 /// the existing chain and invalidate the block after it (if it exists) by including a block at
391356 /// the same height but with a different hash to explicitly exclude it as a connection point.
392357 ///
393- /// Additionally, an empty chain can be updated with any chain, and a chain with a single block
394- /// can have it's block invalidated by an update chain with a block at the same height but
395- /// different hash.
358+ /// Additionally, a chain with a single block can have it's block invalidated by an update
359+ /// chain with a block at the same height but different hash.
396360 ///
397361 /// # Errors
398362 ///
399363 /// An error will occur if the update does not correctly connect with `self`.
400364 ///
401- /// Refer to [`Update`] for more about the update struct.
402- ///
403365 /// [module-level documentation]: crate::local_chain
404- pub fn apply_update ( & mut self , update : Update ) -> Result < ChangeSet , CannotConnectError > {
405- let changeset = merge_chains (
406- self . tip . clone ( ) ,
407- update. tip . clone ( ) ,
408- update. introduce_older_blocks ,
409- ) ?;
366+ pub fn apply_update ( & mut self , update : CheckPoint ) -> Result < ChangeSet , CannotConnectError > {
367+ let changeset = merge_chains ( self . tip . clone ( ) , update. clone ( ) ) ?;
410368 // `._check_index_is_consistent_with_tip` and `._check_changeset_is_applied` is called in
411369 // `.apply_changeset`
412370 self . apply_changeset ( & changeset)
@@ -464,11 +422,8 @@ impl LocalChain {
464422 conn => Some ( conn) ,
465423 } ;
466424
467- let update = Update {
468- tip : CheckPoint :: from_block_ids ( [ conn, prev, Some ( this) ] . into_iter ( ) . flatten ( ) )
469- . expect ( "block ids must be in order" ) ,
470- introduce_older_blocks : false ,
471- } ;
425+ let update = CheckPoint :: from_block_ids ( [ conn, prev, Some ( this) ] . into_iter ( ) . flatten ( ) )
426+ . expect ( "block ids must be in order" ) ;
472427
473428 self . apply_update ( update)
474429 . map_err ( ApplyHeaderError :: CannotConnect )
@@ -769,7 +724,6 @@ impl std::error::Error for ApplyHeaderError {}
769724fn merge_chains (
770725 original_tip : CheckPoint ,
771726 update_tip : CheckPoint ,
772- introduce_older_blocks : bool ,
773727) -> Result < ChangeSet , CannotConnectError > {
774728 let mut changeset = ChangeSet :: default ( ) ;
775729 let mut orig = original_tip. into_iter ( ) ;
@@ -829,11 +783,9 @@ fn merge_chains(
829783 }
830784 point_of_agreement_found = true ;
831785 prev_orig_was_invalidated = false ;
832- // OPTIMIZATION 1 -- If we know that older blocks cannot be introduced without
833- // invalidation, we can break after finding the point of agreement.
834786 // OPTIMIZATION 2 -- if we have the same underlying pointer at this point, we
835787 // can guarantee that no older blocks are introduced.
836- if !introduce_older_blocks || Arc :: as_ptr ( & o. 0 ) == Arc :: as_ptr ( & u. 0 ) {
788+ if Arc :: as_ptr ( & o. 0 ) == Arc :: as_ptr ( & u. 0 ) {
837789 return Ok ( changeset) ;
838790 }
839791 } else {
0 commit comments