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

chore(gas_price_service): define port for GasPriceDatabase #2226

Closed
wants to merge 15 commits into from

Conversation

rymnc
Copy link
Member

@rymnc rymnc commented Sep 20, 2024

Note

This is PR 2/n in cleaning up the gas price service. This PR is first of few that moves the algorithm_updater from the sub_services module of fuel-core to fuel-core-gas-price-service.

Please review #2224 before getting to this one ;)

  • chore(gas_price_service): define port for gas price db lookups

Linked Issues/PRs

Description

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification matches the implemented behavior (link update PR if changes are needed)

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

After merging, notify other teams

[Add or remove entries as needed]

@rymnc rymnc added the no changelog Skip the CI check of the changelog modification label Sep 20, 2024
@rymnc rymnc self-assigned this Sep 20, 2024
@rymnc rymnc changed the base branch from master to chore/gas-price-service-ports September 20, 2024 07:14
@rymnc rymnc force-pushed the chore/gas-price-service-ports-p2 branch from 588fa87 to a0a97e8 Compare September 20, 2024 07:40
@rymnc rymnc force-pushed the chore/gas-price-service-ports branch from 352cd0b to 100fee8 Compare September 20, 2024 08:03
@rymnc rymnc force-pushed the chore/gas-price-service-ports-p2 branch 2 times, most recently from ed1ad85 to 97b1cf0 Compare September 20, 2024 08:06
@rymnc rymnc force-pushed the chore/gas-price-service-ports branch from 100fee8 to d45a323 Compare September 20, 2024 08:10
@rymnc rymnc force-pushed the chore/gas-price-service-ports-p2 branch from 97b1cf0 to 4096322 Compare September 20, 2024 10:14
Base automatically changed from chore/gas-price-service-ports to master September 20, 2024 11:17
@rymnc rymnc force-pushed the chore/gas-price-service-ports-p2 branch from 4096322 to 5702371 Compare September 20, 2024 11:29
@MitchTurner
Copy link
Member

I guess this is still in draft. So maybe shouldn't have improved, but since this is all being done incrementally... I'm good with what I'm seeing.

@rymnc rymnc marked this pull request as ready for review September 20, 2024 13:16
@rymnc rymnc requested a review from a team September 20, 2024 13:16
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.

Looks good to me. Just two todos that are missing a reference to an issue.

@@ -51,41 +34,6 @@ mod l2_source_tests;

pub mod storage;

impl<Storage> MetadataStorage for StructuredStorage<Storage>
Copy link
Collaborator

Choose a reason for hiding this comment

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

The main idea of this code was that gas price crate defined default implementation of the MetadataStorage port. I don't see why we don't want to follow that idea=)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Having default implementation allows us test it within this crate, and inherit it later in the fuel-core, if we want to, of course=)

Copy link
Member Author

Choose a reason for hiding this comment

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

retained in 100b5b8

HistoricalView::latest_height(self)
}

fn rollback_last_block(&self) -> StorageResult<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we don't need to leak this kind of functionality to the service.

I think it would be better if FuelService were responsible for database integrity. It is okay if other databases are behind than on-chain database. It is the responsibility of the service to catch up(since only the service knows how to advance the state). But if the on-chain database is behind other databases, then FuelService should roll back them since only FuelService knows that the database supports the state rewind feature.

Copy link
Member

@MitchTurner MitchTurner Sep 23, 2024

Choose a reason for hiding this comment

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

Hmmmm. Kinda confused. InitializationTask currently handles that and I thought we wanted to get rid of it and move that code into GasPriceService.

I think @xgreenx right that it's leaking something, but at the same time we have to leak the idea that they can be out of sync to include the syncing logic into GasPriceService.

Copy link
Member

Choose a reason for hiding this comment

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

i.e. I'm not sure how the FuelService could handle it without accessing the metadata and updater code.

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 think @xgreenx here means that the FuelService should be aware of rollback strategy for each of the db's included within CombinedDatabase, which isn't that complex at the moment where we're leaking business logic, its just rolling back to the same height as the OnChainDb

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 9575a21
seems cleaner than before :)

Copy link
Member Author

