web3j icon indicating copy to clipboard operation
web3j copied to clipboard

web3j.transactionObservable() listened a transaction twice

Open Jesse0722 opened this issue 8 years ago • 5 comments

web3j.transactionObservable() .subscribe listened a transaction(same tx hash) twice with different block number. It there a bug or another problem? Anyone can help me,I'll appreciate. Thanks

Jesse0722 avatar Mar 21 '18 04:03 Jesse0722

@Jesse0722 web3j.transactionObservable() do not work in my project, can you give me a example? please

TTroia avatar Mar 21 '18 07:03 TTroia

@Jesse0722 I guess this can happen in case the same transaction was included in blocks generated by different miners.

fcorneli avatar Mar 26 '18 13:03 fcorneli

when I subcribe a blcokevent ,it doesn't work. Subscription subscription = web3j.blockObservable(false).subscribe(block -> { EthBlock.Block block1 = block.getBlock(); System.out.println("GasLimit:" + block1.getGasLimit()); System.out.println("GasLimitRaw:" + block1.getGasLimitRaw()); System.out.println("GasUsed:" + block1.getGasUsed()); System.out.println("GasUsedRa:" + block1.getGasUsedRaw()); System.out.println("Hash:" + block1.getHash()); System.out.println("Nonce:" + block1.getNonce()); System.out.println("Nonce:" + block1.getNonce()); List<EthBlock.TransactionResult> transactions = block1.getTransactions(); System.out.println("transactions.size:" + transactions.size()); });

shikai2013 avatar Apr 10 '18 05:04 shikai2013

I'm experiencing the same behavior with blocks with web3j.blockObservable(). I frequently get blocks with the same number twice. Is this normal? If so, how should I handle these situations?

Daantie avatar Sep 07 '18 13:09 Daantie

It's normal. As @fcorneli said, the transaction was included in blocks generated by different miners. You can listened the transaction both of them, but the first one usually is useless, called uncle block.
You can synchronize the transaction from block, one by one, and behind several blocks of the hightest block, instead of observing them. Use web3j.ethGetBlockByNumber to get block, and analysis transaction.

Jesse0722 avatar Sep 14 '18 05:09 Jesse0722