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

loopd: don't fail external loop in on fee estimation failure #86

Merged
merged 4 commits into from
Oct 3, 2019

Conversation

guggero
Copy link
Member

@guggero guggero commented Sep 20, 2019

In the LoopInQuote function of client.go an on-chain fee estimation for paying the HTLC is done by calling EstimateFeeToP2WSH on lnd.
This fails in case the lnd wallet has no UTXOs left to construct an estimation transaction with.
For an internal loop in, this can be seen as a hard failure and the swap can't continue.
For an external loop however, it doesn't matter that the lnd wallet has no funds. So we just warn about not being able to estimate the on-chain fee.

Fixes #84

I'm not too happy about sending back an error as a string. The two operations (getting a swap fee quote from the swap server and doing the on-chain fee estimation in lnd) would ideally be separate calls so the client could handle the distinct errors. But this would be a bigger refactor. Open to suggestions here.

Note: The large diff in the looprpc package is mainly due to #74 which was probably generated with a wrong version of github.com/grpc-ecosystem/grpc-gateway. It also included some manual changes in the client.swagger.json that are overwritten when generating again. This can also go into a separate PR if it's too big for this bugfix.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Solid fix! Main comment is that I think we can just use a regular error here, and have that be threaded all the way back through the client (CLI).

looprpc/client.proto Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
@@ -67,6 +67,21 @@ func loopIn(ctx *cli.Context) error {
}

limits := getInLimits(amt, quote)
external := ctx.Bool("external")

// There could have been an error in the on-chain fee estimation if
Copy link
Member

Choose a reason for hiding this comment

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

Following from my last comment, we can use Is/As here instead and gate the warning or exit based on that.

XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
MinerFee int64 `protobuf:"varint,3,opt,name=miner_fee,json=minerFee,proto3" json:"miner_fee,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This regeneration with the correct version of the proto tools, can it be a separate commit?

/**
If an error happens during on-chain fee estimation in lnd, this contains
the error. The client should decide if it's ok to continue (i.e. external
loop in) or not.
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering what the user expects in a quote response when the intention is to use an external address. A zero miner fee? Or a happy case fee (1 inputs, 1 htlc out, 1 change out)?

How about passing in an external bool to the quote request to skip the lnd wallet fee estimation? It makes it all a bit more transparent. Returning an error sometimes for an external funded swap quote may be confusing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea! I like that much more than passing an error back.
I wasn't sure if it was OK to just skip the fee estimation completely on an external swap in.

@guggero
Copy link
Member Author

guggero commented Sep 23, 2019

I did look into returning an error in the response message directly. I haven't found anything useful, it looks like there is no error primitive in protobuf corresponding to a golang error. We could have used numeric error codes. Or send some additional data in the GRPC error body and then parse that in the client (to still get the swap fee that was calculated).

But I like Joost's suggestion much more to just skip on-chain fee estimation completely for an external loop in.

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 🚤

@alexbosworth alexbosworth merged commit 0e09677 into lightninglabs:master Oct 3, 2019
@guggero guggero deleted the external-loop-in-fee-est branch October 4, 2019 06:28
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.

loop in external doesn't work if there's no onchain funds
4 participants