예제 #1
0
 private void StoreTreeBlooms(bool withBloomDb)
 {
     if (withBloomDb)
     {
         for (int i = 0; i <= _blockTree.Head.Number; i++)
         {
             _bloomStorage.Store(i, _blockTree.FindHeader(i).Bloom);
         }
     }
 }
예제 #2
0
        public AddBlockResult Insert(BlockHeader header)
        {
            if (!CanAcceptNewBlocks)
            {
                return(AddBlockResult.CannotAccept);
            }

            if (header.Number == 0)
            {
                throw new InvalidOperationException("Genesis block should not be inserted.");
            }

            if (header.TotalDifficulty == null)
            {
                SetTotalDifficulty(header);
            }

            // validate hash here
            Rlp newRlp = _headerDecoder.Encode(header);

            _headerDb.Set(header.Hash, newRlp.Bytes);

            BlockInfo      blockInfo  = new BlockInfo(header.Hash, header.TotalDifficulty ?? 0);
            ChainLevelInfo chainLevel = new ChainLevelInfo(true, blockInfo);

            _chainLevelInfoRepository.PersistLevel(header.Number, chainLevel);
            _bloomStorage.Store(header.Number, header.Bloom);

            if (header.Number < (LowestInsertedHeader?.Number ?? long.MaxValue))
            {
                LowestInsertedHeader = header;
            }

            if (header.Number > BestKnownNumber)
            {
                BestKnownNumber = header.Number;
            }

            if (header.Number > BestSuggestedHeader.Number)
            {
                BestSuggestedHeader = header;
            }

            return(AddBlockResult.Added);
        }