Skip to content

Commit 27d9bfa

Browse files
committed
fix: cleaned up code
Fixes #8395 Changelog-Fixed: Transactions now correctly create change outputs between 330-546 sat for P2TR/P2WPKH instead of absorbing them as fees
1 parent cdc7a9a commit 27d9bfa

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

bitcoin/tx.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -983,18 +983,14 @@ struct amount_sat change_amount(struct amount_sat excess, u32 feerate_perkw,
983983
size_t total_weight)
984984
{
985985
struct amount_sat fee = change_fee(feerate_perkw, total_weight);
986-
struct amount_sat dust_limit;
987986

988987
if (!amount_sat_sub(&excess, excess, fee))
989988
return AMOUNT_SAT(0);
990989

991-
if (chainparams->is_elements)
992-
dust_limit = AMOUNT_SAT(330); /* P2WPKH */
993-
else
994-
dust_limit = AMOUNT_SAT(330); /* P2TR */
995-
996-
/* Must be non-dust */
997-
if (!amount_sat_greater_eq(excess, dust_limit))
990+
// Change is P2TR (Bitcoin) or P2WPKH (Elements) both have
991+
// dust limit of 330 sat. Legacy types (P2PKH/P2SH) use 546 sat
992+
// but we dont create those as change outputs
993+
if (!amount_sat_greater_eq(excess, AMOUNT_SAT(330)))
998994
return AMOUNT_SAT(0);
999995

1000996
return excess;

0 commit comments

Comments
 (0)