コード例 #1
0
        private bool TryAddTree(Address trackedTree)
        {
            bool treeAdded = false;

            bool wasUntracked = _trackingOverrides.TryGetValue(trackedTree, out bool result) && result;

            if (!wasUntracked)
            {
                if (_stateReader.GetCode(_blockFinder.Head.StateRoot, trackedTree).Length != 0)
                {
                    ShaBaselineTree tree = new ShaBaselineTree(_baselineDb, _metadataBaselineDb, trackedTree.Bytes, TruncationLength, _logger);
                    treeAdded = _baselineTrees.TryAdd(trackedTree, tree);
                    if (treeAdded)
                    {
                        BaselineTreeTracker?tracker = new BaselineTreeTracker(trackedTree, tree, _blockProcessor, _baselineTreeHelper, _blockFinder, _logger);
                        _disposableStack.Push(tracker);
                    }
                }

                _trackingOverrides.TryAdd(trackedTree, false);
            }
            else
            {
                treeAdded = _trackingOverrides.TryUpdate(trackedTree, false, true);
            }

            return(treeAdded);
        }
コード例 #2
0
        private bool TryAddTree(Address trackedTree)
        {
            if (_stateReader.GetCode(_blockFinder.Head.StateRoot, trackedTree).Length == 0)
            {
                return(false);
            }

            ShaBaselineTree tree = new ShaBaselineTree(_baselineDb, trackedTree.Bytes, TruncationLength);

            return(_baselineTrees.TryAdd(trackedTree, tree));
        }
コード例 #3
0
        private BaselineTree RebuildEntireTree(Address treeAddress, Keccak blockHash)
        {
            // bad

            Keccak    leavesTopic        = new Keccak("0x8ec50f97970775682a68d3c6f9caedf60fd82448ea40706b8b65d6c03648b922");
            LogFilter insertLeavesFilter = new LogFilter(
                0,
                new BlockParameter(0L),
                new BlockParameter(blockHash),
                new AddressFilter(treeAddress),
                new TopicsFilter(new SpecificTopic(leavesTopic)));

            Keccak    leafTopic        = new Keccak("0x6a82ba2aa1d2c039c41e6e2b5a5a1090d09906f060d32af9c1ac0beff7af75c0");
            LogFilter insertLeafFilter = new LogFilter(
                0,
                new BlockParameter(0L),
                new BlockParameter(blockHash),
                new AddressFilter(treeAddress),
                new TopicsFilter(new SpecificTopic(leafTopic))); // find tree topics

            var          insertLeavesLogs = _logFinder.FindLogs(insertLeavesFilter);
            var          insertLeafLogs   = _logFinder.FindLogs(insertLeafFilter);
            BaselineTree baselineTree     = new ShaBaselineTree(new MemDb(), Array.Empty <byte>(), 5);

            // Keccak leafTopic = new Keccak("0x8ec50f97970775682a68d3c6f9caedf60fd82448ea40706b8b65d6c03648b922");
            foreach (FilterLog filterLog in insertLeavesLogs
                     .Union(insertLeafLogs)
                     .OrderBy(fl => fl.BlockNumber).ThenBy(fl => fl.LogIndex))
            {
                if (filterLog.Data.Length == 96)
                {
                    Keccak leafHash = new Keccak(filterLog.Data.Slice(32, 32).ToArray());
                    baselineTree.Insert(leafHash);
                }
                else
                {
                    for (int i = 0; i < (filterLog.Data.Length - 128) / 32; i++)
                    {
                        Keccak leafHash = new Keccak(filterLog.Data.Slice(128 + 32 * i, 32).ToArray());
                        baselineTree.Insert(leafHash);
                    }
                }
            }

            return(baselineTree);
        }