Skip to content

Move max funding and payment values to chainparams#1842

Closed
bisoge wants to merge 5 commits intoElementsProject:masterfrom
bisoge:chainparams
Closed

Move max funding and payment values to chainparams#1842
bisoge wants to merge 5 commits intoElementsProject:masterfrom
bisoge:chainparams

Conversation

@bisoge
Copy link
Contributor

@bisoge bisoge commented Aug 14, 2018

For Litecoin use 60x BTC values to stay consistent with lnd.
Also enforces chain hash values are known to receiver.


add_err = channel_add_htlc(peer->channel, REMOTE, id, amount_msat,
add_err = channel_add_htlc(peer->channel, &peer->chain_hash,
REMOTE, id, amount_msat,
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer to hand in the struct chainparams here, and fail at channeld init if we don't know it. Doing the lookup is not really add_htlc's job, IMHO.

*...
* - MUST set `funding_satoshis` to less than 2^24 satoshi.
*/
#define MAX_FUNDING_SATOSHI ((1 << 24) - 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I dislike removing spec quotes (our build checks they're valid, so if spec changes we know where to fix): can we move this into chainparams.c, and then use this value there?

master_badmsg(WIRE_CHANNEL_OFFER_HTLC, inmsg);

e = channel_add_htlc(peer->channel, LOCAL, peer->htlc_id,
e = channel_add_htlc(peer->channel, &peer->chain_hash,
Copy link
Member

Choose a reason for hiding this comment

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

See @rustyrussell's comment above

failmsg = tal_fmt(inmsg, "Too many HTLCs");
goto failed;
case CHANNEL_ERR_UNKNOWN_CHAIN_HASH:
failcode = WIRE_REQUIRED_CHANNEL_FEATURE_MISSING;
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure this is not the correct failcode for an unsupported blockchain.

assert(channel_add_htlc(channel, sender, 1337, msatoshi, 900, &rhash,
dummy_routing, NULL) == CHANNEL_ERR_ADD_OK);
assert(channel_add_htlc(channel,
&chainparams_by_index(0)->genesis_blockhash,
Copy link
Member

Choose a reason for hiding this comment

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

This index needs to be pulled out into a #define or a named const.

*...
* - the chain_hash value is set to a hash of a chain that is unknown
* to the receiver.
*/
Copy link
Member

Choose a reason for hiding this comment

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

Why was this removed? This is perfectly reasonable and blockchain agnostic.

Copy link
Member

@cdecker cdecker left a comment

Choose a reason for hiding this comment

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

The BOLT quotes need to be re-enabled and the magic constants for blockchain 0 need to be extracted into named defines or consts.

@bisoge
Copy link
Contributor Author

bisoge commented Aug 22, 2018

Thanks for the reviews, I believe all the requested changes are addressed.

I ended up adding the chain params to the peer struct, not totally necessary but makes the code simpler. If you would prefer to keep them out of the struct they can always be looked up on demand based on genesis blockhash.

For the test I just switched to a lookup by name instead of using the magic number. If that is not clear enough I can still add a define somewhere.

Finally I was able to restore the BOLT quote and pass the source check. I am not sure why based on the text in the RFC (possibly a bug with check-bolt?), but it wants to match:
"The receiver: - if the chain_hash value, within the open_channel, message is set to a hash of a chain that is unknown to the receiver: - MUST reject the channel."

Copy link
Member

@cdecker cdecker left a comment

Choose a reason for hiding this comment

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

There is really no reason to do the chain_hash check in the add_htlc method at all, so why are we passing that info down, just to fail if something isn't right (which should never happen)?

* - the chain_hash value is set to a hash of a chain that is unknown
* to the receiver.
*/
const struct chainparams *chain_params = chainparams_by_hash(chain_hash);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand why this is being checked here at all. The chain_hash is channel-specific, and the chain is implicitly communicated through the channel that is being updated, so we should not be passing this down here at all.

@cdecker
Copy link
Member

cdecker commented Sep 6, 2018

I proposed #1913 as a replacement for this change.

@bisoge
Copy link
Contributor Author

bisoge commented Sep 8, 2018

@cdecker , agree that adding chainparams to channel struct as done in #1913 is a simpler approach.
Okay with closing this, thanks.

@cdecker cdecker closed this Sep 9, 2018
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