Skip to content

Commit

Permalink
persistence: fix mismatch between blank builders and their inputs
Browse files Browse the repository at this point in the history
Closes #284
  • Loading branch information
dr-orlovsky committed Jan 6, 2025
1 parent b374468 commit 14ca8d8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/containers/partials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,16 @@ impl Hash for TransitionInfo {
}

impl TransitionInfo {
/// # Panics
///
/// If the number of provided seals is zero.
pub fn new(
transition: Transition,
seals: impl AsRef<[XOutputSeal]>,
) -> Result<Self, TransitionInfoError> {
let id = transition.id();
let seals = seals.as_ref();
assert!(!seals.is_empty(), "empty seals provided to transition info constructor");

Check warning on line 168 in src/containers/partials.rs

View check run for this annotation

Codecov / codecov/patch

src/containers/partials.rs#L168

Added line #L168 was not covered by tests
let inputs = Confined::<BTreeSet<_>, 1, U24>::try_from_iter(
seals.iter().copied().map(XOutpoint::from),
)
Expand Down
24 changes: 13 additions & 11 deletions src/persistence/stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1214,25 +1214,27 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
.map_err(|_| ComposeError::TooManyBlanks)?;
}

let (first_builder, second_builder) =
let (first_builder, first_inputs, second_builder, second_inputs) =

Check warning on line 1217 in src/persistence/stock.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L1217

Added line #L1217 was not covered by tests
match (main_builder.has_inputs(), alt_builder.has_inputs()) {
(true, true) => (main_builder, Some(alt_builder)),
(true, false) => (main_builder, None),
(false, true) => (alt_builder, None),
(true, true) => (main_builder, main_inputs, Some(alt_builder), alt_inputs),
(true, false) => (main_builder, main_inputs, None, alt_inputs),
(false, true) => (alt_builder, alt_inputs, None, main_inputs),

Check warning on line 1221 in src/persistence/stock.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L1219-L1221

Added lines #L1219 - L1221 were not covered by tests
(false, false) => return Err(ComposeError::InsufficientState.into()),
};
let first = TransitionInfo::new(first_builder.complete_transition()?, main_inputs)
let first = TransitionInfo::new(first_builder.complete_transition()?, first_inputs)

Check warning on line 1224 in src/persistence/stock.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L1224

Added line #L1224 was not covered by tests
.map_err(|e| {
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
ComposeError::TooManyInputs
})?;
let second = if let Some(second_builder) = second_builder {
Some(TransitionInfo::new(second_builder.complete_transition()?, alt_inputs).map_err(
|e| {
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
ComposeError::TooManyInputs
},
)?)
Some(
TransitionInfo::new(second_builder.complete_transition()?, second_inputs).map_err(
|e| {
debug_assert!(!matches!(e, TransitionInfoError::CloseMethodDivergence(_)));
ComposeError::TooManyInputs
},
)?,

Check warning on line 1236 in src/persistence/stock.rs

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L1231-L1236

Added lines #L1231 - L1236 were not covered by tests
)
} else {
None
};
Expand Down

0 comments on commit 14ca8d8

Please sign in to comment.