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

Add MPT #1442

Merged
merged 228 commits into from
Jun 1, 2020
Merged

Add MPT #1442

Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
228 commits
Select commit Hold shift + click to select a range
493f10b
first push
Jan 10, 2020
54613d3
add TryDelete
Jan 16, 2020
bec65ef
split nodes
Jan 16, 2020
a991041
add GetProof and ut
Jan 16, 2020
468b882
add ut
Jan 16, 2020
9dca50c
format
Jan 16, 2020
d407532
fix some
Jan 16, 2020
61467d7
fix interface
Jan 17, 2020
8605d63
format
Jan 17, 2020
f45396c
rm nullnode typee
Jan 17, 2020
3f083d2
Merge pull request #1 from neo-project/master
Jan 20, 2020
05aaade
Merge pull request #2 from neo-project/master
Feb 4, 2020
8f301d9
rm fullnode size
Feb 10, 2020
3d01c5b
rm Database commit
Feb 10, 2020
eb3c777
first push
Jan 10, 2020
8c05f76
add TryDelete
Jan 16, 2020
a1db507
split nodes
Jan 16, 2020
ac3c4a8
add GetProof and ut
Jan 16, 2020
6eeaa98
add ut
Jan 16, 2020
2037f78
format
Jan 16, 2020
260b1c1
fix some
Jan 16, 2020
2381013
fix interface
Jan 17, 2020
d47429f
format
Jan 17, 2020
d6c91c7
rm nullnode typee
Jan 17, 2020
08acc30
rm fullnode size
Feb 10, 2020
5be8a6d
rm Database commit
Feb 10, 2020
b1721a8
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Feb 10, 2020
1c8831f
Merge pull request #3 from neo-project/master
Feb 10, 2020
75cac28
format
Feb 11, 2020
c606275
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Feb 11, 2020
687e7d6
CalHash
Feb 11, 2020
3989c16
rm Clone()
Feb 11, 2020
79ee48b
use const variable
Feb 11, 2020
63bd578
new line in ut
Feb 11, 2020
6fa37ef
fix some
Feb 11, 2020
40f3b7d
capitalize method name
Feb 12, 2020
bd2db12
fix some
Feb 12, 2020
0b46273
fix ut
Feb 12, 2020
51a823d
Merge pull request #4 from neo-project/master
Feb 12, 2020
39da07b
Merge pull request #5 from neo-project/master
Feb 12, 2020
e88b524
Merge branch 'master' into feature/MPT
Feb 12, 2020
e261c02
format
Feb 12, 2020
c2043c2
fix size and exception
Feb 13, 2020
8c8ee91
format
Feb 13, 2020
8342cb1
format
Feb 14, 2020
7f5314a
rm Serialize and Deserialize use Encode and Decode
Feb 14, 2020
7d01510
format
Feb 14, 2020
0321ab6
format
Feb 14, 2020
c87dfea
format
Feb 14, 2020
f5c8df4
rm prefix
Feb 17, 2020
6cd152e
assign enum value
Feb 17, 2020
978c52a
fix some
Feb 20, 2020
e8afc1a
format
Feb 20, 2020
af83056
empty byte array
Feb 20, 2020
069eede
check if change when commit
Feb 20, 2020
bb89eac
unit test
Feb 20, 2020
d26c149
format
Feb 21, 2020
79f98ce
change nonEmptyChildren to childrenIndexes
Feb 21, 2020
1d0041c
change mpttrie initialize and ut
Feb 21, 2020
d415f27
rm blanks
Feb 21, 2020
a4f3e22
change public to private
Feb 21, 2020
56bf677
calhash to genhash
Feb 21, 2020
78293e0
change variable name
Feb 21, 2020
2a1745b
use Crypto.Hash256
Feb 24, 2020
bb404d4
add ready only trie
Feb 24, 2020
59d0c60
change name MPTDatabase to MPTDb
Feb 24, 2020
5c1013c
1. remove value node delete, same value has same hash and share data …
Feb 25, 2020
b31e255
use list instead dictionary
Feb 27, 2020
64719df
Merge branch 'master' into feature/MPT
vncoelho Mar 7, 2020
9ec487a
change dict to list
Mar 9, 2020
ac0a30f
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Mar 9, 2020
4a81a91
use hashset
Mar 9, 2020
1e36f3b
add read only trie, and fix branch node only remain value child
Mar 18, 2020
ddd44be
Merge branch 'master' into feature/MPT
Mar 19, 2020
3ef79fd
change name
Mar 19, 2020
15d658f
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Mar 19, 2020
2c01995
format
Mar 21, 2020
e5f04cb
format
Mar 21, 2020
0f6a0e3
Merge branch 'master' into feature/MPT
Mar 23, 2020
4afd976
return instead of throw
Mar 23, 2020
e7e1ce3
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Mar 23, 2020
c9851b3
Merge branch 'master' into feature/MPT
Mar 23, 2020
caa9426
Merge branch 'master' of github.com:neo-project/neo
Mar 24, 2020
b9ee482
Merge branch 'master' into feature/MPT
shargon Mar 24, 2020
6d11e2e
mv trie/helper to neo/helper
Mar 25, 2020
dce98a3
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Mar 25, 2020
37e5e02
Optimize
shargon Mar 25, 2020
d6a43dd
Optimize
shargon Mar 25, 2020
57a9cf2
Clean file
shargon Mar 25, 2020
5905b12
use Array.Resize
Mar 26, 2020
2918ce5
one class one file
Mar 26, 2020
eac80cb
change valuenode to leafnode
Mar 26, 2020
78b7f2a
file name
Mar 26, 2020
a0bcb39
format
Mar 26, 2020
e292b3d
use uint256
Mar 26, 2020
23835e4
change name
Mar 26, 2020
57b9dc6
modify ByteArray.Add
Mar 26, 2020
64096b9
Merge branch 'master' into feature/MPT
Mar 26, 2020
65ae1fc
Merge branch 'master' into feature/MPT
Mar 27, 2020
53811e3
Merge branch 'master' into feature/MPT
shargon Mar 31, 2020
6b72dd1
optimize take prefix
Mar 31, 2020
f9a300a
optimize take prefix
Mar 31, 2020
0261593
add equal ut
Mar 31, 2020
4b5459b
Simplify CommonPrefix
shargon Apr 1, 2020
dadb274
add max key
Apr 1, 2020
4022a41
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Apr 1, 2020
6204d0b
use itore
Apr 1, 2020
7e4d12e
rm
Apr 1, 2020
cca3fbd
fix max length
Apr 1, 2020
b0ffd64
use ISnapshot and fix ut
Apr 1, 2020
4002dec
format
Apr 1, 2020
2c11831
Optimize Skip
shargon Apr 1, 2020
ae64dcc
Clean file
shargon Apr 1, 2020
eaf7dcf
Merge branch 'master' into feature/MPT
shargon Apr 1, 2020
8ba4e68
change property name
Apr 2, 2020
f6b8d33
add null check
Apr 2, 2020
9c8d09c
rm linq
Apr 2, 2020
da484e9
Merge branch 'master' into feature/MPT
Apr 9, 2020
7a73e44
concat
Apr 9, 2020
5a8b5f1
use SequenceEqual
Apr 9, 2020
96ffeb0
fix double dispose stream
Apr 9, 2020
e17a481
use start with
Apr 10, 2020
b21c15d
Merge branch 'master' into feature/MPT
Apr 10, 2020
4fa4015
fix some
Apr 10, 2020
e9943e4
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Apr 10, 2020
0e5747b
use startswith
Apr 10, 2020
051a678
Merge branch 'master' into feature/MPT
Apr 10, 2020
cebeabe
Remove Helper.Skip()
erikzhang Apr 10, 2020
f37f43c
Remove Helper.Add()
erikzhang Apr 10, 2020
5fa00cf
Move methods
erikzhang Apr 10, 2020
1c7b492
fix
Apr 10, 2020
c09ef1f
Remove try for dispose
shargon Apr 10, 2020
3bc6ab7
Fix ReadBytes error
shargon Apr 10, 2020
1fc4053
Clean code
shargon Apr 10, 2020
278c3b2
Merge branch 'master' into feature/MPT
Apr 11, 2020
20d27a0
add max value lenght
Apr 11, 2020
7e59d8a
Merge branch 'master' into feature/MPT
Apr 11, 2020
a63f9c3
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Apr 11, 2020
920adc6
add read max lenght
Apr 14, 2020
73f4d65
branchnode value index
Apr 15, 2020
c6075c0
Merge branch 'master' into feature/MPT
shargon Apr 15, 2020
aa06d4c
Merge branch 'master' of github.com:neo-project/neo
Apr 23, 2020
394a87c
code
Apr 24, 2020
1a95fe4
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Apr 24, 2020
5ddf390
fix add longer key
Apr 24, 2020
fb6ddfd
fix ut
Apr 24, 2020
0deb9f5
Merge branch 'master' into feature/MPT
Apr 24, 2020
1140d45
fix size
Apr 24, 2020
9a5ad98
avoid empth key extension node
Apr 26, 2020
174e441
use ISerializable as key value
Apr 28, 2020
5b5f0ad
Merge branch 'master' into feature/MPT
Apr 28, 2020
53613c2
add find and split class
Apr 29, 2020
f8b5963
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Apr 29, 2020
6c1ab3b
format
Apr 29, 2020
ae4c590
define mpt element accessor
Apr 29, 2020
6c80b67
Merge branch 'master' into feature/MPT
Apr 29, 2020
66b1df1
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
Apr 30, 2020
14bc074
assign default value of TestKey and TestValue in constructor
Apr 30, 2020
3650852
set value null when not found
Apr 30, 2020
47dd1c5
use .Length < 1
Apr 30, 2020
4f5eb93
Merge branch 'master' into feature/MPT
May 6, 2020
826fc16
Merge branch 'master' into feature/MPT
May 8, 2020
d4be6ac
Merge branch 'master' of github.com:neo-project/neo
May 11, 2020
ca753a3
Move namespace
erikzhang May 12, 2020
dbfff2c
Move Helper.CommonPrefix()
erikzhang May 12, 2020
dc54eef
Remove Helper.cs
erikzhang May 12, 2020
48d0b61
optimize
erikzhang May 12, 2020
69b2fcc
Update src/neo/Cryptography/MPT/BranchNode.cs
shargon May 12, 2020
d4c21ea
Update src/neo/Cryptography/MPT/MPTReadOnlyDb.cs
shargon May 12, 2020
99e7040
Update src/neo/Cryptography/MPT/MPTReadOnlyDb.cs
shargon May 12, 2020
359ba37
Update src/neo/Cryptography/MPT/MPTTrie.cs
shargon May 12, 2020
bd1284e
Update src/neo/Cryptography/MPT/MPTReadOnlyTrie.cs
shargon May 12, 2020
8f3b069
Update src/neo/Cryptography/MPT/MPTReadOnlyTrie.cs
shargon May 12, 2020
d01b3ed
Update src/neo/Cryptography/MPT/MPTDb.cs
shargon May 12, 2020
a999e1f
Merge branch 'master' into feature/MPT
shargon May 12, 2020
6e1a4b7
Fix UT
shargon May 12, 2020
ad13492
Some VS recommendations
shargon May 12, 2020
fca0884
dotnet format
shargon May 12, 2020
70d0804
Order the result value of Find method
May 15, 2020
5b2462d
Optimize
erikzhang May 15, 2020
6a0411d
Merge branch 'master' into feature/MPT
erikzhang May 15, 2020
01f3b76
Optimize
erikzhang May 17, 2020
5b37105
Use ReflectionCache
erikzhang May 17, 2020
f744d7f
EmptyNode
erikzhang May 17, 2020
b3be508
Remove MPTNode.Dirty
erikzhang May 17, 2020
6bea24d
Remove GenHash() and GetHash()
erikzhang May 17, 2020
11599b3
Optimize EncodeSpecific()
erikzhang May 17, 2020
7914efb
Optimize DecodeSpecific()
erikzhang May 17, 2020
b6e41bc
Merge branch 'master' into feature/MPT
erikzhang May 17, 2020
9e185be
Optimize, simplify and format
erikzhang May 17, 2020
3e5646b
Format
erikzhang May 17, 2020
39274d3
Update MPTNode.cs
erikzhang May 17, 2020
b6af8cd
Merge branch 'master' into feature/MPT
erikzhang May 17, 2020
9ea1ff7
use MemoryStore replace ProofStore
May 18, 2020
03ca94d
rm ToJson()
May 18, 2020
d6b976d
Merge branch 'master' into feature/MPT
erikzhang May 18, 2020
f662cb0
remove ReadOnlyTrie
May 18, 2020
43a0eba
Merge branch 'master' of github.com:neo-project/neo
May 19, 2020
6895937
Use constant prefix
erikzhang May 20, 2020
a223dbd
Rename
erikzhang May 20, 2020
0d91319
Remove MPTDb
erikzhang May 20, 2020
2d21d44
Remove MPTTrie.GetRoot()
erikzhang May 20, 2020
86dd270
Update MPTTrie.cs
erikzhang May 20, 2020
2a8bb6f
Simplify declaring the partial class
erikzhang May 20, 2020
6801a80
Move PutToStore()
erikzhang May 20, 2020
ded26b9
Remove MPTTrie.Get()
erikzhang May 20, 2020
497dcd8
Modify MPTTrie.GetProof()
erikzhang May 20, 2020
c27d094
Format
erikzhang May 20, 2020
ac2c295
Merge branch 'master' into feature/MPT
erikzhang May 20, 2020
df8048d
rm repeated put
May 20, 2020
bd2011f
using
erikzhang May 21, 2020
6839484
Merge branch 'master' into feature/MPT
erikzhang May 21, 2020
6275b0a
Optimize
erikzhang May 26, 2020
2ab6d2e
Merge branch 'master' into feature/MPT
erikzhang May 26, 2020
5f71a37
Merge branch 'master' into feature/MPT
May 26, 2020
e9d047d
Merge branch 'master' of github.com:neo-project/neo
May 26, 2020
1742c55
Merge branch 'master' into feature/MPT
May 26, 2020
822291d
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
May 28, 2020
f915b56
fix mpt find
May 28, 2020
e5e691b
recover key from nibles
May 28, 2020
1623aaf
Merge branch 'master' into feature/MPT
erikzhang May 28, 2020
2bcda02
Readability and format
erikzhang May 28, 2020
d0e33c4
fix find
May 28, 2020
e6087c2
Merge branch 'feature/MPT' of github.com:KickSeason/neo into feature/MPT
May 28, 2020
f35103b
enhance ut
May 28, 2020
528283b
enhance ut(2)
May 28, 2020
8c4c526
Merge branch 'master' into feature/MPT
Jun 1, 2020
eb37222
sync with master
Jun 1, 2020
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
72 changes: 72 additions & 0 deletions src/neo/Trie/MPT/Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;

