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

Refactored delta's vault and storage to use maps #822

Merged
merged 7 commits into from
Aug 22, 2024

Conversation

polydez
Copy link
Contributor

@polydez polydez commented Aug 7, 2024

Resolves #798

In this PR I refactored account's delta storage and vault to use maps instead of vectors. This simplifies all workflows a bit. I also updated all algorithms of building, validating, merging and applying deltas. In order to minimize affection to tests, creation by using updated/cleared items is still supported.

@polydez polydez force-pushed the polydez-delta-refactorings branch from dd9b152 to 7180518 Compare August 9, 2024 15:08
@polydez polydez requested a review from bobbinth August 9, 2024 15:10
@polydez polydez marked this pull request as ready for review August 9, 2024 15:11
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! Not a full review - but I left some comments inline.

One general comment is that I think we should not impose limits on individual deltas (e.g., how many assets can be added or removed etc.). Instead, in a different PR, we can add a way to estimate the size of the delta and impose a limit on that.

Comment on lines 191 to 193
1 => NonFungibleDeltaAction::Add,
-1 => NonFungibleDeltaAction::Remove,
_ => unreachable!("non-fungible asset amount must be 1 or -1"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's change the struct definition to use the enum instead

non_fungible_assets: BTreeMap<Digest, NonFungibleDeltaAction>,

Copy link
Contributor

@Mirko-von-Leipzig Mirko-von-Leipzig Aug 13, 2024

Choose a reason for hiding this comment

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

I actually think there is currently a bug in add and remove asset where non-fungibles can be doubly added or removed. This change would prevent that - and I believe creating a private fn update_non_fungible_asset would be best.

Unless its allowed that delta can have sequential removals so long as in the end it all balances out? i.e. is this valid for a non-fungible delta aggregation:

+1   1
+1   2
+1   3
+1   4
-1   3
-1   2
-1   1 == valid

}

for (&asset, &action) in delta.non_fungible() {
// # SAFETY: the asset must be a valid word representation of a non-fungible asset
Copy link
Contributor

Choose a reason for hiding this comment

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

The safety comment should also explain why its guaranteed safe (currently it just repeats the unsafe comment of the called fn).

Suggested change
// # SAFETY: the asset must be a valid word representation of a non-fungible asset
// SAFETY: the asset must be a valid word representation of a non-fungible asset

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this further -- is this guaranteed by the delta? If yes, should we not change the delta's definition to use NonFungibleAsset instead of a raw Digest?

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 don't see another good solution, because we use add method of fungible asset in order to update its amount. We could change only processing of non-fungible assets, but I don't think it would be a good idea.

Comment on lines 35 to 37
pub const fn new(slots: BTreeMap<u8, Word>, maps: BTreeMap<u8, StorageMapDelta>) -> Self {
Self { slots, maps }
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we combine AccountStorageDelta and AccountStorageDeltaTracker? They seem like the exact same thing.

@polydez polydez requested a review from bobbinth August 13, 2024 15:08
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left some more comments inline.

@polydez polydez requested a review from bobbinth August 20, 2024 10:05
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a few small comments inline. Once these are addressed, we can merge.

@polydez polydez merged commit 4ff85b7 into next Aug 22, 2024
13 checks passed
@polydez polydez deleted the polydez-delta-refactorings branch August 22, 2024 06:51
bobbinth pushed a commit that referenced this pull request Aug 23, 2024
* refactor: use maps in storage and vault deltas

* docs: update CHANGELOG.md

* refactor: address review comments

* tests: fix compilation errors

* refactor: address review comments

* refactor: address review comments
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