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

[Neo Core] Part 1. Isolate Plugins Exceptions from the Node. #3309

Merged
merged 9 commits into from
Jun 16, 2024

Conversation

Jim8y
Copy link
Contributor

@Jim8y Jim8y commented Jun 8, 2024

Description

Currently plugins and the core runs in the same process, and we lack the measure of handling the plugin exceptions. This makes any plugin can have the ability to block the whole node, turning plugin an attack surface for neo core. Issue #3296 is a typical example.

Fixes # #3296 (comment)

Type of change

  • Optimization (the change is only an optimization)
  • Style (the change is only a code style for better maintenance or standard purpose)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Test Configuration:

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Jim8y Jim8y changed the title [Neo Core Bug] Catch plugin exceptions. [Neo Core Bug] Isolate Plugins Exceptions from the Core. Jun 8, 2024
@Jim8y Jim8y changed the title [Neo Core Bug] Isolate Plugins Exceptions from the Core. [Neo Core Bug] Isolate Plugins Exceptions from the Node. Jun 8, 2024
@Jim8y Jim8y added the bug Used to tag confirmed bugs label Jun 8, 2024
@Jim8y
Copy link
Contributor Author

Jim8y commented Jun 8, 2024

@shargon this should be a bug right?

@shargon
Copy link
Member

shargon commented Jun 8, 2024

@shargon this should be a bug right?

Bad design

@Jim8y Jim8y removed the bug Used to tag confirmed bugs label Jun 8, 2024
@shargon shargon changed the title [Neo Core Bug] Isolate Plugins Exceptions from the Node. [Neo Core] Isolate Plugins Exceptions from the Node. Jun 8, 2024
Co-authored-by: Christopher Schuchardt <[email protected]>
@roman-khimov
Copy link
Contributor

I'm not sure it improves things for users. The node will continue to work, sure, but if users have plugins they likely depend on them anyway (RPC/ApplicationLogs), so if node continues to process blocks, but users can't get data from it --- it's still broken from the user's perspective. It will also invalidate plugin state and will require subsequent resynchronization (right now updated nodes can just continue processing).

@Jim8y
Copy link
Contributor Author

Jim8y commented Jun 9, 2024

I'm not sure it improves things for users. The node will continue to work, sure, but if users have plugins they likely depend on them anyway (RPC/ApplicationLogs), so if node continues to process blocks, but users can't get data from it --- it's still broken from the user's perspective. It will also invalidate plugin state and will require subsequent resynchronization (right now updated nodes can just continue processing).

One service down does not mean the whole node including other services should also down. You can't say our brain should stop working if our hand is numb. And one pr only fix one specific problem. This pr isolate the exception from plugin to the core, which i believe is definately a good design, otherwise any plugin can be an attack surface of the whole node. As to your concern please check #3311.

But this is a good one, will update 3311 to make user able to config as stop the whole node.

@cschuchardt88
Copy link
Member

cschuchardt88 commented Jun 9, 2024

I think I will create a continue sync of state when missing data for ApplicationLog. To pickup the missing state.

}
catch (Exception ex)
{
Utility.Log(nameof(Plugin), LogLevel.Error, ex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem I see is that if you have a plugin that uses states, and it fails, you can have a corrupted chain and still work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, #3311 solve that problem

{
handlerAction(handler);
}
catch (Exception ex) when (handler.Target is Plugin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this when? it's only used for plugins

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, need to check plugin exceptions seperately.

Copy link
Member

@vncoelho vncoelho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about create a branch and merge the other related PRs into this branch we review one by one ?

@Jim8y Jim8y changed the base branch from master to plugin-unhandled-exception June 10, 2024 14:10
@Jim8y Jim8y changed the title [Neo Core] Isolate Plugins Exceptions from the Node. [Neo Core] Part 1. Isolate Plugins Exceptions from the Node. Jun 10, 2024
@Jim8y Jim8y merged commit 89d6ea3 into neo-project:plugin-unhandled-exception Jun 16, 2024
7 checks passed
@Jim8y Jim8y deleted the isolate-plugins branch June 16, 2024 11:24
Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good if #3311 is merged

NGDAdmin added a commit that referenced this pull request Jun 21, 2024
* [Neo Core] Part 1. Isolate Plugins Exceptions from the Node. (#3309)

* catch plugin exceptions.

* add UT test

* udpate format

* make the test  more complete

* complete the ut test

* format

* complete UT tests with NonPlugin case

* async invoke

* Update src/Neo/Ledger/Blockchain.cs

Co-authored-by: Christopher Schuchardt <[email protected]>

---------

Co-authored-by: Christopher Schuchardt <[email protected]>

* [Neo Plugin New feature]  UnhandledExceptionPolicy on Plugin Unhandled Exception (#3311)

* catch plugin exceptions.

* add UT test

* udpate format

* make the test  more complete

* complete the ut test

* format

* complete UT tests with NonPlugin case

* async invoke

* stop plugin on exception

* remove watcher from blockchain if uint test is done to avoid cross test data pollution.

* add missing file

* 3 different policy on handling plugin exception

* add missing file

* fix null warning

* format

* Apply suggestions from code review

Clean

* Update src/Neo/Plugins/PluginSettings.cs

Co-authored-by: Shargon <[email protected]>

* Update src/Neo/Plugins/PluginSettings.cs

Co-authored-by: Christopher Schuchardt <[email protected]>

* Update src/Plugins/TokensTracker/TokensTracker.cs

Co-authored-by: Christopher Schuchardt <[email protected]>

* Update src/Plugins/TokensTracker/TokensTracker.json

---------

Co-authored-by: Shargon <[email protected]>
Co-authored-by: Christopher Schuchardt <[email protected]>

* make the exception message clear

---------

Co-authored-by: Christopher Schuchardt <[email protected]>
Co-authored-by: Shargon <[email protected]>
Co-authored-by: NGD Admin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants