bitcoinj icon indicating copy to clipboard operation
bitcoinj copied to clipboard

Wallet.completeTx: throw if inputs contain unconnected outputs

Open msgilligan opened this issue 2 years ago • 9 comments

Rather than (if not segwit) simply add those unconnected outputs to the miner's fee, throw an IllegalArgumentException.

In the case of segwit, the transaction can't be properly signed without knowing the input values.

TODO before or after merging:

  • [ ] Consider adding a checked exception for this new error case -- this should be considered separately, I think.
  • [ ] Rename some of the variables in the unit test -- could be a second commit in this same PR
  • [x] Consider adding connected outputs if they are available in the wallet. See PR #3055 which has a proposed implementation of this feature. After connecting outputs available in the wallet, if any unconnected outputs remain we would throw.

msgilligan avatar May 04 '23 00:05 msgilligan

I'm fine with throwing an exception. Adding inputs with unknown value to the fee seems way too scary. And as you said, with segwit/taproot we can't continue the behaviour anyway.

schildbach avatar May 09 '23 15:05 schildbach

I'm fine with throwing an exception. Adding inputs with unknown value to the fee seems way too scary. And as you said, with segwit/taproot we can't continue the behaviour anyway.

I think we might want to throw a checked exception in this case. This would be an API breaking change, but since we are changing behavior it might be a good idea to explicitly let people know about the new behavior.

msgilligan avatar May 09 '23 16:05 msgilligan

I would have thrown a new subclass of CompletionException but that exception is a RuntimeException.

schildbach avatar May 09 '23 16:05 schildbach

might want to throw a checked exception in this case.

The existing exceptions (e.g. DustySendRequested, MultipleOpReturnRequested) thrown by completeTx extend o.b.w.Wallet.CompletionException which extends RuntimeException, I take back my suggestion that we replace IllegalArgument with a checked exception, but we should probably create a new subclass of o.b.w.Wallet.CompletionException for this case.

msgilligan avatar May 09 '23 16:05 msgilligan

I would have thrown a new subclass of CompletionException but that exception is a RuntimeException.

We both were typing at the same time. I agree it should be a new subclass of o.b.w.W.CompletionException. (Not to be confused with j.u.c.CompletionException added in Java 8.)

msgilligan avatar May 09 '23 16:05 msgilligan

And whatever exception we throw, there are quite some higher-level methods in Wallet that will need to throw that exception too. (Unless handled of course.)

schildbach avatar May 09 '23 16:05 schildbach