-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add duptable support for reth db get
#2897
Conversation
reth db get
Tables:
|
Right now it works this way:
|
bin/reth/src/db/get.rs
Outdated
} | ||
|
||
#[derive(Parser, Debug)] | ||
pub struct DupCommand { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to keep it under get, no need for a new command
@@ -90,6 +91,11 @@ impl<'a, DB: Database> DbTool<'a, DB> { | |||
self.db.view(|tx| tx.get::<T>(key))?.map_err(|e| eyre::eyre!(e)) | |||
} | |||
|
|||
/// Grabs the content of the table for the given key and subkey | |||
pub fn get_dup<T: DupSort>(&mut self, key: T::Key, subkey: T::SubKey) -> Result<Option<T::Value>> { | |||
self.db.view(|tx| tx.cursor_dup_read::<T>().unwrap().seek_by_key_subkey(key, subkey)).unwrap().map_err(|e| eyre::eyre!(e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkrasiuk is this the right way? IIRC we cannot do this fully generically and need to use the structs we've defined for the subkeys by table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pinging @rkrasiuk I'm back on the issue. seek_by_key_subkey
and cursor_dup_read
forces me to pass the Subkey here, so it's impossible having the same macro for both types of tables (Table
and DupSort
), even with new changes from #2935
So if this call with tx.cursor_dup_read::<T>().unwrap().seek_by_key_subkey(key, subkey)
is the correct way of pulling data, we would need to change macro from https://github.com/paradigmxyz/reth/pull/2935/files#diff-bc5df8783f831a8e01372f13a49fbd1d2179d21dc309c8fdba3604bcd0dd372dR92 and create 2 separate macros for "normal" and "DupSort" tables. OR we create a method for DupSort tables but keep the view
function only having fn view<T: Table>
without DupSort.
Let me know your thoughts.
bin/reth/src/db/get.rs
Outdated
]); | ||
} | ||
|
||
fn table_key<T: Table>(&self) -> Result<T::Key, eyre::Error> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks redundant if you combine the two commands
Codecov Report
@@ Coverage Diff @@
## main #2897 +/- ##
===========================================
- Coverage 69.48% 17.36% -52.12%
===========================================
Files 535 515 -20
Lines 71761 66778 -4983
===========================================
- Hits 49860 11595 -38265
- Misses 21901 55183 +33282
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Thanks for the review. Just to note: there is this pr: #2935 which needs to be merged before merging this one since it changes a few things related to this pr |
95ed6d0
to
ccb2f2b
Compare
what I'm looking at right now is how to generate the view_dupsort function inside the same macro, but only for DupSort table type. Since that function would need to have type view_dupsort. I'm looking into the macro's identifiers, and expressions but still struggling to do it correctly |
Closes #2836