Skip to content

Commit

Permalink
Deprecate across the board max_satisfaction_weight
Browse files Browse the repository at this point in the history
Adds a `since=10.0.0` to all `max_satisfaction_weight` deprecations.
Adds a note telling users to check #476 for more details.

Closes #637.
  • Loading branch information
storopoli committed Feb 15, 2024
1 parent 469c113 commit 7fc7661
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
///
/// # Errors
/// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
#[deprecated(note = "use max_weight_to_satisfy instead")]
#[deprecated(
since = "10.0.0",
note = "Use max_weight_to_satisfy instead. The method to count bytes was redesigned and the results will differ from max_weight_to_satisfy. For more details check rust-bitcoin/rust-miniscript#476."
)]
pub fn max_satisfaction_weight(&self) -> Result<usize, Error> {
let scriptsig_len = self.ms.max_satisfaction_size()?;
Ok(4 * (varint_len(scriptsig_len) + scriptsig_len))
Expand Down Expand Up @@ -253,6 +256,10 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
/// Assumes all ec-signatures are 73 bytes, including push opcode and
/// sighash suffix. Includes the weight of the VarInts encoding the
/// scriptSig and witness stack length.
#[deprecated(
since = "10.0.0",
note = "Use max_weight_to_satisfy instead. The method to count bytes was redesigned and the results will differ from max_weight_to_satisfy. For more details check rust-bitcoin/rust-miniscript#476."
)]
pub fn max_satisfaction_weight(&self) -> usize { 4 * (1 + 73 + BareCtx::pk_len(&self.pk)) }
}

Expand Down
6 changes: 4 additions & 2 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
///
/// # Errors
/// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
#[deprecated(note = "use max_weight_to_satisfy instead")]
#[allow(deprecated)]
#[deprecated(
since = "10.0.0",
note = "Use max_weight_to_satisfy instead. The method to count bytes was redesigned and the results will differ from max_weight_to_satisfy. For more details check rust-bitcoin/rust-miniscript#476."
)]
pub fn max_satisfaction_weight(&self) -> Result<usize, Error> {
let weight = match *self {
Descriptor::Bare(ref bare) => bare.max_satisfaction_weight()?,
Expand Down
9 changes: 8 additions & 1 deletion src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
///
/// # Errors
/// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
#[deprecated(note = "use max_weight_to_satisfy instead")]
#[deprecated(
since = "10.0.0",
note = "Use max_weight_to_satisfy instead. The method to count bytes was redesigned and the results will differ from max_weight_to_satisfy. For more details check rust-bitcoin/rust-miniscript#476."
)]
pub fn max_satisfaction_weight(&self) -> Result<usize, Error> {
let (script_size, max_sat_elems, max_sat_size) = match self.inner {
WshInner::SortedMulti(ref smv) => (
Expand Down Expand Up @@ -360,6 +363,10 @@ impl<Pk: MiniscriptKey> Wpkh<Pk> {
/// Assumes all ec-signatures are 73 bytes, including push opcode and
/// sighash suffix. Includes the weight of the VarInts encoding the
/// scriptSig and witness stack length.
#[deprecated(
since = "10.0.0",
note = "Use max_weight_to_satisfy instead. The method to count bytes was redesigned and the results will differ from max_weight_to_satisfy. For more details check rust-bitcoin/rust-miniscript#476."
)]
pub fn max_satisfaction_weight(&self) -> usize { 4 + 1 + 73 + Segwitv0::pk_len(&self.pk) }
}

Expand Down
6 changes: 4 additions & 2 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
///
/// # Errors
/// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
#[deprecated(note = "use max_weight_to_satisfy instead")]
#[allow(deprecated)]
#[deprecated(
since = "10.0.0",
note = "Use max_weight_to_satisfy instead. The method to count bytes was redesigned and the results will differ from max_weight_to_satisfy. For more details check rust-bitcoin/rust-miniscript#476."
)]
pub fn max_satisfaction_weight(&self) -> Result<usize, Error> {
Ok(match self.inner {
// add weighted script sig, len byte stays the same
Expand Down
5 changes: 4 additions & 1 deletion src/descriptor/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
///
/// # Errors
/// When the descriptor is impossible to safisfy (ex: sh(OP_FALSE)).
#[deprecated(note = "use max_weight_to_satisfy instead")]
#[deprecated(
since = "10.0.0",
note = "Use max_weight_to_satisfy instead. The method to count bytes was redesigned and the results will differ from max_weight_to_satisfy. For more details check rust-bitcoin/rust-miniscript#476."
)]
pub fn max_satisfaction_weight(&self) -> Result<usize, Error> {
let tree = match self.tap_tree() {
// key spend path:
Expand Down
6 changes: 6 additions & 0 deletions src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,9 @@ trait PsbtFields {
fn tap_key_origins(
&mut self,
) -> &mut BTreeMap<bitcoin::key::XOnlyPublicKey, (Vec<TapLeafHash>, bip32::KeySource)>;
#[allow(dead_code)]
fn proprietary(&mut self) -> &mut BTreeMap<psbt::raw::ProprietaryKey, Vec<u8>>;
#[allow(dead_code)]
fn unknown(&mut self) -> &mut BTreeMap<psbt::raw::Key, Vec<u8>>;

// `tap_tree` only appears in psbt::Output, so it's returned as an option of a mutable ref
Expand All @@ -1037,9 +1039,11 @@ impl PsbtFields for psbt::Input {
) -> &mut BTreeMap<bitcoin::key::XOnlyPublicKey, (Vec<TapLeafHash>, bip32::KeySource)> {
&mut self.tap_key_origins
}
#[allow(dead_code)]
fn proprietary(&mut self) -> &mut BTreeMap<psbt::raw::ProprietaryKey, Vec<u8>> {
&mut self.proprietary
}
#[allow(dead_code)]
fn unknown(&mut self) -> &mut BTreeMap<psbt::raw::Key, Vec<u8>> { &mut self.unknown }

fn tap_scripts(&mut self) -> Option<&mut BTreeMap<ControlBlock, (ScriptBuf, LeafVersion)>> {
Expand All @@ -1064,9 +1068,11 @@ impl PsbtFields for psbt::Output {
) -> &mut BTreeMap<bitcoin::key::XOnlyPublicKey, (Vec<TapLeafHash>, bip32::KeySource)> {
&mut self.tap_key_origins
}
#[allow(dead_code)]
fn proprietary(&mut self) -> &mut BTreeMap<psbt::raw::ProprietaryKey, Vec<u8>> {
&mut self.proprietary
}
#[allow(dead_code)]
fn unknown(&mut self) -> &mut BTreeMap<psbt::raw::Key, Vec<u8>> { &mut self.unknown }

fn tap_tree(&mut self) -> Option<&mut Option<taproot::TapTree>> { Some(&mut self.tap_tree) }
Expand Down

0 comments on commit 7fc7661

Please sign in to comment.