コード例 #1
0
        public void VisitExtension(TrieNode node, TrieVisitContext trieVisitContext)
        {
            AddProofItem(node, trieVisitContext);
            _nodeToVisitFilter.Remove(node.Keccak);

            Keccak childHash = node.GetChildHash(0);

            if (trieVisitContext.IsStorage)
            {
                _storageNodeInfos[childHash]           = new StorageNodeInfo();
                _storageNodeInfos[childHash].PathIndex = _pathTraversalIndex + node.Path.Length;

                foreach (int storageIndex in _storageNodeInfos[node.Keccak].StorageIndices)
                {
                    bool isPathMatched = IsPathMatched(node, _fullStoragePaths[storageIndex]);
                    if (isPathMatched)
                    {
                        _storageNodeInfos[childHash].StorageIndices.Add(storageIndex);
                        _nodeToVisitFilter.Add(childHash); // always accept so can optimize
                    }
                }
            }

            if (IsPathMatched(node, _fullAccountPath))
            {
                _nodeToVisitFilter.Add(childHash); // always accept so can optimize
                _pathTraversalIndex += node.Path.Length;
            }
        }
コード例 #2
0
        public void VisitBranch(TrieNode node, TrieVisitContext trieVisitContext)
        {
            AddProofBits(node);
            _visitingFilter.Remove(node.Keccak);
            _visitingFilter.Add(node.GetChildHash((byte)Prefix[_pathIndex]));

            _pathIndex++;
        }
コード例 #3
0
 public void VisitExtension(TrieNode node, TrieVisitContext trieVisitContext)
 {
     _nodesVisited++;
     if (trieVisitContext.IsStorage)
     {
         _ignoreThisOne.Add(node.GetChildHash(0));
     }
 }
コード例 #4
0
 public void VisitTree(Keccak rootHash, TrieVisitContext trieVisitContext)
 {
     _stopwatch.Start();
     if (_logger.IsWarn)
     {
         _logger.Warn($"Full Pruning Started on root hash {rootHash}: do not close the node until finished or progress will be lost.");
     }
 }
コード例 #5
0
        public void VisitMissingNode(Keccak nodeHash, TrieVisitContext trieVisitContext)
        {
            if (_logger.IsWarn)
            {
                _logger.Warn($"Full Pruning Failed: Missing node {nodeHash} at level {trieVisitContext.Level}.");
            }

            // if nodes are missing then state trie is not valid and we need to stop copying it
            _pruningContext.CancellationTokenSource.Cancel();
        }
コード例 #6
0
ファイル: TrieNodeTests.cs プロジェクト: uzbekdev1/nethermind
        public void Unknown_node_with_missing_data_can_accept_visitor()
        {
            ITreeVisitor     visitor = Substitute.For <ITreeVisitor>();
            TrieVisitContext context = new TrieVisitContext();
            TrieNode         node    = new TrieNode(NodeType.Unknown);

            node.Accept(visitor, NullTrieNodeResolver.Instance, context);

            visitor.Received().VisitMissingNode(node.Keccak, context);
        }
コード例 #7
0
        public void VisitExtension(TrieNode node, TrieVisitContext trieVisitContext)
        {
            AddProofBits(node);
            _visitingFilter.Remove(node.Keccak);

            Keccak childHash = node.GetChildHash(0);

            _visitingFilter.Add(childHash); // always accept so can optimize

            _pathIndex += node.Path.Length;
        }
コード例 #8
0
ファイル: TrieNodeTests.cs プロジェクト: uzbekdev1/nethermind
        public void Extension_can_accept_visitors()
        {
            ITreeVisitor     visitor = Substitute.For <ITreeVisitor>();
            TrieVisitContext context = new TrieVisitContext();
            TrieNode         ignore  = TrieNodeFactory.CreateLeaf(HexPrefix.Leaf("ccc"), Array.Empty <byte>());
            TrieNode         node    = TrieNodeFactory.CreateExtension(HexPrefix.Extension("aa"), ignore);

            node.Accept(visitor, NullTrieNodeResolver.Instance, context);

            visitor.Received().VisitExtension(node, context);
        }
