-
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
[Change
] DataCache to Match LevelDbStore & RocksDbStore
#3709
[Change
] DataCache to Match LevelDbStore & RocksDbStore
#3709
Conversation
Change
] DataCache to Match LevelDbStore & RocksDbStore
return y.AsSpan().SequenceCompareTo(x.AsSpan()); | ||
return x.AsSpan().SequenceCompareTo(y.AsSpan()); | ||
|
||
return x.AsSpan().SequenceCompareTo(y.AsSpan()) * _direction; |
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.
What about submitting the changes in this first in another PR?
Perhaps this can be discussed faster and merged quicker.
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.
Maybe something like
public int Compare(byte[]? x, byte[]? y)
{
if (ReferenceEquals(x, y)) return 0;
if (x is null) return y is null ? 0 : -_direction;
if (y is null) return _direction;
return _direction * x.AsSpan().SequenceCompareTo(y.AsSpan());
}
Is the length multiplication really needed?
byte[] a = new byte[10];
byte[] b = new byte[20];
ByteArrayComparer comparer = ByteArrayComparer.Default;
Console.WriteLine(comparer.Compare(null, a)); // Expected: -1, Original: -10
Console.WriteLine(comparer.Compare(null, b)); // Expected: -1, Original: -20
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.
Im sorry, I mean MemorySnapshot
was returning all results for null
.
@@ -547,7 +546,7 @@ public void TestBlockchain_ListContracts() | |||
Assert.AreEqual(state.Hash, NativeContract.ContractManagement.GetContract(engine.SnapshotCache, state.Hash).Hash); | |||
|
|||
var list2 = NativeContract.ContractManagement.ListContracts(engine.SnapshotCache); | |||
Assert.AreEqual(list.Count(), list2.Count()); | |||
Assert.AreEqual(list.Count(), list2.Count() - 1); |
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.
Why this changed?
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.
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.
The test didn't change, this line was before
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.
This was an issue with DataCache
being bugged. Let me find out what happening, so I can go into more detail about it.
@@ -290,7 +290,7 @@ public void TestFindRange() | |||
Assert.IsTrue(items[0].Value.EqualsTo(value5)); | |||
Assert.AreEqual(key4, items[1].Key); | |||
Assert.IsTrue(items[1].Value.EqualsTo(value4)); | |||
Assert.AreEqual(2, items.Length); | |||
Assert.AreEqual(3, items.Length); |
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.
Why this changed, and not in the other PR?
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.
Because it from starting key to ending end. It's not in between. We don't skip the 1st one.
// OLD
FindRange([0x00, 0x00, 0x04], [0x00, 0x00, 0x03], Backwards);
// Results: Empty
// NEW
FindRange([0x00, 0x00, 0x04], [0x00, 0x00, 0x03], Backwards);
// Results:
// [0x00, 0x00, 0x04]
// [0x00, 0x00, 0x03]
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.
Could you move this fix into the other pr, and here only the DataCache refactor?
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.
Isn't this part of the DataCache
?
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 rewrote all the code. So it would be hard for me to put back the bug
.
…8/neo into fix/datacache-store
…8/neo into fix/datacache-store
Replace the name, and change the logic, makes harder the review, I reverted the name replacement, you can do it in the next pr (i'm not against to) but in the same PR, makes this review harder and slower. |
@@ -502,7 +502,7 @@ public ExecutionContext LoadScript(Script script, int rvcount = -1, int initialP | |||
// Create and configure context | |||
ExecutionContext context = CreateContext(script, rvcount, initialPosition); | |||
ExecutionContextState state = context.GetState<ExecutionContextState>(); | |||
state.SnapshotCache = SnapshotCache?.CloneCache(); | |||
state.SnapshotCache = SnapshotCache; |
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.
You can't remove this clone, it affects the try/catch safety
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.
All CloneCache
doesn't is the same as SnapshotCache
. No data buffers are moved, neither any caches
. CloneCache
is just a wrapper class. I see the point of it. And if you are right why all tests work still?
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.
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.
@neo-project/core I tried to remove the CloneCache
before, but it's not an easy task.
StorageItem
is a class, and if is not cloned it will be shared between both DataCache
, if in the second one is replace calling FromReplica
(for example), the content of this instance will be changed in both DataCache, and if the second will be discarded, it will change the main one..
Maybe we don't have this unit tests, but it's how it work.
DataCache a;
CloneCache b=new(a)
var before= a.Get(1);
var change=b.Get(1)
change.FromReplica(xxxx)
// before was changed and also a.Get(1)
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.
Well I fixed the issue with StorageItem
in another PR. Because your not at using a IComparer
interface, you are just using the object
as the key. It ends up throwing in dupes keys.
Description
Mostly bug fixes and same data results as the
Leveldb
andRocksdb
.Type of change
How Has This Been Tested?
Checklist: