From b71fae628d97ada84c533ce746d4d7980a9f6d73 Mon Sep 17 00:00:00 2001 From: littleblack111 Date: Tue, 21 Oct 2025 09:23:53 +0800 Subject: perf(Block::verify_pow): directly use self.hash chore(Block::Hash)!: panic when trying to hash with no PoW --- src/blocks.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/blocks.rs') diff --git a/src/blocks.rs b/src/blocks.rs index 758fe71..288e754 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -42,9 +42,9 @@ impl Block { unreachable!() } - pub fn verify_pow(&mut self, pow: u64) -> bool { + pub fn verify_pow(&mut self) -> bool { let mut hasher = DefaultHasher::new(); - (&self.prev_hash, &self.trans, pow).hash(&mut hasher); + self.hash(&mut hasher); hasher .finish() .to_string() @@ -66,15 +66,9 @@ impl Hash for Block { .hash(state); self.trans .hash(state); - if self - .pow - .is_none() - { - Self::calc_pow(self).hash(state); - } else { - self.pow - .hash(state); - } + self.pow + .expect("Cannot hash whole block with no PoW") + .hash(state); } } -- cgit v1.2.3