Update amt for_each caching mechanisms and usages #847
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of changes
Changes introduced in this pull request:
This PR does not yet solve the issue of gas diff on mutation instead of removals, because we do the mutation in place (as it should be if the go implementation was caching and iterating correctly) but they set the value while the amt is being iterated over (memory unsafe). I will find a way around this, but it might involve an inefficient Clone, because we can't exactly pull the element from the amt to set it back into the amt. I will open this PR when I have a functional workaround and tested adequately.This now solves the issue marked above. I've documented that it isn't a perfect solution, since the reads and writes are in different order, which could cause a consensus fault if an out of gas error is hit in the middle of this. We cannot match exactly without memory unsafe usage or an extensive implementation of this, so I think this is a good enough solution for now. I will try to make changes upstream/open a FIP to make their caching more efficient or fix this specific issue.
Currently resyncing to check to make sure no regressions
Go equivalent tests: austinabell/go-amt-ipld@7471915
Reference issue to close (if applicable)
Closes
Other information and links