Broadcast a transaction, issue with Context missing from thread created by BitcoinJ

46 views
Skip to first unread message

NelsoN Melina

unread,
Sep 15, 2017, 9:29:23 AM9/15/17
to bitcoinj

In this code i receive an already signed transaction in the form of a byte array and i would like to broadcast it to the Bitcoin network.

override fun onHandleIntent(intent: Intent?) {
    org
.bitcoinj.core.Context.propagate(Constants.CONTEXT)
   
if (intent != null) {
       
when (intent.action) {
            ACTION_BROADCAST_TRANSACTION
-> {
                initializeBlockchain
(null, 0)
                val transactionByteArray
= intent.getByteArrayExtra("TX")
                val tx
= Transaction(Constants.NETWORK_PARAMETERS, transactionByteArray)
                tx
.getConfidence().setSource(TransactionConfidence.Source.SELF);
                tx
.setPurpose(Transaction.Purpose.USER_PAYMENT);
               
SpvModuleApplication.getWallet()!!.maybeCommitTx(tx)
               
if (peerGroup != null) {
                    val transactionBroadcast
: TransactionBroadcast = peerGroup!!.broadcastTransaction(tx)
                    val future
: ListenableFuture<Transaction> = transactionBroadcast.future()
                   
                    future
.get()
 
..........

Issue is that in my own code i already propagated the context but then internally in BitcoinJ it creates another thread when it has enough peers, and then broadcast the transaction from this thread, which fails as the Context is not propagated there.

Any pointers as to what i am doing wrong ?

Thanks.


09-14 15:14:52.867 8281-8330/com.m.s.test E/ExecutionList: RuntimeException while executing runnable org.bitcoinj.core.TransactionBroadcast$EnoughAvailablePeers@838ec24 with executor org.bitcoinj.utils.Threading$2@7b38d
java.lang.IllegalStateException: missing context
 
at org.bitcoinj.core.Context.get(Context.java:110)
 

at org.bitcoinj.core.Transaction.getConfidence(Transaction.java:1198)
 

at org.bitcoinj.core.TransactionBroadcast$EnoughAvailablePeers.run(TransactionBroadcast.java:134)
 

at org.bitcoinj.utils.Threading$2.execute(Threading.java:141)
 

at com.google.common.util.concurrent.ExecutionList.executeListener(ExecutionList.java:156)
 

at com.google.common.util.concurrent.ExecutionList.execute(ExecutionList.java:145)
 

at com.google.common.util.concurrent.AbstractFuture.set(AbstractFuture.java:185)
 

at com.google.common.util.concurrent.SettableFuture.set(SettableFuture.java:53)
 

at org.bitcoinj.core.PeerGroup$14.onPeerConnected(PeerGroup.java:1938)
 

at org.bitcoinj.core.PeerGroup$11.run(PeerGroup.java:1565)
 

at org.bitcoinj.utils.Threading$UserThread.run(Threading.java:107)

Andreas Schildbach

unread,
Sep 16, 2017, 12:12:29 PM9/16/17
to bitc...@googlegroups.com
Sounds like a bug in bitcoinj. What bitcoinj version are you using?
> --
> You received this message because you are subscribed to the Google
> Groups "bitcoinj" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


NelsoN Melina

unread,
Sep 18, 2017, 9:21:45 AM9/18/17
to bitc...@googlegroups.com
I tried the code from https://github.com/uniquid/bitcoinj as i needed to try this pull request https://github.com/bitcoinj/bitcoinj/pull/1341

At Mycelium we are aiming to use BitcoinJ as one of the main part of our architecture but we need BIP44 implemented. Happy to contribute in the best way.

I am wondering right now if it's not better to contribute on https://github.com/bitcoinj/bitcoinj/pull/1441 instead. But that might be slightly off topic here.

Should we move this conversation elsewhere and focus on the bug ?

Nelson MELINA
Software Development Engineer
http://www.linkedin.com/in/nelsonmelina 


> For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to a topic in the Google Groups "bitcoinj" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/bitcoinj/ro3__Br8KLo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to bitcoinj+unsubscribe@googlegroups.com.

Andreas Schildbach

unread,
Sep 21, 2017, 4:45:50 AM9/21/17
to bitc...@googlegroups.com
Regarding your original issue: it would be great if you could test this
on our master branch, just to know if the issue stems from any custom
modifications.

I think PRs #1341 and #1441 are orthogonal for the most part. So if all
goes well, I expect both to be merged at some point (with modifications,
I added comments to both PRs). If you've got feedback (conceptual or
testing) directly related to one PR, directly commenting on the PRs
seems most productive.

About BIP44 there is a conflict that BIP44 is about multi-account,
whereas bitcoinj has decided to generally not support multiple accounts
per wallet to keep complexity low. You could use multiple wallets
instead. Or you could limit your BIP44 implementation to just one
account, kind of violating the spec.

Anyhow, it's great to see Mycelium onboard. Welcome!


On 09/18/2017 03:21 PM, NelsoN Melina wrote:
> I tried the code from https://github.com/uniquid/bitcoinj as i needed to
> try this pull request https://github.com/bitcoinj/bitcoinj/pull/1341
>
> At Mycelium we are aiming to use BitcoinJ as one of the main part of our
> architecture but we need BIP44 implemented. Happy to contribute in the
> best way.
>
> I am wondering right now if it's not better to contribute
> on https://github.com/bitcoinj/bitcoinj/pull/1441 instead. But that
> might be slightly off topic here.
>
> Should we move this conversation elsewhere and focus on the bug ?
>
> //
>
> /Nelson MELINA Software Development Engineer/
>
> /http://www.linkedin.com/in/nelsonmelina /
> > an email to bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>
> > <mailto:bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "bitcoinj" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/bitcoinj/ro3__Br8KLo/unsubscribe
> <https://groups.google.com/d/topic/bitcoinj/ro3__Br8KLo/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to
> bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "bitcoinj" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to bitcoinj+u...@googlegroups.com
> <mailto:bitcoinj+u...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages