コード例 #1
0
ファイル: SyncServer.cs プロジェクト: prestwich/nethermind
        // TODO - Cancellation token?
        // TODO - not a fan of this function name - CatchUpCHT, AddMissingCHTBlocks, ...?
        public Task BuildCHT()
        {
            return(Task.Run(() =>
            {
                lock (_chtLock)
                {
                    if (_cht == null)
                    {
                        throw new InvalidAsynchronousStateException("CHT reference is null when building CHT.");
                    }

                    // Note: The spec says this should be 2048, but I don't think we'd ever want it to be higher than the max reorg depth we allow.
                    long maxSection = CanonicalHashTrie.GetSectionFromBlockNo(_blockTree.FindLatestHeader().Number - Sync.MaxReorgLength);
                    long maxKnownSection = _cht.GetMaxSectionIndex();

                    for (long section = (maxKnownSection + 1); section <= maxSection; section++)
                    {
                        long sectionStart = section * CanonicalHashTrie.SectionSize;
                        for (int blockOffset = 0; blockOffset < CanonicalHashTrie.SectionSize; blockOffset++)
                        {
                            _cht.Set(_blockTree.FindHeader(sectionStart + blockOffset));
                        }

                        _cht.Commit(section);
                    }
                }
            }));
        }