diff --git a/neo/Ledger/Blockchain.cs b/neo/Ledger/Blockchain.cs index fa9d7dc5fb..82dac883a6 100644 --- a/neo/Ledger/Blockchain.cs +++ b/neo/Ledger/Blockchain.cs @@ -610,6 +610,25 @@ private void Persist(Block block) foreach (IPersistencePlugin plugin in Plugin.PersistencePlugins) plugin.OnPersist(snapshot, all_application_executed); snapshot.Commit(); + List 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(); + + commitExceptions.Add(ex); + } + } + } + if (commitExceptions != null) throw new AggregateException(commitExceptions); } UpdateCurrentSnapshot(); OnPersistCompleted(block); diff --git a/neo/Plugins/IPersistencePlugin.cs b/neo/Plugins/IPersistencePlugin.cs index cf4ee697fd..af3cbe05b8 100644 --- a/neo/Plugins/IPersistencePlugin.cs +++ b/neo/Plugins/IPersistencePlugin.cs @@ -1,4 +1,5 @@ -using Neo.Persistence; +using System; +using Neo.Persistence; using System.Collections.Generic; using static Neo.Ledger.Blockchain; @@ -7,5 +8,7 @@ namespace Neo.Plugins public interface IPersistencePlugin { void OnPersist(Snapshot snapshot, IReadOnlyList applicationExecutedList); + void OnCommit(Snapshot snapshot); + bool ShouldThrowExceptionFromCommit(Exception ex); } }