Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions neo.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32516.85
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -88,6 +89,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Cryptography.MPTTrie.Te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Network.RPC.Tests", "tests\Neo.Network.RPC.Tests\Neo.Network.RPC.Tests.csproj", "{19B1CF1A-17F4-4E04-AB9C-55CE74952E11}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignClient", "src\Plugins\SignClient\SignClient.csproj", "{CAD55942-48A3-4526-979D-7519FADF19FE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Neo.Plugins.SignClient.Tests", "tests\Neo.Plugins.SignClient.Tests\Neo.Plugins.SignClient.Tests.csproj", "{E2CFEAA1-45F2-4075-94ED-866862C6863F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -214,6 +219,10 @@ Global
{8C866DC8-2E55-4399-9563-2F47FD4602EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C866DC8-2E55-4399-9563-2F47FD4602EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C866DC8-2E55-4399-9563-2F47FD4602EC}.Release|Any CPU.Build.0 = Release|Any CPU
{72997EAB-9B0C-4BC8-B797-955C219C2C97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72997EAB-9B0C-4BC8-B797-955C219C2C97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72997EAB-9B0C-4BC8-B797-955C219C2C97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72997EAB-9B0C-4BC8-B797-955C219C2C97}.Release|Any CPU.Build.0 = Release|Any CPU
{77FDEE2E-9381-4BFC-B9E6-741EDBD6B90F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77FDEE2E-9381-4BFC-B9E6-741EDBD6B90F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77FDEE2E-9381-4BFC-B9E6-741EDBD6B90F}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -226,10 +235,6 @@ Global
{5F984D2B-793F-4683-B53A-80050E6E0286}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F984D2B-793F-4683-B53A-80050E6E0286}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F984D2B-793F-4683-B53A-80050E6E0286}.Release|Any CPU.Build.0 = Release|Any CPU
{72997EAB-9B0C-4BC8-B797-955C219C2C97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72997EAB-9B0C-4BC8-B797-955C219C2C97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72997EAB-9B0C-4BC8-B797-955C219C2C97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72997EAB-9B0C-4BC8-B797-955C219C2C97}.Release|Any CPU.Build.0 = Release|Any CPU
{9ADB4E11-8655-42C2-8A75-E4436F56F17A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9ADB4E11-8655-42C2-8A75-E4436F56F17A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9ADB4E11-8655-42C2-8A75-E4436F56F17A}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -246,6 +251,14 @@ Global
{19B1CF1A-17F4-4E04-AB9C-55CE74952E11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19B1CF1A-17F4-4E04-AB9C-55CE74952E11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19B1CF1A-17F4-4E04-AB9C-55CE74952E11}.Release|Any CPU.Build.0 = Release|Any CPU
{CAD55942-48A3-4526-979D-7519FADF19FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CAD55942-48A3-4526-979D-7519FADF19FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CAD55942-48A3-4526-979D-7519FADF19FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CAD55942-48A3-4526-979D-7519FADF19FE}.Release|Any CPU.Build.0 = Release|Any CPU
{E2CFEAA1-45F2-4075-94ED-866862C6863F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2CFEAA1-45F2-4075-94ED-866862C6863F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2CFEAA1-45F2-4075-94ED-866862C6863F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2CFEAA1-45F2-4075-94ED-866862C6863F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -282,14 +295,16 @@ Global
{FF76D8A4-356B-461A-8471-BC1B83E57BBC} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{5E4947F3-05D3-4806-B0F3-30DAC71B5986} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{8C866DC8-2E55-4399-9563-2F47FD4602EC} = {7F257712-D033-47FF-B439-9D4320D06599}
{72997EAB-9B0C-4BC8-B797-955C219C2C97} = {7F257712-D033-47FF-B439-9D4320D06599}
{77FDEE2E-9381-4BFC-B9E6-741EDBD6B90F} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{B6CB2559-10F9-41AC-8D58-364BFEF9688B} = {C25EB0B0-0CAC-4CC1-8F36-F9229EFB99EC}
{5F984D2B-793F-4683-B53A-80050E6E0286} = {C25EB0B0-0CAC-4CC1-8F36-F9229EFB99EC}
{72997EAB-9B0C-4BC8-B797-955C219C2C97} = {7F257712-D033-47FF-B439-9D4320D06599}
{9ADB4E11-8655-42C2-8A75-E4436F56F17A} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{E384C5EF-493E-4ED6-813C-6364F968CEE8} = {B5339DF7-5D1D-43BA-B332-74B825E1770E}
{40A23D45-1E81-41A4-B587-16AF26630103} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{19B1CF1A-17F4-4E04-AB9C-55CE74952E11} = {EDE05FA8-8E73-4924-BC63-DD117127EEE1}
{CAD55942-48A3-4526-979D-7519FADF19FE} = {C2DC830A-327A-42A7-807D-295216D30DBB}
{E2CFEAA1-45F2-4075-94ED-866862C6863F} = {7F257712-D033-47FF-B439-9D4320D06599}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BCBA19D9-F868-4C6D-8061-A2B91E06E3EC}
Expand Down
24 changes: 12 additions & 12 deletions src/Neo.Cryptography.MPTTrie/Cryptography/MPTTrie/Trie.Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public bool Delete(byte[] key)
throw new ArgumentException("could not be empty", nameof(key));
if (path.Length > Node.MaxKeyLength)
throw new ArgumentException("exceeds limit", nameof(key));
return TryDelete(ref root, path);
return TryDelete(ref _root, path);
}