namespace Neo.Trie.MPT
{
public static class Helper
{
public static byte[] Concat(this byte[] a, byte[] b)
shargon marked this conversation as resolved.
Show resolved Hide resolved
{
var result = new byte[a.Length + b.Length];
a.CopyTo(result, 0);
b.CopyTo(result, a.Length);
return result;
}

public static byte[] CommonPrefix(this byte[] a, byte[] b)
{
var prefix = new byte[] { };
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
var minLen = a.Length <= b.Length ? a.Length : b.Length;

if (a.Length != 0 && b.Length != 0)
{
for (int i = 0; i < minLen; i++)
{
if (a[i] != b[i]) break;
prefix = prefix.Add(a[i]);
}
}
return prefix;
}

public static bool Equal(this byte[] a, byte[] b)
{
if (a.Length != b.Length) return false;
for (int i = 0; i < a.Length; i++)
{
if (a[i] != b[i]) return false;
}
return true;
}

public static byte[] Skip(this byte[] a, int count)
{
var result = new byte[] { };
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
var len = a.Length - count;
if (0 < len)
{
result = new byte[len];
Array.Copy(a, count, result, 0, len);
}
return result;
}

public static byte[] Add(this byte[] a, byte b)
{
var result = new byte[a.Length + 1];
a.CopyTo(result, 0);
result[a.Length] = b;
return result;
}

public static byte[] ToNibbles(this byte[] path)
{
var result = new byte[path.Length * 2];
for (int i = 0; i < path.Length; i++)
{
result[i * 2] = (byte)(path[i] >> 4);
result[i * 2 + 1] = (byte)(path[i] & 0x0F);
}
return result;
}
}
}
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
52 changes: 52 additions & 0 deletions src/neo/Trie/MPT/MPTDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

using Neo.Persistence;
using System.Text;

namespace Neo.Trie.MPT
{
public class MPTDatabase
{
private ISnapshot store;

public static readonly byte TABLE = 0x4D;
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved

public static readonly byte[] Prefix = Encoding.ASCII.GetBytes("MPT");

private byte[] StoreKey(byte[] hash)
{
return Prefix.Concat(hash);
}

public MPTDatabase(ISnapshot store)
{
this.store = store;
}

public MPTNode Node(byte[] hash)
{
var data = store.TryGet(TABLE, StoreKey(hash));
var n = MPTNode.Decode(data);
return n;
}

public void Delete(byte[] hash)
{
store.Delete(TABLE, StoreKey(hash));
}

public void Put(MPTNode node)
{
store.Put(TABLE, StoreKey(node.GetHash()), node.Encode());
}

public void PutRoot(byte[] root)
{
store.Put(TABLE, StoreKey(Encoding.ASCII.GetBytes("mpt_root")), root);
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
}

public byte[] GetRoot()
{
return store.TryGet(TABLE, StoreKey(Encoding.ASCII.GetBytes("mpt_root")));
}
}
}
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
103 changes: 103 additions & 0 deletions src/neo/Trie/MPT/MPTNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System.IO;
using System.Text;
using Neo.Cryptography;
using Neo.IO;

