Skip to content

The sender's additional_fee_contribution should account for dust outputs #1881

Open

Description

@benalleng

Without any dust calculation it is possible for a sender to add an output and additional_fee_contribution such that they are left with an output below the standard dust threshold. While this is a small subset between dust threshold and below underflow thus rejected we should still account for this and handle it sanely.

Activity

  1. xstoicunicornx commented on Sep 17, 2026

    @xstoicunicornx
    Collaborator

    What do you think about some additional API that will allow callers to ergonomically extract the current transaction to check for broadcastability/dust limits? That way we don't have to worry parsing the dust threshold ourselves and we don't make assumptions on what would be considered dust (since technically this is dependent on relay policy that could change in future versions/new implementations). This is also pretty much how the receiver handles the original PSBT since we don't do any tx validation in PDK (other than validating that inputs and outputs are safe for proceeding with the payjoin) and instead leave validation up to the implementor.

    More broadly speaking I think we should consider what the scope of PDK should be. Should we incorporate accounting for relay policy into PDK scope or should it be limited to orchestrating a safe consensus valid payjoin tx?

  2. kydallaboutlearning commented on Sep 27, 2026

    @kydallaboutlearning

    I'd like to take this on. Proposed approach, building on @xstoicunicornx's scope point:

    Sender-side, in \check_fee_output_amount\ (\payjoin/src/core/send/mod.rs): after \output.value - fee, reject (new \BuildSenderError\ variant) when the remainder is non-zero but below the output's dust threshold, instead of only erroring on underflow. To stay out of relay-policy territory, derive the threshold from rust-bitcoin script primitives (script-type-aware spend cost at min relay rate) rather than a hardcoded constant, and leave exact-zero (fully consumed output) as valid.

    Open questions before I open the PR:

    1. Hard error vs clamp: with \clamp_fee_contribution, should a dust remainder clamp down to a dust-exceeding contribution, or is erroring (current clamp only handles full underflow) preferred?
    2. Is sender-side enforcement the right layer, or would you rather see a public helper so callers check broadcastability themselves?

    Happy to implement whichever direction you prefer — I can have a PR up with tests once confirmed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions