diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 118649506..21ca470f9 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -114,15 +114,6 @@ pub const MAX_TX_OUTPUTS: usize = MAX_INP_OUT_KERN_LEN; /// Maximum kernels in a transaction. pub const MAX_TX_KERNELS: usize = MAX_INP_OUT_KERN_LEN; -/// Whether a block exceeds the maximum acceptable weight -pub fn exceeds_weight(input_len: usize, output_len: usize, kernel_len: usize) -> bool { - let weight = - input_len * BLOCK_INPUT_WEIGHT + - output_len * BLOCK_OUTPUT_WEIGHT + - kernel_len * BLOCK_KERNEL_WEIGHT; - weight > MAX_BLOCK_WEIGHT -} - /// Fork every 250,000 blocks for first 2 years, simple number and just a /// little less than 6 months. pub const HARD_FORK_INTERVAL: u64 = 250_000; diff --git a/core/src/core/block.rs b/core/src/core/block.rs index 8413f045c..a1dbf240f 100644 --- a/core/src/core/block.rs +++ b/core/src/core/block.rs @@ -21,7 +21,7 @@ use std::collections::HashSet; use std::fmt; use std::iter::FromIterator; -use consensus::{self, exceeds_weight, reward, VerifySortOrder, REWARD}; +use consensus::{self, reward, VerifySortOrder, REWARD}; use core::committed::{self, Committed}; use core::hash::{Hash, HashWriter, Hashed, ZERO_HASH}; use core::id::ShortIdentifiable; @@ -760,7 +760,12 @@ impl Block { } fn verify_weight(&self) -> Result<(), Error> { - if exceeds_weight(self.inputs.len(), self.outputs.len(), self.kernels.len()) { + let weight = + self.inputs.len() * consensus::BLOCK_INPUT_WEIGHT + + self.outputs.len() * consensus::BLOCK_OUTPUT_WEIGHT + + self.kernels.len() * consensus::BLOCK_KERNEL_WEIGHT; + + if weight > consensus::MAX_BLOCK_WEIGHT { return Err(Error::WeightExceeded); } Ok(())