Skip to content

Commit

Permalink
persistence: always add opret anchors when preset to a consignment
Browse files Browse the repository at this point in the history
Closes #271
  • Loading branch information
dr-orlovsky committed Sep 17, 2024
1 parent 94aeb57 commit d28d7e6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/persistence/stash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use amplify::confinement;
use amplify::confinement::{Confined, MediumBlob, TinyOrdMap};
use bp::dbc::anchor::MergeError;
use bp::dbc::tapret::TapretCommitment;
use bp::seals::txout::CloseMethod;
use commit_verify::mpc;
use nonasync::persistence::{CloneNoPersistence, Persisting};
use rgb::validation::Scripts;
Expand Down Expand Up @@ -118,6 +119,9 @@ pub enum StashInconsistency {
/// information about witness {0} is absent.
WitnessAbsent(XWitnessId),

/// witness {0} for the bundle {1} misses contract {2} information in {3} anchor.
WitnessMissesContract(XWitnessId, BundleId, ContractId, CloseMethod),

/// bundle {0} is absent.
BundleAbsent(BundleId),

Expand Down
52 changes: 37 additions & 15 deletions src/persistence/stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,24 +1352,46 @@ impl<S: StashProvider, H: StateProvider, P: IndexProvider> Stock<S, H, P> {
AnchorSet::Opret(opret) => (None, Some(opret)),
AnchorSet::Double { tapret, opret } => (Some(tapret), Some(opret)),
};
let mut anchor = None;
if let Some(a) = tapret {
if let Ok(a) = a.to_merkle_proof(contract_id) {
anchor = Some(EAnchor::new(a.mpc_proof, DbcProof::Tapret(a.dbc_proof)));
}
}
if anchor.is_none() {
if let Some(a) = opret {
if let Ok(a) = a.to_merkle_proof(contract_id) {
anchor = Some(EAnchor::new(a.mpc_proof, DbcProof::Opret(a.dbc_proof)));
}
let Ok(tapret) = tapret.map(|a| a.to_merkle_proof(contract_id)).transpose() else {
return Err(StashInconsistency::WitnessMissesContract(
witness_id,
bundle_id,
contract_id,
CloseMethod::TapretFirst,
)
.into());

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

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L1355-L1362

Added lines #L1355 - L1362 were not covered by tests
};
let Ok(opret) = opret.map(|a| a.to_merkle_proof(contract_id)).transpose() else {
return Err(StashInconsistency::WitnessMissesContract(
witness_id,
bundle_id,
contract_id,
CloseMethod::OpretFirst,
)
.into());

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

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L1364-L1371

Added lines #L1364 - L1371 were not covered by tests
};
let anchored_bundles = match (opret, tapret) {
(Some(opret), Some(tapret)) => AnchoredBundles::Double {
tapret_anchor: tapret,
tapret_bundle: bundle.clone(),
opret_anchor: opret,
opret_bundle: bundle,
},
(Some(opret), None) => AnchoredBundles::with(
EAnchor::new(opret.mpc_proof, DbcProof::Opret(opret.dbc_proof)),
bundle,
),
(None, Some(tapret)) => AnchoredBundles::with(
EAnchor::new(tapret.mpc_proof, DbcProof::Tapret(tapret.dbc_proof)),
bundle,
),

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

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L1373-L1387

Added lines #L1373 - L1387 were not covered by tests
(None, None) => {
return Err(
StashInconsistency::BundleMissedInAnchors(bundle_id, contract_id).into()
);

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

View check run for this annotation

Codecov / codecov/patch

src/persistence/stock.rs#L1389-L1391

Added lines #L1389 - L1391 were not covered by tests
}
}
let Some(anchor) = anchor else {
return Err(StashInconsistency::BundleMissedInAnchors(bundle_id, contract_id).into());
};

let anchored_bundles = AnchoredBundles::with(anchor, bundle);
// TODO: Conceal all transitions except the one we need

Ok(BundledWitness {
Expand Down

0 comments on commit d28d7e6

Please sign in to comment.