Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
698ae77
pruning index schema impl
itschaindev Oct 21, 2025
483c93a
lint-fix
itschaindev Oct 21, 2025
9264e1a
revert doc changes
itschaindev Oct 21, 2025
5825d4f
add tests, fix pr feedback
itschaindev Oct 22, 2025
b51a024
Merge branch 'unstable' into jk/index-tables-schema
emhane Oct 22, 2025
c3c3ab0
rename table and struct
itschaindev Oct 22, 2025
2bd59d6
rename file
itschaindev Oct 22, 2025
b107104
add crud test
itschaindev Oct 22, 2025
fbe67f5
fix-lint
itschaindev Oct 22, 2025
8a09b1a
Merge branch 'unstable' into jk/index-tables-schema
itschaindev Oct 22, 2025
1129d5c
signing commit
itschaindev Oct 22, 2025
4d274ff
lint, fmt, docs fix
itschaindev Oct 23, 2025
d9df8ec
change subkey to be the tables' key
itschaindev Oct 23, 2025
3b90e7e
Merge branch 'unstable' into jk/index-tables-schema
itschaindev Oct 23, 2025
9aac65a
revised schema for storing change sets
itschaindev Oct 24, 2025
af0af9a
Merge branch 'unstable' into jk/index-tables-schema
itschaindev Oct 24, 2025
3eea2ea
feat: latest block updates in `store_trie_updates` (#304)
dhyaniarun1993 Oct 25, 2025
b519783
fix tests
itschaindev Oct 27, 2025
e24dd00
Merge branch 'unstable' into jk/index-tables-schema
itschaindev Oct 27, 2025
5d1eeae
pr feedback
itschaindev Oct 27, 2025
51136d0
pr feedback
itschaindev Oct 28, 2025
0a8d374
feat: live collector integration (#306)
dhyaniarun1993 Oct 27, 2025
cd2508b
feat: add mdbx to storage tests (#308)
meyer9 Oct 27, 2025
665432b
fix: merge conflict caused by storage tests (#313)
meyer9 Oct 28, 2025
fef227a
Merge branch 'unstable' into jk/index-tables-schema
itschaindev Oct 28, 2025
1319a24
fix doc test
itschaindev Oct 28, 2025
bbcc4e4
Merge branch 'unstable' into jk/index-tables-schema
dhyaniarun1993 Oct 28, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/optimism/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ tokio = { workspace = true, features = ["sync"] }
# codec
bytes.workspace = true
serde.workspace = true
bincode.workspace = true

# misc
thiserror.workspace = true
Expand Down
125 changes: 125 additions & 0 deletions crates/optimism/trie/src/db/models/change_set.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
use crate::db::{HashedStorageKey, StorageTrieKey};
use alloy_primitives::B256;
use reth_db::{
table::{self, Decode, Encode},
DatabaseError,
};
use reth_trie::StoredNibbles;
use serde::{Deserialize, Serialize};

/// The keys of the entries in the history tables.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct ChangeSet {
/// Keys changed in [`AccountTrieHistory`](super::AccountTrieHistory) table.
pub account_trie_keys: Vec<StoredNibbles>,
/// Keys changed in [`StorageTrieHistory`](super::StorageTrieHistory) table.
pub storage_trie_keys: Vec<StorageTrieKey>,
/// Keys changed in [`HashedAccountHistory`](super::HashedAccountHistory) table.
pub hashed_account_keys: Vec<B256>,
/// Keys changed in [`HashedStorageHistory`](super::HashedStorageHistory) table.
pub hashed_storage_keys: Vec<HashedStorageKey>,
}

impl table::Encode for ChangeSet {
type Encoded = Vec<u8>;

fn encode(self) -> Self::Encoded {
bincode::serialize(&self).expect("ChangeSet serialization should not fail")
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

The panic message 'ChangeSet serialization should not fail' is unhelpful for debugging. Consider providing more context about what data caused the failure or return a Result instead of panicking.

Suggested change
bincode::serialize(&self).expect("ChangeSet serialization should not fail")
bincode::serialize(&self).unwrap_or_else(|e| {
panic!(
"ChangeSet serialization failed for {:?}: {}",
self, e
)
})

Copilot uses AI. Check for mistakes.
}
}

impl table::Decode for ChangeSet {
fn decode(value: &[u8]) -> Result<Self, DatabaseError> {
bincode::deserialize(value).map_err(|_| DatabaseError::Decode)
}
}

impl table::Compress for ChangeSet {
type Compressed = Vec<u8>;

fn compress_to_buf<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) {
let encoded = self.clone().encode();
Copy link

Copilot AI Oct 27, 2025

Choose a reason for hiding this comment

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

Unnecessary clone before encoding. The compress_to_buf method takes &self, so you can serialize directly without cloning. Consider implementing compress_to_buf without the intermediate clone.

Copilot uses AI. Check for mistakes.
buf.put_slice(&encoded);
}
}

impl table::Decompress for ChangeSet {
fn decompress(value: &[u8]) -> Result<Self, DatabaseError> {
Self::decode(value)
}
}

#[cfg(test)]
mod tests {
use super::*;
use alloy_primitives::B256;
use reth_db::table::{Compress, Decompress};

#[test]
fn test_encode_decode_empty_change_set() {
let change_set = ChangeSet {
account_trie_keys: vec![],
storage_trie_keys: vec![],
hashed_account_keys: vec![],
hashed_storage_keys: vec![],
};

let encoded = change_set.clone().encode();
let decoded = ChangeSet::decode(&encoded).expect("Failed to decode");
assert_eq!(change_set, decoded);
}

#[test]
fn test_encode_decode_populated_change_set() {
let account_key = StoredNibbles::from(vec![1, 2, 3, 4]);
let storage_key = StorageTrieKey {
hashed_address: B256::repeat_byte(0x11),
path: StoredNibbles::from(vec![5, 6, 7, 8]),
};
let hashed_storage_key = HashedStorageKey {
hashed_address: B256::repeat_byte(0x22),
hashed_storage_key: B256::repeat_byte(0x33),
};

let change_set = ChangeSet {
account_trie_keys: vec![account_key],
storage_trie_keys: vec![storage_key],
hashed_account_keys: vec![B256::repeat_byte(0x44)],
hashed_storage_keys: vec![hashed_storage_key],
};

let encoded = change_set.clone().encode();
let decoded = ChangeSet::decode(&encoded).expect("Failed to decode");
assert_eq!(change_set, decoded);
}

#[test]
fn test_decode_invalid_data() {
let invalid_data = vec![0xFF; 32];
let result = ChangeSet::decode(&invalid_data);
assert!(result.is_err());
assert!(matches!(result.unwrap_err(), DatabaseError::Decode));
}

#[test]
fn test_compress_decompress() {
let change_set = ChangeSet {
account_trie_keys: vec![StoredNibbles::from(vec![1, 2, 3])],
storage_trie_keys: vec![StorageTrieKey {
hashed_address: B256::ZERO,
path: StoredNibbles::from(vec![4, 5, 6]),
}],
hashed_account_keys: vec![B256::ZERO],
hashed_storage_keys: vec![HashedStorageKey {
hashed_address: B256::ZERO,
hashed_storage_key: B256::repeat_byte(0x42),
}],
};

let mut buf = Vec::new();
change_set.compress_to_buf(&mut buf);

let decompressed = ChangeSet::decompress(&buf).expect("Failed to decompress");
assert_eq!(change_set, decompressed);
}
}
9 changes: 9 additions & 0 deletions crates/optimism/trie/src/db/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod version;
pub use version::*;
mod storage;
pub use storage::*;
mod change_set;
pub use change_set::*;

use alloy_primitives::B256;
use reth_db::{
Expand Down Expand Up @@ -70,4 +72,11 @@ tables! {
type Key = ProofWindowKey;
type Value = BlockNumberHash;
}

/// A reverse mapping of block numbers to a keys of the tables.
/// This is used for efficiently locating data by block number.
table BlockChangeSet {
type Key = u64; // Block number
type Value = ChangeSet;
}
}
Loading