-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix IPersistencePlugin inconsistency #2576
Closed
Qiao-Jin
wants to merge
15
commits into
neo-project:master
from
Qiao-Jin:fix_IPersistencePlugin_inconsistency
Closed
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
7d344cf
fix IPersistencePlugin inconsistency
a2c713b
optimize
ed5d680
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin d19fa73
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
shargon 6023f76
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin ecc664a
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin 46cc3b9
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin 82cd3c9
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
shargon d996d54
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin cb5d7ae
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin 31cbb82
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin 0603d94
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin 6d54ef8
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin ef5ce28
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin 0207615
Merge branch 'master' into fix_IPersistencePlugin_inconsistency
Qiao-Jin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -415,28 +415,36 @@ private void Persist(Block block) | |
Context.System.EventStream.Publish(application_executed); | ||
all_application_executed.Add(application_executed); | ||
} | ||
foreach (IPersistencePlugin plugin in Plugin.PersistencePlugins) | ||
plugin.OnPersist(system, block, snapshot, all_application_executed); | ||
snapshot.Commit(); | ||
List<Exception> commitExceptions = null; | ||
foreach (IPersistencePlugin plugin in Plugin.PersistencePlugins) | ||
{ | ||
try | ||
if (plugin.CurrentHeight < block.Index) | ||
{ | ||
plugin.OnCommit(system, block, snapshot); | ||
plugin.OnPersist(system, block, snapshot, all_application_executed); | ||
} | ||
catch (Exception ex) | ||
} | ||
List<Exception> commitExceptions = null; | ||
foreach (IPersistencePlugin plugin in Plugin.PersistencePlugins) | ||
{ | ||
if (plugin.CurrentHeight < block.Index) | ||
{ | ||
if (plugin.ShouldThrowExceptionFromCommit(ex)) | ||
try | ||
{ | ||
if (commitExceptions == null) | ||
commitExceptions = new List<Exception>(); | ||
plugin.OnCommit(system, block, snapshot); | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (plugin.ShouldThrowExceptionFromCommit(ex)) | ||
{ | ||
if (commitExceptions == null) | ||
commitExceptions = new List<Exception>(); | ||
|
||
commitExceptions.Add(ex); | ||
commitExceptions.Add(ex); | ||
} | ||
} | ||
} | ||
} | ||
if (commitExceptions != null) throw new AggregateException(commitExceptions); | ||
snapshot.Commit(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If snapshot is the last to commit then #2570 (comment) is probably not relevant though, plugins won't ever have N-1 data, rather they could have some N+1, but they won't process it again because of |
||
system.MemPool.UpdatePoolForBlockPersisted(block, snapshot); | ||
} | ||
extensibleWitnessWhiteList = null; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
OnPersist
andOnCommit
could be merged then? Previously they were done at different stages of processing, but now they're very similar and probably this separation is not really needed. It will change plugin interface though (but I doubt we have a lot of third-party plugins now).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is introduced in #568:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we should merge it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'd better keep this strategy to make sure there is no dirty data stored in plugins once some error occurs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it's better to revert if there is an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we merge these 2 functions, it will not be able to work correctly for such scenarios: i.e. there are 2 IPersistencePlugins installed. The first one persists without error but the second one throws some exception caused by dirty data. We can restart nodes again to re-persist data for neo-node and IPersistencePlugins, but the first plugin is already "polluted", I'm afraid the node can only be re-syncronized from 0 height again...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are two plugins, and one throw an exception the problem will be in the plugin, I still thinking that is better to merge it. What do you think @erikzhang ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erikzhang Could you provide opinion upon this question?