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

fix(gas_price_service_v1): block committer api format #2506

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ae2b760
fix(gas_price_service_v1): block committer api format
rymnc Dec 17, 2024
f01a94c
Merge branch 'chore/add-tests-for-v1-gas-service' into fix/block-comm…
MitchTurner Dec 17, 2024
1ed6d98
Move to latest recorded block height concept instead of bundle id
MitchTurner Dec 17, 2024
5175631
Update the mock server, move to use in UTs, write some UTs
MitchTurner Dec 17, 2024
a701116
Fix spelling
MitchTurner Dec 17, 2024
13880ed
Fix integ test
MitchTurner Dec 17, 2024
05574d5
Remove tracing subscriber
MitchTurner Dec 17, 2024
519533d
Lint toml file
MitchTurner Dec 17, 2024
6956ca3
Update crates/services/gas_price_service/src/common/fuel_core_storage…
MitchTurner Dec 17, 2024
a9e5067
Update crates/services/gas_price_service/src/v1/da_source_service/blo…
MitchTurner Dec 17, 2024
a19b0b7
Update crates/services/gas_price_service/src/v1/da_source_service/blo…
MitchTurner Dec 17, 2024
295e5e9
Update crates/services/gas_price_service/src/v1/da_source_service/ser…
MitchTurner Dec 17, 2024
2c4cb2c
Update crates/services/gas_price_service/src/v1/da_source_service/blo…
MitchTurner Dec 17, 2024
5744f3d
Update crates/services/gas_price_service/src/v1/da_source_service/blo…
MitchTurner Dec 17, 2024
24637d7
Appease Clippy-sama
MitchTurner Dec 17, 2024
c215b04
Fix import signature
MitchTurner Dec 18, 2024
7a8e1b4
lint toml
MitchTurner Dec 18, 2024
4655de6
Change latest recorded block to only have one key, add some logs
MitchTurner Dec 18, 2024
eef1e9a
Add more logs
MitchTurner Dec 18, 2024
eb29a3a
Remove test that has different behavior now
MitchTurner Dec 18, 2024
fc107cc
Use range for v1 algorithm commit blocks
MitchTurner Dec 18, 2024
38eebde
Nitpick `From` impls and add comment
MitchTurner Dec 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/services/gas_price_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ fuel-core-storage = { workspace = true, features = ["std"] }
fuel-core-types = { workspace = true, features = ["std"] }
fuel-gas-price-algorithm = { workspace = true }
futures = { workspace = true }
mockito = { version = "1.6.1", optional = true }
num_enum = { workspace = true }
parking_lot = { workspace = true }
reqwest = { workspace = true, features = ["json"] }
serde = { workspace = true }
serde_json = { workspace = true, optional = true }
strum = { workspace = true, features = ["derive"] }
strum_macros = { workspace = true }
thiserror = { workspace = true }
Expand All @@ -32,4 +34,9 @@ tracing = { workspace = true }
fuel-core-services = { workspace = true, features = ["test-helpers"] }
fuel-core-storage = { workspace = true, features = ["test-helpers"] }
fuel-core-types = { path = "./../../types", features = ["test-helpers"] }
mockito = { version = "1.6.1" }
serde_json = { workspace = true }
tracing-subscriber = { workspace = true }

[features]
test-helpers = ["dep:mockito", "dep:serde_json"]
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::{
common::{
fuel_core_storage_adapter::storage::{
BundleIdTable,
GasPriceColumn,
GasPriceMetadata,
RecordedHeights,
},
updater_metadata::UpdaterMetadata,
utils::{
Expand All @@ -14,9 +14,9 @@ use crate::{
},
ports::{
GasPriceServiceAtomicStorage,
GetDaBundleId,
GetLatestRecordedHeight,
GetMetadataStorage,
SetDaBundleId,
SetLatestRecordedHeight,
SetMetadataStorage,
},
};
Expand Down Expand Up @@ -99,25 +99,28 @@ where
}
}

impl<Storage> GetDaBundleId for Storage
impl<Storage> GetLatestRecordedHeight for Storage
where
Storage: Send + Sync,
Storage: StorageInspect<BundleIdTable, Error = StorageError>,
Storage: StorageInspect<RecordedHeights, Error = StorageError>,
{
fn get_bundle_id(&self, block_height: &BlockHeight) -> GasPriceResult<Option<u32>> {
let bundle_id = self
.storage::<BundleIdTable>()
fn get_recorded_height(
&self,
block_height: &BlockHeight,
) -> GasPriceResult<Option<BlockHeight>> {
let recorded_height = self
.storage::<RecordedHeights>()
.get(block_height)
.map_err(|err| GasPriceError::CouldNotFetchDARecord(err.into()))?
.map(|no| *no);
Ok(bundle_id)
Ok(recorded_height)
}
}

impl<Storage> GasPriceServiceAtomicStorage for Storage
where
Storage: 'static,
Storage: GetMetadataStorage + GetDaBundleId,
Storage: GetMetadataStorage + GetLatestRecordedHeight,
Storage: KeyValueInspect<Column = GasPriceColumn> + Modifiable + Send + Sync,
{
type Transaction<'a> = StorageTransaction<&'a mut Storage> where Self: 'a;
Expand All @@ -135,18 +138,18 @@ where
}
}

