-
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
[Neo Core MemoryStore] MemoryStore Unit Tests. #3404
Merged
Merged
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
771acc9
test
Jim8y 1f2a8af
Merge branch 'master' into snapshot-tests
cschuchardt88 2e6979c
fix snapshot issue and add tests
Jim8y 88301ba
Merge branch 'snapshot-tests' of github.com:Jim8y/neo into snapshot-t…
Jim8y 8f37558
fix test
Jim8y 8416d06
Merge branch 'master' into snapshot-tests
Jim8y b928241
Merge branch 'master' into snapshot-tests
NGDAdmin a9a651c
Merge branch 'master' into snapshot-tests
NGDAdmin cbbad90
Merge branch 'master' into snapshot-tests
NGDAdmin 20453f6
apply old snapshot
Jim8y e131adf
memory snapshot tests
Jim8y c09637e
memory test
Jim8y 6cfc25e
add more tests
Jim8y 6d045bc
Merge branch 'master' into memory-snapshot
shargon 38a915c
make it more clear
Jim8y ffae0bf
revert storetest
Jim8y 19cf34a
Merge branch 'master' into memory-snapshot
Jim8y File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
tests/Neo.UnitTests/Persistence/UT_MemoryClonedCache.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright (C) 2015-2024 The Neo Project. | ||
// | ||
// UT_MemoryClonedCache.cs file belongs to the neo project and is free | ||
// software distributed under the MIT software license, see the | ||
// accompanying file LICENSE in the main directory of the | ||
// repository or http://www.opensource.org/licenses/mit-license.php | ||
// for more details. | ||
// | ||
// Redistribution and use in source and binary forms with or without | ||
// modifications are permitted. | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Persistence; | ||
using Neo.SmartContract; | ||
|
||
namespace Neo.UnitTests.Persistence; | ||
|
||
[TestClass] | ||
public class UT_MemoryClonedCache | ||
{ | ||
private MemoryStore _memoryStore; | ||
private MemorySnapshot _snapshot; | ||
private SnapshotCache _snapshotCache; | ||
private DataCache _dataCache; | ||
|
||
[TestInitialize] | ||
public void Setup() | ||
{ | ||
_memoryStore = new MemoryStore(); | ||
_snapshot = _memoryStore.GetSnapshot() as MemorySnapshot; | ||
_snapshotCache = new SnapshotCache(_snapshot); | ||
_dataCache = _snapshotCache.CreateSnapshot(); | ||
} | ||
|
||
[TestCleanup] | ||
public void CleanUp() | ||
{ | ||
_dataCache.Commit(); | ||
_snapshotCache.Commit(); | ||
_memoryStore.Reset(); | ||
} | ||
|
||
[TestMethod] | ||
public void SingleSnapshotCacheTest() | ||
{ | ||
var key1 = new KeyBuilder(0, 1); | ||
var value1 = new StorageItem([0x03, 0x04]); | ||
|
||
_dataCache.Add(key1, value1); | ||
|
||
Assert.IsTrue(_dataCache.Contains(key1)); | ||
Assert.IsFalse(_snapshotCache.Contains(key1)); | ||
Assert.IsFalse(_snapshot.Contains(key1.ToArray())); | ||
Assert.IsFalse(_memoryStore.Contains(key1.ToArray())); | ||
|
||
// After the data cache is committed, it should be dropped | ||
// so its value after the commit is meaningless and should not be used. | ||
_dataCache.Commit(); | ||
|
||
Assert.IsTrue(_dataCache.Contains(key1)); | ||
Assert.IsTrue(_snapshotCache.Contains(key1)); | ||
Assert.IsFalse(_snapshot.Contains(key1.ToArray())); | ||
Assert.IsFalse(_memoryStore.Contains(key1.ToArray())); | ||
|
||
// After the snapshot is committed, it should be dropped | ||
// so its value after the commit is meaningless and should not be used. | ||
_snapshotCache.Commit(); | ||
|
||
Assert.IsTrue(_dataCache.Contains(key1)); | ||
Assert.IsTrue(_snapshotCache.Contains(key1)); | ||
Assert.IsFalse(_snapshot.Contains(key1.ToArray())); | ||
Assert.IsTrue(_memoryStore.Contains(key1.ToArray())); | ||
|
||
// Test delete | ||
|
||
// Reset the snapshot to make it accessible to the new value. | ||
_snapshot = _memoryStore.GetSnapshot() as MemorySnapshot; | ||
_snapshotCache = new SnapshotCache(_snapshot); | ||
_dataCache = _snapshotCache.CreateSnapshot(); | ||
|
||
_dataCache.Delete(key1); | ||
|
||
Assert.IsFalse(_dataCache.Contains(key1)); | ||
Assert.IsTrue(_snapshotCache.Contains(key1)); | ||
Assert.IsTrue(_snapshot.Contains(key1.ToArray())); | ||
Assert.IsTrue(_memoryStore.Contains(key1.ToArray())); | ||
|
||
// After the data cache is committed, it should be dropped | ||
// so its value after the commit is meaningless and should not be used. | ||
_dataCache.Commit(); | ||
|
||
Assert.IsFalse(_dataCache.Contains(key1)); | ||
Assert.IsFalse(_snapshotCache.Contains(key1)); | ||
Assert.IsTrue(_snapshot.Contains(key1.ToArray())); | ||
Assert.IsTrue(_memoryStore.Contains(key1.ToArray())); | ||
|
||
|
||
// After the snapshot cache is committed, it should be dropped | ||
// so its value after the commit is meaningless and should not be used. | ||
_snapshotCache.Commit(); | ||
|
||
Assert.IsTrue(_dataCache.Contains(key1)); | ||
Assert.IsTrue(_snapshotCache.Contains(key1)); | ||
Assert.IsTrue(_snapshot.Contains(key1.ToArray())); | ||
Assert.IsFalse(_memoryStore.Contains(key1.ToArray())); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
I can't agree with this comment (and with related comments in this PR). One of the purposes of DataCache is to serve sequential block's handling in Blockchain (the main part of all Blockchain: OnPersist + transactions handling + PostPersist). And there DataCache usage goes against this comment: we create a single DataCache instance that should be shared between subsequent transaction runs. If transaction is HALTed, then DataCache is being committed and then it's being reused for the next transaction processing, so next transactions can see the changes made by the previous transaction even after DataCacke commit.
So I think that reusage after commit is a substantial part of the DataCache design for sequential execution and can't be prohibited like it's said in the comment.
neo/src/Neo/Ledger/Blockchain.cs
Lines 442 to 461 in c54c204
Parallel execution is different although, and I'm not really sure that it's designed for parallel execution, I'm not that familiar with all DataCache usages.
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.
@AnnaShaleva As i have said everywhere multiple times, the real problem is a committed snapshotcache and clonedcache no longer have the latest store states, that is the reason. You can not agree with what? like any type of execution should be run based on an out dated snapshot? Why would you want to run execution on old store states and get wrong execution result?