Choose a reason for hiding this comment

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

slightly unsure about where you'd like to place the rewind/rollback call ~ i've placed it before the init_sub_services call :)

@rymnc rymnc force-pushed the chore/gas-price-service-ports-p2 branch from 2735d80 to 100b5b8 Compare September 23, 2024 09:30
fn set_metadata(&mut self, metadata: &UpdaterMetadata) -> Result<()>;
}

pub trait GasPriceData: Send + Sync {
Copy link
Contributor

Choose a reason for hiding this comment

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

the name of the port is GasPriceData, but its only function returns a BlockHeight.

Would it be possible to have a comment that explains how the two are related?

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in d51d494

Copy link
Collaborator

Choose a reason for hiding this comment

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

The gas_price_service crate doesn't know about the Database<GasPriceDatabase>=)

The comment and name of the trait should be more clear regarding what expectation to the type that implements it, and maybe some description why

Copy link
Member Author

Choose a reason for hiding this comment

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

clearer in 64818a6

}

Ok(())
}

fn revert_gas_price_db_to_height(
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this fragment of code removed? Is it related to the temporary fix in combined_database.rs?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes we don't need this code anymore since we delegate rolling back of db to FuelService

MitchTurner
MitchTurner previously approved these changes Sep 24, 2024
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.

Sometimes it's hard to know what I should give feedback on or just accept as a stopgap. With that in mind, I don't see any immediate need to hold this up.

S: ShutdownListener,
{
if let Some(on_chain_height) = self.on_chain().latest_height_from_metadata()? {
// todo(https://github.com/FuelLabs/fuel-core/issues/2239): This is a temporary fix
Copy link
Member

Choose a reason for hiding this comment

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

Yeah. We definitely want to throw an error if this fails.

Comment on lines 205 to 208
GasPriceStore: GasPriceData
+ MetadataStorage
+ KeyValueInspect<Column = GasPriceColumn>
+ Modifiable,
Copy link
Member

Choose a reason for hiding this comment

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

We should be careful about these all being bound together. Obviously this is still in an intermediate state, so maybe goes without saying, but ultimately the different ports should be handled independently. If they are the same thing under the hood, that shouldn't be leaked to like this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also don't know the reason for making it generic in this PR; I think we can do it later when we switch from the V0 to the V1 algorithm.

@@ -12,3 +16,13 @@ pub trait L2Data: Send + Sync {
height: &BlockHeight,
) -> StorageResult<Option<Block<Transaction>>>;
}

pub trait MetadataStorage: Send + Sync {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we want to move this trait here? I thought that each service(v0 and v1) would have its own ports. It is the same for storage traits as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

The metadata storage would remain the same since we discussed that we will keep it versioned right

Copy link
Collaborator

Choose a reason for hiding this comment

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

It was up to you=D I was thinking that you will choose the approach with two different columns, since it is more flexible.

@@ -36,25 +30,6 @@ fn database() -> StorageTransaction<InMemoryStorage<GasPriceColumn>> {
InMemoryStorage::default().into_transaction()
}

#[tokio::test]
async fn get_metadata__can_get_most_recent_version() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we want to remove this test?

Copy link
Member Author

Choose a reason for hiding this comment

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

functionally the same as set_metadata__can_set_metadata
there's already asserts for getting the metadata in that test.

Copy link
Member

@MitchTurner MitchTurner Sep 24, 2024

Choose a reason for hiding this comment

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

No. They are testing different functions. It doesn't matter if they are redundant, the point isn't coverage. We should keep 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.

okay

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 62343d7

Comment on lines 205 to 208
GasPriceStore: GasPriceData
+ MetadataStorage
+ KeyValueInspect<Column = GasPriceColumn>
+ Modifiable,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also don't know the reason for making it generic in this PR; I think we can do it later when we switch from the V0 to the V1 algorithm.

}
}

impl MetadataStorage for Database<GasPriceDatabase> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we want to duplicate the implementation here instead of deriving the blanket implementation from gas price service crate?

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 417459d

@rymnc
Copy link
Member Author

rymnc commented Sep 25, 2024

already merged into master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog Skip the CI check of the changelog modification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants