Genesis is height 0 (not height 1) (#1896)
This commit is contained in:
committed by
Ignotus Peverell
parent
b01fcd2f56
commit
d51522a9cd
@@ -713,7 +713,7 @@ impl<'a> HeaderExtension<'a> {
|
||||
pub fn validate_root(&self, header: &BlockHeader) -> Result<(), Error> {
|
||||
// If we are validating the genesis block then we have no prev_root.
|
||||
// So we are done here.
|
||||
if header.height == 1 {
|
||||
if header.height == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -1102,7 +1102,7 @@ impl<'a> Extension<'a> {
|
||||
/// Validate the provided header by comparing its prev_root to the
|
||||
/// root of the current header MMR.
|
||||
pub fn validate_header_root(&self, header: &BlockHeader) -> Result<(), Error> {
|
||||
if header.height == 1 {
|
||||
if header.height == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ use std::u64;
|
||||
|
||||
use croaring::Bitmap;
|
||||
|
||||
use core::hash::Hash;
|
||||
use core::hash::{Hash, ZERO_HASH};
|
||||
use core::merkle_proof::MerkleProof;
|
||||
use core::pmmr::{Backend, ReadonlyPMMR};
|
||||
use core::BlockHeader;
|
||||
@@ -124,6 +124,9 @@ where
|
||||
/// Computes the root of the MMR. Find all the peaks in the current
|
||||
/// tree and "bags" them to get a single peak.
|
||||
pub fn root(&self) -> Hash {
|
||||
if self.is_empty() {
|
||||
return ZERO_HASH;
|
||||
}
|
||||
let mut res = None;
|
||||
for peak in self.peaks().iter().rev() {
|
||||
res = match res {
|
||||
@@ -350,6 +353,11 @@ where
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check if this PMMR is (unpruned_size == 0).
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.unpruned_size() == 0
|
||||
}
|
||||
|
||||
/// Total size of the tree, including intermediary nodes and ignoring any
|
||||
/// pruning.
|
||||
pub fn unpruned_size(&self) -> u64 {
|
||||
|
||||
Reference in New Issue
Block a user