Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

More efficient on chain scanning #994

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub mod vss;
#[cfg(test)]
mod test_utils;

use crate::event::{HTLCStatus, MillisatAmount, PaymentInfo};
pub use crate::gossip::{GOSSIP_SYNC_TIME_KEY, NETWORK_GRAPH_KEY, PROB_SCORER_KEY};
pub use crate::keymanager::generate_seed;
pub use crate::ldkstorage::{CHANNEL_MANAGER_KEY, MONITORS_PREFIX_KEY};
Expand All @@ -49,6 +48,10 @@ use crate::storage::{
};
use crate::{auth::MutinyAuthClient, logging::MutinyLogger};
use crate::{error::MutinyError, nostr::ReservedProfile};
use crate::{
event::{HTLCStatus, MillisatAmount, PaymentInfo},
onchain::FULL_SYNC_STOP_GAP,
};
use crate::{
federation::{FederationClient, FederationIdentity, FederationIndex, FederationStorage},
labels::{get_contact_key, Contact, LabelStorage},
Expand Down Expand Up @@ -775,7 +778,10 @@ impl<S: MutinyStorage> MutinyWalletBuilder<S> {
{
// if we need a full sync from a restore
if mw.storage.get(NEED_FULL_SYNC_KEY)?.unwrap_or_default() {
mw.node_manager.wallet.full_sync().await?;
mw.node_manager
.wallet
.full_sync(crate::onchain::RESTORE_SYNC_STOP_GAP)
.await?;
mw.storage.delete(&[NEED_FULL_SYNC_KEY])?;
}
}
Expand Down Expand Up @@ -1598,7 +1604,10 @@ impl<S: MutinyStorage> MutinyWallet<S> {

self.start().await?;

self.node_manager.wallet.full_sync().await?;
self.node_manager
.wallet
.full_sync(FULL_SYNC_STOP_GAP)
.await?;

Ok(())
}
Expand Down
10 changes: 6 additions & 4 deletions mutiny-core/src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ use crate::logging::MutinyLogger;
use crate::storage::{MutinyStorage, OnChainStorage};
use crate::utils::{now, sleep};

const DEFAULT_STOP_GAP: usize = 20;
const FULL_SYNC_STOP_GAP: usize = 150;
pub(crate) const DEFAULT_STOP_GAP: usize = 10;
pub(crate) const FULL_SYNC_STOP_GAP: usize = 150;
#[cfg(not(test))]
pub(crate) const RESTORE_SYNC_STOP_GAP: usize = 20;

#[derive(Clone)]
pub struct OnChainWallet<S: MutinyStorage> {
Expand Down Expand Up @@ -195,7 +197,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
Err(MutinyError::WalletOperationFailed)
}

pub async fn full_sync(&self) -> Result<(), MutinyError> {
pub async fn full_sync(&self, gap: usize) -> Result<(), MutinyError> {
// get first wallet lock that only needs to read
let (checkpoints, spks) = {
if let Ok(wallet) = self.wallet.try_read() {
Expand All @@ -216,7 +218,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
spks,
core::iter::empty(),
core::iter::empty(),
FULL_SYNC_STOP_GAP,
gap,
5,
)
.await?;
Expand Down
Loading