Skip to content

Conversation

@Alex-CodeLab
Copy link
Contributor

@Alex-CodeLab Alex-CodeLab commented Feb 12, 2020

This plugin starts a minimal, rate limited HTTP Server and returns a invoice.

@darosior
Copy link
Member

Unrelated Travis error, I think #91 fixes that...

Could you add a basic test just to make sure we don't break your plugin's commands upstream ?

@darosior
Copy link
Member

You need to make your plugin executable... Did you test locally ?

pyln.client.lightning.RpcError: RPC call failed: method: plugin, payload: {'subcommand': 'start', 'plugin': '/home/travis/build/lightningd/plugins/request-invoice/requestinvoice.py'}, error: {'code': -32602, 'message': '/home/travis/build/lightningd/plugins/request-invoice/requestinvoice.py is not executable: Permission denied'}

@codecov
Copy link

codecov bot commented Feb 16, 2020

Codecov Report

Merging #90 into master will increase coverage by 0.18%.
The diff coverage is 57.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #90      +/-   ##
==========================================
+ Coverage   52.46%   52.65%   +0.18%     
==========================================
  Files          17       18       +1     
  Lines        1984     2053      +69     
==========================================
+ Hits         1041     1081      +40     
- Misses        943      972      +29     
Impacted Files Coverage Δ
request-invoice/requestinvoice.py 57.97% <57.97%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 279a4e8...1bbedc7. Read the comment docs.

README.md Outdated
[js-api]: https://github.com/darosior/clightningjs
[monitor]: https://github.com/renepickhardt/plugins/tree/master/monitor
[reckless]: https://github.com/darosior/reckless
[request-invoice]: https://github.com/Alex-CodeLab/plugins/tree/master/request-invoice
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably link to the local directory, since the code is here as well 😉

Suggested change
[request-invoice]: https://github.com/Alex-CodeLab/plugins/tree/master/request-invoice
[request-invoice]: https://github.com/lightningd/plugins/tree/master/request-invoice

limiter = Limiter(
app,
key_func=get_remote_address,
default_limits=["200 per day", "50 per hour"]
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the flask-limiter docs this is per IP address, correct?

def getinvoice(amount, description):
global plugin
label = "ln-getinvoice-{}".format(random())
invoice = plugin.rpc.invoice(int(amount)*1000, label, description)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you skip this multiplication you could potentially use things like 1msat or 0.01btc which might be a nicer interface.

We could go one step further and add fiat denominated amounts, and use an exchange rate to convert that into something that c-lightning understands.

@limiter.limit("20 per minute")
def getinvoice(amount, description):
global plugin
label = "ln-getinvoice-{}".format(random())
Copy link
Contributor

Choose a reason for hiding this comment

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

Using random here might cause collisions. Maybe we can use the plugin startup time and a monotonic counter? Or if you want to stick with random labels you could use the uuid module.



# change this
secret= 'caba27ba-45c7-4495-aa53-fd6a5866fbd8'
Copy link
Contributor

Choose a reason for hiding this comment

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

Better grab this from an environment variable, or make it a command line option. Otherwise changing the secret means having to change the source code.

Comment on lines 85 to 87
# if command unknown make start our default command
if command not in commands:
command = "start"
Copy link
Contributor

Choose a reason for hiding this comment

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

This kind of clobbering the command if unknown may be strange. For example if I call invoiceserver STOP 1234 it'd start a new one, because the subcommand is not in the list. Better to return an error here.

Comment on lines 90 to 93
try:
port = int(port)
except:
port = int(plugin.options['invoice-web-port']['value'])
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also rather unexpected, why not just return an error message telling the user that this is not a valid port number?

Comment on lines 52 to 54
if port in jobs:
return False, "server already running"
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is duplicated in the invoiceserver RPC method.


if command == "stop":
if stop_server(port):
return "stopped server on port{}".format(port)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return "stopped server on port{}".format(port)
return "stopped server on port {}".format(port)

Comment on lines 41 to 42
full_path = "python3 " + plugin_path
check_output(["pkill","-f", full_path])
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that's going to be a problem. Hence my suggestion of using threading.Thread() instead of multiprocessing.Process().

@lightningd lightningd deleted a comment from codecov bot Jun 15, 2020
@codecov
Copy link

codecov bot commented Jun 15, 2020

Codecov Report

Merging #90 into master will increase coverage by 0.01%.
The diff coverage is 57.97%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #90      +/-   ##
==========================================
+ Coverage   57.32%   57.34%   +0.01%     
==========================================
  Files          22       23       +1     
  Lines        2580     2649      +69     
==========================================
+ Hits         1479     1519      +40     
- Misses       1101     1130      +29     
Impacted Files Coverage Δ
request-invoice/requestinvoice.py 57.97% <57.97%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd1459a...ce16539. Read the comment docs.

@Alex-CodeLab
Copy link
Contributor Author

care to explain?

@cdecker cdecker reopened this Sep 5, 2020
@cdecker
Copy link
Contributor

cdecker commented Sep 5, 2020

My bad, I misinterpreted this as being a stale PR, and closed it prematurely. I'll review and merge if appropriate.

@darosior
Copy link
Member

Hi @Alex-CodeLab , what's the state of this ?

@Alex-CodeLab
Copy link
Contributor Author

@hi Daroior
I think it is ready since last summer.
(it is active on my node for months without issues.)

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.

3 participants