fireduck64 / jelectrum

An Electrum Server written in Java
MIT License
41 stars 15 forks source link

Disconnects with Sending using the Electrum Client #30

Closed HashEngineering closed 3 years ago

HashEngineering commented 3 years ago

There was a change back in June 2020 to the Electrum Client that requires that there is a fee field in the results for blockchain.scripthash.get_history. In the code here, https://github.com/fireduck64/jelectrum/blob/master/src/jelectrum/ElectrumNotifier.java#L528, fee will not be included if it is negative.

However, in changes to Electrum, fee is required and it is required to be non-negative. If those are not met, then Electrum Client will disconnect from the electrum server. https://github.com/spesmilo/electrum/pull/6315

After some static code analysis, I found this: https://github.com/bitcoinj/bitcoinj/blob/master/core/src/main/java/org/bitcoinj/core/Transaction.java#L504

If a bitcoinj Transaction object does not have its inputs linked to the connected transactions, then the fee cannot be calculated and null is returned.

For this method (getTx), the input transactions need to be retrieved also and then TransactionInput.connect can be used connect to the TransactionOutputs of the inputs: https://github.com/fireduck64/jelectrum/blob/master/src/jelectrum/SerializedTransaction.java#L52

Or perhaps there is a better way with obtain the fee by saving it in the database for later retrieval.

fireduck64 commented 3 years ago

Yeah, I don't use the BitcoinJ transaction connection feature, it caused me some problems long ago. If I recall correctly if you aren't careful it ends up keeping the entire blockchain in memory (or trying to).

But since we are indexing all transactions, we can absolutely calculate the fee. It might be a little complicated.

fireduck64 commented 3 years ago

Thanks for going as deep as you did in opening this issue, that helps a lot.

fireduck64 commented 3 years ago

fixed with 6576b6596aee4cb884b03f7532b655214b3d80d1

HashEngineering commented 3 years ago

You're welcome. I will check out your fix and report back on success/failure.