Skip to content

Commit

Permalink
docs(tip-updater): Elaborate on comments in method to update tip
Browse files Browse the repository at this point in the history
Also changes the fn name of the internal worker to match that of the
outer methods.
  • Loading branch information
Sword-Smith committed May 10, 2024
1 parent 0a540f8 commit 65b283c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/models/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,16 +1151,16 @@ impl GlobalState {
}

/// Update client's state with a new block. Block is assumed to be valid, also wrt. to PoW.
/// The received block will be set as the new tip, regardless of its accumulated PoW.
/// The received block will be set as the new tip, regardless of its accumulated PoW. or its
/// validity.
async fn set_new_tip_internal(
&mut self,
new_block: Block,
coinbase_utxo_info: Option<ExpectedUtxo>,
) -> Result<()> {
// note: we make this fn internal so we can log its duration and ensure it will
// never be called directly by another fn, without the timings.

async fn store_block_internal_worker(
async fn set_new_tip_internal_worker(
myself: &mut GlobalState,
new_block: Block,
coinbase_utxo_info: Option<ExpectedUtxo>,
Expand Down Expand Up @@ -1194,15 +1194,18 @@ impl GlobalState {
.expect("UTXO notification from miner must be accepted");
}

// Get parent of tip for mutator-set data needed for various updates
// Get parent of tip for mutator-set data needed for various updates. Parent of the
// stored block will always exist since all blocks except the genesis block have a
// parent, and the genesis block is considered code, not data, so the genesis block
// will never be changed or updated through this method.
let tip_parent = myself
.chain
.archival_state()
.get_tip_parent()
.await
.expect("Parent must exist when storing a new block");

// Sanity check
// Sanity check that must always be true for a valid block
assert_eq!(
tip_parent.hash(),
new_block.header().prev_block_digest,
Expand Down Expand Up @@ -1231,7 +1234,7 @@ impl GlobalState {
Ok(())
}

crate::macros::duration_async_info!(store_block_internal_worker(
crate::macros::duration_async_info!(set_new_tip_internal_worker(
self,
new_block,
coinbase_utxo_info
Expand Down

0 comments on commit 65b283c

Please sign in to comment.