Skip to content

Commit 14ca8d8

Browse files
committed
persistence: fix mismatch between blank builders and their inputs
Closes #284
1 parent b374468 commit 14ca8d8

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/containers/partials.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,16 @@ impl Hash for TransitionInfo {
156156
}
157157

158158
impl TransitionInfo {
159+
/// # Panics
160+
///
161+
/// If the number of provided seals is zero.
159162
pub fn new(
160163
transition: Transition,
161164
seals: impl AsRef<[XOutputSeal]>,
162165
) -> Result<Self, TransitionInfoError> {
163166
let id = transition.id();
164167
let seals = seals.as_ref();
168+
assert!(!seals.is_empty(), "empty seals provided to transition info constructor");
165169
let inputs = Confined::<BTreeSet<_>, 1, U24>::try_from_iter(
166170
seals.iter().copied().map(XOutpoint::from),
167171
)

src/persistence/stock.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,25 +1214,27 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
12141214
.map_err(|_| ComposeError::TooManyBlanks)?;
12151215
}
12161216

1217-
let (first_builder, second_builder) =
1217+
let (first_builder, first_inputs, second_builder, second_inputs) =
12181218
match (main_builder.has_inputs(), alt_builder.has_inputs()) {
1219-
(true, true) => (main_builder, Some(alt_builder)),
1220-
(true, false) => (main_builder, None),
1221-
(false, true) => (alt_builder, None),
1219+
(true, true) => (main_builder, main_inputs, Some(alt_builder), alt_inputs),
1220+
(true, false) => (main_builder, main_inputs, None, alt_inputs),
1221+
(false, true) => (alt_builder, alt_inputs, None, main_inputs),
12221222
(false, false) => return Err(ComposeError::InsufficientState.into()),
12231223
};
1224-
let first = TransitionInfo::new(first_builder.complete_transition()?, main_inputs)
1224+
let first = TransitionInfo::new(first_builder.complete_transition()?, first_inputs)
12251225
.map_err(|e| {
12261226
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
12271227
ComposeError::TooManyInputs
12281228
})?;
12291229
let second = if let Some(second_builder) = second_builder {
1230-
Some(TransitionInfo::new(second_builder.complete_transition()?, alt_inputs).map_err(
1231-
|e| {
1232-
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
1233-
ComposeError::TooManyInputs
1234-
},
1235-
)?)
1230+
Some(
1231+
TransitionInfo::new(second_builder.complete_transition()?, second_inputs).map_err(
1232+
|e| {
1233+
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
1234+
ComposeError::TooManyInputs
1235+
},
1236+
)?,
1237+
)
12361238
} else {
12371239
None
12381240
};

0 commit comments

Comments
 (0)