public void ReorgOne() { UnprocessedBlockBuffer.Clear(); // remove the last block if (MerkleChain.Count != 0) { var bestBlock = MerkleChain.Max(); if (MerkleChain.TryRemove(bestBlock)) { List <SmartTransaction> affectedTxs = TrackedTransactions.Where(x => x.Height == bestBlock.Height).Select(x => x).ToList(); foreach (var tx in affectedTxs) { TrackedTransactions.TryRemove(tx); // add it back as a mempool transaction, it'll drop out anyway TrackedTransactions.TryAdd(new SmartTransaction(tx.Transaction, Height.MemPool)); } if (MerkleChain.Count != 0) { BestHeight = MerkleChain.Max().Height; } else { BestHeight = Height.Unknown; } } } }
public void ReorgOne() { // remove the last block if (MerkleChain.Count != 0) { if (MerkleChain.TryRemove(MerkleChain.Max())) { BestHeight = MerkleChain.Max().Height; } } }
/// <returns>transactions it processed, empty if not processed any</returns> private HashSet <SmartTransaction> ProcessBlock(Height height, Block block) { var foundTransactions = ProcessTransactions(block.Transactions, height); var smartMerkleBlock = new SmartMerkleBlock(height, block, foundTransactions.Select(x => x.GetHash()).ToArray()); var sameHeights = MerkleChain.Where(x => x.Height == height); foreach (var elem in sameHeights) { MerkleChain.TryRemove(elem); } MerkleChain.Add(smartMerkleBlock); BestHeight = height; return(foundTransactions); }