Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 17 additions & 1 deletion crates/rbuilder-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub struct Metadata {
pub is_system: bool,
/// Order refund identity.
pub refund_identity: Option<Address>,
/// `RawBundle` field, round-tripped through `Bundle`. Not consumed by rbuilder.
pub disable_cross_region_sharing: Option<bool>,
}

impl Default for Metadata {
Expand All @@ -71,6 +73,7 @@ impl Metadata {
received_at_timestamp,
is_system: false,
refund_identity: None,
disable_cross_region_sharing: None,
}
}

Expand All @@ -95,13 +98,26 @@ impl Metadata {
pub fn set_refund_identity(&mut self, refund_identity: Option<Address>) {
self.refund_identity = refund_identity;
}

pub fn with_disable_cross_region_sharing(
mut self,
disable_cross_region_sharing: Option<bool>,
) -> Self {
self.disable_cross_region_sharing = disable_cross_region_sharing;
self
}

pub fn set_disable_cross_region_sharing(&mut self, disable_cross_region_sharing: Option<bool>) {
self.disable_cross_region_sharing = disable_cross_region_sharing;
}
Comment on lines +102 to +112

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor API note: the new field semantically represents "disable" (a bool flag), and modelling it as Option<bool> invites three states β€” None, Some(false), Some(true) β€” where only two are meaningful. If the goal is to round-trip the wire-format Option<bool> faithfully, this is fine, but consider if the internal Metadata could store a plain bool (defaulting to false) and only the wire RawBundleMetadata keeps the Option. As written, None and Some(false) are indistinguishable in behaviour but produce different serialized output, which can lead to roundtrip surprises.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Option is used to have correct RawBuilder -> Bundle -> RawBundle conversion

}

impl InMemorySize for Metadata {
fn size(&self) -> usize {
mem::size_of::<time::OffsetDateTime>() + // received_at_timestamp
mem::size_of::<Option<Address>>() + // refund_identity
mem::size_of::<bool>() // is_system
mem::size_of::<bool>() + // is_system
mem::size_of::<Option<bool>>() // disable_cross_region_sharing
}
}

Expand Down
19 changes: 16 additions & 3 deletions crates/rbuilder-primitives/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{
Bundle, BundleRefund, BundleReplacementData, BundleReplacementKey, BundleVersion, MempoolTx,
Order, RawTransactionDecodable, TransactionSignedEcRecoveredWithBlobs, TxWithBlobsCreateError,
LAST_BUNDLE_VERSION,
Metadata, Order, RawTransactionDecodable, TransactionSignedEcRecoveredWithBlobs,
TxWithBlobsCreateError, LAST_BUNDLE_VERSION,
};
use alloy_consensus::constants::EIP4844_TX_TYPE_ID;
use alloy_eips::eip2718::Eip2718Error;
Expand Down Expand Up @@ -153,6 +153,9 @@ pub struct RawBundleMetadata {
/// bundleHash, externally set unique identifier for the bundle
#[serde(skip_serializing_if = "Option::is_none")]
pub bundle_hash: Option<B256>,
/// Disable multiplexing bundle to other region builders.
#[serde(skip_serializing_if = "Option::is_none")]
pub disable_cross_region_sharing: Option<bool>,
}

impl RawBundleMetadata {
Expand Down Expand Up @@ -231,6 +234,12 @@ impl RawBundleMetadata {
version,
));
}
if self.disable_cross_region_sharing.is_some() {
return Err(RawBundleConvertError::FieldNotSupportedByVersion(
"disable_cross_region_sharing".to_owned(),
version,
));
}
Comment on lines +237 to +242

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The V1 rejection added here isn't covered by test_error_bundle_decoding_invalid_fields_v1 (serialize.rs:1014). Consider adding r#" "disableCrossRegionSharing": true "# to the extra_invalid_fields array so this branch is exercised β€” otherwise a future change that drops/breaks this check won't be caught.

Ok(())
}
BundleVersion::V2 => Ok(()),
Expand Down Expand Up @@ -377,7 +386,8 @@ impl RawBundle {
max_timestamp: metadata.max_timestamp.filter(|t| *t != 0),
signer: metadata.signing_address,
refund_identity: metadata.refund_identity,
metadata: Default::default(),
metadata: Metadata::default()
.with_disable_cross_region_sharing(metadata.disable_cross_region_sharing),
dropping_tx_hashes: metadata.dropping_tx_hashes,
refund,
version,
Expand Down Expand Up @@ -417,6 +427,7 @@ impl RawBundle {
delayed_refund: value.refund.as_ref().map(|br| br.delayed),
version: Some(Self::encode_version(value.version)),
bundle_hash: value.external_hash,
disable_cross_region_sharing: value.metadata.disable_cross_region_sharing,
},
}
}
Expand Down Expand Up @@ -1018,6 +1029,8 @@ mod tests {
r#" "refundPercent": 1 "#,
r#" "refundRecipient": "0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5" "#,
r#" "refundTxHashes": ["0x75662ab9cb6d1be7334723db5587435616352c7e581a52867959ac24006ac1fe"] "#,
r#" "delayedRefund": true "#,
r#" "disableCrossRegionSharing": true "#,
];

for field in extra_invalid_fields {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl<ConfigType: LiveBuilderConfig> SyntheticOrdersSource<ConfigType> {
received_at_timestamp: time::OffsetDateTime::from_unix_timestamp(0).unwrap(),
is_system: false,
refund_identity: None,
disable_cross_region_sharing: None,
},
dropping_tx_hashes: Default::default(),
refund: None,
Expand Down
1 change: 1 addition & 0 deletions crates/rbuilder/src/backtest/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ mod test {
refund_identity: None,
version: Some(RawBundle::encode_version(LAST_BUNDLE_VERSION)),
bundle_hash: None,
disable_cross_region_sharing: None,
},
})),
}
Expand Down
Loading