Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update croaring dependency to 1.0.1, croaring-sys 1.1.0 #122

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions chain/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Portable>(&bytes))
} else {
Err(Error::NotFoundErr("legacy block input bitmap".to_string()).into())
}
Expand Down
2 changes: 1 addition & 1 deletion chain/src/txhashset/bitmap_accumulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
6 changes: 3 additions & 3 deletions chain/src/txhashset/txhashset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -1627,7 +1627,7 @@ fn input_pos_to_rewind(
head_header: &BlockHeader,
batch: &Batch<'_>,
) -> Result<Bitmap, Error> {
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(&current.hash()) {
Expand Down
4 changes: 1 addition & 3 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions core/src/pow/cuckatoo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ where
proof_size,
links: vec![],
adj_list: vec![],
visited: Bitmap::create(),
visited: Bitmap::new(),
solutions: vec![],
nil: T::max_value(),
})
Expand All @@ -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(())
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/pow/lean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down Expand Up @@ -67,15 +67,15 @@ 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();
nodes.add(node);
}

// 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) {
Expand Down
4 changes: 1 addition & 3 deletions store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 10 additions & 10 deletions store/src/leaf_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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::<Portable>(),
);
}

Expand Down Expand Up @@ -115,16 +115,16 @@ 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.
bitmap.or_inplace(&rewind_rm_pos);

// 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))
}

Expand All @@ -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.
Expand All @@ -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::<Portable>())?;
file.flush()?;
Ok(())
}
Expand All @@ -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::<Portable>())?;
w.flush()
})?;

Expand Down
4 changes: 2 additions & 2 deletions store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ where
Ok(())
}

use croaring::Bitmap;
use croaring::{Bitmap, Portable};
use std::io::{self, Read};
/// Read Bitmap from a file
pub fn read_bitmap<P: AsRef<Path>>(file_path: P) -> io::Result<Bitmap> {
let mut bitmap_file = File::open(file_path)?;
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::<Portable>(&buffer))
}
2 changes: 1 addition & 1 deletion store/src/pmmr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl<T: PMMRable> PMMRBackend<T> {
}

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
Expand Down
25 changes: 13 additions & 12 deletions store/src/prune_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -59,15 +59,15 @@ impl PruneList {
PruneList {
path,
bitmap,
pruned_cache: Bitmap::create(),
pruned_cache: Bitmap::new(),
shift_cache: vec![],
leaf_shift_cache: vec![],
}
}

/// 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.
Expand All @@ -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);
Expand All @@ -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::<Portable>(),
prune_list.pruned_cache.cardinality(),
prune_list.pruned_cache.get_serialized_size_in_bytes(),
prune_list.pruned_cache.get_serialized_size_in_bytes::<Portable>(),
prune_list.shift_cache.len(),
prune_list.leaf_shift_cache.len(),
);
Expand All @@ -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::<Portable>())?;
w.flush()
})?;
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions store/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Loading