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

Add support for HamtV0 from forest(commit hash: b622af5a6) #1808

Merged
merged 18 commits into from
Aug 2, 2023
Merged

Add support for HamtV0 from forest(commit hash: b622af5a6) #1808

merged 18 commits into from
Aug 2, 2023

Conversation

creativcoder
Copy link
Contributor

@creativcoder creativcoder changed the title Add support for HamtV0 from b622af5a6 Add support for HamtV0 from forest(commit hash: b622af5a6) Jul 11, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2023

Codecov Report

Merging #1808 (a34fcf6) into master (22ba961) will decrease coverage by 4.92%.
Report is 7 commits behind head on master.
The diff coverage is 76.92%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1808      +/-   ##
==========================================
- Coverage   75.31%   70.40%   -4.92%     
==========================================
  Files         149      101      -48     
  Lines       14558     8524    -6034     
==========================================
- Hits        10965     6001    -4964     
+ Misses       3593     2523    -1070     
Files Changed Coverage Δ
ipld/hamt/src/hamt.rs 68.55% <ø> (-15.73%) ⬇️
ipld/hamt/src/lib.rs 100.00% <ø> (ø)
ipld/hamt/src/pointer.rs 83.06% <71.87%> (-3.54%) ⬇️
ipld/hamt/src/node.rs 97.37% <100.00%> (ø)

... and 70 files with indirect coverage changes

@creativcoder creativcoder marked this pull request as ready for review July 14, 2023 12:50
@@ -33,21 +34,26 @@ use crate::{Config, Error, Hash, HashAlgorithm, Sha256};
/// assert_eq!(map.get::<_>(&1).unwrap(), None);
/// let cid = map.flush().unwrap();
/// ```
pub type Hamt<BS, V, K = BytesKey> = HamtImpl<BS, V, version::V3, K, Sha256>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to continue to take H as a type parameter to avoid breaking the API.


/// Default bit width for indexing a hash at each depth level
const DEFAULT_BIT_WIDTH: u32 = 8;
/// Default bit width for indexing a hash at each depth level for Hamt v0
pub const DEFAULT_BIT_WIDTH_V0: u32 = 5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this private unless we need it to be public for some reason.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this field due to #1828 and filecoin-project/builtin-actors#1346. Basically, the user should just pass the bit-width they need and I'm going to deprecate the "default" methods as they're useless.

As far as I can tell, the v0 bit-width was also 8 by default. We just set it to 5 everywhere.

Comment on lines 148 to 155
let ipld = Ipld::deserialize(deserializer)?;
let (_key, value) = match ipld {
Ipld::Map(map) => map
.into_iter()
.next()
.ok_or("Expected at least one element".to_string()),
other => Err(format!("Expected `Ipld::Map`, got {:#?}", other)),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should decode this as a tagged enum instead of using Ipld and looking at the types.

#[derive(Deserialize, Serialize)]
enum PointerDe<K, V> {
    #[serde(name = "l")]
    Link(Cid),
    #[serde(name = "v")]
    Values(KeyValuePair<K, V>),
}

Copy link
Contributor Author

@creativcoder creativcoder Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had to change l and v to 0 and 1 respectively to read genesis header in forest and I'm able to boot forest daemon.
Changes made:

    #[derive(Serialize)]
    pub(super) enum PointerSer<'a, K, V> {
        #[serde(rename = "0")]
        Vals(&'a [KeyValuePair<K, V>]),
        #[serde(rename = "1")]
        Link(&'a Cid),
    }

    #[derive(Deserialize, Serialize)]
    pub enum PointerDe<K, V> {
        #[serde(rename = "0")]
        Link(Cid),
        #[serde(rename = "1")]
        Vals(Vec<KeyValuePair<K, V>>),
    }

But Hamtv0 tests in this repo fails with:

thread 'test_default::test_hamtv0' panicked at 'called `Result::unwrap()` on an `Err` value: Dynamic(Serialization error for Cbor protocol: TypeMismatch { name: "CBOR tag", byte: 1 })', ipld/hamt/tests/hamt_tests.rs:1022:69

with the above changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. I thought it was k/v. I must be thinking of IPFS HAMTs.

But Hamtv0 tests in this repo fails with:

Hm. Something funky is going on there. Can you push the code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or push it to a new branch)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed the changes with failing hamtv0 tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a sneaky bug. The Vals/Pointer variants were swapped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i see, interesting! thanks

ipld/hamt/src/hamt.rs Show resolved Hide resolved
@@ -15,18 +15,37 @@ use super::node::Node;
use super::{Error, Hash, HashAlgorithm, KeyValuePair};
use crate::Config;

pub mod version {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this crate-private if possible, or #[doc(hidden)] otherwise.

Comment on lines 68 to 71
pub(super) enum PointerSer<'a, K, V> {
Vals(&'a [KeyValuePair<K, V>]),
Link(&'a Cid),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused at how this works. For v0, we want to serialize to a map of "0"/"1" to a cid/list of links. As far as I know, this here will serialize use "Vals" and "Link" as the keys?

creativcoder and others added 5 commits August 1, 2023 04:55
Well, that was an sneaky bug.
The user needs to pass the bit width based on the context. This constant
isn't actually used anywhere except tests anyways (which, IMO, is
confusing as I'd expect it to be used by-default for v0 hamts if
specified like that).
@Stebalien Stebalien enabled auto-merge (squash) August 2, 2023 23:31
@Stebalien Stebalien merged commit 0f247eb into filecoin-project:master Aug 2, 2023
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants