Skip to content

Commit 60f663e

Browse files
avoryllimattsse
andauthored
fix(payload): emit events for Freeze payload outcomes (paradigmxyz#19435)
Co-authored-by: Matthias Seitz <[email protected]>
1 parent c78bca2 commit 60f663e

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

crates/payload/basic/src/better_payload_emitter.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ where
3838
args: BuildArguments<Self::Attributes, Self::BuiltPayload>,
3939
) -> Result<BuildOutcome<Self::BuiltPayload>, PayloadBuilderError> {
4040
match self.inner.try_build(args) {
41-
Ok(BuildOutcome::Better { payload, cached_reads }) => {
42-
let _ = self.better_payloads_tx.send(Arc::new(payload.clone()));
43-
Ok(BuildOutcome::Better { payload, cached_reads })
41+
Ok(res) => {
42+
if let Some(payload) = res.payload().cloned() {
43+
let _ = self.better_payloads_tx.send(Arc::new(payload));
44+
}
45+
Ok(res)
4446
}
4547
res => res,
4648
}

crates/payload/basic/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,19 +706,32 @@ pub enum BuildOutcome<Payload> {
706706
}
707707

708708
impl<Payload> BuildOutcome<Payload> {
709-
/// Consumes the type and returns the payload if the outcome is `Better`.
709+
/// Consumes the type and returns the payload if the outcome is `Better` or `Freeze`.
710710
pub fn into_payload(self) -> Option<Payload> {
711711
match self {
712712
Self::Better { payload, .. } | Self::Freeze(payload) => Some(payload),
713713
_ => None,
714714
}
715715
}
716716

717+
/// Consumes the type and returns the payload if the outcome is `Better` or `Freeze`.
718+
pub const fn payload(&self) -> Option<&Payload> {
719+
match self {
720+
Self::Better { payload, .. } | Self::Freeze(payload) => Some(payload),
721+
_ => None,
722+
}
723+
}
724+
717725
/// Returns true if the outcome is `Better`.
718726
pub const fn is_better(&self) -> bool {
719727
matches!(self, Self::Better { .. })
720728
}
721729

730+
/// Returns true if the outcome is `Freeze`.
731+
pub const fn is_frozen(&self) -> bool {
732+
matches!(self, Self::Freeze { .. })
733+
}
734+
722735
/// Returns true if the outcome is `Aborted`.
723736
pub const fn is_aborted(&self) -> bool {
724737
matches!(self, Self::Aborted { .. })

0 commit comments

Comments
 (0)