simondlr/bitcoinj — pull request #1 by simondlr (2014-01-20 15:53:36+00:00)
Title: Patch for InsufficientMoneyException for PaymentChannels.

When throwing InsufficientMoneyException it might be useful for clients to know how much is missing, and this is thus required when throwing the exception.

However, for payment channels, when the channel size is too large (SERVER_REQUESTED_TOO_MUCH_VALUE), the client doesn't store how much satoshis is missing. The exception usually gets thrown at another stage (in destroyConnection, for example). The client doesn't have access anymore to the requested value (or rather the missing satoshis).

This patch adds a variable to the clients that when the server requests too much value, it stores the missing amount for later use (when the exception is thrown).

It also changes maxValue to contractValue (that is what is passed through anyway).

I've tested both examples, and it seems to be working fine (channel size and min_payment mismatch). I'm just not entirely sure if perhaps there needs to be more done in terms of state management.

Also, I suspect perhaps there needs to a separate CloseReason for MIN_PAYMENT mismatch. The current one: SERVER_REQUESTED_TOO_MUCH_VALUE is not descriptive of what's actually happening. It could go both ways (too much, or too little). And it's not checking for that either. It just needs to match. Something like CloseReason.MIN_PAYMENT_MISMATCH.