Skip to content

Initial implementation of wallet functionality - #33

Merged
tnull merged 2 commits into
lightningdevkit:mainfrom
tnull:2022-11-initial-wallet
Jan 27, 2023
Merged

Initial implementation of wallet functionality#33
tnull merged 2 commits into
lightningdevkit:mainfrom
tnull:2022-11-initial-wallet

Conversation

@tnull

Copy link
Copy Markdown
Collaborator

This PR implements the initial wallet functionality, which was previously included in access.rs.

@tnull
tnullforce-pushed the 2022-11-initial-wallet branch 2 times, most recently from 5264c2a to cca2687CompareNovember 30, 2022 12:02
@tnull
tnullforce-pushed the 2022-11-initial-wallet branch from 71c560d to a919af3CompareDecember 15, 2022 11:28
@tnull

Copy link
Copy Markdown
CollaboratorAuthor

Now includes a custom KeysInterface implementation that overrides the shutdown/destination scripts so that they immediately show up in the BDK wallet after closing/claiming on-chain.

@tnull
tnullforce-pushed the 2022-11-initial-wallet branch 3 times, most recently from 7d54c61 to 4fd40d8CompareDecember 16, 2022 17:02
Comment threadsrc/wallet.rs Outdated
@tnull
tnullforce-pushed the 2022-11-initial-wallet branch 2 times, most recently from a05b1f0 to 35a25ffCompareDecember 19, 2022 10:38
@tnull
tnullforce-pushed the 2022-11-initial-wallet branch 2 times, most recently from 7d7d108 to c1c43f2CompareJanuary 11, 2023 09:46
Comment threadsrc/wallet.rs Outdated
Comment threadsrc/wallet.rs
Comment on lines +58 to +84
pub(crate) fn set_runtime(&self, tokio_runtime: Arc<tokio::runtime::Runtime>) {
*self.tokio_runtime.write().unwrap() = Some(tokio_runtime);
}

pub(crate) fn drop_runtime(&self) {
*self.tokio_runtime.write().unwrap() = None;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure how well this fits into the larger picture -- but related to #10 (comment) -- another approach to avoid these may be to have any functions needing a runtime take it as a parameter. For sync traits, implement them on something like (Wallet<D>, Arc<tokio::runtime::Runtime>) if the implementation needs to call those functions.

@tnulltnullJan 16, 2023

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Unfortunately the latter wouldn't work I think, as we need to give the BroadcasterInterface / FeeEstimator impls to ChannelManager and ChainMonitor. However, as we want to make parameters of them and/or Wallet configurable (e.g., wallet entropy source, Filter impl) based on chain data source, etc., we'd need to instantiate these in the Builder, where we do however not have access to a tokio runtime.

Comment threadsrc/wallet.rs Outdated
Comment threadsrc/wallet.rs Outdated
Comment on lines +87 to +142
// We double-check that no inputs try to spend non-witness outputs. As we use a SegWit
// wallet descriptor this technically shouldn't ever happen, but better safe than sorry.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where / how is this enforced?

@tnulltnullJan 17, 2023

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

This is guaranteed as we're using a Bip84 descriptor template for the BDK wallet, which happens currently in lib.rs.

Comment threadsrc/wallet.rs Outdated
Comment threadsrc/wallet.rs
Comment threadsrc/wallet.rs
Comment on lines +333 to +326
fn get_destination_script(&self) -> Script {
let address =
self.wallet.get_new_address().expect("Failed to retrieve new address from wallet.");
address.script_pubkey()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wish there were a better way of doing this without needing all the boilerplate to override / delegate. Wonder if we should think about parameterizing KeysManager in some way to make this simpler.

@tnulltnullJan 16, 2023

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Yes, I'm not a fan of this solution either, also because we now have an redundant unused key in KeysManager, which could be used directly by any future code change. I'd be +1 to introducing some upstream changes to let us override that key.
However, last time I spoke to @TheBlueMatt about the matter he thought the current solution would be the cleanest way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yea, if we're trying to wrap an inner there's not much else we can do. If we wanted to drop the boilerplate we could have expose the KeysManager to the user and have them use that when they need a NodeSigner/EntropySource, but that's maybe even worse.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like you could parameterize KeysManager with a strategy for generating the scripts. Either from keys derived from the seed or from some other wallet. Then you wouldn't wrap at all but rather have Wallet implement a trait that this new parameter is bounded by.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Are we fine going ahead with the current version, until we decide on some upstream changes and have them implemented?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, that's fine by me.

@tnull
tnullforce-pushed the 2022-11-initial-wallet branch 2 times, most recently from 829eab3 to 876403eCompareJanuary 16, 2023 15:34

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new commits on top of #10 look good in isolation.

Comment threadsrc/wallet.rs
}
}

