0

I use bitcoinj to create the following method to broadcast a raw transacion in testnet, and I did see on bitcoin explorer that it has been broadcast. But even the transaction has been already broadcast, it always return false message, please help me to solve this issue, I don't know if there is a problem when sync with the peer or if my broadcast method is wrong.

//sync with the peer
static WalletAppKit kit = new WalletAppKit(params, new File("."), "sendrequest-example");
kit.startAsync();
kit.awaitRunning();

//transaction broadcast method
public static boolean broadcastTransaction (Transaction tx) {
        System.out.println("Broadcast transaction: ");
        System.out.println(tx);
        try {
            TransactionBroadcast broadcast = kit.peerGroup().broadcastTransaction(tx);
            broadcast.future().get(20,TimeUnit.SECONDS);
            System.out.println(tx.getHash() + "broadcasted successfully!");
            return true;
        } catch (Exception e) {
            System.out.println("e.getMessage() = " + e.getMessage());
        }
        return false;
    }

The false message is always as following, although the transaction has been indeed broadcast.

e.getMessage() = Waited 20 seconds (plus 1985971 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@20d525[status=PENDING]
e.getMessage() = Waited 20 seconds (plus 4214583 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@38afe297[status=PENDING]
0

This looks like an implementation choice of the PeerGroup.broadcastTransaction method of bitcoinj.

If you send a transaction out to one or more peers, there is no guarantee that any of those peers will forward them on to others, and no way to verify it without having another node somewhere else on the bitcoin network listening for it (or listening to it from the same node but from different peers). You can only attempt to have some level of confidence that the transaction has been broadcast by sending it to multiple peers.

The broadcastTransaction method appears to have some confidence calculation in it, and probably does not complete the promise unless the confidence is met. I've not explored the details of it, but I'd suspect you're perhaps not connected to enough peers for it to have the confidence. Are you only connected to one peer perhaps? Maybe you need a longer timeout? Check the details of how the broadcast is implemented and you might figure it out.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.