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

feat: allow constructing an AMT from an iterator or borrowed values. #1083

Merged
merged 2 commits into from
Nov 18, 2022

Conversation

Stebalien
Copy link
Member

This works because we never have to read or deserialize when creating an AMT from scratch.

Most of the code changes are actually just re-arranging the implementation into three sections:

  1. The first that has no type restrictions (useful for avoiding type bounds where we don't need them).
  2. The second for the newly changed function that doesn't have the V: DeserializeOwned requirement.
  3. The third for everything else.

@Stebalien Stebalien mentioned this pull request Nov 15, 2022
4 tasks
@codecov-commenter
Copy link

Codecov Report

Merging #1083 (9fc2eb4) into master (e1a44a4) will increase coverage by 0.10%.
The diff coverage is 73.07%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1083      +/-   ##
==========================================
+ Coverage   51.69%   51.80%   +0.10%     
==========================================
  Files         125      125              
  Lines       10914    10928      +14     
==========================================
+ Hits         5642     5661      +19     
+ Misses       5272     5267       -5     
Impacted Files Coverage Δ
ipld/amt/src/amt.rs 87.15% <73.07%> (+2.79%) ⬆️
fvm/src/gas/mod.rs 62.85% <0.00%> (-0.72%) ⬇️
ipld/amt/src/node.rs 86.82% <0.00%> (+0.25%) ⬆️

Copy link
Contributor

@mriise mriise left a comment

Choose a reason for hiding this comment

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

This ended up a lot cleaner than I expected!

D: fvm_ipld_encoding::serde_bytes::Deserializer<'de>,
{
use serde::de::Error;
Err(D::Error::custom("can't deserialize"))
Copy link
Contributor

Choose a reason for hiding this comment

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

"FakeDeserialize can't be deserialized"

/// Generates an AMT with block store and array of cbor marshallable objects and returns Cid
///
/// This can be called with an iterator of _references_ to values to avoid copying.
pub fn new_from_iter(block_store: BS, vals: impl IntoIterator<Item = V>) -> Result<Cid, Error> {
Copy link
Member

Choose a reason for hiding this comment

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

Need the bitwidth here; that's another reason I couldn't use this method. Because event HAMTs are not mutable, I think it makes sense to optimise for lower depth, but curious about your opinion. I think a bitwidth of 5 or 8 makes the most sense here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Depends on the max serialized size of an event, really.

@Stebalien Stebalien enabled auto-merge (squash) November 15, 2022 19:17
This works because we never have to read or deserialize when creating an
AMT from scratch.
@Stebalien Stebalien merged commit 8692dc2 into master Nov 18, 2022
@Stebalien Stebalien deleted the feat/amt-from-iter-borrowed branch November 18, 2022 17:02
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.

4 participants