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

rm block hash that was always empty #3136

Merged
merged 3 commits into from
Apr 27, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/3136-rm-empty-block-hash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Removed block hash and all the associated functions that were using it.
([\#3136](https://github.com/anoma/namada/pull/3136))
3 changes: 1 addition & 2 deletions crates/apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions crates/apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
21 changes: 8 additions & 13 deletions crates/apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!(
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down
8 changes: 5 additions & 3 deletions crates/apps/src/lib/node/ledger/shell/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 2 additions & 13 deletions crates/apps/src/lib/node/ledger/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
})
}

Expand Down
4 changes: 1 addition & 3 deletions crates/apps/src/lib/node/ledger/shims/abcipp_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions crates/apps/src/lib/node/ledger/shims/abcipp_shim_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -172,7 +172,6 @@ pub mod shim {

#[derive(Debug, Clone)]
pub struct FinalizeBlock {
pub hash: BlockHash,
pub header: Header,
pub byzantine_validators: Vec<Misbehavior>,
pub txs: Vec<ProcessedTx>,
Expand All @@ -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(),
Expand Down
25 changes: 10 additions & 15 deletions crates/apps/src/lib/node/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down