Skip to content

Commit

Permalink
core: rename s/Header/BlockHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Aug 19, 2024
1 parent 3978c63 commit f8b9522
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 68 deletions.
8 changes: 4 additions & 4 deletions crates/core/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ impl Epochs {
#[derive(
Clone, Debug, BorshSerialize, BorshDeserialize, BorshDeserializer, Default,
)]
pub struct Header {
pub struct BlockHeader {
/// Merkle root hash of block
pub hash: Hash,
/// Timestamp associated to block
Expand All @@ -532,7 +532,7 @@ pub struct Header {
pub next_validators_hash: Hash,
}

impl Header {
impl BlockHeader {
/// The number of bytes when this header is encoded
pub fn encoded_len(&self) -> usize {
self.serialize_to_vec().len()
Expand Down Expand Up @@ -729,9 +729,9 @@ pub mod testing {
}

/// A dummy header used for testing
pub fn get_dummy_header() -> Header {
pub fn get_dummy_header() -> BlockHeader {
use crate::time::DurationSecs;
Header {
BlockHeader {
hash: Hash([0; 32]),
#[allow(
clippy::disallowed_methods,
Expand Down
2 changes: 1 addition & 1 deletion crates/ibc/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ where
fn get_block_header(
&self,
height: BlockHeight,
) -> StorageResult<Option<namada_storage::Header>> {
) -> StorageResult<Option<namada_storage::BlockHeader>> {
StorageRead::get_block_header(self.state, height)
}

Expand Down
12 changes: 9 additions & 3 deletions crates/ibc/src/vp/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::marker::PhantomData;

use namada_core::address::Address;
use namada_core::arith::checked;
use namada_core::chain::{BlockHeight, Epoch, Epochs, Header};
use namada_core::chain::{BlockHeader, BlockHeight, Epoch, Epochs};
use namada_core::collections::{HashMap, HashSet};
use namada_core::storage::{Key, TxIndex};
use namada_events::Event;
Expand Down Expand Up @@ -152,7 +152,10 @@ Self: 'iter;
self.ctx.get_block_height()
}

fn get_block_header(&self, height: BlockHeight) -> Result<Option<Header>> {
fn get_block_header(
&self,
height: BlockHeight,
) -> Result<Option<BlockHeader>> {
self.ctx.get_block_header(height)
}

Expand Down Expand Up @@ -339,7 +342,10 @@ where
self.ctx.get_block_height()
}

fn get_block_header(&self, height: BlockHeight) -> Result<Option<Header>> {
fn get_block_header(
&self,
height: BlockHeight,
) -> Result<Option<BlockHeader>> {
self.ctx.get_block_header(height)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/node/src/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use namada_sdk::state::write_log::StorageModification;
use namada_sdk::state::{
ResultExt, StorageResult, StorageWrite, EPOCH_SWITCH_BLOCKS_DELAY,
};
use namada_sdk::storage::{BlockResults, Epoch, Header};
use namada_sdk::storage::{BlockHeader, BlockResults, Epoch};
use namada_sdk::tx::data::protocol::ProtocolTxType;
use namada_sdk::tx::data::VpStatusFlags;
use namada_sdk::tx::event::{Batch, Code};
Expand Down Expand Up @@ -215,7 +215,7 @@ where
/// validator changes, and evidence of byzantine behavior. Applies slashes
/// if necessary. Returns a boolean indicating if a new epoch and the height
/// of the new block.
fn update_state(&mut self, header: Header) -> (BlockHeight, bool) {
fn update_state(&mut self, header: BlockHeader) -> (BlockHeight, bool) {
let height = self.state.in_mem().get_last_block_height().next_height();

self.state
Expand Down
6 changes: 3 additions & 3 deletions crates/node/src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ pub mod test_utils {
use namada_sdk::proof_of_stake::storage::validator_consensus_key_handle;
use namada_sdk::state::mockdb::MockDB;
use namada_sdk::state::{LastBlock, StorageWrite};
use namada_sdk::storage::{Epoch, Header};
use namada_sdk::storage::{BlockHeader, Epoch};
use namada_sdk::tendermint::abci::types::VoteInfo;
use tempfile::tempdir;
use tokio::sync::mpsc::{Sender, UnboundedReceiver};
Expand Down Expand Up @@ -1904,7 +1904,7 @@ pub mod test_utils {
impl Default for FinalizeBlock {
fn default() -> Self {
FinalizeBlock {
header: Header {
header: BlockHeader {
hash: Hash([0; 32]),
#[allow(clippy::disallowed_methods)]
time: DateTimeUtc::now(),
Expand Down Expand Up @@ -1965,7 +1965,7 @@ pub mod test_utils {
byzantine_validators: Option<Vec<Misbehavior>>,
) {
// Let the header time be always ahead of the next epoch min start time
let header = Header {
let header = BlockHeader {
time: shell.state.in_mem().next_epoch_min_start_time.next_second(),
..Default::default()
};
Expand Down
6 changes: 3 additions & 3 deletions crates/node/src/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use data_encoding::HEXUPPER;
use itertools::Either;
use lazy_static::lazy_static;
use namada_sdk::address::Address;
use namada_sdk::chain::{BlockHeight, Epoch, Header};
use namada_sdk::chain::{BlockHeader, BlockHeight, Epoch};
use namada_sdk::collections::HashMap;
use namada_sdk::control_flow::time::Duration;
use namada_sdk::eth_bridge::oracle::config::Config as OracleConfig;
Expand Down Expand Up @@ -483,7 +483,7 @@ impl MockNode {
};
// build finalize block abci request
let req = FinalizeBlock {
header: Header {
header: BlockHeader {
hash: Hash([0; 32]),
#[allow(clippy::disallowed_methods)]
time: DateTimeUtc::now(),
Expand Down Expand Up @@ -602,7 +602,7 @@ impl MockNode {

// process proposal succeeded, now run finalize block
let req = FinalizeBlock {
header: Header {
header: BlockHeader {
hash: Hash([0; 32]),
#[allow(clippy::disallowed_methods)]
time: DateTimeUtc::now(),
Expand Down
6 changes: 3 additions & 3 deletions crates/node/src/shims/abcipp_shim_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub mod shim {

use bytes::Bytes;
use namada_sdk::hash::Hash;
use namada_sdk::storage::Header;
use namada_sdk::storage::BlockHeader;
use namada_sdk::tendermint::abci::types::CommitInfo;
use namada_sdk::tendermint::account::Id;
use namada_sdk::tendermint::block::Height;
Expand All @@ -193,7 +193,7 @@ pub mod shim {

#[derive(Debug, Clone)]
pub struct FinalizeBlock {
pub header: Header,
pub header: BlockHeader,
pub block_hash: Hash,
pub byzantine_validators: Vec<Misbehavior>,
pub txs: Vec<ProcessedTx>,
Expand All @@ -217,7 +217,7 @@ pub mod shim {
fn from(req: tm_request::BeginBlock) -> FinalizeBlock {
let header = req.header;
FinalizeBlock {
header: Header {
header: BlockHeader {
hash: Hash::try_from(header.app_hash.as_bytes())
.unwrap_or_default(),
time: DateTimeUtc::try_from(header.time).unwrap(),
Expand Down
7 changes: 5 additions & 2 deletions crates/node/src/storage/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use namada_sdk::state::{
StoreType, DB,
};
use namada_sdk::storage::{
BlockHeight, DbColFam, Epoch, Header, Key, KeySeg, BLOCK_CF, DIFFS_CF,
BlockHeader, BlockHeight, DbColFam, Epoch, Key, KeySeg, BLOCK_CF, DIFFS_CF,
REPLAY_PROTECTION_CF, ROLLBACK_CF, STATE_CF, SUBSPACE_CF,
};
use namada_sdk::{decode, encode, ethereum_events};
Expand Down Expand Up @@ -1265,7 +1265,10 @@ impl DB for RocksDB {
Ok(())
}

fn read_block_header(&self, height: BlockHeight) -> Result<Option<Header>> {
fn read_block_header(
&self,
height: BlockHeight,
) -> Result<Option<BlockHeader>> {
let block_cf = self.get_column_family(BLOCK_CF)?;
let header_key = format!("{}/{BLOCK_HEADER_KEY_SEGMENT}", height.raw());
self.read_value(block_cf, header_key)
Expand Down
12 changes: 6 additions & 6 deletions crates/parameters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ where

#[cfg(test)]
mod tests {
use namada_core::chain::Header;
use namada_core::chain::BlockHeader;
use namada_core::time::DateTimeUtc;
use namada_storage::testing::TestStorage;

Expand Down Expand Up @@ -721,7 +721,7 @@ mod tests {

storage.set_mock_block_header(
height,
Header {
BlockHeader {
time: DateTimeUtc::from_unix_timestamp(timestamp).unwrap(),
..Default::default()
},
Expand All @@ -744,7 +744,7 @@ mod tests {

storage.set_mock_block_header(
height,
Header {
BlockHeader {
time: DateTimeUtc::from_unix_timestamp(timestamp).unwrap(),
..Default::default()
},
Expand Down Expand Up @@ -777,7 +777,7 @@ mod tests {

storage.set_mock_block_header(
height,
Header {
BlockHeader {
time: DateTimeUtc::from_unix_timestamp(timestamp).unwrap(),
..Default::default()
},
Expand All @@ -801,7 +801,7 @@ mod tests {
for height in 1u64..=2 {
storage.set_mock_block_header(
BlockHeight(height),
Header {
BlockHeader {
time: DateTimeUtc::unix_epoch(),
..Default::default()
},
Expand All @@ -824,7 +824,7 @@ mod tests {

storage.set_mock_block_header(
height,
Header {
BlockHeader {
time: DateTimeUtc::from_unix_timestamp(timestamp).unwrap(),
..Default::default()
},
Expand Down
6 changes: 3 additions & 3 deletions crates/sdk/src/queries/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use masp_primitives::sapling::Node;
use namada_account::{Account, AccountPublicKeysMap};
use namada_core::address::Address;
use namada_core::arith::checked;
use namada_core::chain::{BlockHeight, Epoch, Header};
use namada_core::chain::{BlockHeader, BlockHeight, Epoch};
use namada_core::dec::Dec;
use namada_core::hash::Hash;
use namada_core::hints;
Expand Down Expand Up @@ -120,7 +120,7 @@ router! {SHELL,
( "ibc_packet" / [event_type: IbcEventType] / [source_port: PortId] / [source_channel: ChannelId] / [destination_port: PortId] / [destination_channel: ChannelId] / [sequence: Sequence]) -> Option<Event> = ibc_packet,

// Get the block header associated with the requested height
( "block_header" / [height: BlockHeight] ) -> Option<Header> = block_header,
( "block_header" / [height: BlockHeight] ) -> Option<BlockHeader> = block_header,

// Return an estimate of the maximum time taken to decide a block
( "max_block_time" ) -> DurationSecs = max_block_time,
Expand Down Expand Up @@ -161,7 +161,7 @@ where
fn block_header<D, H, V, T>(
ctx: RequestCtx<'_, D, H, V, T>,
height: BlockHeight,
) -> namada_storage::Result<Option<Header>>
) -> namada_storage::Result<Option<BlockHeader>>
where
D: 'static + DB + for<'iter> DBIter<'iter> + Sync,
H: 'static + StorageHasher + Sync,
Expand Down
6 changes: 3 additions & 3 deletions crates/state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use namada_storage::conversion_state::ConversionState;
use namada_storage::tx_queue::ExpiredTxsQueue;
use namada_storage::types::CommitOnlyData;
use namada_storage::{
BlockHeight, BlockResults, Epoch, Epochs, EthEventsQueue, Header, Key,
BlockHeader, BlockHeight, BlockResults, Epoch, Epochs, EthEventsQueue, Key,
KeySeg, StorageHasher, TxIndex, EPOCH_TYPE_LENGTH,
};

Expand All @@ -39,7 +39,7 @@ where
/// 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>,
pub header: Option<BlockHeader>,
/// The most recently committed block, if any.
pub last_block: Option<LastBlock>,
/// The epoch of the most recently committed block. If it is `Epoch(0)`,
Expand Down Expand Up @@ -189,7 +189,7 @@ where
/// Set the block header.
/// The header is not in the Merkle tree as it's tracked by Tendermint.
/// Hence, we don't update the tree when this is set.
pub fn set_header(&mut self, header: Header) -> Result<()> {
pub fn set_header(&mut self, header: BlockHeader) -> Result<()> {
self.header = Some(header);
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub use in_memory::{
use namada_core::address::Address;
use namada_core::arith::{self, checked};
pub use namada_core::chain::{
BlockHash, BlockHeight, Epoch, Epochs, Header, BLOCK_HASH_LENGTH,
BlockHash, BlockHeader, BlockHeight, Epoch, Epochs, BLOCK_HASH_LENGTH,
BLOCK_HEIGHT_LENGTH,
};
use namada_core::eth_bridge_pool::is_pending_transfer_key;
Expand Down Expand Up @@ -167,7 +167,7 @@ pub trait StateRead: StorageRead + Debug {
fn get_block_header(
&self,
height: Option<BlockHeight>,
) -> Result<(Option<Header>, u64)> {
) -> Result<(Option<BlockHeader>, u64)> {
match height {
Some(h) if h == self.in_mem().get_block_height().0 => {
let header = self.in_mem().header.clone();
Expand Down Expand Up @@ -313,7 +313,7 @@ macro_rules! impl_storage_read {
fn get_block_header(
&self,
height: BlockHeight,
) -> std::result::Result<Option<storage::Header>, namada_storage::Error>
) -> std::result::Result<Option<BlockHeader>, namada_storage::Error>
{
let (header, gas) =
StateRead::get_block_header(self, Some(height)).into_storage_result()?;
Expand Down
4 changes: 2 additions & 2 deletions crates/state/src/wl_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::ops::{Deref, DerefMut};
use namada_core::address::Address;
use namada_core::arith::checked;
use namada_core::borsh::BorshSerializeExt;
use namada_core::chain::{ChainId, Header};
use namada_core::chain::{BlockHeader, ChainId};
use namada_core::masp::MaspEpoch;
use namada_core::parameters::{EpochDuration, Parameters};
use namada_core::storage;
Expand Down Expand Up @@ -567,7 +567,7 @@ where
#[cfg(any(test, feature = "testing", feature = "benches"))]
{
if self.in_mem.header.is_none() {
self.in_mem.header = Some(Header {
self.in_mem.header = Some(BlockHeader {
hash: Hash::default(),
#[allow(clippy::disallowed_methods)]
time: DateTimeUtc::now(),
Expand Down
9 changes: 6 additions & 3 deletions crates/storage/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Debug;
use std::num::TryFromIntError;

use namada_core::address::EstablishedAddressGen;
use namada_core::chain::{BlockHeight, Epoch, Epochs, Header};
use namada_core::chain::{BlockHeader, BlockHeight, Epoch, Epochs};
use namada_core::hash::{Error as HashError, Hash};
use namada_core::storage::{BlockResults, DbColFam, EthEventsQueue, Key};
use namada_core::time::DateTimeUtc;
Expand Down Expand Up @@ -85,7 +85,7 @@ pub struct BlockStateWrite<'a> {
/// Merkle tree stores
pub merkle_tree_stores: MerkleTreeStoresWrite<'a>,
/// Header of the block
pub header: Option<&'a Header>,
pub header: Option<&'a BlockHeader>,
/// Height of the block
pub height: BlockHeight,
/// Time of the block
Expand Down Expand Up @@ -154,7 +154,10 @@ pub trait DB: Debug {
) -> Result<()>;

/// Read the block header with the given height from the DB
fn read_block_header(&self, height: BlockHeight) -> Result<Option<Header>>;
fn read_block_header(
&self,
height: BlockHeight,
) -> Result<Option<BlockHeader>>;

/// Read the merkle tree stores with the given epoch. If a store_type is
/// given, it reads only the specified tree. Otherwise, it reads all
Expand Down
Loading

0 comments on commit f8b9522

Please sign in to comment.