namespace Neo.Trie.MPT
{
public enum NodeType
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
{
FullNode,
ShortNode,
HashNode,
ValueNode,
}
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved

public class NodeFlag
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
{
public byte[] Hash;
public bool Dirty;

public NodeFlag()
{
Dirty = true;
}
}

public abstract class MPTNode : ISerializable
{
public NodeFlag Flag;
protected NodeType nType;

protected abstract byte[] calHash();
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved

public virtual byte[] GetHash()
{
if (!Flag.Dirty) return Flag.Hash;
Flag.Hash = calHash();
Flag.Dirty = false;
return (byte[])Flag.Hash.Clone();
}

public void ResetFlag()
{
Flag = new NodeFlag();
}

public int Size { get; }
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved

public MPTNode()
{
Flag = new NodeFlag();
}

public virtual void Serialize(BinaryWriter writer)
{
writer.Write((byte)nType);
}

public virtual void Deserialize(BinaryReader reader)
{

ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
}

public byte[] Encode()
{
return this.ToArray();
}

public static MPTNode Decode(byte[] data)
{
var nodeType = (NodeType)data[0];
data = data.Skip(1);

using (MemoryStream ms = new MemoryStream(data, false))
using (BinaryReader reader = new BinaryReader(ms, Encoding.UTF8))
{
switch (nodeType)
{
case NodeType.FullNode:
{
var n = new FullNode();
n.Deserialize(reader);
return n;
}
case NodeType.ShortNode:
{
var n = new ShortNode();
n.Deserialize(reader);
return n;
}
case NodeType.ValueNode:
{
var n = new ValueNode();
n.Deserialize(reader);
return n;
}
default:
throw new System.Exception();
}
}
}
}
}
58 changes: 58 additions & 0 deletions src/neo/Trie/MPT/MPTNode/FullNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.IO;
using Neo.Cryptography;
using Neo.IO;

