private void LoadScenario(Scenario scenario, ISyncConfig syncConfig)
        {
            _syncConfig             = syncConfig;
            _syncConfig.PivotNumber = _pivotNumber.ToString();
            _syncConfig.PivotHash   = scenario.Blocks.Last().Hash.ToString();

            _feed = new ReceiptsSyncFeed(
                _selector,
                _specProvider,
                _blockTree,
                _receiptStorage,
                _syncPeerPool,
                _syncConfig,
                _syncReport,
                LimboLogs.Instance);

            _blockTree.Genesis.Returns(scenario.Blocks[0].Header);
            _blockTree.FindCanonicalBlockInfo(Arg.Any <long>()).Returns(
                ci =>
            {
                Block block = scenario.Blocks[ci.Arg <long>()];
                if (block == null)
                {
                    return(null);
                }

                BlockInfo blockInfo   = new BlockInfo(block.Hash, block.TotalDifficulty ?? 0);
                blockInfo.BlockNumber = ci.Arg <long>();
                return(blockInfo);
            });

            _blockTree.FindBlock(Keccak.Zero, BlockTreeLookupOptions.None)
            .ReturnsForAnyArgs(ci =>
                               scenario.BlocksByHash.ContainsKey(ci.Arg <Keccak>())
                        ? scenario.BlocksByHash[ci.Arg <Keccak>()]
                        : null);

            _blockTree.FindHeader(Keccak.Zero, BlockTreeLookupOptions.None)
            .ReturnsForAnyArgs(ci =>
                               scenario.BlocksByHash.ContainsKey(ci.Arg <Keccak>())
                        ? scenario.BlocksByHash[ci.Arg <Keccak>()].Header
                        : null);

            _receiptStorage.LowestInsertedReceiptBlockNumber.Returns((long?)null);
            _blockTree.LowestInsertedBodyNumber.Returns(scenario.LowestInsertedBody.Number);
        }
Beispiel #2
0
        public void GetInfosForBatch(BlockInfo?[] blockInfos)
        {
            int collected = 0;

            long currentNumber = LowestInsertWithoutGaps;

            lock (_statuses)
            {
                while (collected < blockInfos.Length && currentNumber != 0)
                {
                    if (blockInfos[collected] != null)
                    {
                        collected++;
                        continue;
                    }

                    switch (_statuses[currentNumber])
                    {
                    case FastBlockStatus.Unknown:
                        blockInfos[collected]    = _blockTree.FindCanonicalBlockInfo(currentNumber);
                        _statuses[currentNumber] = FastBlockStatus.Sent;
                        collected++;
                        break;

                    case FastBlockStatus.Inserted:
                        if (currentNumber == LowestInsertWithoutGaps)
                        {
                            LowestInsertWithoutGaps--;
                            Interlocked.Decrement(ref _queueSize);
                        }

                        break;

                    case FastBlockStatus.Sent:
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    currentNumber--;
                }
            }
        }