Skip to content
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

Closed

Conversation

dragan2234
Copy link

@dragan2234 dragan2234 commented May 29, 2023

Closes #2836

@dragan2234 dragan2234 changed the title init work WIP: Add duptable support for reth db get May 29, 2023
@onbjerg onbjerg changed the title WIP: Add duptable support for reth db get feat: add duptable support for reth db get May 29, 2023
@onbjerg onbjerg added C-enhancement New feature or request A-cli Related to the reth CLI labels May 29, 2023
@dragan2234
Copy link
Author

Tables:

    (TableType::DupSort, PlainStorageState::const_name()),
    (TableType::DupSort, AccountChangeSet::const_name()),
    (TableType::DupSort, StorageChangeSet::const_name()),
    (TableType::DupSort, HashedStorage::const_name()),
    (TableType::DupSort, StoragesTrie::const_name()),

@dragan2234
Copy link
Author

Right now it works this way:

reth db get-dup <table> <key> <subkey>

@dragan2234 dragan2234 marked this pull request as ready for review May 30, 2023 19:34
@dragan2234 dragan2234 requested a review from onbjerg as a code owner May 30, 2023 19:34
}

#[derive(Parser, Debug)]
pub struct DupCommand {
Copy link
Member

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))
Copy link
Member

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?

Copy link
Author

@dragan2234 dragan2234 Jun 22, 2023

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.

]);
}

fn table_key<T: Table>(&self) -> Result<T::Key, eyre::Error>
Copy link
Member

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-commenter
Copy link

codecov-commenter commented May 31, 2023

Codecov Report

Merging #2897 (8d45e47) into main (e8b09cc) will decrease coverage by 52.12%.
The diff coverage is 0.00%.

❗ Current head 8d45e47 differs from pull request most recent head ccb2f2b. Consider uploading reports for the commit ccb2f2b to get more accurate results

@@             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     
Flag Coverage Δ
integration-tests 17.36% <0.00%> (+1.01%) ⬆️
unit-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
bin/reth/src/db/get.rs 0.00% <0.00%> (-75.65%) ⬇️
bin/reth/src/db/mod.rs 0.00% <0.00%> (-10.39%) ⬇️
bin/reth/src/utils.rs 0.00% <0.00%> (-4.69%) ⬇️

... and 429 files with indirect coverage changes

@dragan2234
Copy link
Author

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

@onbjerg onbjerg added the S-blocked This cannot more forward until something else changes label Jun 19, 2023
@dragan2234 dragan2234 marked this pull request as draft June 23, 2023 00:46
@dragan2234
Copy link
Author

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

@github-actions github-actions bot added the S-stale This issue/PR is stale and will close with no further activity label Aug 1, 2023
@github-actions github-actions bot closed this Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Related to the reth CLI C-enhancement New feature or request S-blocked This cannot more forward until something else changes S-stale This issue/PR is stale and will close with no further activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add duptable support for reth db get
4 participants