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

Add decompression traits and a test case #2295

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

Dentosal
Copy link
Member

@Dentosal Dentosal commented Oct 4, 2024

#1609 (comment)

Add a test case for decompressing DA-compressed blocks. FIx CombinedDb::from_config to respects state_rewind_policy with tmp RocksDB.

@Dentosal Dentosal self-assigned this Oct 4, 2024
@Dentosal Dentosal added the no changelog Skip the CI check of the changelog modification label Oct 5, 2024
Base automatically changed from dento/da-compression to master October 5, 2024 17:29
@Dentosal Dentosal force-pushed the dento/da-compression-decompress-test branch from fb37322 to 72dd40d Compare October 15, 2024 14:35
@Dentosal Dentosal removed the no changelog Skip the CI check of the changelog modification label Oct 15, 2024
@Dentosal Dentosal requested a review from a team October 15, 2024 15:22
netrome
netrome previously approved these changes Oct 15, 2024
Copy link
Contributor

@netrome netrome left a comment

Choose a reason for hiding this comment

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

LGTM, one question from me.

@Dentosal Dentosal requested a review from a team October 15, 2024 18:02
on_chain: Database::rocksdb_temp(state_rewind_policy)?,
off_chain: Database::rocksdb_temp(state_rewind_policy)?,
relayer: Database::rocksdb_temp(state_rewind_policy)?,
gas_price: Default::default(),
Copy link
Contributor

Choose a reason for hiding this comment

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

out of curiosity, why the difference for the gas_price database?

Copy link
Member Author

Choose a reason for hiding this comment

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

@xgreenx might know, I have no idea

Copy link
Collaborator

Choose a reason for hiding this comment

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

Because gas price table and relayer table doesn't need to support state rewind in the case of the temporary database(right now at least). Because we don't have any logic around it.

Copy link
Member

@MitchTurner MitchTurner left a comment

Choose a reason for hiding this comment

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

WIP. I want to give it another, deeper pass.

@@ -94,6 +94,19 @@ impl CombinedDatabase {
})
}

/// A test-only temporary rocksdb database with given rewind policy.
#[cfg(feature = "rocksdb")]
Copy link
Member

Choose a reason for hiding this comment

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

Should this also be "test-helpers" if it's "test-only"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 5251318

Copy link
Member Author

Choose a reason for hiding this comment

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

I reverted this in beaee56 since it seems like we're using it with when empty path is provided, and I'm not sure if we need that outside tests as well.

};
let decompressed = decompress(compression_config, db_tx, block).await.unwrap();

assert!(decompressed.transactions.len() == 2);
Copy link
Member

Choose a reason for hiding this comment

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

Might as well check that the second tx matches the one submitted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Some fields will differ, as the returned tx would have to be executed to generate full values

tests/tests/da_compression.rs Outdated Show resolved Hide resolved
crates/fuel-core/src/graphql_api/da_compression.rs Outdated Show resolved Hide resolved
Comment on lines +115 to +123
let db = &srv.shared.database;
let mut tx_inner = db.off_chain().clone().into_transaction();
let db_tx = DecompressDbTx {
db_tx: DbTx {
db_tx: &mut tx_inner,
},
onchain_db: db.on_chain().view_at(&0u32.into()).unwrap(),
};
let decompressed = decompress(compression_config, db_tx, block).await.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

I guess I'm a little confused by using the shared db for decompressing the info. Shouldn't we be able to decompress it with an isolated, clean db?

Maybe that's not the point of this test.

Copy link
Member

Choose a reason for hiding this comment

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

decompression requires some previous indexation to be done on the data, it can't be done from an empty database afaiu

rafal-ch
rafal-ch previously approved these changes Oct 16, 2024
Copy link
Contributor

@rafal-ch rafal-ch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

crates/fuel-core/src/graphql_api/da_compression.rs Outdated Show resolved Hide resolved
crates/fuel-core/src/graphql_api/da_compression.rs Outdated Show resolved Hide resolved
state_rewind_policy: StateRewindPolicy,
) -> DatabaseResult<Self> {
Ok(Self {
on_chain: Database::rocksdb_temp(state_rewind_policy)?,
Copy link
Member

Choose a reason for hiding this comment

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

perhaps we should use ShallowTempDir here? we moved it from fuel-core to the benches crate but if the use case is the same we can use it

Copy link
Member Author

Choose a reason for hiding this comment

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

What's the reason behind this?

Copy link
Member

Choose a reason for hiding this comment

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

because we have a way to clean up the directory after shutdown.. not sure if this method deletes the db after we are done with it.

Comment on lines +115 to +123
let db = &srv.shared.database;
let mut tx_inner = db.off_chain().clone().into_transaction();
let db_tx = DecompressDbTx {
db_tx: DbTx {
db_tx: &mut tx_inner,
},
onchain_db: db.on_chain().view_at(&0u32.into()).unwrap(),
};
let decompressed = decompress(compression_config, db_tx, block).await.unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

decompression requires some previous indexation to be done on the data, it can't be done from an empty database afaiu

Co-authored-by: Rafał Chabowski <[email protected]>
@Dentosal Dentosal dismissed stale reviews from rafal-ch and netrome via a7324f7 October 17, 2024 10:11
netrome
netrome previously approved these changes Oct 25, 2024
Dentosal and others added 2 commits October 28, 2024 08:47
This PR extends the `fuel-core` too make public some functionality that
could be useful to reuse in the watchtower
https://github.com/FuelLabs/network-watchtower.

### Before requesting review
- [x] I have reviewed the code myself
crates/fuel-core/src/combined_database.rs Outdated Show resolved Hide resolved
crates/fuel-core/src/combined_database.rs Outdated Show resolved Hide resolved
on_chain: Database::rocksdb_temp(state_rewind_policy)?,
off_chain: Database::rocksdb_temp(state_rewind_policy)?,
relayer: Database::rocksdb_temp(state_rewind_policy)?,
gas_price: Default::default(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because gas price table and relayer table doesn't need to support state rewind in the case of the temporary database(right now at least). Because we don't have any logic around it.

db_tx: DbTx {
db_tx: &mut tx_inner,
},
onchain_db: db.on_chain().view_at(&0u32.into()).unwrap(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice if in the test you highlighted somehow that we use the previous state of the database because it is important detail=)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment to that effect in aca530a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants