public Blockchain(NeoSystem system, IStore store) { this.system = system; this.MemPool = new MemoryPool(system, ProtocolSettings.Default.MemoryPoolMaxTransactions); this.Store = store; this.View = new ReadOnlyView(store); lock (lockObj) { if (singleton != null) { throw new InvalidOperationException(); } header_index.AddRange(View.HeaderHashList.Find().OrderBy(p => (uint)p.Key).SelectMany(p => p.Value.Hashes)); stored_header_count += (uint)header_index.Count; if (stored_header_count == 0) { header_index.AddRange(View.Blocks.Find().OrderBy(p => p.Value.Index).Select(p => p.Key)); } else { HashIndexState hashIndex = View.HeaderHashIndex.Get(); if (hashIndex.Index >= stored_header_count) { DataCache <UInt256, TrimmedBlock> cache = View.Blocks; for (UInt256 hash = hashIndex.Hash; hash != header_index[(int)stored_header_count - 1];) { header_index.Insert((int)stored_header_count, hash); hash = cache[hash].PrevHash; } } } if (header_index.Count == 0) { Persist(GenesisBlock); } else { UpdateCurrentSnapshot(); MemPool.LoadPolicy(currentSnapshot); } singleton = this; } }