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

Serialized storage cache #3669

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Serialized storage cache #3669

wants to merge 15 commits into from

Conversation

shargon
Copy link
Member

@shargon shargon commented Jan 13, 2025

Description

Close #3145
Alternative to #3146

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Pending

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@shargon shargon mentioned this pull request Jan 13, 2025
15 tasks
@shargon shargon added the Blocked This issue can't be worked at the moment label Jan 13, 2025
@shargon shargon removed the Blocked This issue can't be worked at the moment label Jan 20, 2025
@shargon shargon marked this pull request as ready for review January 21, 2025 10:51
Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

Good, it should work this way. But I'd suggest to process existing chains with this change in order to ensure that cache persisting logic works as expected.

@@ -192,7 +199,7 @@ internal override ContractTask InitializeAsync(ApplicationEngine engine, Hardfor
var cachedCommittee = new CachedCommittee(engine.ProtocolSettings.StandbyCommittee.Select(p => (p, BigInteger.Zero)));
engine.SnapshotCache.Add(CreateStorageKey(Prefix_Committee), new StorageItem(cachedCommittee));
engine.SnapshotCache.Add(_votersCount, new StorageItem(System.Array.Empty<byte>()));
engine.SnapshotCache.Add(CreateStorageKey(Prefix_GasPerBlock).AddBigEndian(0u), new StorageItem(5 * GAS.Factor));
engine.SnapshotCache.Add(CreateStorageKey(Prefix_GasPerBlock).AddBigEndian(0u), new LastGasPerBlock(5 * GAS.Factor, 0));
Copy link
Member

Choose a reason for hiding this comment

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

It's clear that Neo is always deployed in genesis block, but I'd suggest to use persisting block index instead of raw 0 because this way initialization code becomes more generic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also for the key?

lock (_dictionary)
{
Add(key, value.GetStorageItem());
_serializedCacheChanges[typeof(T)] = value;
Copy link
Member

Choose a reason for hiding this comment

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

Use AddToCache instead of raw _serializedCacheChanges[typeof(T)] = value;?

/// <summary>
/// Serialized cache
/// </summary>
SerializedCache SerializedCache { get; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding this to the IReadOnlyStore makes the interface more complex, and each implementation needs to be modified.

Another way:
Add a wrapper class for IStore

class SerializedCacheStore {
     private readonly IStore _store,
     public SerializedCache SerializedCache { get; } = new();

    public(IStore store) { _store = store}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize OnPersist
3 participants