Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow persistence plugins to commit as a final step. #568

Merged
merged 5 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions neo/Ledger/Blockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,25 @@ private void Persist(Block 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)
jsolman marked this conversation as resolved.
Show resolved Hide resolved
{
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();
OnPersistCompleted(block);
Expand Down
5 changes: 4 additions & 1 deletion neo/Plugins/IPersistencePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Neo.Persistence;
using System;
using Neo.Persistence;
using System.Collections.Generic;
using static Neo.Ledger.Blockchain;

Expand All @@ -7,5 +8,7 @@ namespace Neo.Plugins
public interface IPersistencePlugin
{
void OnPersist(Snapshot snapshot, IReadOnlyList<ApplicationExecuted> applicationExecutedList);
void OnCommit(Snapshot snapshot);
bool ShouldThrowExceptionFromCommit(Exception ex);
}
}