Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docstrings of Storage fields relating to blocks #650

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/miscellaneous/650-last-block.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Improve some docstrings relating to block heights
([#650](https://github.com/anoma/namada/pull/650))
9 changes: 2 additions & 7 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,21 +259,16 @@ where
.begin_block(hash, height)
.expect("Beginning a block shouldn't fail");

let header_time = header.time;
self.storage
.set_header(header)
.expect("Setting a header shouldn't fail");

self.byzantine_validators = byzantine_validators;

let header = self
.storage
.header
.as_ref()
.expect("Header must have been set in prepare_proposal.");
let time = header.time;
let new_epoch = self
.storage
.update_epoch(height, time)
.update_epoch(height, header_time)
.expect("Must be able to update epoch");

self.slash();
Expand Down
30 changes: 21 additions & 9 deletions shared/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ where
pub db: D,
/// The ID of the chain
pub chain_id: ChainId,
/// The storage for the current (yet to be committed) block
/// Block storage data
pub block: BlockStorage<H>,
/// The latest block header
/// During `FinalizeBlock`, this is the header of the block that is
/// going to be committed. After a block is committed, this is reset to
/// `None` until the next `FinalizeBlock` phase is reached.
pub header: Option<Header>,
/// The height of the committed block
/// The height of the most recently committed block, or `BlockHeight(0)` if
/// no block has been committed for this chain yet.
pub last_height: BlockHeight,
/// The epoch of the committed block
/// The epoch of the most recently committed block. If it is `Epoch(0)`,
/// then no block may have been committed for this chain yet.
pub last_epoch: Epoch,
/// Minimum block height at which the next epoch may start
pub next_epoch_min_start_height: BlockHeight,
Expand All @@ -76,11 +80,19 @@ where
pub struct BlockStorage<H: StorageHasher> {
/// Merkle tree of all the other data in block storage
pub tree: MerkleTree<H>,
/// Hash of the block
/// During `FinalizeBlock`, this is updated to be the hash of the block
/// that is going to be committed. If it is `BlockHash::default()`,
/// then no `FinalizeBlock` stage has been reached yet.
pub hash: BlockHash,
/// Height of the block (i.e. the level)
/// From the start of `FinalizeBlock` until the end of `Commit`, this is
/// height of the block that is going to be committed. Otherwise, it is the
/// height of the most recently committed block, or `BlockHeight(0)` if no
/// block has been committed yet.
pub height: BlockHeight,
/// Epoch of the block
/// From the start of `FinalizeBlock` until the end of `Commit`, this is
/// height of the block that is going to be committed. Otherwise it is the
/// epoch of the most recently committed block, or `Epoch(0)` if no block
/// has been committed yet.
pub epoch: Epoch,
/// Predecessor block epochs
pub pred_epochs: Epochs,
Expand Down Expand Up @@ -516,12 +528,12 @@ where
(self.chain_id.to_string(), CHAIN_ID_LENGTH as _)
}

/// Get the current (yet to be committed) block height
/// Get the block height
pub fn get_block_height(&self) -> (BlockHeight, u64) {
(self.block.height, MIN_STORAGE_GAS)
}

/// Get the current (yet to be committed) block hash
/// Get the block hash
pub fn get_block_hash(&self) -> (BlockHash, u64) {
(self.block.hash.clone(), BLOCK_HASH_LENGTH as _)
}
Expand Down