Skip to content

Initial implementation of wallet functionality #33

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

Merged
merged 2 commits into from
Jan 27, 2023

Conversation

tnull
Copy link
Collaborator

@tnull tnull commented Nov 24, 2022

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

@tnull tnull force-pushed the 2022-11-initial-wallet branch 2 times, most recently from 5264c2a to cca2687 Compare November 30, 2022 12:02
@tnull tnull force-pushed the 2022-11-initial-wallet branch from 71c560d to a919af3 Compare December 15, 2022 11:28
@tnull
Copy link
Collaborator Author

tnull commented Dec 15, 2022

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 tnull force-pushed the 2022-11-initial-wallet branch 3 times, most recently from 7d54c61 to 4fd40d8 Compare December 16, 2022 17:02
@tnull tnull force-pushed the 2022-11-initial-wallet branch 2 times, most recently from a05b1f0 to 35a25ff Compare December 19, 2022 10:38
@tnull tnull requested review from jkczyz and TheBlueMatt January 4, 2023 12:52
@tnull tnull force-pushed the 2022-11-initial-wallet branch 2 times, most recently from 7d7d108 to c1c43f2 Compare January 11, 2023 09:46
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
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.

Copy link
Collaborator Author

@tnull tnull Jan 16, 2023

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.

src/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
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?

Copy link
Collaborator Author

@tnull tnull Jan 17, 2023

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 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
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.

Copy link
Collaborator Author

@tnull tnull Jan 16, 2023

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.

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
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
Collaborator Author

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
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 tnull force-pushed the 2022-11-initial-wallet branch 2 times, most recently from 829eab3 to 876403e Compare January 16, 2023 15:34
Copy link

@TheBlueMatt TheBlueMatt left a comment

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.

}
}

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

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 tnull force-pushed the 2022-11-initial-wallet branch from 876403e to 6fe5475 Compare January 16, 2023 22:24
@tnull
Copy link
Collaborator Author

tnull commented Jan 16, 2023

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

Uh, rebased.

@tnull tnull requested a review from jkczyz January 17, 2023 17:09
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
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 tnull force-pushed the 2022-11-initial-wallet branch 4 times, most recently from 77ce8ce to bf9bcc2 Compare January 17, 2023 22:48
@tnull tnull force-pushed the 2022-11-initial-wallet branch from a11268a to 4728f13 Compare January 26, 2023 22:22
@tnull
Copy link
Collaborator Author

tnull commented Jan 26, 2023

Squashed without further changes.

@tnull tnull requested a review from jkczyz January 26, 2023 22:23
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 modulo some minor comments.

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
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 added 2 commits January 27, 2023 08:57
This implementation of `KeysInterface` allows to override the
shutdown/destination scripts and forwards any other calls to an inner
instance of `KeysManager` otherwise.
@tnull tnull force-pushed the 2022-11-initial-wallet branch from 4728f13 to 97716a4 Compare January 27, 2023 14:57
@tnull
Copy link
Collaborator Author

tnull commented Jan 27, 2023

Squashed again with the following changes:

> git diff-tree -U2 4728f13 97716a4
diff --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:main Jan 27, 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.

4 participants