Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0a3fa71
feat: codec for [u8; 4]
jcnelson Nov 4, 2025
b49e29c
feat: compress trie ptrs in multiple ways: don't store back_block val…
jcnelson Nov 4, 2025
c6929bf
chore: add method documentation
jcnelson Nov 5, 2025
e2bbdaa
fix: remove redundant unit tests
jcnelson Nov 5, 2025
bcad6ed
chore: debug read I/O failures
jcnelson Nov 5, 2025
045dc0a
feat: if a node is copied to a new trie as part of MARF::walk_cow(), …
jcnelson Nov 5, 2025
f6e7014
chore: new error variants, including Error::Patch(..)
jcnelson Nov 5, 2025
4dfce7e
chore: clean up formatting and unused variables
jcnelson Nov 5, 2025
a112f52
chore: remove unused variable
jcnelson Nov 5, 2025
e5d6ec5
feat: use patch nodes in place of complete node copies in order to av…
jcnelson Nov 5, 2025
1d492bd
feat: when storing a TrieRAM to disk, look at .cowptr and .patches in…
jcnelson Nov 5, 2025
adad821
feat: light unit tests for compression
jcnelson Nov 5, 2025
00c6c5b
fix: typo in comment
jcnelson Nov 5, 2025
295d227
chore: better debugging in proof tests
jcnelson Nov 5, 2025
83831c7
chore: return block hash from which a node was read
jcnelson Nov 5, 2025
ab778c0
chore: better rusqlite conventions
jcnelson Nov 5, 2025
4420530
chore: address clippy warnings
jcnelson Nov 5, 2025
eecc737
Merge branch 'develop' into feat/marf-compression
jcnelson Nov 7, 2025
73a2a9d
chore: fix consenus test bug in which the wrong trie root would get r…
jcnelson Dec 2, 2025
dc944e3
Merge branch 'develop' into feat/marf-compression
jcnelson Dec 2, 2025
ed3475a
Merge branch 'develop' into feat/marf-compression
jcnelson Dec 2, 2025
756d79e
crc: addressing nits, #6593
federico-stacks Dec 4, 2025
bad16e8
test: add tests to validate cur_block and cur_block_id out of sync, #…
federico-stacks Dec 5, 2025
40908f4
crc: use stacks_common not crate, #6593
federico-stacks Dec 5, 2025
27de3b6
crc: use idiomatic Seek methods for Start(0) and Current(0), #6593
federico-stacks Dec 5, 2025
f989667
crc: resolve small duplication on dump/dump_compressed, #6593
federico-stacks Dec 5, 2025
d481601
chore: merge with develop
federico-stacks Dec 11, 2025
fdc3e60
feat: avoid marf compression for unconfirmed trie, #6593
federico-stacks Dec 11, 2025
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
32 changes: 21 additions & 11 deletions stackslib/src/chainstate/stacks/index/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,17 +2180,22 @@ impl<'a, T: MarfTrieId> TrieStorageTransaction<'a, T> {
if real_bhh != &bhh {
// note: this was moved from the block_retarget function
// to avoid stepping on the borrow checker.
debug!("Retarget block {} to {}", bhh, real_bhh);
debug!(
"Retarget block {} to {}. Current block ID is {:?}",
bhh, real_bhh, &self.data.cur_block_id
);
// switch over state
self.data.retarget_block(real_bhh.clone());
}
self.with_trie_blobs(|db, blobs| match blobs {
let new_block_id = self.with_trie_blobs(|db, blobs| match blobs {
Some(blobs) => blobs.store_trie_blob(db, real_bhh, &buffer),
None => {
test_debug!("Stored trie blob {} to db", real_bhh);
trie_sql::write_trie_blob(db, real_bhh, &buffer)
}
})?
})?;
self.data.set_block(real_bhh.clone(), Some(new_block_id));
new_block_id
Comment on lines 1768 to +2206
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, where all block data are always set at once via set_block, it seems to supersede the retarget management, so that logic could likely be removed. I wrote some local unit tests to validate this behavior, and also checked the behaviour running integration tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added unit tests: bad16e8

}
FlushOptions::MinedTable(real_bhh) => {
if self.unconfirmed() {
Expand Down Expand Up @@ -2610,11 +2615,14 @@ impl<T: MarfTrieId> TrieStorageConnection<'_, T> {
/// when following a backptr, which stores the block identifier directly.
pub fn open_block_known_id(&mut self, bhh: &T, id: u32) -> Result<(), Error> {
trace!(
"open_block_known_id({},{}) (unconfirmed={:?},{})",
"open_block_known_id({},{}) (unconfirmed={:?},{}) from {},{:?} in {}",
bhh,
id,
&self.unconfirmed_block_id,
self.unconfirmed()
self.unconfirmed(),
&self.data.cur_block,
&self.data.cur_block_id,
self.db_path,
);
if *bhh == self.data.cur_block && self.data.cur_block_id.is_some() {
// no-op
Expand All @@ -2636,10 +2644,11 @@ impl<T: MarfTrieId> TrieStorageConnection<'_, T> {
/// that all node reads will occur relative to it.
pub fn open_block(&mut self, bhh: &T) -> Result<(), Error> {
trace!(
"open_block({}) (unconfirmed={:?},{})",
"open_block({}) (unconfirmed={:?},{}) in {}",
bhh,
&self.unconfirmed_block_id,
self.unconfirmed()
self.unconfirmed(),
self.db_path
);
self.bench.open_block_start();

Expand Down Expand Up @@ -3059,8 +3068,9 @@ impl<T: MarfTrieId> TrieStorageConnection<'_, T> {
self.unconfirmed()
);

let (saved_block_hash, saved_block_id) = self.get_cur_block_and_id();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Managing the block restore appears unnecessary, since none of the downstream code (including the invoked methods) modifies the currently opened block.

It’s harmless to keep the restore in place, but it doesn’t have any observable effect, so we could safely remove it to simplify the logic.

I also ran the consensus tests and some integration tests without the block-restore logic, and they all passed.


let cur_block_id = block_id;
let cur_block = self.get_block_hash_caching(cur_block_id)?.to_owned();
let mut node_hash_opt = None;
let mut patches: Vec<(u32, TriePtr, TrieNodePatch)> = vec![];
for _ in 0..MAX_PATCH_DEPTH {
Expand All @@ -3070,7 +3080,7 @@ impl<T: MarfTrieId> TrieStorageConnection<'_, T> {
let node = node.apply_patches(&patches, cur_block_id).ok_or_else(|| {
Error::CorruptionError("Failed to apply patches to node".to_string())
})?;
self.open_block(&cur_block)?;
self.open_block_maybe_id(&saved_block_hash, saved_block_id)?;
return Ok((node, node_hash_opt.unwrap_or(hash)));
}
Err(Error::Patch(hash_opt, node_patch)) => {
Expand All @@ -3087,12 +3097,12 @@ impl<T: MarfTrieId> TrieStorageConnection<'_, T> {
}
}
Err(e) => {
self.open_block(&cur_block)?;
self.open_block_maybe_id(&saved_block_hash, saved_block_id)?;
return Err(e);
}
}
}
self.open_block(&cur_block)?;
self.open_block_maybe_id(&saved_block_hash, saved_block_id)?;
return Err(Error::NodeTooDeep);
}

Expand Down
Loading