mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-02 16:21:42 +00:00
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
This commit is contained in:
@@ -1469,7 +1469,7 @@ pub struct BlobParameters {
|
||||
|
||||
// A wrapper around a vector of BlobParameters to ensure that the vector is reverse
|
||||
// sorted by epoch.
|
||||
#[derive(arbitrary::Arbitrary, Serialize, Debug, PartialEq, Clone)]
|
||||
#[derive(arbitrary::Arbitrary, Debug, PartialEq, Clone)]
|
||||
pub struct BlobSchedule(Vec<BlobParameters>);
|
||||
|
||||
impl<'de> Deserialize<'de> for BlobSchedule {
|
||||
@@ -1513,6 +1513,18 @@ impl BlobSchedule {
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for BlobSchedule {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut schedule = self.0.clone();
|
||||
// reversing the list to get an ascending order
|
||||
schedule.reverse();
|
||||
schedule.serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a BlobSchedule {
|
||||
type Item = &'a BlobParameters;
|
||||
type IntoIter = std::slice::Iter<'a, BlobParameters>;
|
||||
@@ -2620,6 +2632,19 @@ mod yaml_tests {
|
||||
default_max_blobs_per_block_electra()
|
||||
);
|
||||
assert_eq!(spec.max_blobs_per_block_within_fork(ForkName::Fulu), 20);
|
||||
|
||||
// Check that serialization is in ascending order
|
||||
let yaml = serde_yaml::to_string(&spec.blob_schedule).expect("should serialize");
|
||||
|
||||
// Deserialize back to Vec<BlobParameters> to check order
|
||||
let deserialized: Vec<BlobParameters> =
|
||||
serde_yaml::from_str(&yaml).expect("should deserialize");
|
||||
|
||||
// Should be in ascending order by epoch
|
||||
assert!(
|
||||
deserialized.iter().map(|bp| bp.epoch.as_u64()).is_sorted(),
|
||||
"BlobSchedule should serialize in ascending order by epoch"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user