From 5db6f0a5319e36e88576bcc17fb63009c6a9cf2c Mon Sep 17 00:00:00 2001 From: who-biz <37732338+who-biz@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:27:09 -0500 Subject: [PATCH] Update croaring dependency to 1.0.1, croaring-sys 1.1.0 - Also removes dependency on a git repository, instead using published crate --- Cargo.lock | 14 ++++++------- chain/Cargo.toml | 4 +--- chain/src/store.rs | 4 ++-- chain/src/txhashset/bitmap_accumulator.rs | 2 +- chain/src/txhashset/txhashset.rs | 6 +++--- core/Cargo.toml | 4 +--- core/src/pow/cuckatoo.rs | 4 ++-- core/src/pow/lean.rs | 8 ++++---- store/Cargo.toml | 4 +--- store/src/leaf_set.rs | 20 +++++++++--------- store/src/lib.rs | 4 ++-- store/src/pmmr.rs | 2 +- store/src/prune_list.rs | 25 ++++++++++++----------- store/src/types.rs | 3 +-- 14 files changed, 49 insertions(+), 55 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a70f1d9..88592ee5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -503,21 +503,21 @@ dependencies = [ [[package]] name = "croaring" -version = "0.3.10" -source = "git+https://github.com/EricShimizuKarbstein/croaring-rs.git?branch=not-native-march#59e23d8d8b0cef377d6dc506a1b872b09eebba47" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7266f0a7275b00ce4c4f4753e8c31afdefe93828101ece83a06e2ddab1dd1010" dependencies = [ + "byteorder 1.5.0", "croaring-sys", - "libc", ] [[package]] name = "croaring-sys" -version = "0.3.10" -source = "git+https://github.com/EricShimizuKarbstein/croaring-rs.git?branch=not-native-march#59e23d8d8b0cef377d6dc506a1b872b09eebba47" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e47112498c394a7067949ebc07ef429b7384a413cf0efcf675846a47bcd307fb" dependencies = [ - "bindgen", "cc", - "libc", ] [[package]] diff --git a/chain/Cargo.toml b/chain/Cargo.toml index 2a99f115..7c2a3919 100755 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -15,9 +15,7 @@ bitflags = "1" byteorder = "1" failure = "0.1" failure_derive = "0.1" -# FIRME: In the long run we should fix the conflicts and use a recent version of croaring -# croaring = "0.4.5" -croaring = { git = "https://github.com/EricShimizuKarbstein/croaring-rs.git", branch = "not-native-march", version = "0.3.10" } +croaring = "1.0.1" log = "0.4" serde = "1" serde_derive = "1" diff --git a/chain/src/store.rs b/chain/src/store.rs index 2f559e53..f4483f22 100644 --- a/chain/src/store.rs +++ b/chain/src/store.rs @@ -22,7 +22,7 @@ use crate::core::pow::{Difficulty, PoWType}; use crate::core::ser::ProtocolVersion; use crate::types::{CommitPos, Tip}; use crate::util::secp::pedersen::Commitment; -use croaring::Bitmap; +use croaring::{Bitmap, Portable}; use epic_store as store; use epic_store::{option_to_not_found, to_key, Error, SerIterator}; use std::convert::TryInto; @@ -402,7 +402,7 @@ impl<'a> Batch<'a> { .db .get(&to_key(BLOCK_INPUT_BITMAP_PREFIX, &mut bh.to_vec())) { - Ok(Bitmap::deserialize(&bytes)) + Ok(Bitmap::deserialize::(&bytes)) } else { Err(Error::NotFoundErr("legacy block input bitmap".to_string()).into()) } diff --git a/chain/src/txhashset/bitmap_accumulator.rs b/chain/src/txhashset/bitmap_accumulator.rs index 9ab52a93..01cc4319 100644 --- a/chain/src/txhashset/bitmap_accumulator.rs +++ b/chain/src/txhashset/bitmap_accumulator.rs @@ -148,7 +148,7 @@ impl BitmapAccumulator { let mut pmmr = PMMR::at(&mut self.backend, last_pos); let chunk_pos = pmmr::insertion_to_pmmr_index(chunk_idx + 1); let rewind_pos = chunk_pos.saturating_sub(1); - pmmr.rewind(rewind_pos, &Bitmap::create()) + pmmr.rewind(rewind_pos, &Bitmap::new()) .map_err(|e| ErrorKind::Other(e))?; Ok(()) } diff --git a/chain/src/txhashset/txhashset.rs b/chain/src/txhashset/txhashset.rs index ade47455..0f923332 100644 --- a/chain/src/txhashset/txhashset.rs +++ b/chain/src/txhashset/txhashset.rs @@ -774,7 +774,7 @@ impl<'a> HeaderExtension<'a> { let header_pos = pmmr::insertion_to_pmmr_index(header.height + 1); self.pmmr - .rewind(header_pos, &Bitmap::create()) + .rewind(header_pos, &Bitmap::new()) .map_err(&ErrorKind::TxHashSetErr)?; // Update our head to reflect the header we rewound to. @@ -1193,7 +1193,7 @@ impl<'a> Extension<'a> { .rewind(output_pos, &bitmap) .map_err(&ErrorKind::TxHashSetErr)?; self.kernel_pmmr - .rewind(kernel_pos, &Bitmap::create()) + .rewind(kernel_pos, &Bitmap::new()) .map_err(&ErrorKind::TxHashSetErr)?; Ok(()) } @@ -1627,7 +1627,7 @@ fn input_pos_to_rewind( head_header: &BlockHeader, batch: &Batch<'_>, ) -> Result { - let mut bitmap = Bitmap::create(); + let mut bitmap = Bitmap::new(); let mut current = head_header.clone(); while current.height > block_header.height { if let Ok(block_bitmap) = batch.get_block_input_bitmap(¤t.hash()) { diff --git a/core/Cargo.toml b/core/Cargo.toml index f3db807b..f19dc782 100755 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -12,9 +12,7 @@ edition = "2018" [dependencies] blake2 = { package = "blake2-rfc", version = "0.2" } byteorder = "1" -# FIRME: In the long run we should fix the conflicts and use a recent version of croaring -# croaring = "0.4.5" -croaring = { git = "https://github.com/EricShimizuKarbstein/croaring-rs.git", branch = "not-native-march", version = "0.3.10" } +croaring = "1.0.1" enum_primitive = "0.1" failure = "0.1" failure_derive = "0.1" diff --git a/core/src/pow/cuckatoo.rs b/core/src/pow/cuckatoo.rs index 2155bbfa..9466b32c 100755 --- a/core/src/pow/cuckatoo.rs +++ b/core/src/pow/cuckatoo.rs @@ -61,7 +61,7 @@ where proof_size, links: vec![], adj_list: vec![], - visited: Bitmap::create(), + visited: Bitmap::new(), solutions: vec![], nil: T::max_value(), }) @@ -72,7 +72,7 @@ where self.links = Vec::with_capacity(2 * self.max_nodes as usize); self.adj_list = vec![T::max_value(); 2 * self.max_nodes as usize]; self.solutions = vec![Proof::zero(self.proof_size); 1]; - self.visited = Bitmap::create(); + self.visited = Bitmap::new(); Ok(()) } diff --git a/core/src/pow/lean.rs b/core/src/pow/lean.rs index 7ce55a1b..034ac8a8 100755 --- a/core/src/pow/lean.rs +++ b/core/src/pow/lean.rs @@ -36,8 +36,8 @@ impl Lean { let params = CuckooParams::new(edge_bits, 42).unwrap(); // edge bitmap, before trimming all of them are on - let mut edges = Bitmap::create_with_capacity(params.num_edges as u32); - edges.flip_inplace(0..params.num_edges); + let mut edges = Bitmap::with_container_capacity(params.num_edges as u32); + edges.flip_inplace(0..params.num_edges as u32); Lean { params, edges } } @@ -67,7 +67,7 @@ impl Lean { fn count_and_kill(&mut self) { // on each side u or v of the bipartite graph for uorv in 0..2 { - let mut nodes = Bitmap::create(); + let mut nodes = Bitmap::new(); // increment count for each node for e in self.edges.iter() { let node = self.params.sipnode(e, uorv, false).unwrap(); @@ -75,7 +75,7 @@ impl Lean { } // then kill edges with lone nodes (no neighbour at ^1) - let mut to_kill = Bitmap::create(); + let mut to_kill = Bitmap::new(); for e in self.edges.iter() { let node = self.params.sipnode(e, uorv, false).unwrap(); if !nodes.contains(node ^ 1) { diff --git a/store/Cargo.toml b/store/Cargo.toml index c9e2eab2..debced37 100755 --- a/store/Cargo.toml +++ b/store/Cargo.toml @@ -11,9 +11,7 @@ edition = "2018" [dependencies] byteorder = "1" -# FIRME: In the long run we should fix the conflicts and use a recent version of croaring -# croaring = "0.4.5" -croaring = { git = "https://github.com/EricShimizuKarbstein/croaring-rs.git", branch = "not-native-march", version = "0.3.10" } +croaring = "1.0.1" env_logger = "0.5" libc = "0.2" failure = "0.1" diff --git a/store/src/leaf_set.rs b/store/src/leaf_set.rs index 0bfefb69..32d8e6a6 100644 --- a/store/src/leaf_set.rs +++ b/store/src/leaf_set.rs @@ -17,7 +17,7 @@ use std::path::{Path, PathBuf}; -use croaring::Bitmap; +use croaring::{Bitmap, Portable}; use crate::core::core::hash::Hashed; use crate::core::core::pmmr; @@ -44,14 +44,14 @@ impl LeafSet { let bitmap = if file_path.exists() { read_bitmap(&file_path)? } else { - Bitmap::create() + Bitmap::new() }; if !bitmap.is_empty() { debug!( "bitmap {} pos ({} bytes)", bitmap.cardinality(), - bitmap.get_serialized_size_in_bytes(), + bitmap.get_serialized_size_in_bytes::(), ); } @@ -115,8 +115,8 @@ impl LeafSet { // First remove pos from leaf_set that were // added after the point we are rewinding to. - let to_remove = ((cutoff_pos + 1) as u32)..bitmap.maximum(); - bitmap.remove_range_closed(to_remove); + let to_remove = ((cutoff_pos + 1) as u32)..bitmap.maximum().unwrap_or_default(); + bitmap.remove_range(to_remove); // Then add back output pos to the leaf_set // that were removed. @@ -124,7 +124,7 @@ impl LeafSet { // Invert bitmap for the leaf pos and return the resulting bitmap. bitmap - .flip(1..(cutoff_pos + 1)) + .flip(1..(cutoff_pos + 1) as u32) .and(&self.unpruned_pre_cutoff(cutoff_pos, prune_list)) } @@ -134,8 +134,8 @@ impl LeafSet { pub fn rewind(&mut self, cutoff_pos: u64, rewind_rm_pos: &Bitmap) { // First remove pos from leaf_set that were // added after the point we are rewinding to. - let to_remove = ((cutoff_pos + 1) as u32)..self.bitmap.maximum(); - self.bitmap.remove_range_closed(to_remove); + let to_remove = ((cutoff_pos + 1) as u32)..self.bitmap.maximum().unwrap_or_default(); + self.bitmap.remove_range(to_remove); // Then add back output pos to the leaf_set // that were removed. @@ -161,7 +161,7 @@ impl LeafSet { let cp_path = format!("{}.{}", self.path.to_str().unwrap(), header.hash()); let mut file = BufWriter::new(File::create(cp_path)?); - file.write_all(&cp_bitmap.serialize())?; + file.write_all(&cp_bitmap.serialize::())?; file.flush()?; Ok(()) } @@ -174,7 +174,7 @@ impl LeafSet { // Write the updated bitmap file to disk. save_via_temp_file(&self.path, ".tmp", |w| { let mut w = BufWriter::new(w); - w.write_all(&self.bitmap.serialize())?; + w.write_all(&self.bitmap.serialize::())?; w.flush() })?; diff --git a/store/src/lib.rs b/store/src/lib.rs index 297244dd..294098f7 100644 --- a/store/src/lib.rs +++ b/store/src/lib.rs @@ -110,7 +110,7 @@ where Ok(()) } -use croaring::Bitmap; +use croaring::{Bitmap, Portable}; use std::io::{self, Read}; /// Read Bitmap from a file pub fn read_bitmap>(file_path: P) -> io::Result { @@ -118,5 +118,5 @@ pub fn read_bitmap>(file_path: P) -> io::Result { let f_md = bitmap_file.metadata()?; let mut buffer = Vec::with_capacity(f_md.len() as usize); bitmap_file.read_to_end(&mut buffer)?; - Ok(Bitmap::deserialize(&buffer)) + Ok(Bitmap::deserialize::(&buffer)) } diff --git a/store/src/pmmr.rs b/store/src/pmmr.rs index cf6464f3..b7eb76e4 100644 --- a/store/src/pmmr.rs +++ b/store/src/pmmr.rs @@ -411,7 +411,7 @@ impl PMMRBackend { } fn pos_to_rm(&self, cutoff_pos: u64, rewind_rm_pos: &Bitmap) -> (Bitmap, Bitmap) { - let mut expanded = Bitmap::create(); + let mut expanded = Bitmap::new(); let leaf_pos_to_rm = self.leaf_set diff --git a/store/src/prune_list.rs b/store/src/prune_list.rs index f14ec191..bcc94978 100644 --- a/store/src/prune_list.rs +++ b/store/src/prune_list.rs @@ -24,7 +24,7 @@ use std::io::{self, BufWriter, Write}; use std::path::{Path, PathBuf}; -use croaring::Bitmap; +use croaring::{Bitmap, Portable}; use crate::core::core::pmmr::{bintree_postorder_height, family, path}; use crate::{read_bitmap, save_via_temp_file}; @@ -59,7 +59,7 @@ impl PruneList { PruneList { path, bitmap, - pruned_cache: Bitmap::create(), + pruned_cache: Bitmap::new(), shift_cache: vec![], leaf_shift_cache: vec![], } @@ -67,7 +67,7 @@ impl PruneList { /// Instatiate a new empty prune list. pub fn empty() -> PruneList { - PruneList::new(None, Bitmap::create()) + PruneList::new(None, Bitmap::new()) } /// Open an existing prune_list or create a new one. @@ -76,7 +76,7 @@ impl PruneList { let bitmap = if file_path.exists() { read_bitmap(&file_path)? } else { - Bitmap::create() + Bitmap::new() }; let mut prune_list = PruneList::new(Some(file_path), bitmap); @@ -87,9 +87,9 @@ impl PruneList { if !prune_list.bitmap.is_empty() { debug!("bitmap {} pos ({} bytes), pruned_cache {} pos ({} bytes), shift_cache {}, leaf_shift_cache {}", prune_list.bitmap.cardinality(), - prune_list.bitmap.get_serialized_size_in_bytes(), + prune_list.bitmap.get_serialized_size_in_bytes::(), prune_list.pruned_cache.cardinality(), - prune_list.pruned_cache.get_serialized_size_in_bytes(), + prune_list.pruned_cache.get_serialized_size_in_bytes::(), prune_list.shift_cache.len(), prune_list.leaf_shift_cache.len(), ); @@ -116,7 +116,7 @@ impl PruneList { if let Some(ref path) = self.path { save_via_temp_file(path, ".tmp", |w| { let mut w = BufWriter::new(w); - w.write_all(&self.bitmap.serialize())?; + w.write_all(&self.bitmap.serialize::())?; w.flush() })?; } @@ -131,13 +131,13 @@ impl PruneList { /// Return the total shift from all entries in the prune_list. /// This is the shift we need to account for when adding new entries to our PMMR. pub fn get_total_shift(&self) -> u64 { - self.get_shift(self.bitmap.maximum() as u64) + self.get_shift(self.bitmap.maximum().unwrap_or_default() as u64) } /// Return the total leaf_shift from all entries in the prune_list. /// This is the leaf_shift we need to account for when adding new entries to our PMMR. pub fn get_total_leaf_shift(&self) -> u64 { - self.get_leaf_shift(self.bitmap.maximum() as u64) + self.get_leaf_shift(self.bitmap.maximum().unwrap_or_default() as u64) } /// Computes by how many positions a node at pos should be shifted given the @@ -276,9 +276,10 @@ impl PruneList { if self.bitmap.is_empty() { return; } - self.pruned_cache = Bitmap::create_with_capacity(self.bitmap.maximum()); - for pos in 1..=self.bitmap.maximum() { - let path = path(pos as u64, self.bitmap.maximum() as u64); + self.pruned_cache = + Bitmap::with_container_capacity(self.bitmap.maximum().unwrap_or_default()); + for pos in 1..=self.bitmap.maximum().unwrap_or_default() { + let path = path(pos as u64, self.bitmap.maximum().unwrap_or_default() as u64); let pruned = path.into_iter().any(|x| self.bitmap.contains(x as u32)); if pruned { self.pruned_cache.add(pos as u32) diff --git a/store/src/types.rs b/store/src/types.rs index c722dce8..8dd6a88e 100644 --- a/store/src/types.rs +++ b/store/src/types.rs @@ -16,8 +16,7 @@ use memmap; use tempfile::tempfile; use crate::core::ser::{ - self, BinWriter, ProtocolVersion, Readable, Reader, StreamingReader, Writeable, - Writer, + self, BinWriter, ProtocolVersion, Readable, Reader, StreamingReader, Writeable, Writer, }; use std::fmt::Debug; use std::fs::{self, File, OpenOptions};