-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: master
Are you sure you want to change the base?
Serialized storage cache #3669
Conversation
There was a problem hiding this 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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; } |
There was a problem hiding this comment.
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}
}
Description
Close #3145
Alternative to #3146
Type of change
How Has This Been Tested?
Test Configuration:
Checklist: