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

Put Hamt reordering fix under a feature #783

Merged
merged 3 commits into from
Oct 26, 2020
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
2 changes: 2 additions & 0 deletions ipld/hamt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ lazycell = "1.2.1"
[features]
identity = []
go-interop = []
# TODO would be best to just cut a release with v1 functionality and use that when needed
v2 = []
# This feature should just be used for testing (ignoring links that don't exist in store)
ignore-dead-links = []

Expand Down
14 changes: 10 additions & 4 deletions ipld/hamt/src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use lazycell::LazyCell;
use serde::de::{self, DeserializeOwned};
use serde::ser;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::cmp::Ordering;

/// Pointer to index values or a link to another child node.
#[derive(Debug)]
Expand Down Expand Up @@ -143,6 +142,7 @@ where
}

// Collect values from child nodes to collapse.
#[allow(unused_mut)]
let mut child_vals: Vec<KeyValuePair<K, V>> = n
.pointers
.iter_mut()
Expand All @@ -158,9 +158,15 @@ where

// Sorting by key, values are inserted based on the ordering of the key itself,
// so when collapsed, it needs to be ensured that this order is equal.
child_vals.sort_unstable_by(|a, b| {
a.key().partial_cmp(b.key()).unwrap_or(Ordering::Equal)
});
// ! This was fixed only with the v2 actors upgrade, not used in v1
#[cfg(feature = "v2")]
{
use std::cmp::Ordering;

child_vals.sort_unstable_by(|a, b| {
a.key().partial_cmp(b.key()).unwrap_or(Ordering::Equal)
});
}

// Replace link node with child values
*self = Pointer::Values(child_vals);
Expand Down