Skip to content

Conversation

rustyrussell
Copy link
Contributor

Somehow I dropped this: I had a PR which I decided to split into pieces, and never resubmitted. I was reviewing the milestones for 0.7.1 when I noticed.

Closes: #2483

We generated code which didn't compile (we never had one before though).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Instead of lightningd telling us when it's ready, we ask it.
This also provides an opportunity to have a plugin hook at this point.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
New fields don't have to be spelled out twice.

The raw version are called _only, so we don't miss a call
accidentally.  We can rename them when we finally deprecated old
fields.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Copy link
Contributor

@ZmnSCPxj ZmnSCPxj left a comment

Choose a reason for hiding this comment

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

Minor nit in function arguments.

const char *msatfieldname)
void json_add_amount_msat_compat(struct json_stream *result,
struct amount_msat msat,
const char *rawfieldname,
Copy link
Contributor

Choose a reason for hiding this comment

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

Other json_add_* functions have field names before the value being printed.
Mildly suggest, to follow other functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd agree, but it's a lot of churn for a function we're going to phase out, so I think it's a bit gratuitous for now.

Copy link
Collaborator

@m-schmoock m-schmoock left a comment

Choose a reason for hiding this comment

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

I like really it. As ususal, well structured, testcase, doc..
I didn't finish my implementation it as I noticed you already worked on this last month (#2576 (comment))....

Here my remarks:

  • If possible add the remote routing fees to the payload
  • msat/sat fieldname/parameter name confusions everywhere, maybe I misunderstood the _compat function?

struct amount_msat max_htlc_value_in_flight_msat;
struct amount_sat channel_reserve_satoshis;
struct amount_msat htlc_minimum_msat;
u32 feerate_per_kw;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we already know remote routing fees (base, ppm) here? If yes, we should add it to payload so plugin knows...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we don't ever get told those directly; we learn them like everyone else, when/if it advertizes the channel.

doc/PLUGINS.md Outdated
"max_htlc_value_in_flight_msat": "18446744073709551615msat",
"channel_reserve_satoshis": "1000000msat",
"htlc_minimum_msat": "0msat",
"feerate_per_kw": 7500
Copy link
Collaborator

Choose a reason for hiding this comment

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

missing comma end of line :-)

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, and there's a trailing one on the last line, which isn't valid JSON either. Fixed!

void json_add_amount_sat_compat(struct json_stream *result UNNEEDED,
struct amount_sat sat UNNEEDED,
const char *rawfieldname UNNEEDED,
const char *msatfieldname)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you are already touching this line, rename msatfieldname to satfieldname

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, these are always msat fields, since we unified on that as standard.

void json_add_amount_sat_compat(struct json_stream *result UNNEEDED,
struct amount_sat sat UNNEEDED,
const char *rawfieldname UNNEEDED,
const char *msatfieldname)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here, rename to satfieldname

json_add_amount_sat(response, utxos[i]->amount,
"value", "amount_msat");
json_add_amount_sat_compat(response, utxos[i]->amount,
"value", "amount_msat");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I'm off here, but isn't that supposte to be called amount_sat?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No... we always print amounts as msat now, to avoid confusion.

void json_add_amount_sat_compat(struct json_stream *result,
struct amount_sat sat,
const char *rawfieldname,
const char *msatfieldname)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be satfieldname?

}

void json_add_amount_sat_only(struct json_stream *result,
const char *msatfieldname,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here too?

"our_amount_msat");
json_add_amount_sat_compat(response, c->funding,
"channel_total_sat",
"amount_msat");
Copy link
Collaborator

Choose a reason for hiding this comment

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

... same here in line 512 and 515, since this msat/sat is mixed up everywhere, maybe its just me??


@plugin.hook('openchannel')
def on_openchannel(openchannel, plugin):
print("{} VARS".format(len(openchannel.keys())))
Copy link
Member

Choose a reason for hiding this comment

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

You could just include from pprint import pprint which recursively prettyprints whatever you pass to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't work as well due to undefined ordering, however, and the fact that it prints "{" and "}":

b"2019-05-20T22:47:55.079Z plugin-reject_odd_funding_amounts.py {'channel_flags': 1,"
b"2019-05-20T22:47:55.079Z plugin-reject_odd_funding_amounts.py  'channel_reserve_satoshis': '1000000msat',"
b"2019-05-20T22:47:55.079Z plugin-reject_odd_funding_amounts.py  'dust_limit_satoshis': '546000msat',"
b"2019-05-20T22:47:55.079Z plugin-reject_odd_funding_amounts.py  'feerate_per_kw': 7500,"

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
@rustyrussell rustyrussell force-pushed the guilt/channel-fund-hook branch from 54b583d to 2abc7e7 Compare May 20, 2019 22:56
@niftynei
Copy link
Collaborator

ACK 2abc7e7

@niftynei niftynei merged commit e5b5f1d into ElementsProject:master May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

There should be a hook for accepting channel opens
5 participants