Skip to content

Commit a6c34c8

Browse files
committed
set KEYCHAIN_COMPACTION_SIZE_THRESHOLD_BYTES 256KB
1 parent 4597b31 commit a6c34c8

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

mutiny-core/src/onchain.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use web_time::Instant;
4747
pub(crate) const FULL_SYNC_STOP_GAP: usize = 150;
4848
pub(crate) const RESTORE_SYNC_STOP_GAP: usize = 50;
4949
const PARALLEL_REQUESTS: usize = 10;
50-
const KEYCHAIN_COMPACTION_SIZE_THRESHOLD_BYTES: usize = 128 * 1024; // 128KB
50+
const KEYCHAIN_COMPACTION_SIZE_THRESHOLD_BYTES: usize = 256 * 1024; // 256KB
5151

5252
#[derive(Clone)]
5353
pub struct OnChainWallet<S: MutinyStorage> {
@@ -872,7 +872,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
872872
if total_size < KEYCHAIN_COMPACTION_SIZE_THRESHOLD_BYTES {
873873
log_info!(
874874
self.logger,
875-
"Keychain size {}is below threshold {}, not compacting",
875+
"Keychain size {} bytes is below threshold {} bytes, not compacting",
876876
total_size,
877877
KEYCHAIN_COMPACTION_SIZE_THRESHOLD_BYTES
878878
);
@@ -883,7 +883,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
883883
"Keychain size threshold exceeded {} Bytes, spawning simplified compaction task.",
884884
KEYCHAIN_COMPACTION_SIZE_THRESHOLD_BYTES
885885
);
886-
self.log_keychain_size(&changes);
886+
self.log_keychain_size(&changes, false);
887887

888888
let mut new_wallet = self.new_wallet()?;
889889
let update = full_scan(&new_wallet, RESTORE_SYNC_STOP_GAP, self.blockchain.clone()).await?;
@@ -900,7 +900,7 @@ impl<S: MutinyStorage> OnChainWallet<S> {
900900
let new_changeset = new_wallet.take_staged().ok_or(MutinyError::Other(anyhow!(
901901
"Failed to take staged changeset from new wallet"
902902
)))?;
903-
self.log_keychain_size(&new_changeset);
903+
self.log_keychain_size(&new_changeset, true);
904904
self.storage.restore_changes(&new_changeset)?;
905905
*wallet = new_wallet;
906906
drop(wallet); // drop so we can read from wallet
@@ -933,8 +933,8 @@ impl<S: MutinyStorage> OnChainWallet<S> {
933933
Ok(true)
934934
}
935935

936-
fn log_keychain_size(&self, keychain: &ChangeSet) {
937-
let total_size = serde_json::to_vec(&keychain).unwrap_or_default().len();
936+
fn log_keychain_size(&self, keychain: &ChangeSet, is_post_compaction: bool) {
937+
let total_size = serde_json::to_vec(keychain).unwrap_or_default().len();
938938
let local_chain_size = serde_json::to_vec(&keychain.local_chain)
939939
.map(|v| v.len())
940940
.unwrap_or(0);
@@ -944,13 +944,22 @@ impl<S: MutinyStorage> OnChainWallet<S> {
944944
let indexer_size = serde_json::to_vec(&keychain.indexer)
945945
.map(|v| v.len())
946946
.unwrap_or(0);
947-
log_debug!(self.logger,
948-
"PRE-COMPACTION size: {} bytes. Approx component sizes (bytes): LocalChain={}, TxGraph={}, Indexer={}",
949-
total_size,
950-
local_chain_size,
951-
tx_graph_size,
952-
indexer_size
953-
);
947+
948+
let prefix = if is_post_compaction {
949+
"POST-COMPACTION"
950+
} else {
951+
"PRE-COMPACTION"
952+
};
953+
954+
log_debug!(
955+
self.logger,
956+
"{} size: {} bytes. Approx component sizes (bytes): LocalChain={}, TxGraph={}, Indexer={}",
957+
prefix,
958+
total_size,
959+
local_chain_size,
960+
tx_graph_size,
961+
indexer_size
962+
);
954963
}
955964
}
956965

0 commit comments

Comments
 (0)