impl<Storage> SetDaBundleId for Storage
impl<Storage> SetLatestRecordedHeight for Storage
where
Storage: Send + Sync,
Storage: StorageMutate<BundleIdTable, Error = StorageError>,
Storage: StorageMutate<RecordedHeights, Error = StorageError>,
{
fn set_bundle_id(
fn set_recorded_height(
&mut self,
block_height: &BlockHeight,
bundle_id: u32,
recorded_height: BlockHeight,
) -> GasPriceResult<()> {
self.storage_as_mut::<BundleIdTable>()
.insert(block_height, &bundle_id)
self.storage_as_mut::<RecordedHeights>()
.insert(block_height, &recorded_height)
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we only insert to the DB. Should we consider pruning old data at some point?

Copy link
Member

Choose a reason for hiding this comment

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

We only have one key now, so it's very small.

.map_err(|err| GasPriceError::CouldNotFetchDARecord(err.into()))?;
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,16 @@ impl TableWithBlueprint for UnrecordedBlocksTable {
}
}

pub struct BundleIdTable;
pub struct RecordedHeights;
rafal-ch marked this conversation as resolved.
Show resolved Hide resolved

/// The sequence number or bundle id of the posted blocks.
type BundleId = u32;

impl Mappable for BundleIdTable {
impl Mappable for RecordedHeights {
Copy link
Member Author

Choose a reason for hiding this comment

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

perhaps a comment here about using a fixed key vs different keys to store the last recorded block height?

Copy link
Member

Choose a reason for hiding this comment

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

I think I prefer this since we get to explicitly call for the height specified in the metadata. In the case that the metadata is behind the DB height, we can still get the right height.

type Key = Self::OwnedKey;
type OwnedKey = BlockHeight;
type Value = Self::OwnedValue;
type OwnedValue = BundleId;
type OwnedValue = BlockHeight;
}

impl TableWithBlueprint for BundleIdTable {
impl TableWithBlueprint for RecordedHeights {
rafal-ch marked this conversation as resolved.
Show resolved Hide resolved
type Blueprint = Plain<Primitive<4>, Postcard>;
type Column = GasPriceColumn;

Expand Down
23 changes: 15 additions & 8 deletions crates/services/gas_price_service/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,33 @@ pub trait GetMetadataStorage: Send + Sync {
-> Result<Option<UpdaterMetadata>>;
}

pub trait SetDaBundleId: Send + Sync {
fn set_bundle_id(&mut self, block_height: &BlockHeight, bundle_id: u32)
-> Result<()>;
pub trait SetLatestRecordedHeight: Send + Sync {
/// For any given L2 block produced, the DA will have committed some
fn set_recorded_height(
&mut self,
block_height: &BlockHeight,
recorded_height: BlockHeight,
) -> Result<()>;
}

pub trait GetDaBundleId: Send + Sync {
fn get_bundle_id(&self, block_height: &BlockHeight) -> Result<Option<u32>>;
pub trait GetLatestRecordedHeight: Send + Sync {
fn get_recorded_height(
&self,
block_height: &BlockHeight,
) -> Result<Option<BlockHeight>>;
}

pub trait GasPriceServiceAtomicStorage
where
Self: 'static,
Self: Send + Sync,
Self: GetMetadataStorage + GetDaBundleId,
Self: GetMetadataStorage + GetLatestRecordedHeight,
{
type Transaction<'a>: AsUnrecordedBlocks
+ SetMetadataStorage
+ GetMetadataStorage
+ SetDaBundleId
+ GetDaBundleId
+ SetLatestRecordedHeight
+ GetLatestRecordedHeight
where
Self: 'a;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod service;
#[derive(Debug, Default, Clone, Eq, Hash, PartialEq)]
pub struct DaBlockCosts {
pub bundle_id: u32,
// TODO: Should this be a range?
Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds like it should

pub l2_blocks: Vec<u32>,
pub bundle_size_bytes: u32,
pub blob_cost_wei: u128,
Expand Down
Loading
Loading