diff --git a/.changelog/unreleased/bug-fixes/3136-rm-empty-block-hash.md b/.changelog/unreleased/bug-fixes/3136-rm-empty-block-hash.md new file mode 100644 index 0000000000..5e90befb9f --- /dev/null +++ b/.changelog/unreleased/bug-fixes/3136-rm-empty-block-hash.md @@ -0,0 +1,2 @@ +- Removed block hash and all the associated functions that were using it. + ([\#3136](https://github.com/anoma/namada/pull/3136)) \ No newline at end of file diff --git a/crates/apps/src/lib/bench_utils.rs b/crates/apps/src/lib/bench_utils.rs index 8dbb038312..5a36ea86e5 100644 --- a/crates/apps/src/lib/bench_utils.rs +++ b/crates/apps/src/lib/bench_utils.rs @@ -17,7 +17,6 @@ use masp_primitives::zip32::ExtendedFullViewingKey; use masp_proofs::prover::LocalTxProver; use namada::core::address::{self, Address, InternalAddress}; use namada::core::chain::ChainId; -use namada::core::hash::Hash; use namada::core::key::common::SecretKey; use namada::core::masp::{ ExtendedViewingKey, PaymentAddress, TransferSource, TransferTarget, @@ -570,7 +569,7 @@ impl BenchShell { self.inner .state .in_mem_mut() - .begin_block(Hash::default().into(), last_height + 1) + .begin_block(last_height + 1) .unwrap(); self.inner.commit(); diff --git a/crates/apps/src/lib/client/rpc.rs b/crates/apps/src/lib/client/rpc.rs index 307c12b516..25ca873547 100644 --- a/crates/apps/src/lib/client/rpc.rs +++ b/crates/apps/src/lib/client/rpc.rs @@ -133,8 +133,7 @@ pub async fn query_block(context: &impl Namada) { Some(block) => { display_line!( context.io(), - "Last committed block ID: {}, height: {}, time: {}", - block.hash, + "Last committed block height: {}, time: {}", block.height, block.time ); diff --git a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs index f2a61a809b..2dc9dfe426 100644 --- a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -3,7 +3,7 @@ use data_encoding::HEXUPPER; use masp_primitives::merkle_tree::CommitmentTree; use masp_primitives::sapling::Node; -use namada::core::storage::{BlockHash, BlockResults, Epoch, Header}; +use namada::core::storage::{BlockResults, Epoch, Header}; use namada::gas::event::WithGasUsed; use namada::governance::pgf::inflation as pgf_inflation; use namada::hash::Hash; @@ -62,7 +62,7 @@ where let mut response = shim::response::FinalizeBlock::default(); // Begin the new block and check if a new epoch has begun - let (height, new_epoch) = self.update_state(req.header, req.hash); + let (height, new_epoch) = self.update_state(req.header); let (current_epoch, _gas) = self.state.in_mem().get_current_epoch(); let update_for_tendermint = matches!( @@ -550,21 +550,16 @@ where Ok(response) } - /// Sets the metadata necessary for a new block, including - /// the hash, height, validator changes, and evidence of - /// byzantine behavior. Applies slashes if necessary. - /// Returns a bool indicating if a new epoch began and - /// the height of the new block. - fn update_state( - &mut self, - header: Header, - hash: BlockHash, - ) -> (BlockHeight, bool) { + /// Sets the metadata necessary for a new block, including the height, + /// validator changes, and evidence of byzantine behavior. Applies slashes + /// if necessary. Returns a bool indicating if a new epoch began and the + /// height of the new block. + fn update_state(&mut self, header: Header) -> (BlockHeight, bool) { let height = self.state.in_mem().get_last_block_height() + 1; self.state .in_mem_mut() - .begin_block(hash, height) + .begin_block(height) .expect("Beginning a block shouldn't fail"); let header_time = header.time; diff --git a/crates/apps/src/lib/node/ledger/shell/mod.rs b/crates/apps/src/lib/node/ledger/shell/mod.rs index 7c880e7693..d3b9b1d54b 100644 --- a/crates/apps/src/lib/node/ledger/shell/mod.rs +++ b/crates/apps/src/lib/node/ledger/shell/mod.rs @@ -1416,7 +1416,7 @@ mod test_utils { use namada::core::hash::Hash; use namada::core::keccak::KeccakHash; use namada::core::key::*; - use namada::core::storage::{BlockHash, Epoch, Header}; + use namada::core::storage::{Epoch, Header}; use namada::proof_of_stake::parameters::PosParams; use namada::proof_of_stake::storage::validator_consensus_key_handle; use namada::state::mockdb::MockDB; @@ -1866,7 +1866,6 @@ mod test_utils { impl Default for FinalizeBlock { fn default() -> Self { FinalizeBlock { - hash: BlockHash([0u8; 32]), header: Header { hash: Hash([0; 32]), #[allow(clippy::disallowed_methods)] diff --git a/crates/apps/src/lib/node/ledger/shell/queries.rs b/crates/apps/src/lib/node/ledger/shell/queries.rs index 672e221b2d..dd7ddce5e3 100644 --- a/crates/apps/src/lib/node/ledger/shell/queries.rs +++ b/crates/apps/src/lib/node/ledger/shell/queries.rs @@ -63,7 +63,7 @@ where // access to the `Shell` there #[cfg(test)] mod test_queries { - use namada::core::storage::{BlockHash, Epoch}; + use namada::core::storage::Epoch; use namada::eth_bridge::storage::eth_bridge_queries::is_bridge_comptime_enabled; use namada::ledger::pos::PosQueries; use namada::proof_of_stake::storage::read_consensus_validator_set_addresses_with_stake; @@ -95,8 +95,10 @@ mod test_queries { for (curr_epoch, curr_block_height, can_send) in epoch_assertions { - shell.state.in_mem_mut().begin_block( - BlockHash::default(), curr_block_height.into()).unwrap(); + shell.state + .in_mem_mut() + .begin_block(curr_block_height.into()) + .unwrap(); if prev_epoch != Some(curr_epoch) { prev_epoch = Some(curr_epoch); diff --git a/crates/apps/src/lib/node/ledger/shell/testing/node.rs b/crates/apps/src/lib/node/ledger/shell/testing/node.rs index 9e3e984f46..21887b98de 100644 --- a/crates/apps/src/lib/node/ledger/shell/testing/node.rs +++ b/crates/apps/src/lib/node/ledger/shell/testing/node.rs @@ -17,7 +17,7 @@ use namada::core::ethereum_events::EthereumEvent; use namada::core::ethereum_structs; use namada::core::hash::Hash; use namada::core::key::tm_consensus_key_raw_hash; -use namada::core::storage::{BlockHash, BlockHeight, Epoch, Header}; +use namada::core::storage::{BlockHeight, Epoch, Header}; use namada::core::time::DateTimeUtc; use namada::eth_bridge::oracle::config::Config as OracleConfig; use namada::ledger::dry_run_tx; @@ -442,7 +442,6 @@ impl MockNode { }; // build finalize block abci request let req = FinalizeBlock { - hash: BlockHash([0u8; 32]), header: Header { hash: Hash([0; 32]), #[allow(clippy::disallowed_methods)] @@ -560,7 +559,6 @@ impl MockNode { // process proposal succeeded, now run finalize block let req = FinalizeBlock { - hash: BlockHash([0u8; 32]), header: Header { hash: Hash([0; 32]), #[allow(clippy::disallowed_methods)] @@ -757,16 +755,7 @@ impl<'a> Client for &'a MockNode { .map(|b| b.height.0 as u32) .unwrap_or_default() .into(), - last_block_app_hash: locked - .state - .in_mem() - .last_block - .as_ref() - .map(|b| b.hash.0) - .unwrap_or_default() - .to_vec() - .try_into() - .unwrap(), + last_block_app_hash: tendermint::AppHash::default(), }) } diff --git a/crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs b/crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs index d7e1231ad1..2668b37cea 100644 --- a/crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs +++ b/crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs @@ -6,7 +6,7 @@ use std::task::{Context, Poll}; use futures::future::FutureExt; use namada::core::hash::Hash; use namada::core::key::tm_raw_hash_to_string; -use namada::core::storage::{BlockHash, BlockHeight}; +use namada::core::storage::BlockHeight; use namada::proof_of_stake::storage::find_validator_by_raw_hash; use namada::time::{DateTimeUtc, Utc}; use namada::tx::data::hash_tx; @@ -159,8 +159,6 @@ impl AbcippShim { } let mut end_block_request: FinalizeBlock = begin_block_request.into(); - let hash = self.get_hash(); - end_block_request.hash = BlockHash::from(hash); end_block_request.txs = txs; self.service .call(Request::FinalizeBlock(end_block_request)) diff --git a/crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs b/crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs index 8f99c7c5bf..005a025ade 100644 --- a/crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs +++ b/crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs @@ -152,7 +152,7 @@ pub mod shim { pub mod request { use namada::core::hash::Hash; - use namada::core::storage::{BlockHash, Header}; + use namada::core::storage::Header; use namada::core::time::DateTimeUtc; use super::VoteInfo; @@ -172,7 +172,6 @@ pub mod shim { #[derive(Debug, Clone)] pub struct FinalizeBlock { - pub hash: BlockHash, pub header: Header, pub byzantine_validators: Vec, pub txs: Vec, @@ -184,7 +183,6 @@ pub mod shim { fn from(req: tm_request::BeginBlock) -> FinalizeBlock { let header = req.header; FinalizeBlock { - hash: BlockHash::default(), header: Header { hash: Hash::try_from(header.app_hash.as_bytes()) .unwrap_or_default(), diff --git a/crates/apps/src/lib/node/ledger/storage/mod.rs b/crates/apps/src/lib/node/ledger/storage/mod.rs index 8dcc303e37..3f71a9dce2 100644 --- a/crates/apps/src/lib/node/ledger/storage/mod.rs +++ b/crates/apps/src/lib/node/ledger/storage/mod.rs @@ -60,7 +60,7 @@ mod tests { use namada::core::ethereum_events::Uint; use namada::core::hash::Hash; use namada::core::keccak::KeccakHash; - use namada::core::storage::{BlockHash, BlockHeight, Key}; + use namada::core::storage::{BlockHeight, Key}; use namada::core::time::DurationSecs; use namada::core::{address, storage}; use namada::eth_bridge::storage::proof::BridgePoolRootProof; @@ -146,7 +146,7 @@ mod tests { ); state .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(100)) + .begin_block(BlockHeight(100)) .expect("begin_block failed"); let key = Key::parse("key").expect("cannot parse the key string"); let value: u64 = 1; @@ -188,7 +188,6 @@ mod tests { // save the last state and the storage let root = state.in_mem().merkle_root().0; - let hash = state.in_mem().get_block_hash().0; let address_gen = state.in_mem().address_gen.clone(); // Release DB lock @@ -207,7 +206,6 @@ mod tests { state.in_mem().get_state().expect("no block exists"); assert_eq!(loaded_root.0, root); assert_eq!(height, 100); - assert_eq!(state.in_mem().get_block_hash().0, hash); assert_eq!(state.in_mem().address_gen, address_gen); let (val, _) = state.db_read(&key).expect("read failed"); assert_eq!(val.expect("no value"), value_bytes); @@ -271,7 +269,7 @@ mod tests { ); state .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(100)) + .begin_block(BlockHeight(100)) .expect("begin_block failed"); let addr = state @@ -359,8 +357,7 @@ mod tests { let key = Key::parse("key").expect("cannot parse the key string"); for (height, write_value) in blocks_write_value.clone() { - let hash = BlockHash::default(); - state.in_mem_mut().begin_block(hash, height)?; + state.in_mem_mut().begin_block(height)?; assert_eq!( height, state.in_mem().block.height, @@ -463,9 +460,8 @@ mod tests { state.db_write(&key, bytes)?; // Update and commit - let hash = BlockHash::default(); let height = BlockHeight(1); - state.in_mem_mut().begin_block(hash, height)?; + state.in_mem_mut().begin_block(height)?; // Epoch 0 state.in_mem_mut().block.pred_epochs.new_epoch(height); let mut batch = PersistentState::batch(); @@ -484,9 +480,8 @@ mod tests { state.in_mem().block.height, state.in_mem().merkle_root(), ); - let hash = BlockHash::default(); let next_height = state.in_mem().block.height.next_height(); - state.in_mem_mut().begin_block(hash, next_height)?; + state.in_mem_mut().begin_block(next_height)?; batch = PersistentState::batch(); } match write_type { @@ -567,7 +562,7 @@ mod tests { state .in_mem_mut() - .begin_block(BlockHash::default(), new_epoch_start) + .begin_block(new_epoch_start) .expect("begin_block failed"); let key = ibc_key("key").unwrap(); @@ -585,7 +580,7 @@ mod tests { let new_epoch_start = BlockHeight(6); state .in_mem_mut() - .begin_block(BlockHash::default(), new_epoch_start) + .begin_block(new_epoch_start) .expect("begin_block failed"); let key = ibc_key("key2").unwrap(); @@ -610,7 +605,7 @@ mod tests { let new_epoch_start = BlockHeight(11); state .in_mem_mut() - .begin_block(BlockHash::default(), new_epoch_start) + .begin_block(new_epoch_start) .expect("begin_block failed"); let nonce = nonce + 1; @@ -643,7 +638,7 @@ mod tests { state .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(12)) + .begin_block(BlockHeight(12)) .expect("begin_block failed"); let nonce = nonce + 1; diff --git a/crates/apps/src/lib/node/ledger/storage/rocksdb.rs b/crates/apps/src/lib/node/ledger/storage/rocksdb.rs index 262875629d..2e7b39f0c2 100644 --- a/crates/apps/src/lib/node/ledger/storage/rocksdb.rs +++ b/crates/apps/src/lib/node/ledger/storage/rocksdb.rs @@ -805,7 +805,6 @@ impl DB for RocksDB { let next_height_prefix = format!("{}/", height.next_height().raw()); read_opts.set_iterate_upper_bound(next_height_prefix); let mut merkle_tree_stores = MerkleTreeStoresRead::default(); - let mut hash = None; let mut time = None; let mut epoch: Option = None; let mut pred_epochs = None; @@ -852,9 +851,6 @@ impl DB for RocksDB { "header" => { // the block header doesn't have to be restored } - "hash" => { - hash = Some(decode(bytes).map_err(Error::CodingError)?) - } "time" => { time = Some(decode(bytes).map_err(Error::CodingError)?) } @@ -904,30 +900,25 @@ impl DB for RocksDB { } } } - match (hash, time, epoch, pred_epochs, address_gen) { - ( - Some(hash), - Some(time), - Some(epoch), - Some(pred_epochs), - Some(address_gen), - ) => Ok(Some(BlockStateRead { - merkle_tree_stores, - hash, - height, - time, - epoch, - pred_epochs, - results, - conversion_state, - next_epoch_min_start_height, - next_epoch_min_start_time, - update_epoch_blocks_delay, - address_gen, - ethereum_height, - eth_events_queue, - commit_only_data, - })), + match (time, epoch, pred_epochs, address_gen) { + (Some(time), Some(epoch), Some(pred_epochs), Some(address_gen)) => { + Ok(Some(BlockStateRead { + merkle_tree_stores, + height, + time, + epoch, + pred_epochs, + results, + conversion_state, + next_epoch_min_start_height, + next_epoch_min_start_time, + update_epoch_blocks_delay, + address_gen, + ethereum_height, + eth_events_queue, + commit_only_data, + })) + } _ => Err(Error::Temporary { error: "Essential data couldn't be read from the DB" .to_string(), @@ -944,7 +935,6 @@ impl DB for RocksDB { let BlockStateWrite { merkle_tree_stores, header, - hash, height, time, epoch, @@ -1105,13 +1095,6 @@ impl DB for RocksDB { .put_cf(block_cf, key.to_string(), h.serialize_to_vec()); } } - // Block hash - { - let key = prefix_key - .push(&"hash".to_owned()) - .map_err(Error::KeyError)?; - batch.0.put_cf(block_cf, key.to_string(), encode(&hash)); - } // Block time { let key = prefix_key @@ -2107,7 +2090,7 @@ mod imp { mod test { use namada::core::address::EstablishedAddressGen; use namada::core::hash::Hash; - use namada::core::storage::{BlockHash, Epochs}; + use namada::core::storage::Epochs; use namada::state::{MerkleTree, Sha256Hasher}; use tempfile::tempdir; use test_log::test; @@ -2657,7 +2640,6 @@ mod test { ) -> Result<()> { let merkle_tree = MerkleTree::::default(); let merkle_tree_stores = merkle_tree.stores(); - let hash = BlockHash::default(); #[allow(clippy::disallowed_methods)] let time = DateTimeUtc::now(); let next_epoch_min_start_height = BlockHeight::default(); @@ -2671,7 +2653,6 @@ mod test { let block = BlockStateWrite { merkle_tree_stores, header: None, - hash: &hash, height, time, epoch, diff --git a/crates/ibc/src/actions.rs b/crates/ibc/src/actions.rs index 71bb4d8bde..257dc2643e 100644 --- a/crates/ibc/src/actions.rs +++ b/crates/ibc/src/actions.rs @@ -78,10 +78,6 @@ where StorageRead::get_block_header(self.state, height) } - fn get_block_hash(&self) -> StorageResult { - self.state.get_block_hash() - } - fn get_block_epoch(&self) -> StorageResult { self.state.get_block_epoch() } diff --git a/crates/namada/src/ledger/governance/mod.rs b/crates/namada/src/ledger/governance/mod.rs index e17d0196c2..a40d275fc4 100644 --- a/crates/namada/src/ledger/governance/mod.rs +++ b/crates/namada/src/ledger/governance/mod.rs @@ -1266,8 +1266,8 @@ mod test { use namada_state::mockdb::MockDB; use namada_state::testing::TestState; use namada_state::{ - BlockHash, BlockHeight, Epoch, FullAccessState, Key, Sha256Hasher, - State, StorageRead, TxIndex, + BlockHeight, Epoch, FullAccessState, Key, Sha256Hasher, State, + StorageRead, TxIndex, }; use namada_token::storage_key::balance_key; use namada_tx::action::{Action, GovAction, Write}; @@ -1298,10 +1298,7 @@ mod test { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(1)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(1)).unwrap(); state } diff --git a/crates/namada/src/ledger/native_vp/ibc/context.rs b/crates/namada/src/ledger/native_vp/ibc/context.rs index 1c44b638ff..8bf297e98d 100644 --- a/crates/namada/src/ledger/native_vp/ibc/context.rs +++ b/crates/namada/src/ledger/native_vp/ibc/context.rs @@ -16,7 +16,7 @@ use crate::ledger::ibc::storage::is_ibc_key; use crate::ledger::native_vp::CtxPreStorageRead; use crate::state::write_log::StorageModification; use crate::state::PrefixIter; -use crate::storage::{BlockHash, BlockHeight, Epoch, Header, Key, TxIndex}; +use crate::storage::{BlockHeight, Epoch, Header, Key, TxIndex}; use crate::token::{ self as token, burn_tokens, credit_tokens, transfer, Amount, }; @@ -139,10 +139,6 @@ where self.ctx.get_block_header(height) } - fn get_block_hash(&self) -> Result { - self.ctx.get_block_hash() - } - fn get_block_epoch(&self) -> Result { self.ctx.get_block_epoch() } @@ -329,10 +325,6 @@ where self.ctx.get_block_header(height) } - fn get_block_hash(&self) -> Result { - self.ctx.get_block_hash() - } - fn get_block_epoch(&self) -> Result { self.ctx.get_block_epoch() } diff --git a/crates/namada/src/ledger/native_vp/ibc/mod.rs b/crates/namada/src/ledger/native_vp/ibc/mod.rs index 2e581b3b1c..5160671e3f 100644 --- a/crates/namada/src/ledger/native_vp/ibc/mod.rs +++ b/crates/namada/src/ledger/native_vp/ibc/mod.rs @@ -493,7 +493,7 @@ mod tests { }; use crate::ledger::parameters::EpochDuration; use crate::ledger::{ibc, pos}; - use crate::storage::{BlockHash, BlockHeight, TxIndex}; + use crate::storage::{BlockHeight, TxIndex}; use crate::tendermint::time::Time as TmTime; use crate::time::DurationSecs; use crate::token::storage_key::balance_key; @@ -549,10 +549,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(1)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(1)).unwrap(); state } @@ -934,10 +931,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(1)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(1)).unwrap(); let height = Height::new(0, 1).unwrap(); let header = MockHeader { @@ -1010,10 +1004,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // update the client let client_id = get_client_id(); @@ -1131,10 +1122,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare a message let mut counterparty = get_conn_counterparty(); @@ -1241,10 +1229,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(1)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(1)).unwrap(); // prepare data let mut counterparty = get_conn_counterparty(); @@ -1335,10 +1320,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let height = Height::new(0, 1).unwrap(); @@ -1462,10 +1444,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // update the connection to Open let conn = get_connection(ConnState::Open); @@ -1572,10 +1551,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // update the connection to Open let conn = get_connection(ConnState::Open); @@ -1669,10 +1645,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let msg = MsgChannelOpenInit { @@ -1792,10 +1765,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let proof_height = Height::new(0, 1).unwrap(); @@ -1923,10 +1893,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let proof_height = Height::new(0, 1).unwrap(); @@ -2031,10 +1998,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let proof_height = Height::new(0, 1).unwrap(); @@ -2142,10 +2106,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let msg = IbcMsgTransfer { @@ -2285,10 +2246,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let sender = established_address_1(); @@ -2528,10 +2486,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let transfer_ack = AcknowledgementStatus::success(ack_success_b64()); @@ -2679,10 +2634,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let msg = MsgTimeout { @@ -2839,10 +2791,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let msg = MsgTimeoutOnClose { @@ -2984,10 +2933,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let msg = IbcMsgNftTransfer { @@ -3128,10 +3074,7 @@ mod tests { .in_mem_mut() .set_header(get_dummy_header()) .expect("Setting a dummy header shouldn't fail"); - state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); // prepare data let sender = established_address_1(); diff --git a/crates/namada/src/ledger/native_vp/mod.rs b/crates/namada/src/ledger/native_vp/mod.rs index b5375d5702..c09836ce3e 100644 --- a/crates/namada/src/ledger/native_vp/mod.rs +++ b/crates/namada/src/ledger/native_vp/mod.rs @@ -26,7 +26,7 @@ use crate::ibc::IbcEvent; use crate::ledger::gas::VpGasMeter; use crate::state; use crate::state::{ResultExt, StorageRead}; -use crate::storage::{BlockHash, BlockHeight, Epoch, Header, Key, TxIndex}; +use crate::storage::{BlockHeight, Epoch, Header, Key, TxIndex}; use crate::vm::prefix_iter::PrefixIterators; use crate::vm::WasmCacheAccess; @@ -215,10 +215,6 @@ where self.ctx.get_block_header(height) } - fn get_block_hash(&self) -> Result { - self.ctx.get_block_hash() - } - fn get_block_epoch(&self) -> Result { self.ctx.get_block_epoch() } @@ -296,10 +292,6 @@ where self.ctx.get_block_header(height) } - fn get_block_hash(&self) -> Result { - self.ctx.get_block_hash() - } - fn get_block_epoch(&self) -> Result { self.ctx.get_block_epoch() } @@ -369,11 +361,6 @@ where .into_storage_result() } - fn get_block_hash(&self) -> Result { - vp_host_fns::get_block_hash(self.gas_meter, self.state) - .into_storage_result() - } - fn get_block_epoch(&self) -> Result { vp_host_fns::get_block_epoch(self.gas_meter, self.state) .into_storage_result() diff --git a/crates/namada/src/ledger/vp_host_fns.rs b/crates/namada/src/ledger/vp_host_fns.rs index 393e18d01f..0d9af77cb4 100644 --- a/crates/namada/src/ledger/vp_host_fns.rs +++ b/crates/namada/src/ledger/vp_host_fns.rs @@ -7,8 +7,7 @@ use std::num::TryFromIntError; use namada_core::address::{Address, ESTABLISHED_ADDRESS_BYTES_LEN}; use namada_core::hash::{Hash, HASH_LENGTH}; use namada_core::storage::{ - BlockHash, BlockHeight, Epoch, Epochs, Header, Key, TxIndex, - TX_INDEX_LENGTH, + BlockHeight, Epoch, Epochs, Header, Key, TxIndex, TX_INDEX_LENGTH, }; use namada_gas::MEMORY_ACCESS_GAS_PER_BYTE; use namada_state::write_log::WriteLog; @@ -263,20 +262,6 @@ where Ok(header) } -/// Getting the block hash. The height is that of the block to which the -/// current transaction is being applied. -pub fn get_block_hash( - gas_meter: &RefCell, - state: &S, -) -> EnvResult -where - S: StateRead + Debug, -{ - let (hash, gas) = state.in_mem().get_block_hash(); - add_gas(gas_meter, gas)?; - Ok(hash) -} - /// Getting the block hash. The height is that of the block to which the /// current transaction is being applied. pub fn get_tx_code_hash( diff --git a/crates/namada/src/vm/host_env.rs b/crates/namada/src/vm/host_env.rs index 9327a8838e..1f8afb028e 100644 --- a/crates/namada/src/vm/host_env.rs +++ b/crates/namada/src/vm/host_env.rs @@ -1645,28 +1645,6 @@ where Ok(tx_idx.0) } -/// Getting the block hash function exposed to the wasm VM Tx environment. The -/// hash is that of the block to which the current transaction is being applied. -pub fn tx_get_block_hash( - env: &TxVmEnv, - result_ptr: u64, -) -> TxResult<()> -where - MEM: VmMemory, - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, - CA: WasmCacheAccess, -{ - let state = env.state(); - let (hash, gas) = state.in_mem().get_block_hash(); - tx_charge_gas::(env, gas)?; - let gas = env - .memory - .write_bytes(result_ptr, hash.0) - .map_err(|e| TxRuntimeError::MemoryError(Box::new(e)))?; - tx_charge_gas::(env, gas) -} - /// Getting the block epoch function exposed to the wasm VM Tx /// environment. The epoch is that of the block to which the current /// transaction is being applied. @@ -1843,29 +1821,6 @@ where }) } -/// Getting the block hash function exposed to the wasm VM VP environment. The -/// hash is that of the block to which the current transaction is being applied. -pub fn vp_get_block_hash( - env: &VpVmEnv, - result_ptr: u64, -) -> vp_host_fns::EnvResult<()> -where - MEM: VmMemory, - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, - EVAL: VpEvaluator, - CA: WasmCacheAccess, -{ - let gas_meter = env.ctx.gas_meter(); - let state = env.state(); - let hash = vp_host_fns::get_block_hash(gas_meter, &state)?; - let gas = env - .memory - .write_bytes(result_ptr, hash.0) - .map_err(|e| vp_host_fns::RuntimeError::MemoryError(Box::new(e)))?; - vp_host_fns::add_gas(gas_meter, gas) -} - /// Getting the transaction hash function exposed to the wasm VM VP environment. pub fn vp_get_tx_code_hash( env: &VpVmEnv, diff --git a/crates/namada/src/vm/wasm/host_env.rs b/crates/namada/src/vm/wasm/host_env.rs index 87600662b7..cf181e580e 100644 --- a/crates/namada/src/vm/wasm/host_env.rs +++ b/crates/namada/src/vm/wasm/host_env.rs @@ -79,7 +79,6 @@ where "namada_tx_get_tx_index" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_tx_index), "namada_tx_get_block_height" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_height), "namada_tx_get_block_header" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_header), - "namada_tx_get_block_hash" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_hash), "namada_tx_get_block_epoch" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_block_epoch), "namada_tx_get_pred_epochs" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_pred_epochs), "namada_tx_get_native_token" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_native_token), @@ -125,7 +124,6 @@ where "namada_vp_get_tx_index" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_tx_index), "namada_vp_get_block_height" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_height), "namada_vp_get_block_header" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_header), - "namada_vp_get_block_hash" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_hash), "namada_vp_get_tx_code_hash" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_tx_code_hash), "namada_vp_get_block_epoch" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_block_epoch), "namada_vp_get_pred_epochs" => Function::new_native_with_env(wasm_store, env.clone(), host_env::vp_get_pred_epochs), diff --git a/crates/state/src/in_memory.rs b/crates/state/src/in_memory.rs index 7bff934f4c..3ab184bb64 100644 --- a/crates/state/src/in_memory.rs +++ b/crates/state/src/in_memory.rs @@ -14,9 +14,8 @@ use namada_storage::conversion_state::ConversionState; use namada_storage::tx_queue::ExpiredTxsQueue; use namada_storage::types::CommitOnlyData; use namada_storage::{ - BlockHash, BlockHeight, BlockResults, Epoch, Epochs, EthEventsQueue, - Header, Key, KeySeg, StorageHasher, TxIndex, BLOCK_HASH_LENGTH, - BLOCK_HEIGHT_LENGTH, EPOCH_TYPE_LENGTH, + BlockHeight, BlockResults, Epoch, Epochs, EthEventsQueue, Header, Key, + KeySeg, StorageHasher, TxIndex, BLOCK_HEIGHT_LENGTH, EPOCH_TYPE_LENGTH, }; use crate::{Error, Result}; @@ -81,8 +80,6 @@ where pub struct LastBlock { /// Block height pub height: BlockHeight, - /// Block hash - pub hash: BlockHash, /// Block time pub time: DateTimeUtc, } @@ -92,10 +89,6 @@ pub struct LastBlock { pub struct BlockStorage { /// Merkle tree of all the other data in block storage pub tree: MerkleTree, - /// 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, /// 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::sentinel` @@ -124,7 +117,6 @@ where ) -> Self { let block = BlockStorage { tree: MerkleTree::default(), - hash: BlockHash::default(), height: BlockHeight::default(), epoch: Epoch::default(), pred_epochs: Epochs::default(), @@ -179,12 +171,7 @@ where /// Block data is in the Merkle tree as it's tracked by Tendermint in the /// block header. Hence, we don't update the tree when this is set. - pub fn begin_block( - &mut self, - hash: BlockHash, - height: BlockHeight, - ) -> Result<()> { - self.block.hash = hash; + pub fn begin_block(&mut self, height: BlockHeight) -> Result<()> { self.block.height = height; Ok(()) } @@ -209,14 +196,6 @@ where ) } - /// Get the block hash - pub fn get_block_hash(&self) -> (BlockHash, u64) { - ( - self.block.hash.clone(), - BLOCK_HASH_LENGTH as u64 * MEMORY_ACCESS_GAS_PER_BYTE, - ) - } - /// Get the current (yet to be committed) block epoch pub fn get_current_epoch(&self) -> (Epoch, u64) { ( diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 79e34b972a..3457af2212 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -280,14 +280,6 @@ macro_rules! impl_storage_read { Ok(header) } - fn get_block_hash( - &self, - ) -> std::result::Result { - let (hash, gas) = self.in_mem().get_block_hash(); - self.charge_gas(gas).into_storage_result()?; - Ok(hash) - } - fn get_block_epoch( &self, ) -> std::result::Result { @@ -607,7 +599,6 @@ pub mod testing { let tree = MerkleTree::default(); let block = BlockStorage { tree, - hash: BlockHash::default(), height: BlockHeight::default(), epoch: Epoch::default(), pred_epochs: Epochs::default(), diff --git a/crates/state/src/wl_state.rs b/crates/state/src/wl_state.rs index 4934647624..2de598b67b 100644 --- a/crates/state/src/wl_state.rs +++ b/crates/state/src/wl_state.rs @@ -478,7 +478,6 @@ where fn load_last_state(&mut self) { if let Some(BlockStateRead { merkle_tree_stores, - hash, height, time, epoch, @@ -500,12 +499,11 @@ where { { let in_mem = &mut self.0.in_mem; - in_mem.block.hash = hash.clone(); in_mem.block.height = height; in_mem.block.epoch = epoch; in_mem.block.results = results; in_mem.block.pred_epochs = pred_epochs; - in_mem.last_block = Some(LastBlock { height, hash, time }); + in_mem.last_block = Some(LastBlock { height, time }); in_mem.last_epoch = epoch; in_mem.next_epoch_min_start_height = next_epoch_min_start_height; @@ -570,7 +568,6 @@ where let state = BlockStateWrite { merkle_tree_stores: self.in_mem.block.tree.stores(), header: self.in_mem.header.as_ref(), - hash: &self.in_mem.block.hash, height: self.in_mem.block.height, time: self .in_mem @@ -601,7 +598,6 @@ where .expect("Must have a block header on commit"); self.in_mem.last_block = Some(LastBlock { height: self.in_mem.block.height, - hash: header.hash.into(), time: header.time, }); self.in_mem.last_epoch = self.in_mem.block.epoch; diff --git a/crates/storage/src/db.rs b/crates/storage/src/db.rs index dde0a6dc34..6cb13f9a39 100644 --- a/crates/storage/src/db.rs +++ b/crates/storage/src/db.rs @@ -3,8 +3,8 @@ use std::fmt::Debug; use namada_core::address::EstablishedAddressGen; use namada_core::hash::{Error as HashError, Hash}; use namada_core::storage::{ - BlockHash, BlockHeight, BlockResults, DbColFam, Epoch, Epochs, - EthEventsQueue, Header, Key, + BlockHeight, BlockResults, DbColFam, Epoch, Epochs, EthEventsQueue, Header, + Key, }; use namada_core::time::DateTimeUtc; use namada_core::{ethereum_events, ethereum_structs}; @@ -48,8 +48,6 @@ pub type Result = std::result::Result; pub struct BlockStateRead { /// Merkle tree stores pub merkle_tree_stores: MerkleTreeStoresRead, - /// Hash of the block - pub hash: BlockHash, /// Height of the block pub height: BlockHeight, /// Time of the block @@ -85,8 +83,6 @@ pub struct BlockStateWrite<'a> { pub merkle_tree_stores: MerkleTreeStoresWrite<'a>, /// Header of the block pub header: Option<&'a Header>, - /// Hash of the block - pub hash: &'a BlockHash, /// Height of the block pub height: BlockHeight, /// Time of the block diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index e39bb485a2..674e706243 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -81,10 +81,6 @@ pub trait StorageRead { /// Getting the block header. fn get_block_header(&self, height: BlockHeight) -> Result>; - /// Getting the block hash. The height is that of the block to which the - /// current transaction is being applied. - fn get_block_hash(&self) -> Result; - /// Getting the block epoch. The epoch is that of the block to which the /// current transaction is being applied. fn get_block_epoch(&self) -> Result; @@ -374,10 +370,6 @@ pub mod testing { Ok(None) } - fn get_block_hash(&self) -> Result { - Ok(BlockHash::default()) - } - fn get_block_epoch(&self) -> Result { Ok(self.epoch) } diff --git a/crates/storage/src/mockdb.rs b/crates/storage/src/mockdb.rs index ca60eae55c..c3739996b3 100644 --- a/crates/storage/src/mockdb.rs +++ b/crates/storage/src/mockdb.rs @@ -121,7 +121,6 @@ impl DB for MockDB { let prefix = format!("{}/", height.raw()); let upper_prefix = format!("{}/", height.next_height().raw()); let mut merkle_tree_stores = MerkleTreeStoresRead::default(); - let mut hash = None; let mut time = None; let mut epoch: Option = None; let mut pred_epochs = None; @@ -154,9 +153,6 @@ impl DB for MockDB { "header" => { // the block header doesn't have to be restored } - "hash" => { - hash = Some(decode(bytes).map_err(Error::CodingError)?) - } "time" => { time = Some(decode(bytes).map_err(Error::CodingError)?) } @@ -196,30 +192,25 @@ impl DB for MockDB { } } } - match (hash, time, epoch, pred_epochs, address_gen) { - ( - Some(hash), - Some(time), - Some(epoch), - Some(pred_epochs), - Some(address_gen), - ) => Ok(Some(BlockStateRead { - merkle_tree_stores, - hash, - height, - time, - epoch, - pred_epochs, - next_epoch_min_start_height, - next_epoch_min_start_time, - update_epoch_blocks_delay, - address_gen, - results, - conversion_state, - ethereum_height, - eth_events_queue, - commit_only_data, - })), + match (time, epoch, pred_epochs, address_gen) { + (Some(time), Some(epoch), Some(pred_epochs), Some(address_gen)) => { + Ok(Some(BlockStateRead { + merkle_tree_stores, + height, + time, + epoch, + pred_epochs, + next_epoch_min_start_height, + next_epoch_min_start_time, + update_epoch_blocks_delay, + address_gen, + results, + conversion_state, + ethereum_height, + eth_events_queue, + commit_only_data, + })) + } _ => Err(Error::Temporary { error: "Essential data couldn't be read from the DB" .to_string(), @@ -236,7 +227,6 @@ impl DB for MockDB { let BlockStateWrite { merkle_tree_stores, header, - hash, time, height, epoch, @@ -318,13 +308,6 @@ impl DB for MockDB { .insert(key.to_string(), h.serialize_to_vec()); } } - // Block hash - { - let key = prefix_key - .push(&"hash".to_owned()) - .map_err(Error::KeyError)?; - self.0.borrow_mut().insert(key.to_string(), encode(&hash)); - } // Block time { let key = prefix_key diff --git a/crates/tests/src/e2e/helpers.rs b/crates/tests/src/e2e/helpers.rs index 1118a38ba2..282738201f 100644 --- a/crates/tests/src/e2e/helpers.rs +++ b/crates/tests/src/e2e/helpers.rs @@ -343,11 +343,12 @@ pub fn get_height(test: &Test, ledger_address: &str) -> Result { &["block", "--node", ledger_address], Some(10) )?; - let (unread, matched) = find.exp_regex("Last committed block ID: .*")?; + let (unread, matched) = + find.exp_regex("Last committed block height: .*")?; // Expected `matched` string is e.g.: // // ``` - // Last committed block F10B5E77F972F68CA051D289474B6E75574B446BF713A7B7B71D7ECFC61A3B21, height: 4, time: 2022-10-20T10:52:28.828745Z + // Last committed block height: 4, time: 2022-10-20T10:52:28.828745Z // ``` let height_str = strip_trailing_newline(&matched) .trim() diff --git a/crates/tests/src/vm_host_env/ibc.rs b/crates/tests/src/vm_host_env/ibc.rs index c69cd43d08..a328246afa 100644 --- a/crates/tests/src/vm_host_env/ibc.rs +++ b/crates/tests/src/vm_host_env/ibc.rs @@ -8,9 +8,7 @@ use ibc_testkit::testapp::ibc::clients::mock::consensus_state::MockConsensusStat use ibc_testkit::testapp::ibc::clients::mock::header::MockHeader; use namada::core::address::{self, Address, InternalAddress}; use namada::core::hash::Hash; -use namada::core::storage::{ - self, BlockHash, BlockHeight, Epoch, Key, TxIndex, -}; +use namada::core::storage::{self, BlockHeight, Epoch, Key, TxIndex}; use namada::core::time::DurationSecs; use namada::gas::TxGasMeter; use namada::governance::parameters::GovernanceParameters; @@ -235,10 +233,7 @@ pub fn init_storage() -> (Address, Address) { .in_mem_mut() .set_header(tm_dummy_header()) .unwrap(); - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(1)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(1)).unwrap(); }); // initialize a token @@ -291,10 +286,7 @@ pub fn init_storage() -> (Address, Address) { .in_mem_mut() .set_header(tm_dummy_header()) .unwrap(); - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); }); (token, account) diff --git a/crates/tests/src/vm_host_env/mod.rs b/crates/tests/src/vm_host_env/mod.rs index 424330a39c..9167162fd3 100644 --- a/crates/tests/src/vm_host_env/mod.rs +++ b/crates/tests/src/vm_host_env/mod.rs @@ -28,7 +28,7 @@ mod tests { use namada::account::pks_handle; use namada::core::hash::Hash; use namada::core::key::*; - use namada::core::storage::{self, BlockHash, BlockHeight, Key, KeySeg}; + use namada::core::storage::{self, BlockHeight, Key, KeySeg}; use namada::core::time::DateTimeUtc; use namada::core::{address, key}; use namada::ibc::context::nft_transfer_mod::testing::DummyNftTransferModule; @@ -348,10 +348,6 @@ mod tests { tx::ctx().get_block_height().unwrap(), tx_host_env::with(|env| env.state.in_mem().get_block_height().0) ); - assert_eq!( - tx::ctx().get_block_hash().unwrap(), - tx_host_env::with(|env| env.state.in_mem().get_block_hash().0) - ); assert_eq!( tx::ctx().get_block_epoch().unwrap(), tx_host_env::with(|env| env.state.in_mem().get_current_epoch().0) @@ -615,10 +611,6 @@ mod tests { vp::CTX.get_block_height().unwrap(), vp_host_env::with(|env| env.state.in_mem().get_block_height().0) ); - assert_eq!( - vp::CTX.get_block_hash().unwrap(), - vp_host_env::with(|env| env.state.in_mem().get_block_hash().0) - ); assert_eq!( vp::CTX.get_block_epoch().unwrap(), vp_host_env::with(|env| env.state.in_mem().get_current_epoch().0) @@ -727,10 +719,7 @@ mod tests { // Commit env.commit_tx_and_block(); // update the block height for the following client update - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); env.state .in_mem_mut() .set_header(tm_dummy_header()) @@ -802,10 +791,7 @@ mod tests { // Commit env.commit_tx_and_block(); // for the next block - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); env.state .in_mem_mut() .set_header(tm_dummy_header()) @@ -878,10 +864,7 @@ mod tests { // Commit env.commit_tx_and_block(); // for the next block - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); env.state .in_mem_mut() .set_header(tm_dummy_header()) @@ -956,10 +939,7 @@ mod tests { // Commit env.commit_tx_and_block(); // for the next block - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); env.state .in_mem_mut() .set_header(tm_dummy_header()) @@ -1034,10 +1014,7 @@ mod tests { // Commit env.commit_tx_and_block(); // for the next block - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); env.state .in_mem_mut() .set_header(tm_dummy_header()) @@ -1229,10 +1206,7 @@ mod tests { // Commit env.commit_tx_and_block(); // for the next block - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); env.state .in_mem_mut() .set_header(tm_dummy_header()) @@ -1767,10 +1741,7 @@ mod tests { let mut env = tx_host_env::take(); env.commit_tx_and_block(); // for the next block - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); env.state .in_mem_mut() .set_header(tm_dummy_header()) @@ -1851,10 +1822,7 @@ mod tests { let mut env = tx_host_env::take(); env.commit_tx_and_block(); // for the next block - env.state - .in_mem_mut() - .begin_block(BlockHash::default(), BlockHeight(2)) - .unwrap(); + env.state.in_mem_mut().begin_block(BlockHeight(2)).unwrap(); env.state .in_mem_mut() .set_header(tm_dummy_header()) diff --git a/crates/tests/src/vm_host_env/tx.rs b/crates/tests/src/vm_host_env/tx.rs index 3223316bd4..0580fc0699 100644 --- a/crates/tests/src/vm_host_env/tx.rs +++ b/crates/tests/src/vm_host_env/tx.rs @@ -504,7 +504,6 @@ mod native_tx_host_env { native_host_fn!(tx_get_block_height() -> u64); native_host_fn!(tx_get_tx_index() -> u32); native_host_fn!(tx_get_block_header(height: u64) -> i64); - native_host_fn!(tx_get_block_hash(result_ptr: u64)); native_host_fn!(tx_get_block_epoch() -> u64); native_host_fn!(tx_get_pred_epochs() -> i64); native_host_fn!(tx_get_native_token(result_ptr: u64)); diff --git a/crates/tests/src/vm_host_env/vp.rs b/crates/tests/src/vm_host_env/vp.rs index 82eab877a6..7cc2eb02ee 100644 --- a/crates/tests/src/vm_host_env/vp.rs +++ b/crates/tests/src/vm_host_env/vp.rs @@ -347,7 +347,6 @@ mod native_vp_host_env { native_host_fn!(vp_get_block_height() -> u64); native_host_fn!(vp_get_tx_index() -> u32); native_host_fn!(vp_get_block_header(height: u64) -> i64); - native_host_fn!(vp_get_block_hash(result_ptr: u64)); native_host_fn!(vp_get_tx_code_hash(result_ptr: u64)); native_host_fn!(vp_get_block_epoch() -> u64); native_host_fn!(vp_get_pred_epochs() -> i64); diff --git a/crates/tx_prelude/src/lib.rs b/crates/tx_prelude/src/lib.rs index c178a6e065..a8f4b4c143 100644 --- a/crates/tx_prelude/src/lib.rs +++ b/crates/tx_prelude/src/lib.rs @@ -168,17 +168,6 @@ impl StorageRead for Ctx { } } - fn get_block_hash(&self) -> Result { - let result = Vec::with_capacity(BLOCK_HASH_LENGTH); - unsafe { - namada_tx_get_block_hash(result.as_ptr() as _); - } - let slice = unsafe { - slice::from_raw_parts(result.as_ptr(), BLOCK_HASH_LENGTH) - }; - Ok(BlockHash::try_from(slice).expect("Cannot convert the hash")) - } - fn get_block_epoch(&self) -> Result { Ok(Epoch(unsafe { namada_tx_get_block_epoch() })) } diff --git a/crates/vm_env/src/lib.rs b/crates/vm_env/src/lib.rs index 7a5e4afb42..0ddc8d6e58 100644 --- a/crates/vm_env/src/lib.rs +++ b/crates/vm_env/src/lib.rs @@ -104,9 +104,6 @@ pub mod tx { // Get the current block header pub fn namada_tx_get_block_header(height: u64) -> i64; - // Get the current block hash - pub fn namada_tx_get_block_hash(result_ptr: u64); - // Get the current block epoch pub fn namada_tx_get_block_epoch() -> u64; @@ -219,9 +216,6 @@ pub mod vp { // Get the current block header pub fn namada_vp_get_block_header(height: u64) -> i64; - // Get the current block hash - pub fn namada_vp_get_block_hash(result_ptr: u64); - // Get the current tx hash pub fn namada_vp_get_tx_code_hash(result_ptr: u64); diff --git a/crates/vp_env/src/lib.rs b/crates/vp_env/src/lib.rs index c57295c1cc..5e1b8908c6 100644 --- a/crates/vp_env/src/lib.rs +++ b/crates/vp_env/src/lib.rs @@ -8,9 +8,7 @@ use masp_primitives::transaction::Transaction; use namada_core::address::Address; use namada_core::borsh::BorshDeserialize; use namada_core::hash::Hash; -use namada_core::storage::{ - BlockHash, BlockHeight, Epoch, Epochs, Header, Key, TxIndex, -}; +use namada_core::storage::{BlockHeight, Epoch, Epochs, Header, Key, TxIndex}; use namada_core::token::Transfer; use namada_ibc::{decode_message, IbcEvent, IbcMessage}; use namada_storage::{OptionExt, StorageRead}; @@ -66,10 +64,6 @@ where height: BlockHeight, ) -> Result, namada_storage::Error>; - /// Getting the block hash. The height is that of the block to which the - /// current transaction is being applied. - fn get_block_hash(&self) -> Result; - /// Getting the block epoch. The epoch is that of the block to which the /// current transaction is being applied. fn get_block_epoch(&self) -> Result; diff --git a/crates/vp_prelude/src/lib.rs b/crates/vp_prelude/src/lib.rs index a23a5fbe72..6db9494fc7 100644 --- a/crates/vp_prelude/src/lib.rs +++ b/crates/vp_prelude/src/lib.rs @@ -24,9 +24,7 @@ use namada_core::chain::CHAIN_ID_LENGTH; pub use namada_core::collections::HashSet; use namada_core::hash::{Hash, HASH_LENGTH}; use namada_core::internal::HostEnvResult; -use namada_core::storage::{ - BlockHash, BlockHeight, Epoch, Epochs, Header, TxIndex, BLOCK_HASH_LENGTH, -}; +use namada_core::storage::{BlockHeight, Epoch, Epochs, Header, TxIndex}; pub use namada_core::validity_predicate::{VpError, VpErrorExtResult}; pub use namada_core::*; pub use namada_governance::pgf::storage as pgf_storage; @@ -308,11 +306,6 @@ impl<'view> VpEnv<'view> for Ctx { get_block_header(height) } - fn get_block_hash(&self) -> Result { - // Both `CtxPreStorageRead` and `CtxPostStorageRead` have the same impl - get_block_hash() - } - fn get_block_epoch(&self) -> Result { // Both `CtxPreStorageRead` and `CtxPostStorageRead` have the same impl get_block_epoch() @@ -466,10 +459,6 @@ impl StorageRead for CtxPreStorageRead<'_> { get_block_header(height) } - fn get_block_hash(&self) -> Result { - get_block_hash() - } - fn get_block_epoch(&self) -> Result { get_block_epoch() } @@ -543,10 +532,6 @@ impl StorageRead for CtxPostStorageRead<'_> { get_block_header(height) } - fn get_block_hash(&self) -> Result { - get_block_hash() - } - fn get_block_epoch(&self) -> Result { get_block_epoch() } @@ -614,16 +599,6 @@ fn get_block_header( } } -fn get_block_hash() -> Result { - let result = Vec::with_capacity(BLOCK_HASH_LENGTH); - unsafe { - namada_vp_get_block_hash(result.as_ptr() as _); - } - let slice = - unsafe { slice::from_raw_parts(result.as_ptr(), BLOCK_HASH_LENGTH) }; - Ok(BlockHash::try_from(slice).expect("Cannot convert the hash")) -} - fn get_block_epoch() -> Result { Ok(Epoch(unsafe { namada_vp_get_block_epoch() })) }