This repository was archived by the owner on Jan 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 212
feat(supervisor/storage): derivation schema #1808
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
57fe112
feat: added reth dependency to create db table
sadiq1971 f4a1fd6
added storage crate for supervisor
sadiq1971 4d50280
removed unused imports
sadiq1971 ff3a19d
defined schema for log storage
sadiq1971 28fa0e8
merged main
sadiq1971 15312c7
added space
sadiq1971 49d1349
lint fixed
sadiq1971 226af96
Merge branch 'main' into sa/feat/log-storage
dhyaniarun1993 b2f29ad
refactoring
dhyaniarun1993 eb3ef5e
added executing message to log entry
sadiq1971 433d36e
doc fixed
sadiq1971 7ab59ad
Merge branch 'main' of github.com:op-rs/kona into sa/feat/log-storage
sadiq1971 19afcbb
minor fixes
dhyaniarun1993 dda9760
Merge branch 'main' into sa/feat/log-storage
dhyaniarun1993 2de12ec
test cases added
dhyaniarun1993 d6e2388
Merge branch 'main' into sa/feat/log-storage
dhyaniarun1993 01cc5f6
lintfix
dhyaniarun1993 f12e7a3
main merged and conflict resolved
dhyaniarun1993 f17f9aa
block schema updated and test cases added
dhyaniarun1993 5483329
lintfix
dhyaniarun1993 2177686
feat: derivation table schema added
dhyaniarun1993 e4b3210
table added for source to derived block
dhyaniarun1993 c092a1a
minor fixes
dhyaniarun1993 5c816d8
blockHeader -> blockRef
dhyaniarun1993 249558f
lintfix
dhyaniarun1993 bc3d120
typo fixes
dhyaniarun1993 644f020
deny setting updated
dhyaniarun1993 932cd99
Merge branch 'sa/feat/log-storage' into feat/derivation-schema
dhyaniarun1993 2ec942c
testcase fixes
dhyaniarun1993 3eed5a4
main merged and conflict resolved
dhyaniarun1993 4b3057e
rust doc fixes
dhyaniarun1993 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| //! Common model types used across various storage tables. | ||
|
|
||
| use derive_more::{Deref, DerefMut}; | ||
| use reth_codecs::Compact; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Wrapper for `Vec<u64>` to represent a list of numbers. | ||
| // todo: add support for Vec<64> in table | ||
| #[derive( | ||
| Deref, DerefMut, Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize, Compact, | ||
| )] | ||
| pub struct U64List(pub Vec<u64>); | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use reth_codecs::Compact; | ||
|
|
||
| #[test] | ||
| fn test_u64list_compact_empty() { | ||
| let original_list = U64List(Vec::new()); | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| let bytes_written = original_list.to_compact(&mut buffer); | ||
|
|
||
| assert_eq!( | ||
| bytes_written, | ||
| buffer.len(), | ||
| "Bytes written should match buffer length for empty list" | ||
| ); | ||
| let (deserialized_list, remaining_buf) = U64List::from_compact(&buffer, bytes_written); | ||
|
|
||
| assert_eq!( | ||
| original_list, deserialized_list, | ||
| "Original and deserialized empty lists should be equal" | ||
| ); | ||
| assert!( | ||
| remaining_buf.is_empty(), | ||
| "Remaining buffer should be empty after deserialization of empty list" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_u64list_compact_with_data() { | ||
| let original_list = U64List(vec![10, 20, 30, 40, 50]); | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| let bytes_written = original_list.to_compact(&mut buffer); | ||
|
|
||
| assert_eq!( | ||
| bytes_written, | ||
| buffer.len(), | ||
| "Bytes written should match buffer length for list with data" | ||
| ); | ||
| let (deserialized_list, remaining_buf) = U64List::from_compact(&buffer, bytes_written); | ||
|
|
||
| assert_eq!( | ||
| original_list, deserialized_list, | ||
| "Original and deserialized lists with data should be equal" | ||
| ); | ||
| assert!( | ||
| remaining_buf.is_empty(), | ||
| "Remaining buffer should be empty after deserialization of list with data" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_u64list_deref() { | ||
| let list = U64List(vec![1, 2, 3]); | ||
| assert_eq!(list.len(), 3); | ||
| assert_eq!(list[0], 1); | ||
| assert!(!list.is_empty()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_u64list_deref_mut() { | ||
| let mut list = U64List(vec![1, 2, 3]); | ||
| list.push(4); | ||
| assert_eq!(list.0, vec![1, 2, 3, 4]); | ||
|
|
||
| list.sort(); | ||
| assert_eq!(list.0, vec![1, 2, 3, 4]); | ||
|
|
||
| list.clear(); | ||
| assert!(list.is_empty()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| //! Models for storing blockchain derivation in the database. | ||
| //! | ||
| //! This module defines the data structure and schema used for tracking | ||
| //! how blocks are derived from source. This is particularly relevant | ||
| //! in rollup contexts, such as linking an L2 block to its originating L1 block. | ||
|
|
||
| use super::BlockRef; | ||
| use reth_codecs::Compact; | ||
| use serde::{Deserialize, Serialize}; | ||
|
|
||
| /// Represents a pair of blocks where one block [`derived`](`Self::derived`) is derived | ||
| /// from another [`source`](`Self::source`). | ||
| /// | ||
| /// This structure is used to track the lineage of blocks where L2 blocks are derived from L1 | ||
| /// blocks. It stores the [`BlockRef`] information for both the source and the derived blocks. | ||
| /// It is stored as value in the [`DerivedBlocks`](`crate::models::DerivedBlocks`) table. | ||
| #[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)] | ||
| pub struct DerivedBlockPair { | ||
| /// The block that was derived from the [`source`](`Self::source`) block. | ||
| pub derived: BlockRef, | ||
| /// The source block from which the [`derived`](`Self::derived`) block was created. | ||
| pub source: BlockRef, | ||
| } | ||
|
|
||
| impl Compact for DerivedBlockPair { | ||
| fn to_compact<B: bytes::BufMut + AsMut<[u8]>>(&self, buf: &mut B) -> usize { | ||
| let mut bytes_written = 0; | ||
| bytes_written += self.derived.to_compact(buf); | ||
| bytes_written += self.source.to_compact(buf); | ||
| bytes_written | ||
| } | ||
|
|
||
| fn from_compact(buf: &[u8], _len: usize) -> (Self, &[u8]) { | ||
| let (derived, remaining_buf) = BlockRef::from_compact(buf, buf.len()); | ||
| let (source, final_remaining_buf) = | ||
| BlockRef::from_compact(remaining_buf, remaining_buf.len()); | ||
| (Self { derived, source }, final_remaining_buf) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::models::BlockRef; | ||
| use alloy_primitives::B256; | ||
| use reth_codecs::Compact; | ||
|
|
||
| fn test_b256(val: u8) -> B256 { | ||
| let mut val_bytes = [0u8; 32]; | ||
| val_bytes[0] = val; | ||
| let b256_from_val = B256::from(val_bytes); | ||
| B256::random() ^ b256_from_val | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_derived_block_pair_compact_roundtrip() { | ||
| let source_ref = | ||
| BlockRef { number: 100, hash: test_b256(1), parent_hash: test_b256(2), time: 1000 }; | ||
| let derived_ref = | ||
| BlockRef { number: 200, hash: test_b256(3), parent_hash: test_b256(4), time: 1010 }; | ||
|
|
||
| let original_pair = DerivedBlockPair { source: source_ref, derived: derived_ref }; | ||
|
|
||
| let mut buffer = Vec::new(); | ||
| let bytes_written = original_pair.to_compact(&mut buffer); | ||
|
|
||
| assert_eq!(bytes_written, buffer.len(), "Bytes written should match buffer length"); | ||
| let (deserialized_pair, remaining_buf) = | ||
| DerivedBlockPair::from_compact(&buffer, bytes_written); | ||
|
|
||
| assert_eq!( | ||
| original_pair, deserialized_pair, | ||
| "Original and deserialized pairs should be equal" | ||
| ); | ||
| assert!(remaining_buf.is_empty(), "Remaining buffer should be empty after deserialization"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.