Initial implementation of wallet functionality#33
Initial implementation of wallet functionality#33tnull merged 2 commits intolightningdevkit:mainfrom
Conversation
5264c2a to
cca2687
Compare
71c560d to
a919af3
Compare
|
Now includes a custom |
7d54c61 to
4fd40d8
Compare
a05b1f0 to
35a25ff
Compare
7d7d108 to
c1c43f2
Compare
| 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; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| // 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. |
There was a problem hiding this comment.
Where / how is this enforced?
There was a problem hiding this comment.
This is guaranteed as we're using a Bip84 descriptor template for the BDK wallet, which happens currently in lib.rs.
| fn get_destination_script(&self) -> Script { | ||
| let address = | ||
| self.wallet.get_new_address().expect("Failed to retrieve new address from wallet."); | ||
| address.script_pubkey() | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Are we fine going ahead with the current version, until we decide on some upstream changes and have them implemented?
829eab3 to
876403e
Compare
TheBlueMatt
left a comment
There was a problem hiding this comment.
The new commits on top of #10 look good in isolation.
| } | ||
| } | ||
|
|
||
| pub(crate) fn set_runtime(&self, tokio_runtime: Arc<tokio::runtime::Runtime>) { |
There was a problem hiding this comment.
Curious to see how this works once we get everything landed :)
876403e to
6fe5475
Compare
Uh, rebased. |
| fn get_destination_script(&self) -> Script { | ||
| let address = | ||
| self.wallet.get_new_address().expect("Failed to retrieve new address from wallet."); | ||
| address.script_pubkey() | ||
| } |
There was a problem hiding this comment.
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.
77ce8ce to
bf9bcc2
Compare
a11268a to
4728f13
Compare
|
Squashed without further changes. |
jkczyz
left a comment
There was a problem hiding this comment.
LGTM modulo some minor comments.
| fn get_destination_script(&self) -> Script { | ||
| let address = | ||
| self.wallet.get_new_address().expect("Failed to retrieve new address from wallet."); | ||
| address.script_pubkey() | ||
| } |
This implementation of `KeysInterface` allows to override the shutdown/destination scripts and forwards any other calls to an inner instance of `KeysManager` otherwise.
4728f13 to
97716a4
Compare
|
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 |
…-help-command server: Handle --help command
This PR implements the initial wallet functionality, which was previously included in
access.rs.