diff --git a/src/Nethermind/Ethereum.Trie.Test/TrieTests.cs b/src/Nethermind/Ethereum.Trie.Test/TrieTests.cs index aedee4459aa..c6bdd5aca56 100644 --- a/src/Nethermind/Ethereum.Trie.Test/TrieTests.cs +++ b/src/Nethermind/Ethereum.Trie.Test/TrieTests.cs @@ -24,7 +24,6 @@ public class TrieTests [SetUp] public void Setup() { - TrieNode.AllowBranchValues = true; _db = new MemDb(); } @@ -59,7 +58,9 @@ private static IEnumerable LoadTests() { return TestLoader.LoadFromFile, TrieTest>( "trietest.json", - dwj => dwj.Select(Convert)); + dwj => dwj.Select(Convert)) + // Remove branch value tests + .Where(t => t.Input.All(kvp => kvp.Key.Length == 32)); } private static IEnumerable LoadSecureTests() @@ -73,7 +74,9 @@ private static IEnumerable LoadAnyOrderTests() { IEnumerable tests = TestLoader.LoadFromFile, TrieTest>( "trieanyorder.json", - dwj => dwj.Select(p => new TrieTest(p.Key, p.Value.In.ToList(), p.Value.Root))); + dwj => dwj.Select(p => new TrieTest(p.Key, p.Value.In.ToList(), p.Value.Root))) + // Remove branch value tests + .Where(t => t.Input.All(kvp => kvp.Key.Length == 32)); return GetTestPermutations(tests); } @@ -81,7 +84,9 @@ private static IEnumerable LoadHexEncodedSecureTests() { IEnumerable tests = TestLoader.LoadFromFile, TrieTest>( "hex_encoded_securetrie_test.json", - dwj => dwj.Select(p => new TrieTest(p.Key, p.Value.In.ToList(), p.Value.Root))); + dwj => dwj.Select(p => new TrieTest(p.Key, p.Value.In.ToList(), p.Value.Root))) + // Remove branch value tests + .Where(t => t.Input.All(kvp => kvp.Key.Length == 32)); return GetTestPermutations(tests); } diff --git a/src/Nethermind/Nethermind.State.Test/NodeTests.cs b/src/Nethermind/Nethermind.State.Test/NodeTests.cs index 62d9772ab44..d90924a4212 100644 --- a/src/Nethermind/Nethermind.State.Test/NodeTests.cs +++ b/src/Nethermind/Nethermind.State.Test/NodeTests.cs @@ -14,18 +14,6 @@ namespace Nethermind.Store.Test [TestFixture, Parallelizable(ParallelScope.Children)] public class NodeTest { - [OneTimeSetUp] - public void Setup() - { - TrieNode.AllowBranchValues = true; - } - - [OneTimeTearDown] - public void TearDown() - { - TrieNode.AllowBranchValues = false; - } - [Test] public void Two_children_store_encode() { @@ -141,7 +129,6 @@ public void Child_and_value_store_encode() private static ITrieNodeResolver BuildATreeFromNode(TrieNode node) { - TrieNode.AllowBranchValues = true; TreePath emptyPath = TreePath.Empty; CappedArray rlp = node.RlpEncode(null, ref emptyPath); node.ResolveKey(null, ref emptyPath, true); diff --git a/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs b/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs index 0223672333f..90c759a9ee2 100644 --- a/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs +++ b/src/Nethermind/Nethermind.Trie/TrieNode.Decoder.cs @@ -132,7 +132,7 @@ public static CappedArray RlpEncodeBranch(TrieNode item, ITrieNodeResolver { Metrics.TreeNodeRlpEncodings++; - int valueRlpLength = AllowBranchValues ? Rlp.LengthOf(item.Value.AsSpan()) : 1; + const int valueRlpLength = 1; int contentLength = valueRlpLength + (UseParallel(canBeParallel) ? GetChildrenRlpLengthForBranchParallel(tree, ref path, item, pool) : GetChildrenRlpLengthForBranch(tree, ref path, item, pool)); int sequenceLength = Rlp.LengthOfSequence(contentLength); CappedArray result = pool.SafeRentBuffer(sequenceLength); @@ -140,14 +140,7 @@ public static CappedArray RlpEncodeBranch(TrieNode item, ITrieNodeResolver int position = Rlp.StartSequence(resultSpan, 0, contentLength); WriteChildrenRlpBranch(tree, ref path, item, resultSpan.Slice(position, contentLength - valueRlpLength), pool); position = sequenceLength - valueRlpLength; - if (AllowBranchValues) - { - Rlp.Encode(resultSpan, position, item.Value); - } - else - { - result.AsSpan()[position] = 128; - } + result.AsSpan()[position] = 128; return result; diff --git a/src/Nethermind/Nethermind.Trie/TrieNode.cs b/src/Nethermind/Nethermind.Trie/TrieNode.cs index b207653aedf..5537f4d5359 100644 --- a/src/Nethermind/Nethermind.Trie/TrieNode.cs +++ b/src/Nethermind/Nethermind.Trie/TrieNode.cs @@ -39,15 +39,6 @@ public sealed partial class TrieNode private object?[]? _data; private int _isDirty; - /// - /// Ethereum Patricia Trie specification allows for branch values, - /// although branched never have values as all the keys are of equal length. - /// Keys are of length 64 for TxTrie and ReceiptsTrie and StateTrie. - /// - /// We leave this switch for testing purposes. - /// - public static bool AllowBranchValues { private get; set; } - /// /// Sealed node is the one that is already immutable except for reference counting and resolving existing data /// @@ -134,32 +125,8 @@ public ref readonly CappedArray ValueRef return ref Unsafe.Unbox>(data); } - if (!AllowBranchValues) - { - // branches that we use for state will never have value set as all the keys are equal length - return ref CappedArray.Empty; - } - - ref object? obj = ref _data![BranchesCount]; - if (obj is null) - { - RlpFactory rlp = _rlp; - if (rlp is null) - { - obj = CappedArray.EmptyBoxed; - return ref CappedArray.Empty; - } - else - { - ValueRlpStream rlpStream = rlp.GetRlpStream(); - SeekChild(ref rlpStream, BranchesCount); - byte[]? bArr = rlpStream.DecodeByteArray(); - obj = new CappedArray(bArr); - return ref Unsafe.Unbox>(obj); - } - } - - return ref Unsafe.Unbox>(obj); + // branches that we use for state will never have value set as all the keys are equal length + return ref CappedArray.Empty; } } @@ -198,7 +165,7 @@ private void SetValue(in CappedArray value, bool overrideSealed = false) ThrowAlreadySealed(); } - if (IsBranch && !AllowBranchValues) + if (IsBranch) { // in Ethereum all paths are of equal length, hence branches will never have values // so we decided to save 1/17th of the array size in memory @@ -246,11 +213,6 @@ public bool IsValidWithOneNodeLess } } - if (AllowBranchValues) - { - nonEmptyNodes += Value.Length > 0 ? 1 : 0; - } - return nonEmptyNodes > 2; } } @@ -1077,7 +1039,7 @@ void Initialize(NodeType nodeType) var data = nodeType switch { NodeType.Unknown => ThrowCannotResolveException(), - NodeType.Branch => new object[AllowBranchValues ? BranchesCount + 1 : BranchesCount], + NodeType.Branch => new object[BranchesCount], _ => new object[2], };