Merge rust-bitcoin/rust-bitcoin#4342: Remove Option return from `minimal_non_dust`

0498f7b7b7 Remove Option return from `minimal_non_dust` (jrakibi)

Pull request description:

  Closes #4221

  This removes the `Option` return type from `minimal_non_dust

  Overflow is only possible in 2 cases:
  - `dust_relay_fee` would need to be excessively high
  - script size would have to exceed ~6.15 × 10¹⁵ bytes (≈ 6 petabytes)

  we now panic with the same message we had before in  cf12ba262a/bitcoin/src/blockdata/script/borrowed.rs (L412)

ACKs for top commit:
  tcharding:
    ACK 0498f7b7b7
  apoelstra:
    ACK 0498f7b7b7d43cc015d6788efe826df25d6156a5; successfully ran local tests

Tree-SHA512: 826a5d4ebb9c237cdd261f7d8b25fb2118cfba7d79b031839a619e12c440cbd34bbf830ffe513c104ef34e8ae50320e314c736a55be9ba7a82ae50f6022b9cf0
This commit is contained in:
merge-script 2025-04-15 17:19:54 +00:00
commit ee43f9235b
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 7 additions and 6 deletions

View File

@ -261,7 +261,7 @@ crate::internal_macros::define_extension_trait! {
/// Returns the minimum value an output with this script should have in order to be
/// broadcastable on todays Bitcoin network.
#[deprecated(since = "0.32.0", note = "use `minimal_non_dust` etc. instead")]
fn dust_value(&self) -> Option<Amount> { self.minimal_non_dust() }
fn dust_value(&self) -> Amount { self.minimal_non_dust() }
/// Returns the minimum value an output with this script should have in order to be
/// broadcastable on today's Bitcoin network.
@ -272,8 +272,9 @@ crate::internal_macros::define_extension_trait! {
/// To use a custom value, use [`minimal_non_dust_custom`].
///
/// [`minimal_non_dust_custom`]: Script::minimal_non_dust_custom
fn minimal_non_dust(&self) -> Option<Amount> {
fn minimal_non_dust(&self) -> Amount {
self.minimal_non_dust_internal(DUST_RELAY_TX_FEE.into())
.expect("dust_relay_fee or script length should not be absurdly large")
}
/// Returns the minimum value an output with this script should have in order to be

View File

@ -684,7 +684,7 @@ fn default_dust_value() {
// well-known scriptPubKey types.
let script_p2wpkh = Builder::new().push_int_unchecked(0).push_slice([42; 20]).into_script();
assert!(script_p2wpkh.is_p2wpkh());
assert_eq!(script_p2wpkh.minimal_non_dust(), Some(Amount::from_sat_u32(294)));
assert_eq!(script_p2wpkh.minimal_non_dust(), Amount::from_sat_u32(294));
assert_eq!(
script_p2wpkh.minimal_non_dust_custom(FeeRate::from_sat_per_vb_unchecked(6)),
Some(Amount::from_sat_u32(588))
@ -698,7 +698,7 @@ fn default_dust_value() {
.push_opcode(OP_CHECKSIG)
.into_script();
assert!(script_p2pkh.is_p2pkh());
assert_eq!(script_p2pkh.minimal_non_dust(), Some(Amount::from_sat_u32(546)));
assert_eq!(script_p2pkh.minimal_non_dust(), Amount::from_sat_u32(546));
assert_eq!(
script_p2pkh.minimal_non_dust_custom(FeeRate::from_sat_per_vb_unchecked(6)),
Some(Amount::from_sat_u32(1092))

View File

@ -183,8 +183,8 @@ crate::internal_macros::define_extension_trait! {
/// To use a custom value, use [`minimal_non_dust_custom`].
///
/// [`minimal_non_dust_custom`]: TxOut::minimal_non_dust_custom
fn minimal_non_dust(script_pubkey: ScriptBuf) -> Option<TxOut> {
Some(TxOut { value: script_pubkey.minimal_non_dust()?, script_pubkey })
fn minimal_non_dust(script_pubkey: ScriptBuf) -> TxOut {
TxOut { value: script_pubkey.minimal_non_dust(), script_pubkey }
}
/// Constructs a new `TxOut` with given script and the smallest possible `value` that is **not** dust