コード例 #9
0
ファイル: TrieNodeTests.cs プロジェクト: uzbekdev1/nethermind
        public void Leaf_with_contract_without_storage_and_empty_code_can_accept_visitors()
        {
            ITreeVisitor     visitor = Substitute.For <ITreeVisitor>();
            TrieVisitContext context = new TrieVisitContext();
            Account          account = new Account(1, 100, Keccak.EmptyTreeHash, Keccak.OfAnEmptyString);
            AccountDecoder   decoder = new AccountDecoder();
            TrieNode         node    = TrieNodeFactory.CreateLeaf(HexPrefix.Leaf("aa"), decoder.Encode(account).Bytes);

            node.Accept(visitor, NullTrieNodeResolver.Instance, context);

            visitor.Received().VisitLeaf(node, context, node.Value);
        }
コード例 #10
0
ファイル: TrieNodeTests.cs プロジェクト: uzbekdev1/nethermind
        public void Leaf_with_simple_account_can_accept_visitors()
        {
            ITreeVisitor     visitor = Substitute.For <ITreeVisitor>();
            TrieVisitContext context = new TrieVisitContext();
            Account          account = new Account(100);
            AccountDecoder   decoder = new AccountDecoder();
            TrieNode         node    = TrieNodeFactory.CreateLeaf(HexPrefix.Leaf("aa"), decoder.Encode(account).Bytes);

            node.Accept(visitor, NullTrieNodeResolver.Instance, context);

            visitor.Received().VisitLeaf(node, context, node.Value);
        }
コード例 #11
0
        public void Extension_can_accept_visitors()
        {
            ITreeVisitor     visitor = Substitute.For <ITreeVisitor>();
            TrieVisitContext context = new TrieVisitContext();
            PatriciaTree     tree    = new PatriciaTree();
            TrieNode         ignore  = new TrieNode(NodeType.Unknown);
            TrieNode         node    = new TrieNode(NodeType.Extension);

            node.SetChild(0, ignore);

            node.Accept(visitor, tree, context);

            visitor.Received().VisitExtension(node, context);
        }
コード例 #12
0
        public void Leaf_with_simple_account_can_accept_visitors()
        {
            ITreeVisitor     visitor = Substitute.For <ITreeVisitor>();
            TrieVisitContext context = new TrieVisitContext();
            PatriciaTree     tree    = new PatriciaTree();
            Account          account = new Account(100);
            AccountDecoder   decoder = new AccountDecoder();
            TrieNode         node    = new TrieNode(NodeType.Leaf);

            node.Value = decoder.Encode(account).Bytes;

            node.Accept(visitor, tree, context);

            visitor.Received().VisitLeaf(node, context, node.Value);
        }
コード例 #13
0
        public void Leaf_with_contract_without_storage_and_empty_code_can_accept_visitors()
        {
            ITreeVisitor     visitor = Substitute.For <ITreeVisitor>();
            TrieVisitContext context = new TrieVisitContext();
            PatriciaTree     tree    = new PatriciaTree();
            Account          account = new Account(1, 100, Keccak.EmptyTreeHash, Keccak.OfAnEmptyString);
            AccountDecoder   decoder = new AccountDecoder();
            TrieNode         node    = new TrieNode(NodeType.Leaf);

            node.Value = decoder.Encode(account).Bytes;

            node.Accept(visitor, tree, context);

            visitor.Received().VisitLeaf(node, context, node.Value);
        }
コード例 #14
0
ファイル: TrieNodeTests.cs プロジェクト: uzbekdev1/nethermind
        public void Branch_can_accept_visitors()
        {
            ITreeVisitor     visitor = Substitute.For <ITreeVisitor>();
            TrieVisitContext context = new TrieVisitContext();
            TrieNode         node    = new TrieNode(NodeType.Branch);

            for (int i = 0; i < 16; i++)
            {
                node.SetChild(i, null);
            }

            node.Accept(visitor, NullTrieNodeResolver.Instance, context);

            visitor.Received().VisitBranch(node, context);
        }
