Skip to content

Commit

Permalink
Null timestamp for bundles are handled as unset timestamp (flashbots#440
Browse files Browse the repository at this point in the history
)

## 📝 Summary

<!--- A general summary of your changes -->

## 💡 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:

* [ ] Run `make lint`
* [ ] Run `make test`
* [ ] Added tests (if applicable)
  • Loading branch information
dvush authored Feb 24, 2025
1 parent 6cdb89c commit 9929ccf
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
12 changes: 11 additions & 1 deletion crates/rbuilder/src/live_builder/order_input/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
RawBundle, RawBundleDecodeResult, RawShareBundle, RawShareBundleDecodeResult, RawTx,
TxEncoding,
},
BundleReplacementData, BundleReplacementKey, MempoolTx, Order,
BundleReplacementData, BundleReplacementKey, MempoolTx, Order, OrderId,
},
telemetry::mark_command_received,
};
Expand Down Expand Up @@ -138,8 +138,18 @@ async fn handle_eth_send_bundle(
return;
}
};

match bundle_res {
RawBundleDecodeResult::NewBundle(bundle) => {
if bundle.max_timestamp == Some(0) {
let order = OrderId::Bundle(bundle.uuid);
warn!(
?order,
min_timestamp = bundle.min_timestamp,
max_timestamp = bundle.max_timestamp,
"Bundle has timestamp 0"
);
}
let order = Order::Bundle(bundle);
let parse_duration = start.elapsed();
let target_block = order.target_block().unwrap_or_default();
Expand Down
49 changes: 47 additions & 2 deletions crates/rbuilder/src/primitives/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ pub struct RawBundle {
pub min_timestamp: Option<u64>,
/// maxTimestamp (Optional) `Number`, the maximum timestamp for which this bundle is valid, in
/// seconds since the unix epoch
/// A value of 0 means it is unset.
#[serde(skip_serializing_if = "Option::is_none")]
pub max_timestamp: Option<u64>,
/// See [`BundleReplacementData`] sequence_number
Expand Down Expand Up @@ -228,8 +229,9 @@ impl RawBundle {
hash: Default::default(),
uuid: Default::default(),
replacement_data,
// we assume that 0 timestamp is the same as timestamp not set
min_timestamp: self.min_timestamp,
max_timestamp: self.max_timestamp,
max_timestamp: self.max_timestamp.filter(|t| *t != 0),
signer: self.signing_address,
metadata: Default::default(),
dropping_tx_hashes: self.dropping_tx_hashes,
Expand Down Expand Up @@ -955,7 +957,19 @@ mod tests {
#[test]
fn test_correct_bundle_uuid_null_reverting_hashes() {
// raw json string
let bundle_json ="{\"txs\":[\"0x02f901c00182123184cd0a3c00850d8c3ac83483186a00949f51040aec194a89cb6a7e852e79ea07cc0bf6488203abb9014e524f05aadf99a0839818b3f120ebac9b73f82b617dc6a5550000000000000004aa7fdb4059a9fc0400000000000000000000000000000000000000000000000000000000000000000000000000540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e0000000000000001270250af8569d4ff712aaebc2f5971a824249fa7000000000000030015153da0e9e13cfc167b3d417d3721bf545479bb000bb800003c00540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e00000000000000015533b61d314f7faf87df530de362f457a342ec1e00000000000003008107fca5494375fc743a9fc4d4844353a1af3d94000bb800003c00540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e0000000000000001b81ab4b74522a25525e583f94dba73521cc4d56b0000000000000100308c6fbd6a14881af333649f17f2fde9cd75e2a6000000000000c080a061a306a26e0a66973364614912553f32c7915e899b188164bf2e99b97e08d0e8a00c76b844dc4b72c2040f14e69f0f9c3fa290a2db7c4a245d045155090ec7d746\"],\"replacementUuid\":null,\"signingAddress\":\"0x564d55a3a73f6efb907afe92b1706602b2d54018\",\"blockNumber\":\"0x142dd19\",\"minTimestamp\":null,\"maxTimestamp\":null,\"revertingTxHashes\":null}";
let bundle_json = r#"
{
"txs": [
"0x02f901c00182123184cd0a3c00850d8c3ac83483186a00949f51040aec194a89cb6a7e852e79ea07cc0bf6488203abb9014e524f05aadf99a0839818b3f120ebac9b73f82b617dc6a5550000000000000004aa7fdb4059a9fc0400000000000000000000000000000000000000000000000000000000000000000000000000540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e0000000000000001270250af8569d4ff712aaebc2f5971a824249fa7000000000000030015153da0e9e13cfc167b3d417d3721bf545479bb000bb800003c00540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e00000000000000015533b61d314f7faf87df530de362f457a342ec1e00000000000003008107fca5494375fc743a9fc4d4844353a1af3d94000bb800003c00540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e0000000000000001b81ab4b74522a25525e583f94dba73521cc4d56b0000000000000100308c6fbd6a14881af333649f17f2fde9cd75e2a6000000000000c080a061a306a26e0a66973364614912553f32c7915e899b188164bf2e99b97e08d0e8a00c76b844dc4b72c2040f14e69f0f9c3fa290a2db7c4a245d045155090ec7d746"
],
"replacementUuid": null,
"signingAddress": "0x564d55a3a73f6efb907afe92b1706602b2d54018",
"blockNumber": "0x142dd19",
"minTimestamp": null,
"maxTimestamp": null,
"revertingTxHashes": null
}
"#;

let bundle_request: RawBundle =
serde_json::from_str(bundle_json).expect("failed to decode bundle");
Expand All @@ -981,6 +995,37 @@ mod tests {
assert_eq!(bundle.max_timestamp, None);
}

#[test]
fn test_correct_bundle_zero_timestamp_decoding() {
// raw json string
let bundle_json = r#"
{
"txs": [
"0x02f901c00182123184cd0a3c00850d8c3ac83483186a00949f51040aec194a89cb6a7e852e79ea07cc0bf6488203abb9014e524f05aadf99a0839818b3f120ebac9b73f82b617dc6a5550000000000000004aa7fdb4059a9fc0400000000000000000000000000000000000000000000000000000000000000000000000000540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e0000000000000001270250af8569d4ff712aaebc2f5971a824249fa7000000000000030015153da0e9e13cfc167b3d417d3721bf545479bb000bb800003c00540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e00000000000000015533b61d314f7faf87df530de362f457a342ec1e00000000000003008107fca5494375fc743a9fc4d4844353a1af3d94000bb800003c00540101d99034942c4a883ff3ed6cda6c91fe505a58eb2e0000000000000001b81ab4b74522a25525e583f94dba73521cc4d56b0000000000000100308c6fbd6a14881af333649f17f2fde9cd75e2a6000000000000c080a061a306a26e0a66973364614912553f32c7915e899b188164bf2e99b97e08d0e8a00c76b844dc4b72c2040f14e69f0f9c3fa290a2db7c4a245d045155090ec7d746"
],
"minTimestamp": 0,
"maxTimestamp": 0
}
"#;

let bundle_request: RawBundle =
serde_json::from_str(bundle_json).expect("failed to decode bundle");

let bundle = bundle_request
.clone()
.decode_new_bundle(TxEncoding::WithBlobData)
.expect("failed to convert bundle request to bundle");

assert_eq!(
bundle.hash,
fixed_bytes!("08b57aa2df6e4729c55b809d1110f16aba30956cfc17f7ad771441d6d418f991")
);
assert_eq!(bundle.uuid, uuid!("3255ceb4-fdc5-592d-a501-2183727ca3df"));

assert_eq!(bundle.min_timestamp, Some(0));
assert_eq!(bundle.max_timestamp, None);
}

#[test]
fn test_correct_raw_tx_decoding() {
// raw json string
Expand Down

0 comments on commit 9929ccf

Please sign in to comment.