Skip to content

Commit 1046dfb

Browse files
authored
Serialize bpo schedule in asending order (#7753)
N/A Serializes the blob_schedule in ascending order to match other clients. This is needed to keep the output of `eth/v1/config/spec` http endpoint consistent across clients. cc @barnabasbusa
1 parent 3f06e5d commit 1046dfb

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

consensus/types/src/chain_spec.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ pub struct BlobParameters {
14691469

14701470
// A wrapper around a vector of BlobParameters to ensure that the vector is reverse
14711471
// sorted by epoch.
1472-
#[derive(arbitrary::Arbitrary, Serialize, Debug, PartialEq, Clone)]
1472+
#[derive(arbitrary::Arbitrary, Debug, PartialEq, Clone)]
14731473
pub struct BlobSchedule(Vec<BlobParameters>);
14741474

14751475
impl<'de> Deserialize<'de> for BlobSchedule {
@@ -1513,6 +1513,18 @@ impl BlobSchedule {
15131513
}
15141514
}
15151515

1516+
impl Serialize for BlobSchedule {
1517+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
1518+
where
1519+
S: Serializer,
1520+
{
1521+
let mut schedule = self.0.clone();
1522+
// reversing the list to get an ascending order
1523+
schedule.reverse();
1524+
schedule.serialize(serializer)
1525+
}
1526+
}
1527+
15161528
impl<'a> IntoIterator for &'a BlobSchedule {
15171529
type Item = &'a BlobParameters;
15181530
type IntoIter = std::slice::Iter<'a, BlobParameters>;
@@ -2620,6 +2632,19 @@ mod yaml_tests {
26202632
default_max_blobs_per_block_electra()
26212633
);
26222634
assert_eq!(spec.max_blobs_per_block_within_fork(ForkName::Fulu), 20);
2635+
2636+
// Check that serialization is in ascending order
2637+
let yaml = serde_yaml::to_string(&spec.blob_schedule).expect("should serialize");
2638+
2639+
// Deserialize back to Vec<BlobParameters> to check order
2640+
let deserialized: Vec<BlobParameters> =
2641+
serde_yaml::from_str(&yaml).expect("should deserialize");
2642+
2643+
// Should be in ascending order by epoch
2644+
assert!(
2645+
deserialized.iter().map(|bp| bp.epoch.as_u64()).is_sorted(),
2646+
"BlobSchedule should serialize in ascending order by epoch"
2647+
);
26232648
}
26242649

26252650
#[test]

0 commit comments

Comments
 (0)