private bool TryDelete(ref Node node, ReadOnlySpan<byte> path)
Expand All @@ -34,7 +34,7 @@ private bool TryDelete(ref Node node, ReadOnlySpan<byte> path)
{
if (path.IsEmpty)
{
if (!full) cache.DeleteNode(node.Hash);
if (!_full) _cache.DeleteNode(node.Hash);
node = new Node();
return true;
}
Expand All @@ -47,20 +47,20 @@ private bool TryDelete(ref Node node, ReadOnlySpan<byte> path)
var oldHash = node.Hash;
var result = TryDelete(ref node.Next, path[node.Key.Length..]);
if (!result) return false;
if (!full) cache.DeleteNode(oldHash);
if (!_full) _cache.DeleteNode(oldHash);
if (node.Next.IsEmpty)
{
node = node.Next;
return true;
}
if (node.Next.Type == NodeType.ExtensionNode)
{
if (!full) cache.DeleteNode(node.Next.Hash);
if (!_full) _cache.DeleteNode(node.Next.Hash);
node.Key = new([.. node.Key.Span, .. node.Next.Key.Span]);
node.Next = node.Next.Next;
}
node.SetDirty();
cache.PutNode(node);
_cache.PutNode(node);
return true;
}
return false;
Expand All @@ -78,7 +78,7 @@ private bool TryDelete(ref Node node, ReadOnlySpan<byte> path)
result = TryDelete(ref node.Children[path[0]], path[1..]);
}
if (!result) return false;
if (!full) cache.DeleteNode(oldHash);
if (!_full) _cache.DeleteNode(oldHash);
List<byte> childrenIndexes = new List<byte>(Node.BranchChildCount);
for (int i = 0; i < Node.BranchChildCount; i++)
{
Expand All @@ -88,7 +88,7 @@ private bool TryDelete(ref Node node, ReadOnlySpan<byte> path)
if (childrenIndexes.Count > 1)
{
node.SetDirty();
cache.PutNode(node);
_cache.PutNode(node);
return true;
}
var lastChildIndex = childrenIndexes[0];
Expand All @@ -100,20 +100,20 @@ private bool TryDelete(ref Node node, ReadOnlySpan<byte> path)
}
if (lastChild.Type == NodeType.HashNode)
{
lastChild = cache.Resolve(lastChild.Hash);
lastChild = _cache.Resolve(lastChild.Hash);
if (lastChild is null) throw new InvalidOperationException("Internal error, can't resolve hash");
}
if (lastChild.Type == NodeType.ExtensionNode)
{
if (!full) cache.DeleteNode(lastChild.Hash);
if (!_full) _cache.DeleteNode(lastChild.Hash);
lastChild.Key = new([.. childrenIndexes.ToArray(), .. lastChild.Key.Span]);
lastChild.SetDirty();
cache.PutNode(lastChild);
_cache.PutNode(lastChild);
node = lastChild;
return true;
}
node = Node.NewExtension(childrenIndexes.ToArray(), lastChild);
cache.PutNode(node);
_cache.PutNode(node);
return true;
}
case NodeType.Empty:
Expand All @@ -122,7 +122,7 @@ private bool TryDelete(ref Node node, ReadOnlySpan<byte> path)
}
case NodeType.HashNode:
{
var newNode = cache.Resolve(node.Hash);
var newNode = _cache.Resolve(node.Hash);
if (newNode is null) throw new InvalidOperationException("Internal error, can't resolve hash when mpt delete");
node = newNode;
return TryDelete(ref node, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private ReadOnlySpan<byte> Seek(ref Node node, ReadOnlySpan<byte> path, out Node
break;
case NodeType.HashNode:
{
var newNode = cache.Resolve(node.Hash);
var newNode = _cache.Resolve(node.Hash);
if (newNode is null) throw new InvalidOperationException("Internal error, can't resolve hash when mpt seek");
node = newNode;
return Seek(ref node, path, out start);
Expand Down Expand Up @@ -84,7 +84,7 @@ private ReadOnlySpan<byte> Seek(ref Node node, ReadOnlySpan<byte> path, out Node
}
if (path.Length > Node.MaxKeyLength || from.Length > Node.MaxKeyLength)
throw new ArgumentException("exceeds limit");
path = Seek(ref root, path, out Node start).ToArray();
path = Seek(ref _root, path, out Node start).ToArray();
if (from.Length > 0)
{
for (int i = 0; i < from.Length && i < path.Length; i++)
Expand Down Expand Up @@ -120,7 +120,7 @@ private ReadOnlySpan<byte> Seek(ref Node node, ReadOnlySpan<byte> path, out Node
break;
case NodeType.HashNode:
{
var newNode = cache.Resolve(node.Hash);
var newNode = _cache.Resolve(node.Hash);
if (newNode is null) throw new InvalidOperationException("Internal error, can't resolve hash when mpt find");
node = newNode;
foreach (var item in Travers(node, path, from, offset))
Expand Down
6 changes: 3 additions & 3 deletions src/Neo.Cryptography.MPTTrie/Cryptography/MPTTrie/Trie.Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public byte[] this[byte[] key]
throw new ArgumentException("could not be empty", nameof(key));
if (path.Length > Node.MaxKeyLength)
throw new ArgumentException("exceeds limit", nameof(key));
var result = TryGet(ref root, path, out var value);
var result = TryGet(ref _root, path, out var value);
return result ? value.ToArray() : throw new KeyNotFoundException();
}
}
Expand All @@ -38,7 +38,7 @@ public bool TryGetValue(byte[] key, out byte[] value)
throw new ArgumentException("could not be empty", nameof(key));
if (path.Length > Node.MaxKeyLength)
throw new ArgumentException("exceeds limit", nameof(key));
var result = TryGet(ref root, path, out var val);
var result = TryGet(ref _root, path, out var val);
if (result)
value = val.ToArray();
return result;
Expand All @@ -61,7 +61,7 @@ private bool TryGet(ref Node node, ReadOnlySpan<byte> path, out ReadOnlySpan<byt
break;
case NodeType.HashNode:
{
var newNode = cache.Resolve(node.Hash);
var newNode = _cache.Resolve(node.Hash);
if (newNode is null) throw new InvalidOperationException("Internal error, can't resolve hash when mpt get");
node = newNode;
return TryGet(ref node, path, out value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public bool TryGetProof(byte[] key, out HashSet<byte[]> proof)
if (path.Length > Node.MaxKeyLength)
throw new ArgumentException("exceeds limit", nameof(key));
proof = new HashSet<byte[]>(ByteArrayEqualityComparer.Default);
return GetProof(ref root, path, proof);
return GetProof(ref _root, path, proof);
}

private bool GetProof(ref Node node, ReadOnlySpan<byte> path, HashSet<byte[]> set)
Expand All @@ -46,7 +46,7 @@ private bool GetProof(ref Node node, ReadOnlySpan<byte> path, HashSet<byte[]> se
break;
case NodeType.HashNode:
{
var newNode = cache.Resolve(node.Hash);
var newNode = _cache.Resolve(node.Hash);
if (newNode is null) throw new InvalidOperationException("Internal error, can't resolve hash when mpt getproof");
node = newNode;
return GetProof(ref node, path, set);
Expand Down
30 changes: 15 additions & 15 deletions src/Neo.Cryptography.MPTTrie/Cryptography/MPTTrie/Trie.Put.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Put(byte[] key, byte[] value)
if (val.Length > Node.MaxValueLength)
throw new ArgumentException("exceed limit", nameof(value));
var n = Node.NewLeaf(val);
Put(ref root, path, n);
Put(ref _root, path, n);
}

private void Put(ref Node node, ReadOnlySpan<byte> path, Node val)
Expand All @@ -49,15 +49,15 @@ private void Put(ref Node node, ReadOnlySpan<byte> path, Node val)
{
if (path.IsEmpty)
{
if (!full) cache.DeleteNode(node.Hash);
if (!_full) _cache.DeleteNode(node.Hash);
node = val;
cache.PutNode(node);
_cache.PutNode(node);
return;
}
var branch = Node.NewBranch();
branch.Children[Node.BranchChildCount - 1] = node;
Put(ref branch.Children[path[0]], path[1..], val);
cache.PutNode(branch);
_cache.PutNode(branch);
node = branch;
break;
}
Expand All @@ -67,12 +67,12 @@ private void Put(ref Node node, ReadOnlySpan<byte> path, Node val)
{
var oldHash = node.Hash;
Put(ref node.Next, path[node.Key.Length..], val);
if (!full) cache.DeleteNode(oldHash);
if (!_full) _cache.DeleteNode(oldHash);
node.SetDirty();
cache.PutNode(node);
_cache.PutNode(node);
return;
}
if (!full) cache.DeleteNode(node.Hash);
if (!_full) _cache.DeleteNode(node.Hash);
var prefix = CommonPrefix(node.Key.Span, path);
var pathRemain = path[prefix.Length..];
var keyRemain = node.Key.Span[prefix.Length..];
Expand All @@ -85,7 +85,7 @@ private void Put(ref Node node, ReadOnlySpan<byte> path, Node val)
else
{
var exNode = Node.NewExtension(keyRemain[1..].ToArray(), node.Next);
cache.PutNode(exNode);
_cache.PutNode(exNode);
child.Children[keyRemain[0]] = exNode;
}
if (pathRemain.IsEmpty)
Expand All @@ -98,11 +98,11 @@ private void Put(ref Node node, ReadOnlySpan<byte> path, Node val)
Put(ref grandChild, pathRemain[1..], val);
child.Children[pathRemain[0]] = grandChild;
}
cache.PutNode(child);
_cache.PutNode(child);
if (prefix.Length > 0)
{
var exNode = Node.NewExtension(prefix.ToArray(), child);
cache.PutNode(exNode);
_cache.PutNode(exNode);
node = exNode;
}
else
Expand All @@ -122,9 +122,9 @@ private void Put(ref Node node, ReadOnlySpan<byte> path, Node val)
{
Put(ref node.Children[path[0]], path[1..], val);
}
if (!full) cache.DeleteNode(oldHash);
if (!_full) _cache.DeleteNode(oldHash);
node.SetDirty();
cache.PutNode(node);
_cache.PutNode(node);
break;
}
case NodeType.Empty:
Expand All @@ -137,15 +137,15 @@ private void Put(ref Node node, ReadOnlySpan<byte> path, Node val)
else
{
newNode = Node.NewExtension(path.ToArray(), val);
cache.PutNode(newNode);
_cache.PutNode(newNode);
}
node = newNode;
if (val.Type == NodeType.LeafNode) cache.PutNode(val);
if (val.Type == NodeType.LeafNode) _cache.PutNode(val);
break;
}
case NodeType.HashNode:
{
Node newNode = cache.Resolve(node.Hash);
Node newNode = _cache.Resolve(node.Hash);
if (newNode is null) throw new InvalidOperationException("Internal error, can't resolve hash when mpt put");
node = newNode;
Put(ref node, path, val);
Expand Down
Loading