mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
cleanup verify_weight code
This commit is contained in:
parent
5ee11046a5
commit
fb30b02f99
2 changed files with 7 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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(())
|
||||
|
|
Loading…
Reference in a new issue