Author

Topic: Is there a way to see why a transaction isn't getting relayed? (Read 1592 times)

legendary
Activity: 1498
Merit: 1000
An unencrypted wallet sents the testnet coins fine. It is an encrypted wallet issue, hope this information helps.
legendary
Activity: 1498
Merit: 1000
It seems that the key is getting set to null in the Privkey variable and the encrypted variable, I am going to try with a new unencrypted wallet and see what I can do, and see if it was the encryption. Here is a debug screenshot.

legendary
Activity: 1498
Merit: 1000
Here is the output of wallet.toString()
Code:
Wallet containing 6.30 BTC in:
  1 unspent transactions
  0 spent transactions
  0 pending transactions
  0 dead transactions
Last seen best block: (112773) 00000000761cc5b4eb871e745ae1512143e1fea5f2b26d639a8baf07c8bb35e1
Encryption: Scrypt/AES

Keys:
  addr:n3LRVzswykPCUASzD9tgwFUNAyZqFrTXva pub:0285084a41af1d5e16bc704399892d47f552a6d677f4ac0ca095bbde6fa8ee0cfc encrypted
  addr:n41AVgo7xj1LtFeKqH3iKNfPbfJBGcm6s1 pub:02ab19d8c48d52f52e549aab88f1f178984c2a5955b43f063b4db8187937b8ddc2 timestamp:1381115208

>>> UNSPENT:
Sends 0.00 and receives 6.30, total value 6.30.
  ff0dd34050e4b62be5a46d513debc8ac6489346428441f9a8d0e964be95a7d73: Seen by 1 peer. Appeared in best chain at height 112773, depth 1, work done 4295032833.
     in   [3046022100e1d8132ca9fa32f6880d43dae9cb8be4dd1e9a05e41db001702a5c1892785f14022100ca1578a92da58becf550fd36589350be4f10808f1814d69d683ab1c33a2b1f3f01] [0313e5d56288e6775255cae5ddf0ef8a7f72244c3f6ec53189e061b077d5c983ed]  / 3bb2ccd413fc24f0eba81f8e516cbf0e0ff26d7071d0715c27eb580db550a7c7:0
     out  DUP HASH160 [f6a8994404b8f34ce00f018c04ed6991f09f25fc] EQUALVERIFY CHECKSIG  6.30 BTC
     out  DUP HASH160 [61a9491d44c98ac08bd0fb043a6ec927f3f6b064] EQUALVERIFY CHECKSIG  159.10 BTC

And here is the parts where I set u bitcoinj.

Code:
public class BitcoinJWallet{
    public static NetworkParameters params;
    public static Wallet wallet;
    public static PeerGroup peerGroup;
    private AbstractBlockChain chain;
    private File walletFile;
    private ECKey key;
    public  BitcoinJWallet(){
    params = TestNet3Params.get();
    setupWallet();
    wallet.addEventListener(new WalletConfirmations());
    setupBlockchain();
    setupPeerGroup();

    }
    public void setupWallet(){
    final File walletFile = new File("site.wallet");
    try {
        wallet = Wallet.loadFromFile(walletFile);
    } catch (UnreadableWalletException e) {
    wallet = new Wallet(params);
          wallet.addKey(new ECKey());
          try {
wallet.saveToFile(walletFile);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
         if(!wallet.isEncrypted()){
         wallet.encrypt(config.WALLET_PASSWORD);
         }
         wallet.autosaveToFile(walletFile, 500, TimeUnit.MILLISECONDS, null);
}
    key = wallet.getKeys().get(0);
 
    }
    public void setupBlockchain(){
    try{
    File file = new File("site.spvchain");
    boolean chainExistedAlready = file.exists();
    SPVBlockStore blockStore = new SPVBlockStore(params, file);
    if (!chainExistedAlready) {
        File checkpointsFile = new File("checkpoints");
        if (checkpointsFile.exists()) {
            FileInputStream stream = new FileInputStream(checkpointsFile);
            CheckpointManager.checkpoint(params, stream, blockStore, key.getCreationTimeSeconds());
        }
    }
    chain = new BlockChain(params, wallet, blockStore);
    }catch(Exception e){
    e.printStackTrace();
    }
    }
    public void setupPeerGroup(){
    peerGroup = new PeerGroup(params, chain);
    try {
peerGroup.addAddress(new PeerAddress(InetAddress.getByName("127.0.0.1"), 18333));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
    peerGroup.addPeerDiscovery(new DnsDiscovery(params));
    peerGroup.addWallet(wallet);
    peerGroup.startAndWait();
    peerGroup.downloadBlockChain();
    }
legendary
Activity: 1526
Merit: 1134
You could look at WalletAppKit to simplify the setup code.

I can't see the issue off-hand and I'm heading out for the night in a few minutes. It's apparently a bug or at the very least, poor documentation on how to use the encryption feature. If you put a breakpoint on Transaction.signInputs() line 837:

Code:
            if (key.hasPrivKey() || key.isEncrypted()) {
                signatures[i] = calculateSignature(i, key, aesKey, connectedPubKeyScript, hashType, anyoneCanPay);
            } else {
                // Create a dummy signature to ensure the transaction is of the correct size when we try to ensure
                // the right fee-per-kb is attached. If the wallet doesn't have the privkey, the user is assumed to
                // be doing something special and that they will replace the dummy signature with a real one later.
                signatures[i] = TransactionSignature.dummy();
            }

then take a look at the key object and see why both hasPrivKey() and isEncrypted() are false. I'd expect hasPrivKey to be false and isEncrypted to be true.

If you can't see what's going wrong, send me all your code and I'll try and make time tomorrow or Monday night to debug it.
legendary
Activity: 1526
Merit: 1134
BTW you don't need commitTx - broadcastTransaction will call it for you once the transaction propagates (which in this case it isn't, but that's a separate issue).

The issue is that the signature is being substituted with a dummy signature because the private key isn't usable. We can see this here:

Quote
INFO:   completed:   88073e5a03ceae663c587c5dd2c0cf9254429356d6da50a1e85ac8ca22261665: Unknown confidence level.
     in   [30460221010000000000000000000000000000000000000000000000000000000000000000022101000000000000000000000000000000000000000000000000000000000000000001] [02ab19d8c48d52f52e549aab88f1f178984c2a5955b43f063b4db8187937b8ddc2]  / ff0dd34050e4b62be5a46d513debc8ac6489346428441f9a8d0e964be95a7d73:0

That big run of zeros means it's using Transaction.dummySignature(), which is meant to be replaced by something else later. So the question is, why does it think it doesn't have the private key. I guess the issue is how the wallet is being encrypted. Therefore the next step is - please paste the output of wallet.toString() and ideally, the rest of your program.
legendary
Activity: 1526
Merit: 1134
Can you post your code please? I've not seen a case of invalid signatures before, but of course if you use the API wrong you could create such things accidentally.
legendary
Activity: 1498
Merit: 1000
I looked in my debug.log and posted it tech support board to get clear statement of why bitcoind will not relay bitcoinj transactions on the testnet. Maybe possible bug.

https://bitcointalk.org/index.php?topic=309499.new#new
legendary
Activity: 1498
Merit: 1000
I am directly connected to my bitcoind on the testnet but none of my transactions are getting relayed. Even when I send to an address the bitcoind controls it doesn't show it being unconfirmed or any balance. How can I debug these transactions?
Jump to: