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

Cache storage keys #1767

Merged
merged 19 commits into from
Oct 24, 2023
Merged

Cache storage keys #1767

merged 19 commits into from
Oct 24, 2023

Conversation

magicxyyz
Copy link
Contributor

Adds LRU cache for static storage keys.

@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label Jul 18, 2023
Copy link
Contributor

@anodar anodar left a comment

Choose a reason for hiding this comment

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

Please consider adding some tests that cover your changes.

arbos/addressSet/addressSet.go Outdated Show resolved Hide resolved
arbos/addressSet/addressSet.go Show resolved Hide resolved
arbos/addressSet/addressSet.go Show resolved Hide resolved
arbos/storage/storage.go Outdated Show resolved Hide resolved
arbos/storage/storage.go Outdated Show resolved Hide resolved
Comment on lines 157 to 159
_ = retStorage.ClearByUint64(beneficiaryOffset)
_ = retStorage.ClearByUint64(timeoutOffset)
_ = retStorage.ClearByUint64(timeoutWindowsLeftOffset)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we ignore these errors ?

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 added a comment with explanation, but if it would be better I can add the error checks there. The explenation:

we ignore returned error as we expect that if one ClearByUint64 fails, than all consecutive calls to ClearByUint64 will fail with the same error (not modifying state), and then ClearBytes will also fail with the same error (also not modifying state) - and this one we check and return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please let me know what you think

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation! I think it would be a good practice to handle error immediately rather than relying the fact that this will trigger another error below that we handle. It's easier that way to understand for a reader.

You can address it in follow up PR though.

util/containers/safe_lru.go Outdated Show resolved Hide resolved
util/containers/safe_lru.go Outdated Show resolved Hide resolved
arbos/addressTable/addressTable.go Show resolved Hide resolved
arbos/storage/storage.go Outdated Show resolved Hide resolved
@magicxyyz magicxyyz requested a review from anodar October 13, 2023 16:33
Copy link
Contributor

@anodar anodar left a comment

Choose a reason for hiding this comment

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

LGTM.

Left few comments, but you can address them in follow-up pr if you wish.

<-start
ss := s.OpenCachedSubStorage(subSpaceID)
if !bytes.Equal(ss.storageKey, expectedKey) {
errs <- fmt.Errorf("unexpected storage key, want: %v, have: %v", expectedKey, ss.storageKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +129 to +133
select {
case err := <-errs:
t.Fatal(err)
default:
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For reporting mismatch you should opt for Errorf [0]. One would use Fatalf more fore something that makes rest of the test meaningless, e.g. error when setting up RPC connection or something like that.

And we should display all errors from that channel.

[0] https://google.github.io/styleguide/go/decisions#keep-going

@joshuacolvin0 joshuacolvin0 merged commit 5386672 into master Oct 24, 2023
7 checks passed
@joshuacolvin0 joshuacolvin0 deleted the cache-storage-keys branch October 24, 2023 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ArbOS s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants