-
Notifications
You must be signed in to change notification settings - Fork 45
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
Bump to BDK alpha 10 #526
Bump to BDK alpha 10 #526
Conversation
WalkthroughThe updates across the Changes
Recent Review DetailsConfiguration used: CodeRabbit UI Files selected for processing (10)
Files skipped from review as they are similar to previous changes (10)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
use crate::types::AddressInfo; | ||
use crate::types::Balance; | ||
use crate::types::CanonicalTx; | ||
use crate::types::ChainPosition; | ||
use crate::types::FullScanRequest; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
The import of FullScanRequest
in bdk-ffi/src/lib.rs
does not appear to be used within the module. This could indicate that the import is unnecessary unless there are hidden usages not captured by the search. It is recommended to review the necessity of this import to maintain clean and efficient code.
- File:
bdk-ffi/src/lib.rs
- Import statement on line 43 might be unnecessary as no usage was found in the module.
Analysis chain
Ensure that FullScanRequest
is used within this module since it's being imported.
Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify usage of `FullScanRequest` in the current module.
# Test: Search for the usage of `FullScanRequest`. Expect: At least one occurrence.
rg --type rust $'FullScanRequest' src/lib.rs
Length of output: 94
Script:
#!/bin/bash
# Description: Check if the file src/lib.rs exists in the repository.
# Test: Search for the file src/lib.rs using fd to ensure the file path is correct.
fd 'lib.rs' --type file
Length of output: 42
Script:
#!/bin/bash
# Description: Verify usage of `FullScanRequest` in the correct module file.
# Test: Search for the usage of `FullScanRequest` in bdk-ffi/src/lib.rs. Expect: At least one occurrence.
rg --type rust $'FullScanRequest' bdk-ffi/src/lib.rs
Length of output: 86
bdk-ffi/src/esplora.rs
Outdated
request: Arc<FullScanRequest>, | ||
stop_gap: u64, | ||
parallel_requests: u64, | ||
) -> Result<Arc<Update>, EsploraError> { | ||
let wallet = wallet.get_wallet(); | ||
|
||
let previous_tip = wallet.latest_checkpoint(); | ||
let keychain_spks = wallet.all_unbounded_spk_iters().into_iter().collect(); | ||
|
||
let (update_graph, last_active_indices) = self | ||
.0 | ||
.full_scan(keychain_spks, stop_gap as usize, parallel_requests as usize) | ||
.map_err(|e| EsploraError::from(*e))?; | ||
|
||
let missing_heights = update_graph.missing_heights(wallet.local_chain()); | ||
let chain_update = self | ||
.0 | ||
.update_local_chain(previous_tip, missing_heights) | ||
.map_err(|e| EsploraError::from(*e))?; | ||
|
||
let update = BdkUpdate { | ||
last_active_indices, | ||
graph: update_graph, | ||
chain: Some(chain_update), | ||
// using option and take is not ideal but the only way to take full ownership of the request | ||
// TODO: if the option is None should throw error like "already consumed request" or "invalid request" | ||
let request: BdkFullScanRequest<KeychainKind> = request.0.lock().unwrap().take().unwrap(); | ||
|
||
let result: BdkFullScanResult<KeychainKind> = | ||
self.0 | ||
.full_scan(request, stop_gap as usize, parallel_requests as usize)?; | ||
|
||
let update = bdk::wallet::Update { | ||
last_active_indices: result.last_active_indices, | ||
graph: result.graph_update, | ||
chain: Some(result.chain_update), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor the full_scan
method to avoid using unwrap()
directly on Mutex
locks and Option
types, as this could lead to panics if the lock is poisoned or the option is None
.
- let request: BdkFullScanRequest<KeychainKind> = request.0.lock().unwrap().take().unwrap();
+ let request_lock = request.0.lock().expect("Lock poisoned");
+ let request: BdkFullScanRequest<KeychainKind> = request_lock.take().expect("Request already consumed or invalid");
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
request: Arc<FullScanRequest>, | |
stop_gap: u64, | |
parallel_requests: u64, | |
) -> Result<Arc<Update>, EsploraError> { | |
let wallet = wallet.get_wallet(); | |
let previous_tip = wallet.latest_checkpoint(); | |
let keychain_spks = wallet.all_unbounded_spk_iters().into_iter().collect(); | |
let (update_graph, last_active_indices) = self | |
.0 | |
.full_scan(keychain_spks, stop_gap as usize, parallel_requests as usize) | |
.map_err(|e| EsploraError::from(*e))?; | |
let missing_heights = update_graph.missing_heights(wallet.local_chain()); | |
let chain_update = self | |
.0 | |
.update_local_chain(previous_tip, missing_heights) | |
.map_err(|e| EsploraError::from(*e))?; | |
let update = BdkUpdate { | |
last_active_indices, | |
graph: update_graph, | |
chain: Some(chain_update), | |
// using option and take is not ideal but the only way to take full ownership of the request | |
// TODO: if the option is None should throw error like "already consumed request" or "invalid request" | |
let request: BdkFullScanRequest<KeychainKind> = request.0.lock().unwrap().take().unwrap(); | |
let result: BdkFullScanResult<KeychainKind> = | |
self.0 | |
.full_scan(request, stop_gap as usize, parallel_requests as usize)?; | |
let update = bdk::wallet::Update { | |
last_active_indices: result.last_active_indices, | |
graph: result.graph_update, | |
chain: Some(result.chain_update), | |
request: Arc<FullScanRequest>, | |
stop_gap: u64, | |
parallel_requests: u64, | |
) -> Result<Arc<Update>, EsploraError> { | |
// using option and take is not ideal but the only way to take full ownership of the request | |
// TODO: if the option is None should throw error like "already consumed request" or "invalid request" | |
let request_lock = request.0.lock().expect("Lock poisoned"); | |
let request: BdkFullScanRequest<KeychainKind> = request_lock.take().expect("Request already consumed or invalid"); | |
let result: BdkFullScanResult<KeychainKind> = | |
self.0 | |
.full_scan(request, stop_gap as usize, parallel_requests as usize)?; | |
let update = bdk::wallet::Update { | |
last_active_indices: result.last_active_indices, | |
graph: result.graph_update, | |
chain: Some(result.chain_update), |
bdk-ffi/src/esplora.rs
Outdated
// using option and take is not ideal but the only way to take full ownership of the request | ||
// TODO: if the option is None should throw error like "already consumed request" or "invalid request" | ||
let request: BdkSyncRequest = request.0.lock().unwrap().take().unwrap(); | ||
|
||
let result: BdkSyncResult = self.0.sync(request, parallel_requests as usize)?; | ||
|
||
let update = bdk::wallet::Update { | ||
last_active_indices: BTreeMap::default(), | ||
graph: result.graph_update, | ||
chain: Some(result.chain_update), | ||
}; | ||
|
||
Ok(Arc::new(Update(update))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the full_scan
method, refactor the sync
method to handle potential errors more gracefully instead of using unwrap()
.
- let request: BdkSyncRequest = request.0.lock().unwrap().take().unwrap();
+ let request_lock = request.0.lock().expect("Lock poisoned");
+ let request: BdkSyncRequest = request_lock.take().expect("Request already consumed or invalid");
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
// using option and take is not ideal but the only way to take full ownership of the request | |
// TODO: if the option is None should throw error like "already consumed request" or "invalid request" | |
let request: BdkSyncRequest = request.0.lock().unwrap().take().unwrap(); | |
let result: BdkSyncResult = self.0.sync(request, parallel_requests as usize)?; | |
let update = bdk::wallet::Update { | |
last_active_indices: BTreeMap::default(), | |
graph: result.graph_update, | |
chain: Some(result.chain_update), | |
}; | |
Ok(Arc::new(Update(update))) | |
} | |
// using option and take is not ideal but the only way to take full ownership of the request | |
// TODO: if the option is None should throw error like "already consumed request" or "invalid request" | |
let request_lock = request.0.lock().expect("Lock poisoned"); | |
let request: BdkSyncRequest = request_lock.take().expect("Request already consumed or invalid"); | |
let result: BdkSyncResult = self.0.sync(request, parallel_requests as usize)?; | |
let update = bdk::wallet::Update { | |
last_active_indices: BTreeMap::default(), | |
graph: result.graph_update, | |
chain: Some(result.chain_update), | |
}; | |
Ok(Arc::new(Update(update))) | |
} |
bdk-ffi/src/types.rs
Outdated
pub struct FullScanRequest(pub(crate) Mutex<Option<BdkFullScanRequest<KeychainKind>>>); | ||
pub struct SyncRequest(pub(crate) Mutex<Option<BdkSyncRequest>>); | ||
// pub struct FullScanRequest(pub(crate) Option<BdkFullScanRequest<KeychainKind>>); | ||
// pub struct FullScanRequest(pub(crate) BdkFullScanRequest<KeychainKind>); | ||
// pub struct FullScanRequest(pub(crate) Mutex<BdkFullScanRequest<KeychainKind>>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of Mutex
around FullScanRequest
and SyncRequest
is appropriate for thread-safe access, but ensure that the commented-out alternatives are removed if they are no longer considered.
- // pub struct FullScanRequest(pub(crate) Option<BdkFullScanRequest<KeychainKind>>);
- // pub struct FullScanRequest(pub(crate) BdkFullScanRequest<KeychainKind>);
- // pub struct FullScanRequest(pub(crate) Mutex<BdkFullScanRequest<KeychainKind>>);
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
pub struct FullScanRequest(pub(crate) Mutex<Option<BdkFullScanRequest<KeychainKind>>>); | |
pub struct SyncRequest(pub(crate) Mutex<Option<BdkSyncRequest>>); | |
// pub struct FullScanRequest(pub(crate) Option<BdkFullScanRequest<KeychainKind>>); | |
// pub struct FullScanRequest(pub(crate) BdkFullScanRequest<KeychainKind>); | |
// pub struct FullScanRequest(pub(crate) Mutex<BdkFullScanRequest<KeychainKind>>); | |
pub struct FullScanRequest(pub(crate) Mutex<Option<BdkFullScanRequest<KeychainKind>>>); | |
pub struct SyncRequest(pub(crate) Mutex<Option<BdkSyncRequest>>); |
ed80b19
to
bd55330
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Out of diff range and nitpick comments (1)
bdk-python/tests/test_offline_wallet.py (1)
Line range hint
16-16
: Undefined name 'Wallet' used in the test method.- wallet: Wallet = bdk.Wallet( + wallet: bdk.Wallet = bdk.Wallet(
112d3eb
to
11fe3f9
Compare
@reez @notmandatory I ended up adding 2 new variants on the EsploraError enum, let request: BdkSyncRequest = request
.0
.lock()
.unwrap()
.take()
.ok_or(EsploraError::SyncRequestAlreadyConsumed)?; Let me know what you think! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Out of diff range and nitpick comments (1)
bdk-python/tests/test_offline_wallet.py (1)
Line range hint
16-16
: Undefined name 'Wallet' used.- wallet: Wallet = bdk.Wallet( + wallet: bdk.Wallet = bdk.Wallet(
11fe3f9
to
0ed71ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Out of diff range and nitpick comments (1)
bdk-python/tests/test_offline_wallet.py (1)
Line range hint
16-16
: Undefined name 'Wallet' used; should be 'bdk.Wallet'.- wallet: Wallet = bdk.Wallet( + wallet: bdk.Wallet = bdk.Wallet(
⛏️ Only nit I have is to consolidate into one error with a slightly shorter name like |
I like this idea of consolidating 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some changes in terms of adding/exposing commit
in this PR, and then using apply_update
and commit
after we create a Request
and Update
.
Since this spans a few different files in a few different places I didn't add it as a comment to each spot, but for example after:
val fullScanRequest: FullScanRequest = wallet.startFullScan()
val update = esploraClient.fullScan(fullScanRequest, 10uL, 1uL)
... we need to then apply the update and then commit
Let me know if any of that is unclear, or any thoughts or comments on that.
0ed71ae
to
72b5bfd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Out of diff range and nitpick comments (1)
bdk-python/tests/test_offline_wallet.py (1)
Line range hint
16-16
: Undefined name 'Wallet' used; it should be 'bdk.Wallet'.- wallet: Wallet = bdk.Wallet( + wallet: bdk.Wallet = bdk.Wallet(
.lock() | ||
.unwrap() | ||
.take() | ||
.ok_or(EsploraError::RequestAlreadyConsumed)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ good to add a new error for this.
de6638c
to
4b6d05e
Compare
4b6d05e
to
e9a7628
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR brings in the alpha 10 version of BDK.
New wallet method for fetching new addresses, the fantastic new full_scan and sync methods on the Esplora client, and no more generic on the Wallet type.
Changelog