danielmcclure / bitcoinj

Automatically exported from code.google.com/p/bitcoinj
Apache License 2.0
0 stars 1 forks source link

Wallet.completeTx created transaction with negative fee value #612

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I created a testnet transaction using Wallet.createTx(...), the result of which 
was a transaction whose aggregate output value *exceeded* its aggregate input 
value by 0.13 mBTC!

I'm attaching an excerpt from `wallet-tool dump ...` as well as the "hexlified" 
raw transaction. The transaction has lots of inputs. Obviously, when it was 
broadcast, it was rejected by peers:

...
2015-03-23 10:35:56,810 [NioClientManager] WARN  org.bitcoinj.core.Peer - 
Received unhandled message: Reject: tx 
c00614d8491739c2adcebb99d7397d2d6d89580e05e72e4869a172615aca1835 for reason 
'insufficient fee' (66)
...
2015-03-23 10:35:57,070 [NioClientManager] WARN  org.bitcoinj.core.Peer - 
Received unhandled message: Reject: tx 
c00614d8491739c2adcebb99d7397d2d6d89580e05e72e4869a172615aca1835 for reason 
'insufficient fee' (66)
...
2015-03-23 11:20:13,001 [NioClientManager] WARN  org.bitcoinj.core.Peer - 
Received unhandled message: Reject: tx 
c00614d8491739c2adcebb99d7397d2d6d89580e05e72e4869a172615aca1835 for reason 
'insufficient fee' (66)
...

Original issue reported on code.google.com by mbogos...@gmail.com on 25 Mar 2015 at 11:43

Attachments:

GoogleCodeExporter commented 9 years ago
This issue's title should have read:

> Wallet.completeTx created transaction with negative fee value

The first line should have read:

> I created a testnet transaction using Wallet.completeTx(...), ...

There's no such thing as "Wallet.createTx". I don't know what I was thinking 
(but it *has* been a long day...). ;o)

Original comment by mbogos...@gmail.com on 25 Mar 2015 at 11:52

GoogleCodeExporter commented 9 years ago
Can you show the code that did this? Are you using bitcoinj latest master?

Original comment by andreas....@gmail.com on 26 Mar 2015 at 9:02

GoogleCodeExporter commented 9 years ago
bitcoinj was from the v0.12.2 release. Here's the code snippet:

    Transaction createTx(final WalletAppKit kit,
            final BigInteger amount,
            final ECKey otherPublicKey)
            throws InsufficientMoneyException {
        final ECKey myKey = kit.wallet().freshReceiveKey();
        final Transaction tx = new Transaction(kit.params());
        final Script script =
            ScriptBuilder.createMultiSigOutputScript(1, ImmutableList.of(myKey, otherPublicKey));
        tx.addOutput(amount.longValue()), script);
        Wallet.SendRequest sendRequest = Wallet.SendRequest.forTx(tx);
        kit.wallet().completeTx(sendRequest);

        return tx;
    }

Original comment by mbogos...@gmail.com on 26 Mar 2015 at 1:55

GoogleCodeExporter commented 9 years ago
Is that repeatable? I mean if you run the same code with the same wallet do you 
get the same transaction out?

The code that is supposed to prevent this is "throw new 
InsufficientMoneyException(valueMissing)" in Wallet.java. You could try 
stepping through the fee calculation logic to find out how it managed to miss 
this line. The fee calculator code is complicated (maybe too complicated - not 
sure handling all the edge cases is really worth it), but I don't recall this 
problem cropping up before.

Original comment by mh.in.en...@gmail.com on 27 Mar 2015 at 12:42