コード例 #15
0
        public void Extension_with_leaf_can_be_visited()
        {
            ITreeVisitor visitor = Substitute.For <ITreeVisitor>();

            visitor.ShouldVisit(Arg.Any <Keccak>()).Returns(true);

            TrieVisitContext context = new TrieVisitContext();
            PatriciaTree     tree    = new PatriciaTree();
            TrieNode         node    = new TrieNode(NodeType.Extension);

            node.SetChild(0, _accountLeaf);

            node.Accept(visitor, tree, context);

            visitor.Received().VisitExtension(node, context);
            visitor.Received().VisitLeaf(_accountLeaf, context, _accountLeaf.Value);
        }
コード例 #16
0
        public void VisitLeaf(TrieNode node, TrieVisitContext trieVisitContext, byte[] value = null)
        {
            _nodesVisited++;

            if (trieVisitContext.IsStorage)
            {
                return;
            }

            AccountDecoder accountDecoder = new AccountDecoder();
            Account        account        = accountDecoder.Decode(node.Value.AsRlpStream());

            _balance += account.Balance;
            _accountsVisited++;

            _logger.Info($"Balance after visiting {_accountsVisited} accounts and {_nodesVisited} nodes: {_balance}");
        }
コード例 #17
0
        public void VisitBranch(TrieNode node, TrieVisitContext trieVisitContext)
        {
            _logger.Info($"Balance after visiting {_accountsVisited} accounts and {_nodesVisited} nodes: {_balance}");
            _nodesVisited++;

            if (trieVisitContext.IsStorage)
            {
                for (int i = 0; i < 16; i++)
                {
                    Keccak childHash = node.GetChildHash(i);
                    if (childHash != null)
                    {
                        _ignoreThisOne.Add(childHash);
                    }
                }
            }
        }
コード例 #18
0
 private void AddEmpty(TrieNode node, TrieVisitContext trieVisitContext)
 {
     if (trieVisitContext.IsStorage)
     {
         if (_storageNodeInfos.ContainsKey(node.Keccak))
         {
             foreach (int storageIndex in _storageNodeInfos[node.Keccak].StorageIndices)
             {
                 _storageProofItems[storageIndex].Add(Bytes.Empty);
             }
         }
     }
     else
     {
         _accountProofItems.Add(Bytes.Empty);
     }
 }
コード例 #19
0
        public void VisitLeaf(TrieNode node, TrieVisitContext trieVisitContext, byte[] value)
        {
            AddProofItem(node, trieVisitContext);
            _nodeToVisitFilter.Remove(node.Keccak);

            if (trieVisitContext.IsStorage)
            {
                foreach (int storageIndex in _storageNodeInfos[node.Keccak].StorageIndices)
                {
                    Nibble[] thisStoragePath = _fullStoragePaths[storageIndex];
                    bool     isPathMatched   = IsPathMatched(node, thisStoragePath);
                    if (isPathMatched)
                    {
                        _accountProof.StorageProofs[storageIndex].Value = new RlpStream(node.Value).DecodeByteArray();
                    }
                }
            }
            else
            {
                Account account       = _accountDecoder.Decode(new RlpStream(node.Value));
                bool    isPathMatched = IsPathMatched(node, _fullAccountPath);
                if (isPathMatched)
                {
                    _accountProof.Nonce       = account.Nonce;
                    _accountProof.Balance     = account.Balance;
                    _accountProof.StorageRoot = account.StorageRoot;
                    _accountProof.CodeHash    = account.CodeHash;

                    if (_fullStoragePaths.Length > 0)
                    {
                        _nodeToVisitFilter.Add(_accountProof.StorageRoot);
                        _storageNodeInfos[_accountProof.StorageRoot]           = new StorageNodeInfo();
                        _storageNodeInfos[_accountProof.StorageRoot].PathIndex = 0;
                        for (int i = 0; i < _fullStoragePaths.Length; i++)
                        {
                            _storageNodeInfos[_accountProof.StorageRoot].StorageIndices.Add(i);
                        }
                    }
                }
            }

            _pathTraversalIndex = 0;
        }
