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

Allow for withdrawing on-chain funds #61

Merged
merged 1 commit into from
Apr 26, 2023

Conversation

tnull
Copy link
Collaborator

@tnull tnull commented Apr 4, 2023

Based on #13, fixes #58.

Previously we only exposed methods to generate new addresses, retrieve
the balance, and fund channels. Here, we fix the oversight and allow
users to actually withdraw their funds again.

We also rename some API methods for consistent use of the term onchain.

This was referenced Apr 4, 2023
@tnull tnull added this to the 0.1 milestone Apr 4, 2023
@@ -208,6 +208,60 @@ where
Ok(self.inner.lock().unwrap().get_balance()?)
}

pub(crate) fn send_to_address(
Copy link

Choose a reason for hiding this comment

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

Perhaps it is better to allow pass an optional fee rate?
Also a lightning node user would probably want to send all the onchain funds (empty the wallet) so perhaps this use case should be taken into account when exposing this ability at the Node level.

Copy link
Collaborator Author

@tnull tnull Apr 4, 2023

Choose a reason for hiding this comment

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

Perhaps it is better to allow pass an optional fee rate?

We likely don't want to expose all the complexity of on-chain fee estimation to the user, but provide sane defaults, otherwise we'll end up replicating more and more of BDK/LDK APIs. We could consider letting them set a specific ConfirmationTarget, but I'm not fully convinced that we want to complicate the API that far here. That said, we probably should provide a config knob allowing to bound the fee rate (for all on-chain operations) eventually, which is tracked here: #55

Also a lightning node user would probably want to send all the onchain funds (empty the wallet) so perhaps this use case should be taken into account when exposing this ability at the Node level.

Ah, good idea. I now added a withdraw_all method (and renamed send_onchain_payment to withdraw for consistency).

@tnull tnull changed the title Allow for spending on-chain funds Allow for withdrawing on-chain funds Apr 4, 2023
@tnull tnull force-pushed the 2023-04-allow-onchain-spending branch from d5c5e01 to 4ca987c Compare April 7, 2023 08:12
@tnull tnull force-pushed the 2023-04-allow-onchain-spending branch from 4ca987c to 76070f9 Compare April 17, 2023 18:28
@tnull
Copy link
Collaborator Author

tnull commented Apr 17, 2023

Rebased after #13 has been merged.

@tnull tnull force-pushed the 2023-04-allow-onchain-spending branch from 64c4f18 to 7f128d9 Compare April 20, 2023 13:00
@tnull tnull force-pushed the 2023-04-allow-onchain-spending branch from 7f128d9 to fde2fe9 Compare April 25, 2023 08:56
@tnull
Copy link
Collaborator Author

tnull commented Apr 25, 2023

Rebased on main.

self.wallet.get_balance()
}

/// Send an on-chain payment to the given address.
pub fn send_to_onchain_address(
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why we don't expose the wallet? Something to do with the runtime?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think there are a number of reasons. For example I'd really like to keep the main API centered around a single Node object, at least as long as that is still feasible. We hopefully never get to a place where the API surface is getting unfeasibly large for a single object. If it does this might rather act as a canary that we should refactor it into something more minimal rather than breaking out individual objects.

Additionally, it's tbd how and what additional wallet behavior we will/should expose to give users more flexibility. Post-0.1 we might think about offering a wallet interface to allow users to bring their own implementation, which I'm however still not convinced of, as this might as well be quite a footgun. However, if we were to go this route, the exposed API also needs to be separate from the concrete wallet implementation. We'll see..

src/wallet.rs Outdated
Ok(txid)
}

pub(crate) fn drain_to_address(&self, address: &bitcoin::Address) -> Result<Txid, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we dry this up by delegating to send_to_address or I suppose some common helper taking Option<u64> for the amount?

Copy link
Collaborator Author

@tnull tnull Apr 26, 2023

Choose a reason for hiding this comment

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

The former is unfortunately not possible, as we won't ever get the amount right, which is exactly the use case of drain_to_address. However I now DRYed it up into a single method taking an amount_msat_or_drain: Option<u64>.

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

LGTM. Please squash.

Previously we only exposed methods to generate new addresses, retrieve
the balance, and fund channels. Here, we fix the oversight and allow
users to actually withdraw their funds again.

We also rename some API methods for consistency of the term `onchain`.
@tnull tnull force-pushed the 2023-04-allow-onchain-spending branch from 0690996 to 1f3dfa8 Compare April 26, 2023 15:33
@tnull
Copy link
Collaborator Author

tnull commented Apr 26, 2023

Squashed without further changes.

@tnull tnull merged commit 1895a84 into lightningdevkit:main Apr 26, 2023
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.

Missing onchain operations
3 participants