pub(crate) fn set_runtime(&self, tokio_runtime: Arc<tokio::runtime::Runtime>) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Curious to see how this works once we get everything landed :)

@tnull
tnullforce-pushed the 2022-11-initial-wallet branch from 876403e to 6fe5475CompareJanuary 16, 2023 22:24
@tnull

Copy link
Copy Markdown
CollaboratorAuthor

The new commits on top of #10 look good in isolation.

Uh, rebased.

@tnull
tnull requested a review from jkczyzJanuary 17, 2023 17:09
Comment threadsrc/wallet.rs Outdated
Comment threadsrc/wallet.rs
Comment on lines +333 to +326
fn get_destination_script(&self) -> Script {
let address =
self.wallet.get_new_address().expect("Failed to retrieve new address from wallet.");
address.script_pubkey()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like you could parameterize KeysManager with a strategy for generating the scripts. Either from keys derived from the seed or from some other wallet. Then you wouldn't wrap at all but rather have Wallet implement a trait that this new parameter is bounded by.

@tnull
tnullforce-pushed the 2022-11-initial-wallet branch 4 times, most recently from 77ce8ce to bf9bcc2CompareJanuary 17, 2023 22:48
@tnull
tnullforce-pushed the 2022-11-initial-wallet branch from a11268a to 4728f13CompareJanuary 26, 2023 22:22
@tnull

Copy link
Copy Markdown
CollaboratorAuthor

Squashed without further changes.

@tnull
tnull requested a review from jkczyzJanuary 26, 2023 22:23

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM modulo some minor comments.

Comment threadsrc/wallet.rs
Comment on lines +333 to +326
fn get_destination_script(&self) -> Script {
let address =
self.wallet.get_new_address().expect("Failed to retrieve new address from wallet.");
address.script_pubkey()
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, that's fine by me.

Comment threadsrc/wallet.rs Outdated
Comment threadsrc/wallet.rs
This implementation of `KeysInterface` allows to override the
shutdown/destination scripts and forwards any other calls to an inner
instance of `KeysManager` otherwise.
@tnull
tnullforce-pushed the 2022-11-initial-wallet branch from 4728f13 to 97716a4CompareJanuary 27, 2023 14:57
@tnull

Copy link
Copy Markdown
CollaboratorAuthor

Squashed again with the following changes:

> git diff-tree -U2 4728f13 97716a4diff --git a/src/wallet.rs b/src/wallet.rs
index 598d627..dab6cdc 100644
--- a/src/wallet.rs+++ b/src/wallet.rs@@ -111,5 +111,10 @@ where
}
Err(e) => {
- log_error!(self.logger, "Failed to update fee rate estimation: {}", e);+ log_error!(+ self.logger,+ "Failed to update fee rate estimation for {:?}: {}",+ target,+ e+ );
}
}
@@ -223,5 +228,5 @@ where
D: BatchDatabase,
{
- /// Constructs a `WalletKeysManager` that+ /// Constructs a `WalletKeysManager` that overrides the destination and shutdown scripts.
///
/// See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and

@tnull
tnull merged commit adfdc24 into lightningdevkit:mainJan 27, 2023
Comment threadsrc/wallet.rs
joostjager pushed a commit to joostjager/ldk-node that referenced this pull request Jan 28, 2026
Sign up for freeto 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.

4 participants

@tnull@TheBlueMatt@jkczyz@wpaulino