Skip to content

Commit

Permalink
Merge branch 'james/mainline/last-block' (#650)
Browse files Browse the repository at this point in the history
* james/mainline/last-block:
  Add changelog
  Remove unnecessary clone
  Update docstrings of Storage fields relating to blocks
  • Loading branch information
tzemanovic committed Nov 16, 2022
2 parents 7cab394 + 4673045 commit 06911fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
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 @@ -268,21 +268,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 @@ -80,13 +80,17 @@ where
/// The address of the native token - this is not stored in DB, but read
/// from genesis
pub native_token: Address,
/// 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 @@ -108,11 +112,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,
/// Results of applying transactions
pub results: BlockResults,
Expand Down Expand Up @@ -599,12 +611,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

0 comments on commit 06911fa

Please sign in to comment.