Skip to content

Commit

Permalink
log the "merged" root when validating roots
Browse files Browse the repository at this point in the history
  • Loading branch information
antiochp committed Nov 14, 2019
1 parent e979690 commit 6fe57ad
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions chain/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use crate::core::core::hash::{Hash, Hashed, ZERO_HASH};
use crate::core::core::{Block, BlockHeader};
use crate::core::pow::Difficulty;
use crate::core::ser;
use crate::core::ser::{self, PMMRIndexHashable};
use crate::error::{Error, ErrorKind};
use crate::util::RwLock;

Expand Down Expand Up @@ -217,18 +217,19 @@ pub struct TxHashSetRoots {
impl TxHashSetRoots {
/// Accessor for the underlying output PMMR root
pub fn output_root(&self) -> Hash {
self.output_roots.pmmr_root
self.output_roots.output_root()
}

/// Validate roots against the provided block header.
pub fn validate(&self, header: &BlockHeader) -> Result<(), Error> {
debug!(
"validate roots: {} at {}, output_root: {}, output pmmr: {} (bitmap: {})",
"validate roots: {} at {}, output_root: {}, output pmmr: {} (bitmap: {}, merged: {})",
header.hash(),
header.height,
header.output_root,
self.output_roots.pmmr_root,
self.output_roots.output_root(),
self.output_roots.bitmap_root,
self.output_roots.merged_root(header),
);

if header.output_root != self.output_roots.pmmr_root {
Expand All @@ -252,6 +253,20 @@ pub struct OutputRoots {
pub bitmap_root: Hash,
}

impl OutputRoots {
/// The root of the underlying output PMMR.
pub fn output_root(&self) -> Hash {
self.pmmr_root
}

/// Hash the root of the output PMMR and the root of the bitmap accumulator
/// together with the size of the output PMMR (for consistency with existing PMMR impl).
/// H(pmmr_size | pmmr_root | bitmap_root)
pub fn merged_root(&self, header: &BlockHeader) -> Hash {
(self.pmmr_root, self.bitmap_root).hash_with_index(header.output_mmr_size)
}
}

/// A helper to hold the output pmmr position of the txhashset in order to keep them
/// readable.
#[derive(Debug)]
Expand Down

0 comments on commit 6fe57ad

Please sign in to comment.