namespace Neo.Trie.MPT
{
public class FullNode : MPTNode
{
public MPTNode[] Children = new MPTNode[17];
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved

public FullNode()
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
{
nType = NodeType.FullNode;
for (int i = 0; i < Children.Length; i++)
{
Children[i] = HashNode.EmptyNode();
}
}

protected override byte[] calHash()
{
var bytes = new byte[0];
for (int i = 0; i < Children.Length; i++)
{
bytes = bytes.Concat(Children[i].GetHash());
}
return bytes.Sha256();
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
}

public FullNode Clone()
{
var cloned = new FullNode();
for (int i = 0; i < Children.Length; i++)
{
cloned.Children[i] = Children[i];
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
}
return cloned;
}

public override void Serialize(BinaryWriter writer)
{
base.Serialize(writer);
for (int i = 0; i < Children.Length; i++)
{
writer.WriteVarBytes(Children[i].GetHash());
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
}
}

public override void Deserialize(BinaryReader reader)
{
for (int i = 0; i < Children.Length; i++)
{
var hashNode = new HashNode(reader.ReadVarBytes());
Children[i] = hashNode;
}
}
}
}
31 changes: 31 additions & 0 deletions src/neo/Trie/MPT/MPTNode/HashNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

namespace Neo.Trie.MPT
{
public class HashNode : MPTNode
{
public byte[] Hash;
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved

public HashNode()
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
{
nType = NodeType.HashNode;
}

public HashNode(byte[] hash)
{
nType = NodeType.HashNode;
Hash = (byte[])hash.Clone();
}

protected override byte[] calHash()
{
return (byte[])Hash.Clone();
}

public static HashNode EmptyNode()
{
return new HashNode(new byte[] { });
}

public bool IsEmptyNode => Hash.Length == 0;
}
}
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
48 changes: 48 additions & 0 deletions src/neo/Trie/MPT/MPTNode/ShortNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.IO;
using Neo.Cryptography;
using Neo.IO;

namespace Neo.Trie.MPT
{
public class ShortNode : MPTNode
{
public byte[] Key;

public MPTNode Next;

public new int Size => Key.Length + Next.Size;
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved

protected override byte[] calHash()
{
return Key.Concat(Next.GetHash()).Sha256();
}
public ShortNode()
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
{
nType = NodeType.ShortNode;
}

public ShortNode Clone()
{
var cloned = new ShortNode()
{
Key = (byte[])Key.Clone(),
Next = Next,
};
return cloned;
}

public override void Serialize(BinaryWriter writer)
{
base.Serialize(writer);
writer.WriteVarBytes(Key);
writer.WriteVarBytes(Next.GetHash());
}

public override void Deserialize(BinaryReader reader)
{
Key = reader.ReadVarBytes();
var hashNode = new HashNode(reader.ReadVarBytes());
Next = hashNode;
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
ZhangTao1596 marked this conversation as resolved.
Show resolved Hide resolved
Loading