Skip to content

Commit 4132e6d

Browse files
authored
Make cross regions more typed (#923)
## 📝 Summary Option<bool> is bad ## 💡 Motivation and Context <!--- (Optional) Why is this change required? What problem does it solve? Remove this section if not applicable. --> --- ## ✅ I have completed the following steps: * [x] Run `make lint` * [x] Run `make test` * [x] Added tests (if applicable)
1 parent fd5d6f9 commit 4132e6d

4 files changed

Lines changed: 13 additions & 16 deletions

File tree

crates/rbuilder-primitives/src/lib.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct Metadata {
5252
/// Order refund identity.
5353
pub refund_identity: Option<Address>,
5454
/// `RawBundle` field, round-tripped through `Bundle`. Not consumed by rbuilder.
55-
pub disable_cross_region_sharing: Option<bool>,
55+
pub disable_cross_region_sharing: bool,
5656
}
5757

5858
impl Default for Metadata {
@@ -73,7 +73,7 @@ impl Metadata {
7373
received_at_timestamp,
7474
is_system: false,
7575
refund_identity: None,
76-
disable_cross_region_sharing: None,
76+
disable_cross_region_sharing: false,
7777
}
7878
}
7979

@@ -99,25 +99,18 @@ impl Metadata {
9999
self.refund_identity = refund_identity;
100100
}
101101

102-
pub fn with_disable_cross_region_sharing(
103-
mut self,
104-
disable_cross_region_sharing: Option<bool>,
105-
) -> Self {
102+
pub fn with_disable_cross_region_sharing(mut self, disable_cross_region_sharing: bool) -> Self {
106103
self.disable_cross_region_sharing = disable_cross_region_sharing;
107104
self
108105
}
109-
110-
pub fn set_disable_cross_region_sharing(&mut self, disable_cross_region_sharing: Option<bool>) {
111-
self.disable_cross_region_sharing = disable_cross_region_sharing;
112-
}
113106
}
114107

115108
impl InMemorySize for Metadata {
116109
fn size(&self) -> usize {
117110
mem::size_of::<time::OffsetDateTime>() + // received_at_timestamp
118111
mem::size_of::<Option<Address>>() + // refund_identity
119112
mem::size_of::<bool>() + // is_system
120-
mem::size_of::<Option<bool>>() // disable_cross_region_sharing
113+
mem::size_of::<bool>() // disable_cross_region_sharing
121114
}
122115
}
123116

crates/rbuilder-primitives/src/serialize.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,12 @@ pub struct RawBundleMetadata {
154154
#[serde(skip_serializing_if = "Option::is_none")]
155155
pub bundle_hash: Option<B256>,
156156
/// Disable multiplexing bundle to other region builders.
157-
#[serde(skip_serializing_if = "Option::is_none")]
158-
pub disable_cross_region_sharing: Option<bool>,
157+
#[serde(default, skip_serializing_if = "is_false")]
158+
pub disable_cross_region_sharing: bool,
159+
}
160+
161+
fn is_false(b: &bool) -> bool {
162+
!*b
159163
}
160164

161165
impl RawBundleMetadata {
@@ -234,7 +238,7 @@ impl RawBundleMetadata {
234238
version,
235239
));
236240
}
237-
if self.disable_cross_region_sharing.is_some() {
241+
if self.disable_cross_region_sharing {
238242
return Err(RawBundleConvertError::FieldNotSupportedByVersion(
239243
"disable_cross_region_sharing".to_owned(),
240244
version,

crates/rbuilder/src/backtest/build_block/synthetic_orders.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<ConfigType: LiveBuilderConfig> SyntheticOrdersSource<ConfigType> {
9898
received_at_timestamp: time::OffsetDateTime::from_unix_timestamp(0).unwrap(),
9999
is_system: false,
100100
refund_identity: None,
101-
disable_cross_region_sharing: None,
101+
disable_cross_region_sharing: false,
102102
},
103103
dropping_tx_hashes: Default::default(),
104104
refund: None,

crates/rbuilder/src/backtest/store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ mod test {
744744
refund_identity: None,
745745
version: Some(RawBundle::encode_version(LAST_BUNDLE_VERSION)),
746746
bundle_hash: None,
747-
disable_cross_region_sharing: None,
747+
disable_cross_region_sharing: false,
748748
},
749749
})),
750750
}

0 commit comments

Comments
 (0)