private void _snapshotCommit(StoreView snapshot, string partial) { switch (partial) { case "blocks": snapshot.Blocks.Commit(); break; case "transactions": snapshot.Transactions.Commit(); break; default: snapshot.Commit(); break; } }
public bool Commit() { if (IsValid()) { if (_entityview.IsModified()) { _entityview.Commit(); if (Entity.IsNew) { Domain.Store st = ClientEnvironment.StoreService.Save(Entity); Entity.ID = st.ID; } else { ClientEnvironment.StoreService.SaveOrUpdate(Entity); } _modified = true; return(true); } } return(false); }
private void Persist(Block block) { using (SnapshotView snapshot = GetSnapshot()) { if (block.Index == header_index.Count) { header_index.Add(block.Hash); snapshot.HeaderHashIndex.GetAndChange().Set(block); } List <ApplicationExecuted> all_application_executed = new List <ApplicationExecuted>(); snapshot.PersistingBlock = block; if (block.Index > 0) { using (ApplicationEngine engine = new ApplicationEngine(TriggerType.System, null, snapshot, 0, true)) { engine.LoadScript(onPersistNativeContractScript); if (engine.Execute() != VMState.HALT) { throw new InvalidOperationException(); } ApplicationExecuted application_executed = new ApplicationExecuted(engine); Context.System.EventStream.Publish(application_executed); all_application_executed.Add(application_executed); } } snapshot.Blocks.Add(block.Hash, block.Trim()); StoreView clonedSnapshot = snapshot.Clone(); // Warning: Do not write into variable snapshot directly. Write into variable clonedSnapshot and commit instead. foreach (Transaction tx in block.Transactions) { var state = new TransactionState { BlockIndex = block.Index, Transaction = tx }; clonedSnapshot.Transactions.Add(tx.Hash, state); clonedSnapshot.Transactions.Commit(); using (ApplicationEngine engine = new ApplicationEngine(TriggerType.Application, tx, clonedSnapshot, tx.SystemFee)) { engine.LoadScript(tx.Script); state.VMState = engine.Execute(); if (state.VMState == VMState.HALT) { clonedSnapshot.Commit(); } else { clonedSnapshot = snapshot.Clone(); } ApplicationExecuted application_executed = new ApplicationExecuted(engine); Context.System.EventStream.Publish(application_executed); all_application_executed.Add(application_executed); } } snapshot.BlockHashIndex.GetAndChange().Set(block); foreach (IPersistencePlugin plugin in Plugin.PersistencePlugins) { plugin.OnPersist(snapshot, all_application_executed); } snapshot.Commit(); List <Exception> commitExceptions = null; foreach (IPersistencePlugin plugin in Plugin.PersistencePlugins) { try { plugin.OnCommit(snapshot); } catch (Exception ex) { if (plugin.ShouldThrowExceptionFromCommit(ex)) { if (commitExceptions == null) { commitExceptions = new List <Exception>(); } commitExceptions.Add(ex); } } } if (commitExceptions != null) { throw new AggregateException(commitExceptions); } } UpdateCurrentSnapshot(); block_cache.Remove(block.PrevHash); MemPool.UpdatePoolForBlockPersisted(block, currentSnapshot); Context.System.EventStream.Publish(new PersistCompleted { Block = block }); }