-
Notifications
You must be signed in to change notification settings - Fork 29
feat: simulate bundles in ingress-rpc #46
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
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,9 @@ use op_alloy_flz::tx_estimated_size_fjord_bytes; | |
| use serde::{Deserialize, Serialize}; | ||
| use uuid::Uuid; | ||
|
|
||
| /// Block time in microseconds | ||
| pub const BLOCK_TIME: u128 = 2_000_000; | ||
|
|
||
| #[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub struct Bundle { | ||
|
|
@@ -70,10 +73,14 @@ pub struct BundleWithMetadata { | |
| bundle: Bundle, | ||
| uuid: Uuid, | ||
| transactions: Vec<OpTxEnvelope>, | ||
| meter_bundle_response: MeterBundleResponse, | ||
| } | ||
|
|
||
| impl BundleWithMetadata { | ||
| pub fn load(mut bundle: Bundle) -> Result<Self, String> { | ||
| pub fn load( | ||
| mut bundle: Bundle, | ||
| meter_bundle_response: MeterBundleResponse, | ||
| ) -> Result<Self, String> { | ||
| let uuid = bundle | ||
| .replacement_uuid | ||
| .clone() | ||
|
|
@@ -96,6 +103,7 @@ impl BundleWithMetadata { | |
| bundle, | ||
| transactions, | ||
| uuid, | ||
| meter_bundle_response, | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -178,6 +186,24 @@ pub struct MeterBundleResponse { | |
| pub state_root_time_us: u128, | ||
| } | ||
|
|
||
| impl Default for MeterBundleResponse { | ||
| fn default() -> Self { | ||
|
||
| Self { | ||
| bundle_gas_price: "0".to_string(), | ||
| bundle_hash: B256::default(), | ||
| coinbase_diff: "0".to_string(), | ||
| eth_sent_to_coinbase: "0".to_string(), | ||
| gas_fees: "0".to_string(), | ||
| results: vec![], | ||
| state_block_number: 0, | ||
| state_flashblock_index: None, | ||
| total_gas_used: 0, | ||
| total_execution_time_us: 0, | ||
| state_root_time_us: 0, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
@@ -197,12 +223,15 @@ mod tests { | |
| let tx1_bytes = tx1.encoded_2718(); | ||
| let tx2_bytes = tx2.encoded_2718(); | ||
|
|
||
| let bundle = BundleWithMetadata::load(Bundle { | ||
| replacement_uuid: None, | ||
| txs: vec![tx1_bytes.clone().into()], | ||
| block_number: 1, | ||
| ..Default::default() | ||
| }) | ||
| let bundle = BundleWithMetadata::load( | ||
| Bundle { | ||
| replacement_uuid: None, | ||
| txs: vec![tx1_bytes.clone().into()], | ||
| block_number: 1, | ||
| ..Default::default() | ||
| }, | ||
| MeterBundleResponse::default(), | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert!(!bundle.uuid().is_nil()); | ||
|
|
@@ -225,12 +254,15 @@ mod tests { | |
| assert_eq!(bundle.bundle_hash(), expected_bundle_hash_single); | ||
|
|
||
| let uuid = Uuid::new_v4(); | ||
| let bundle = BundleWithMetadata::load(Bundle { | ||
| replacement_uuid: Some(uuid.to_string()), | ||
| txs: vec![tx1_bytes.clone().into(), tx2_bytes.clone().into()], | ||
| block_number: 1, | ||
| ..Default::default() | ||
| }) | ||
| let bundle = BundleWithMetadata::load( | ||
| Bundle { | ||
| replacement_uuid: Some(uuid.to_string()), | ||
| txs: vec![tx1_bytes.clone().into(), tx2_bytes.clone().into()], | ||
| block_number: 1, | ||
| ..Default::default() | ||
| }, | ||
| MeterBundleResponse::default(), | ||
| ) | ||
| .unwrap(); | ||
|
|
||
| assert_eq!(*bundle.uuid(), uuid); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a
Bundlefailsvalidate_bundlethen there wouldn't be a time to meter bundle, which is why I wrappedMeterBundleResponsearound an OptionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what
BundleWithMetadatais supposed to be. It seems to have two conflicting purposes: 1) transform the bundle data into a more useful format, and 2) provide all the information the bundler needs to receive over Kafka. For (1), it's providing the transaction data twice: once as bytes and once as parsed data structures.But when I dig into the Kafka publishing code, it looks like BundleWithMetadata is never sent over the wire? So is adding it here actually useful? I think we need a type for the actual Kafka event, which would just have a
uuid, abundle, and ameter_bundle_response. In that type,meter_bundle_responsewouldn't be optional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now, but for context, I'm going to have to stop using
BundleWithMetadatainnode-reth's metering crate since I won't have themeter_bundle_responseyet. If there ends up being another type with the utility functions on it (I'm usingbundle_with_metadata.bundle_hash()) then I'll use it, otherwise I'll reintroduce a standalone function for it local to that crate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if that's the case, perhaps in
node-rethit can remain asBundle?since as we discussed offline that i believe the intention with
BundleWithMetadatais the struct to be sent to kafka with things like the metering resultsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the most straightforward thing to do is to never convert it from
Bundleat all. But it'd be nice to have a way to pull in utility functions fromtips-core. Right now they're allBundleWithMetadatamethods, so we'd either want to move them to a new type (in that hypothetical third PR we talked about), change them to standalone utility functions instead of methods, or just reimplement them whereBundleWithMetadatadoesn't fit.