diff --git a/.travis.yml b/.travis.yml index 57d5a9f2..59064ca1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ env: - RUST_BACKTRACE="1" matrix: - TEST_DIR=core + - TEST_DIR=store - TEST_DIR=chain - TEST_DIR=p2p - TEST_DIR=api diff --git a/chain/src/sumtree.rs b/chain/src/sumtree.rs index 707652fe..a35fd42d 100644 --- a/chain/src/sumtree.rs +++ b/chain/src/sumtree.rs @@ -257,27 +257,7 @@ impl<'a> Extension<'a> { // Sizes of the sum trees, used by `extending` on rollback. fn sizes(&self) -> (u64, u64, u64) { - (self.output_pmmr.unpruned_size(), self.rproof_pmmr.unpruned_size(), self.kernel_pmmr.unpruned_size()) - } - - /// Debugging utility to print information about the MMRs. - pub fn dump(&self) { - let sz = self.output_pmmr.unpruned_size(); - if sz > 25 { - return; - } - println!("UXTO set, size: {}", sz); - for n in 0..sz { - print!("{:>8} ", n + 1); - } - println!(""); - for n in 1..(sz+1) { - let ohs = self.output_pmmr.get(n); - match ohs { - Some(hs) => print!("{} ", hs.hash), - None => print!("??"), - } - } - println!(""); + (self.output_pmmr.unpruned_size(), self.rproof_pmmr.unpruned_size(), + self.kernel_pmmr.unpruned_size()) } } diff --git a/core/src/core/pmmr.rs b/core/src/core/pmmr.rs index 2dd265db..db2263f7 100644 --- a/core/src/core/pmmr.rs +++ b/core/src/core/pmmr.rs @@ -318,6 +318,27 @@ impl<'a, T, B> PMMR<'a, T, B> where T: Summable + Hashed + Clone, B: 'a + Backen pub fn unpruned_size(&self) -> u64 { self.last_pos } + + /// Debugging utility to print information about the MMRs. + pub fn dump(&self) { + let sz = self.unpruned_size(); + if sz > 25 { + return; + } + println!("UXTO set, size: {}", sz); + for n in 0..sz { + print!("{:>8} ", n + 1); + } + println!(""); + for n in 1..(sz+1) { + let ohs = self.get(n); + match ohs { + Some(hs) => print!("{} ", hs.hash), + None => print!("{:>8} ", "??"), + } + } + println!(""); + } } /// Simple MMR backend implementation based on a Vector. Pruning does not diff --git a/store/src/sumtree.rs b/store/src/sumtree.rs index b7d3199b..4dab8de1 100644 --- a/store/src/sumtree.rs +++ b/store/src/sumtree.rs @@ -22,7 +22,10 @@ use std::os::unix::io::AsRawFd; use std::path::Path; use std::io::Read; -use libc; +#[cfg(any(target_os = "linux"))] +use libc::{off64_t, ftruncate64}; +#[cfg(not(any(target_os = "linux", target_os = "android")))] +use libc::{off_t as off64_t, ftruncate as ftruncate64}; use core::core::pmmr::{self, Summable, Backend, HashSum, VecBackend}; use core::ser; @@ -138,7 +141,7 @@ impl AppendOnlyFile { /// Truncates the underlying file to the provided offset fn truncate(&self, offs: u64) -> io::Result<()> { let fd = self.file.as_raw_fd(); - let res = unsafe { libc::ftruncate64(fd, offs as i64) }; + let res = unsafe { ftruncate64(fd, offs as off64_t) }; if res == -1 { Err(io::Error::last_os_error()) } else { @@ -239,7 +242,7 @@ impl RemoveLog { fn include_tuple(v: &Vec<(u64, u32)>, e: u64) -> bool { if let Err(pos) = v.binary_search(&(e, 0)) { - if pos > 0 && v[pos-1].0 == e { + if pos < v.len() && v[pos].0 == e { return true; } } diff --git a/store/tests/sumtree.rs b/store/tests/sumtree.rs index 817e96ae..e948096a 100644 --- a/store/tests/sumtree.rs +++ b/store/tests/sumtree.rs @@ -80,9 +80,9 @@ fn sumtree_prune_compact() { // pruning some choice nodes { let mut pmmr = PMMR::at(&mut backend, mmr_size); - pmmr.prune(1).unwrap(); - pmmr.prune(4).unwrap(); - pmmr.prune(5).unwrap(); + pmmr.prune(1, 1).unwrap(); + pmmr.prune(4, 1).unwrap(); + pmmr.prune(5, 1).unwrap(); } backend.sync().unwrap(); @@ -118,8 +118,8 @@ fn sumtree_reload() { { let mut pmmr = PMMR::at(&mut backend, mmr_size); root = pmmr.root(); - pmmr.prune(1).unwrap(); - pmmr.prune(4).unwrap(); + pmmr.prune(1, 1).unwrap(); + pmmr.prune(4, 1).unwrap(); } backend.sync().unwrap(); backend.check_compact(1).unwrap(); @@ -128,7 +128,7 @@ fn sumtree_reload() { // prune some more to get rm log data { let mut pmmr = PMMR::at(&mut backend, mmr_size); - pmmr.prune(5).unwrap(); + pmmr.prune(5, 1).unwrap(); } backend.sync().unwrap(); }