コード例 #20
0
        public void VisitBranch(TrieNode node, TrieVisitContext trieVisitContext)
        {
            AddProofItem(node, trieVisitContext);
            _nodeToVisitFilter.Remove(node.Keccak);

            if (trieVisitContext.IsStorage)
            {
                HashSet <int> bumpedIndexes = new HashSet <int>();
                foreach (int storageIndex in _storageNodeInfos[node.Keccak].StorageIndices)
                {
                    Nibble childIndex = _fullStoragePaths[storageIndex][_pathTraversalIndex];
                    Keccak childHash  = node.GetChildHash((byte)childIndex);
                    if (childHash == null)
                    {
                        Console.WriteLine($"Empty at {storageIndex}");

                        AddEmpty(node, trieVisitContext);
                    }
                    else
                    {
                        if (!_storageNodeInfos.ContainsKey(childHash))
                        {
                            _storageNodeInfos[childHash] = new StorageNodeInfo();
                        }

                        if (!bumpedIndexes.Contains((byte)childIndex))
                        {
                            bumpedIndexes.Add((byte)childIndex);
                            _storageNodeInfos[childHash].PathIndex = _pathTraversalIndex + 1;
                        }

                        _storageNodeInfos[childHash].StorageIndices.Add(storageIndex);
                        _nodeToVisitFilter.Add(childHash);
                    }
                }
            }
            else
            {
                _nodeToVisitFilter.Add(node.GetChildHash((byte)_fullAccountPath[_pathTraversalIndex]));
            }

            _pathTraversalIndex++;
        }
コード例 #21
0
        public void Branch_with_children_can_be_visited()
        {
            ITreeVisitor visitor = Substitute.For <ITreeVisitor>();

            visitor.ShouldVisit(Arg.Any <Keccak>()).Returns(true);

            TrieVisitContext context = new TrieVisitContext();
            PatriciaTree     tree    = new PatriciaTree();
            TrieNode         node    = new TrieNode(NodeType.Branch);

            for (int i = 0; i < 16; i++)
            {
                node.SetChild(i, _accountLeaf);
            }

            node.Accept(visitor, tree, context);

            visitor.Received().VisitBranch(node, context);
            visitor.Received(16).VisitLeaf(_accountLeaf, context, _accountLeaf.Value);
        }
コード例 #22
0
ファイル: TrieNodeTests.cs プロジェクト: uzbekdev1/nethermind
        public void Branch_with_children_can_be_visited()
        {
            Context      ctx     = new Context();
            ITreeVisitor visitor = Substitute.For <ITreeVisitor>();

            visitor.ShouldVisit(Arg.Any <Keccak>()).Returns(true);

            TrieVisitContext context = new TrieVisitContext();
            TrieNode         node    = new TrieNode(NodeType.Branch);

            for (int i = 0; i < 16; i++)
            {
                node.SetChild(i, ctx.AccountLeaf);
            }

            node.Accept(visitor, NullTrieNodeResolver.Instance, context);

            visitor.Received().VisitBranch(node, context);
            visitor.Received(16).VisitLeaf(ctx.AccountLeaf, context, ctx.AccountLeaf.Value);
        }
コード例 #23
0
 public void VisitLeaf(TrieNode node, TrieVisitContext trieVisitContext, byte[] value = null)
 {
 }
コード例 #24
0
 public void VisitCode(Keccak codeHash, TrieVisitContext trieVisitContext)
 {
     _nodesVisited++;
 }
コード例 #25
0
 public void VisitMissingNode(Keccak nodeHash, TrieVisitContext trieVisitContext)
 {
 }
コード例 #26
0
 public void VisitTree(Keccak rootHash, TrieVisitContext trieVisitContext)
 {
 }
コード例 #27
0
 public void VisitLeaf(TrieNode node, TrieVisitContext trieVisitContext, byte[] value)
 {
     AddProofBits(node);
     _visitingFilter.Remove(node.Keccak);
     _pathIndex = 0;
 }
コード例 #28
0
 public void VisitCode(Keccak codeHash, TrieVisitContext trieVisitContext)
 {
 }
コード例 #29
0
 public void VisitCode(Keccak codeHash, TrieVisitContext trieVisitContext)
 {
     throw new InvalidOperationException($"{nameof(AccountProofCollector)} does never expect to visit code");
 }
コード例 #30
0
 public void VisitMissingNode(Keccak nodeHash, TrieVisitContext trieVisitContext)
 {
     _logger.Warn($"Missing node {nodeHash}");
 }