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

Conversation

rymnc
Copy link
Member

@rymnc rymnc commented Dec 17, 2024

Note

This PR is wip, we need to decide if we should sunset bundleId's or not

Linked Issues/PRs

Description

the block committer deviated from the spec on the api format, this PR updates the code to match the implementation.

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 force-pushed the fix/block-committer-api branch from c7e96da to ae2b760 Compare December 17, 2024 11:59
@rymnc rymnc added the no changelog Skip the CI check of the changelog modification label Dec 17, 2024
@rymnc rymnc self-assigned this Dec 17, 2024
fn get_recorded_height(
&self,
block_height: &BlockHeight,
) -> GasPriceResult<Option<BlockHeight>> {
let bundle_id = self
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 this should be

let recorded_height = self

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.

@@ -2,6 +2,7 @@
#![deny(clippy::cast_possible_truncation)]
#![deny(unused_crate_dependencies)]
#![deny(warnings)]
extern crate core;
Copy link
Member Author

Choose a reason for hiding this comment

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

do we need this?

Copy link
Member

Choose a reason for hiding this comment

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

Removed.

#![allow(non_snake_case)]

use super::*;
use crate::v1::da_source_service::block_committer_costs::fake_server::FakeServer;
Copy link
Member Author

Choose a reason for hiding this comment

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

think this import can be simplified

Copy link
Member

Choose a reason for hiding this comment

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

Done.

@MitchTurner MitchTurner marked this pull request as ready for review December 18, 2024 00:01
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.

Some nits and minor questions, otherwise lgtm

@@ -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

number: u32,
) -> DaBlockCostsResult<Option<RawDaBlockCosts>> {
async fn get_latest_costs(&self) -> DaBlockCostsResult<Option<RawDaBlockCosts>> {
// Latest: http://localhost:8080/v1/costs?variant=latest&limit=5
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Latest: http://localhost:8080/v1/costs?variant=latest&limit=5

Copy link
Member

Choose a reason for hiding this comment

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

I actually like these. Shows what we're trying to reproduce.

&self,
l2_block_number: u32,
) -> DaBlockCostsResult<Vec<RawDaBlockCosts>> {
// Specific: http://localhost:8080/v1/costs?variant=specific&value=19098935&limit=5
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Specific: http://localhost:8080/v1/costs?variant=specific&value=19098935&limit=5

let variant = values.next().unwrap();
tracing::info!("Variant: {:?}", variant);
match variant {
// Latest: http://localhost:8080/v1/costs?variant=latest&limit=5
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Latest: http://localhost:8080/v1/costs?variant=latest&limit=5

most_recent.into_iter().collect();
serde_json::to_string(&response).unwrap().into()
}
// Specific: http://localhost:8080/v1/costs?variant=specific&value=19098935&limit=5
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Specific: http://localhost:8080/v1/costs?variant=specific&value=19098935&limit=5

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.

Comment on lines 123 to 126
bundle_id: value.bundle_id,
l2_blocks: (value.start_height..=value.end_height).collect(),
bundle_size_bytes: value.size_bytes,
blob_cost_wei: value.cost_wei,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bundle_id: value.bundle_id,
l2_blocks: (value.start_height..=value.end_height).collect(),
bundle_size_bytes: value.size_bytes,
blob_cost_wei: value.cost_wei,
Self::from(&value)

Ok(())
}
}

impl From<RawDaBlockCosts> for DaBlockCosts {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I'd suggest moving the two From<... implementations close to each other.

@MitchTurner MitchTurner merged commit 108aa0d into chore/add-tests-for-v1-gas-service Dec 18, 2024
9 checks passed
@MitchTurner MitchTurner deleted the fix/block-committer-api branch December 18, 2024 19:07
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.

4 participants