void DispatchBlock() { try { _Hasher.Pause("dispatching block"); MinerTrace.Information($"dispatching block with {_ValidatedTxs.Count()} txs"); var txs = FSharpList <Types.Transaction> .Cons(_Coinbase, ListModule.OfSeq(_ValidatedTxs.Select(TransactionValidation.unpoint))); var block = new Types.Block(_Header, txs); var result = new HandleBlockAction(block).Publish().Result.BkResultEnum; if (result == BlockVerificationHelper.BkResultEnum.Accepted) { if (OnMined != null) { OnMined(block); } } else { Reset(); } MinerTrace.Information($" block {block.header.blockNumber} is " + result); } catch (Exception e) { MinerTrace.Error("Dispatch block exception", e); } }
BkResult HandleBlock(HandleBlockAction a) { BlockVerificationHelper action = null; using (var dbTx = _DBContext.GetTransactionContext()) { action = new BlockVerificationHelper( this, dbTx, a.BkHash, a.Bk, a.IsOrphan ); switch (action.Result.BkResultEnum) { case BkResultEnum.AcceptedOrphan: dbTx.Commit(); break; case BkResultEnum.Accepted: if (action.ConfirmedTxs.Any() || action.UnconfirmedTxs.Any()) { UpdateMempool(dbTx, action.ConfirmedTxs, action.UnconfirmedTxs); } else { dbTx.Commit(); } BlockStore.Orphans(dbTx, a.BkHash).ToList().ForEach(t => new HandleBlockAction(t.Key, t.Value, true).Publish()); break; case BkResultEnum.Rejected: return(action.Result); } } //TODO: memory management issues. trying to explicitly collect DynamicMethods GC.Collect(); GC.WaitForPendingFinalizers(); action.QueueActions.ForEach(t => { if (t is MessageAction) { (t as MessageAction).Message.Publish(); } else { t.Publish(); } }); return(action.Result); }