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

pyln: Add safe fallback results for hooks #4031

Merged
merged 2 commits into from
Sep 10, 2020

Conversation

cdecker
Copy link
Member

@cdecker cdecker commented Sep 9, 2020

Hooks do not tolerate failures at all. If we return a JSON-RPC error to a hook
call the only thing the main daemon can really do is to crash. This commit
adds a mapping of error to a safe fallback result, including a warning to the
node operator that this should be addressed in the plugin. The warning is
reported as a **BROKEN** message, and should therefore fail any testing done
on the plugin.

The alternatives would have been

  • Allow plugins to return errors on hook calls, requiring a similar mapping inside lightningd. But I don't like relaxing the requirements on this. It feels magic enough as it is, but prevents us from accidentally hanging due to a plugin.
  • Killing the plugin outright, which is basically just going to use the default action, which in case of security related hooks is bad.

Fixes #3748

Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

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

ACK b7e3829

'/home/travis/build/ElementsProject/lightning/tests/plugins/htlc_accepted-crash.py': opening pipe: No such file or directory

Looks like you forgot to check in htlc_accepted-crash.py

tests/test_plugin.py Outdated Show resolved Hide resolved
r'Hook handler for htlc_accepted failed with an exception.'
)

with pytest.raises(RpcError, match=r'failed: WIRE_TEMPORARY_NODE_FAILURE'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we also test for one of the 'non-recoverable' hooks, db_write or commitment_revocation

Copy link
Member Author

@cdecker cdecker Sep 9, 2020

Choose a reason for hiding this comment

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

I'll look into it, the semantics are a bit different though (db_write hangs indefinitely for example).

Hooks do not tolerate failures at all. If we return a JSON-RPC error to a hook
call the only thing the main daemon can really do is to crash. This commit
adds a mapping of error to a safe fallback result, including a warning to the
node operator that this should be addressed in the plugin. The warning is
reported as a `**BROKEN**` message, and should therefore fail any testing done
on the plugin.

Changelog-Fixed: pyln: Fixed HTLCs hanging indefinitely if the hook function raises an exception. A safe fallback result is now returned instead.
@cdecker
Copy link
Member Author

cdecker commented Sep 9, 2020

ACK b7e3829

'/home/travis/build/ElementsProject/lightning/tests/plugins/htlc_accepted-crash.py': opening pipe: No such file or directory

Looks like you forgot to check in htlc_accepted-crash.py

Good catch, fixed up :-)

@rustyrussell
Copy link
Contributor

Ack 7f0db34

@rustyrussell rustyrussell merged commit bd811fb into ElementsProject:master Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pyln-client plugin: Exception in htlc_accepted hook handler causes payment to hang indefinitely
3 participants