Repository navigation
feat(wallet)!: wallet truncate above #1104
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
Changes from all commits
1e9c886
9730ff6
da5b1f4
dfd062b
ca75f53
392fec3
3c0da64
2165277
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,9 +249,9 @@ impl<W: WalletInterface, N: NetworkManager, S: StorageManager> DashSpvClient<W, | |
| } | ||
|
|
||
| /// Recover from a fork at `fork_height`: stop the client, drop the stored | ||
| /// chain above the fork and run again, so the client syncs onto the branch | ||
| /// the network follows. A loop that was stopped or replaced in the meantime | ||
| /// is left alone. | ||
| /// chain and what the wallets recorded above the fork, and run again, so | ||
| /// the client syncs onto the branch the network follows. A loop that was | ||
| /// stopped or replaced in the meantime is left alone. | ||
| /// | ||
| /// Boxed because the client it runs again can recover from a fork too. | ||
| pub(super) fn handle_fork( | ||
|
|
@@ -266,12 +266,22 @@ impl<W: WalletInterface, N: NetworkManager, S: StorageManager> DashSpvClient<W, | |
| self.stop_locked(forked).await; | ||
|
|
||
| tracing::warn!("Fork at height {}, dropping the stored chain above it", fork_height); | ||
| { | ||
| // The wallets go first: a wallet refusing the fork leaves storage as | ||
| // it is, and storage failing after them keeps the fork unstored, so | ||
| // it is detected and retried. | ||
| let truncated = async { | ||
| self.wallet.write().await.truncate_above(fork_height)?; | ||
| let mut storage = self.storage.lock().await; | ||
| BlockHeaderStorage::truncate_above(&mut *storage, fork_height).await?; | ||
| FilterHeaderStorage::truncate_above(&mut *storage, fork_height).await?; | ||
| FilterStorage::truncate_above(&mut *storage, fork_height).await?; | ||
| BlockStorage::truncate_above(&mut *storage, fork_height).await?; | ||
| Ok::<_, Box<dyn std::error::Error + Send + Sync>>(()) | ||
| } | ||
| .await; | ||
|
|
||
| if let Err(e) = truncated { | ||
| tracing::warn!("Fork at height {} not followed: {}", fork_height, e); | ||
|
Comment on lines
+283
to
+284
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- diff ---'
git diff --no-ext-diff --unified=50 5628202e401185b5353426082313885ef347729c 3c0da64d3112069d9f78deeaba99b1d23470e756 -- dash-spv/src/client/lifecycle.rs
printf '%s\n' '--- lifecycle source ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/client/lifecycle.rs | nl -ba | sed -n '220,330p'
printf '%s\n' '--- fork detector references ---'
rg -n -F -- 'fork_height' dash-spv/src/sync dash-spv/src/client
printf '%s\n' '--- detector parent references ---'
rg -n -F -- 'parent' dash-spv/src/sync/block_headers/manager.rsRepository: dashpay/rust-dashcore Length of output: 14086 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- fork detector ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/sync/block_headers/manager.rs | nl -ba | sed -n '125,230p'
printf '%s\n' '--- truncate declarations and implementations ---'
rg -n -F -- 'truncate_above' dash-spv/src dash-spv
printf '%s\n' '--- run_locked and startup ---'
rg -n -F -- 'async fn run_locked' dash-spv/src/client/lifecycle.rs
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/client/lifecycle.rs | nl -ba | sed -n '80,210p'Repository: dashpay/rust-dashcore Length of output: 19953 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- fork detector ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/sync/block_headers/manager.rs | nl -ba | sed -n '125,230p'
printf '%s\n' '--- truncate declarations and implementations ---'
rg -n -F -- 'truncate_above' dash-spv/src dash-spv
printf '%s\n' '--- run_locked location ---'
rg -n -F -- 'async fn run_locked' dash-spv/src/client/lifecycle.rs
printf '%s\n' '--- lifecycle startup ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/client/lifecycle.rs | nl -ba | sed -n '80,210p'Repository: dashpay/rust-dashcore Length of output: 19950 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- segment truncation ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/storage/segments.rs | nl -ba | sed -n '380,455p'
printf '%s\n' '--- block header storage contract/implementation ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/storage/block_headers.rs | nl -ba | sed -n '1,115p;210,250p'
printf '%s\n' '--- disk storage delegation ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/storage/mod.rs | nl -ba | sed -n '340,455p'
printf '%s\n' '--- lifecycle run functions ---'
rg -n -F -- 'run_locked' dash-spv/src/client/lifecycle.rsRepository: dashpay/rust-dashcore Length of output: 14755 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- lifecycle run and startup ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/client/lifecycle.rs | nl -ba | sed -n '1,220p'
printf '%s\n' '--- fork event consumer ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/client/sync_coordinator.rs | nl -ba | sed -n '125,170p'
printf '%s\n' '--- error declarations ---'
rg -n -F -- 'enum SpvError' dash-spv/src || test "$?" -eq 1
rg -n -F -- 'pub enum' dash-spv/src/error.rs || test "$?" -eq 1
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/error.rs | nl -ba | sed -n '1,180p'Repository: dashpay/rust-dashcore Length of output: 18852 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- lifecycle run and startup ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/client/lifecycle.rs | nl -ba | sed -n '1,220p'
printf '%s\n' '--- fork event consumer ---'
git show 3c0da64d3112069d9f78deeaba99b1d23470e756:dash-spv/src/client/sync_coordinator.rs | nl -ba | sed -n '125,170p'
printf '%s\n' '--- SpvError declaration location ---'
rg -n -F -- 'enum SpvError' dash-spv/src || test "$?" -eq 1
printf '%s\n' '--- error source files ---'
rg --files dash-spv/src | rg '/error(s)?\.rs$' || test "$?" -eq 1Repository: dashpay/rust-dashcore Length of output: 12674 🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- run_locked definition and uses ---'
rg -n -C 18 -F -- 'run_locked' dash-spv/src || test "$?" -eq 1
printf '%s\n' '--- manager startup call sites ---'
rg -n -C 6 -F -- 'start_sync()' dash-spv/src/client || test "$?" -eq 1Repository: dashpay/rust-dashcore Length of output: 7953 Do not restart synchronization after a storage truncation fails.
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| self.run_locked(&mut sync_loop).await | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.