lightning
lightning copied to clipboard
Fix CLN service startup failure by trimming trailing spaces in config parameters
fixes #7132
I would really appreciate some friendly feedback on this, as it is my first PR to the project and I might have misunderstood or missed important details.
~~I did find a similar function strip_trailing_whitespace in plugins/bcli.c, but from what I understand, having void trim_trailing_spaces(char *str); in ccan would still be beneficial, right?~~
I was wondering if it is possible move this
trimfunction inside tal string https://github.com/rustyrussell/ccan/blob/master/ccan/tal/str/str.h
Do you mean to also change the function to use tal for allocating memory for the lines then? I thought it was not necessary since they were already allocated, but I can of course fix that if it is desirable. @vincenzopalazzo
Do you mean to also change the function to use tal for allocating memory for the lines then?
No I mean to have like tal_strtrim or strtrim (not in tal), at the end of the day your code is implementing a subset of functionality to trim an origin string.
Pardon me, but I don't fully understand what you mean. Could you elaborate on your suggestion? To my understanding, the tal functions you are linking to, @vincenzopalazzo , relate to string functions involving memory allocation. If I were to implement tal_strtrim(), from my experience, those implementations remove spaces from the beginning and end and allocate a new string. Is that what you are aiming for here? The current placement of the function trim_trailing_spaces() in ccan/ccan/str/str.c made sense to me because it manipulates an already allocated string.
Like I said at the beginning, I am new here and would appreciate a more thorough explanation if you have time for that.
Thanks for the comment @endothermicdev, I'll start doing a strtrim function in tal tomorrow if you both think that is more useful then 👍
@vincenzopalazzo & @endothermicdev , I've now changed to using tal_strtrim, is this what you had in mind?
@endothermicdev I am having some issues with tests on my local machine using tal_resize like this.
Is there anything in the way I am using it now, that you can see, is not working like it should? I get some out of memory errors from within the tal_resize() on my machine but the tests seems to run fine here in github-actions...
I am working on writing a test for it that I will push with the PR.
The local test I have tried is to add a space after a config varible in the startup_regtest.sh file and then sourced it and start_ln 2.
If someone could have a look at the pytest and tell me if something is wrong in it, that would be appreciated.
Hi @maxrantil sorry this has been so long before I review!
The concept is great, the implementation needs some work though.
There are a few config options where we don't want to trim whitespace. In particular, log-prefix, and alias but you could also argue for things that take paths, such log-file, lightning-dir, pid-file ,conf etc. But I'm happy to just stick with log-prefix and alias.
- This implies that we should add a new flag, OPT_KEEP_WHITESPACE in common/configvar.h, and trim cv->optarg in common/configvar.c before calling
return ot->cb_arg(cv->optarg, ot->u.arg);unless(ot->type & OPT_KEEP_WHITESPACE). - Add this flag to those options which need to preserve whitespace.
- Trimming whitespace is trivial, you should simply do it by replacing the final space with a NUL terminator:
while (strlen(s) != 0 && cisspace(s[strlen(s)-1])
s[strlen(s)-1] = '\0';
- We should note in doc/lightningd-config.5.md: "Because it's a common error, we automatically trim whitespace from the end of most configuration options. Exceptions are noted below". And then note it in alias and log-prefix, and any others you do it to.
Thanks!
Hi @rustyrussell , Thanks for the feedback! I didn't notice the review until now but I will get into it asap.
@rustyrussell or @endothermicdev , do you find it acceptable to manipulate a const char * with memmove() like I do in the trimming func??
Given how close we are to rc1, I simply added a commit with various cleanups. Thanks for this work!
That's fine @rustyrussell ! I learned some new things from studying your changes.
I'm not sure how to fix the error in the test that is failing now, tho.
THose issues were from master, fortunately!
Is there any chance of getting the sphinx bounty of 100k sats for this? 😊 I can't get Sphinx Chat to work with Core lightning on my umbrel node. Is there another way to get the payout if i am eligible for it?
DM sent to @max54302324