-
Notifications
You must be signed in to change notification settings - Fork 131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement blockchain.transaction.get verbose support #36
base: new-index
Are you sure you want to change the base?
Conversation
@shesek Sorry for the ping, could this get merged? I can help if needed. |
Hi, thanks for the contribution and apologies for the slow reply! One of the design goals of the blockstream/electrs fork was to avoid querying the Bitcoin Core RPC in order to serve Electrum RPC requests. The original electrs relies heavily on the Bitcoin Core RPC and can require multiple calls to it to serve a single Electrum RPC request, while this fork never queries the Core RPC to serve user requests (it only queries it periodically to sync new blocks and the mempool). Adding support for Also, generally speaking, I would recommend getting the raw tx and parsing it on your app's side instead of using the |
I see, thanks. I found out that it is indeed not safe to rely on verbose transactions directly, so I get tx confirmations another way. But this will be efficient only with electrum protocol 1.5 when it gets implemented |
Thank you for the clear answer. |
Blockstream electrum servers don't support sending verbose transactions, we use this functionality for getting confirmations of a transaction, this causes geewallet to crash. Blockstream/electrs#36
Blockstream electrum servers doesn't support sending verbose transactions, we use this functionality for getting confirmations of a transaction, this causes geewallet to crash. Blockstream/electrs#36
Blockstream electrum servers doesn't support sending verbose transactions, we use this functionality for getting confirmations of a transaction, this causes geewallet to crash. Blockstream/electrs#36
Blockstream electrum servers doesn't support sending verbose transactions, we use this functionality for getting confirmations of a transaction, this causes geewallet to crash. Blockstream/electrs#36
Blockstream electrum servers doesn't support sending verbose transactions, we use this functionality for getting confirmations of a transaction, this causes geewallet to crash. Blockstream/electrs#36
Blockstream electrum servers doesn't support sending verbose transactions, we use this functionality for getting confirmations of a transaction, this causes geewallet to crash. Blockstream/electrs#36
Blockstream electrum servers doesn't support sending verbose transactions, and we use this functionality for getting confirmations of a transaction, which causes a crash. Blockstream/electrs#36
Blockstream electrum servers don't support sending verbose transactions (see [1]), and we use this functionality to get confirmations of a transaction; so we prevent a crash by blacklisting them. [1] Blockstream/electrs#36
Blockstream electrum servers don't support sending verbose transactions (see [1]), and we use this functionality to get confirmations of a transaction; so we prevent a crash by blacklisting them. [1] Blockstream/electrs#36
Blockstream electrum servers don't support sending verbose transactions (see [1]), and we use this functionality to get confirmations of a transaction; so we prevent a crash by blacklisting them. [1] Blockstream/electrs#36
Hey @MrNaif2018! 👋🏻 Could you please share your workaround to get the transaction confirmations? How do you get them? |
The function queries electrum for a details of the specific transaction and converts it in a format expected by the bitcoin.Chain interface. The simpliest solution is to use `GetTransaction` function to query electrum as it returns the transaction details in verbose format. Unfortunatelly it's not compatible with Esplora/Electrs implementation of ElectrumX server. (see: Blockstream/electrs#36) As a workaround to cover integration with Esplora/Electrs we use `GetRawTransaction` and deserialize the transaction.
The function returns number of confirmations for the given transaction. As Esplora/Electrs doesn't support verbose transactions details in the response, that would contain the confirmations number we need to workaround it. (See: Blockstream/electrs#36) The workaround: 1. Get the raw transaction 2. Deserialize the raw transaction 3. Find transaction block height by finding it in a history of transactions for the output script included in the transaction. 4. Get the latest block height 5. Calculate number of confirmations by subtracting the transaction block height from the latest block height and adding one.
@fujicoin @MrNaif2018 @nkuba What are your thoughts on Blockstream/esplora#423 (comment)?
One workaround is to get the block height via |
As for the basic support at least to make it more compatible, it would be good indeed That's how full SPV-verified transaction fetch should probably be working: But before protocol upgrade it will be kind of slow |
As Esplora/Electrs doesn't support verbose transactions details in the response, that would contain the confirmations number we need to workaround it. (See: Blockstream/electrs#36) The workaround: 1. Get the raw transaction 2. Deserialize the raw transaction 3. Find transaction block height by finding it in a history of transactions for the output script included in the transaction. 4. Get the latest block height 5. Calculate number of confirmations by subtracting the transaction block height from the latest block height and adding one.
The simpliest solution is to request verbose format of transaction. Unfortunatelly it's not compatible with Esplora/Electrs implementation of ElectrumX server. (see: Blockstream/electrs#36) As a workaround to cover integration with Esplora/Electrs we get a raw transaction and deserialize it.
@shesek Please correct me if I'm wrong, but according to the Electrum Protocol You can find a possible workaround here: keep-network/tbtc-v2@26d4f01. WDYT? |
…ol integration (#501) Closes: #422 In this PR we update the implementation of TypeScript Electrum integration to support Esplora/Electrs servers. As per Blockstream/electrs#36 verbose transactions are not supported by Esplora/Electrs. This affects our implementation of `getTransaction` and `getTransactionConfirmations` functions. For a consistent code in the client without alternative paths for different Electrum servers implementations I decided to not use verbose transactions at all. ### [getTransactionConfirmations](26d4f01) 1. Get the raw transaction 2. Deserialize the raw transaction 3. Find transaction block height by finding it in a history of transactions for the output script included in the transaction. 4. Get the latest block height 5. Calculate number of confirmations by subtracting the transaction block height from the latest block height and adding one. ### [getTransaction](a7aedd1) We get a raw transaction and deserialize it with `bcoin`. This lets us define a consistent type for returned transactions (093d4ec). Before these changes, I observed that Electrum server implementations are not consistent with data returned in verbose JSON. ### Electrum tests We can test electrum integration against different kinds of servers. The most popular implementations are: - ElectrumX - Fulcrum - Electrs/Esplora We can find a list of public servers here: https://1209k.com/bitcoin-eye/ele.php?chain=tbtc The electrs-esplora server seems pretty unstable, so we don't want to enable it in tests until we add retries (#485).
Yes you are correct -- the current Electrum protocol specification does require specifying
Also note that the next v2.0 protocol specification intends to make this behavior official:
Well obviously kind of hairy and inefficient, but as far as I know its the best you can get using just the standard Electrum server features (and assuming no |
I tested it against the most popular electrum server implementations: Fulcrum, Esplora/Electrs, and ElectrumX: ## Fulcrum
echo '{"jsonrpc": "2.0", "method": "server.version", "id": 0}' | netcat 176.9.63.51 50001
# {"id":0,"jsonrpc":"2.0","result":["Fulcrum 1.8.2","1.4"]}
echo '{"jsonrpc": "2.0", "method": "blockchain.transaction.get_merkle", "params": ["bf8ec5df1cad3ab003f997e44e8e24ab4f57841587a9892de799220da10a0286"], "id": 0}' | netcat 176.9.63.51 50001
# {"id":0,"jsonrpc":"2.0","result":{"block_height":779744,"merkle":["d112134b2ae54b0cfe9e65dc0963de47c9afcec121ab656ec2b4af3f808f27fd","603009d060ebb55b48e0dc48859002a54768801abc214bf7076b89ad56bd1410","2707c3bb2464b91486d3ceef887b9565f070da752a9a0ee41eb9c740e64301bc","645dbbf3e10db1a257f5bcc6b7f0a0dd394050661932f1b07695930f24aac068","e22e7afe4feb3d74c105c348d57d86440a8de9e88479adfa7e4d2e3e405ff213","2a4fa3ecc95586cdd60b404c0f0a59aec29e96c7d015b3c3332f8069755bb79d","8729490f70fa8a394ce66dbe2c048ff3879ba2a4730fe31108d710255b2d9aab","811f9b6e15ef0be436dfc0c468fe62c34679b8824eba5421eb8055e639c71f4f","ac57fee6ee2b68d80e96d89db77a2428ba704d541902bbb087df6c42a3bfc7e8","955c0f541ce932d0d13e2316d4e990c9047cec6ecd75ecf8109b8691257ef7e3","7cf665de08a9334a24094c10524b6366ef317cdef121869ad3d0a1dff7c36340"],"pos":3}}
## Esplora/Electrs
echo '{"jsonrpc": "2.0", "method": "server.version", "id": 0}' | netcat 35.225.54.191 50001
# {"id":0,"jsonrpc":"2.0","result":["electrs-esplora 0.4.1","1.4"]}
echo '{"jsonrpc": "2.0", "method": "blockchain.transaction.get_merkle", "params": ["bf8ec5df1cad3ab003f997e44e8e24ab4f57841587a9892de799220da10a0286"], "id": 0}' | netcat 35.225.54.191 50001
# {"error":"missing height","id":0,"jsonrpc":"2.0"}
## ElectrumX
echo '{"jsonrpc": "2.0", "method": "server.version", "id": 0}' | netcat 161.97.67.106 50001
# {"jsonrpc":"2.0","result":["ElectrumX 1.16.0","1.4"],"id":0}
echo '{"jsonrpc": "2.0", "method": "blockchain.transaction.get_merkle", "params": ["bf8ec5df1cad3ab003f997e44e8e24ab4f57841587a9892de799220da10a0286"], "id": 0}' | netcat 161.97.67.106 50001
# {"jsonrpc":"2.0","error":{"code":-32602,"message":"1 argument passed to method \"blockchain.transaction.get_merkle\" but it requires 2"},"id":0} It turned out that only Fulcrum supports |
Fulcrum is cool. It is easy to modify for Bitcoin-like coins. Since it is written in C++, there is no problem with processing power. Moreover, it can be easily built with Docker. Confirmed compatibility as a backend for electrum, Trezor Suite, and AtomicDEX. |
@nkuba Yes you are correct. Looks like my memory failed me. Apologies for the confusion! |
Is there any resolution to this? IIUC, if I want to retrieve the hash of a block in which a transaction was included, I now would have no other chance beside to issue ~4-5 sequential requests that not only introduce a lot of overhead but also the risk to have a reorg happen at any point during their runtime, i.e., I'd have to be super-cautious to do this securely. Verbose transactions are supported since Electrum protocol version 1.2, I was very surprised that |
Bulk txs outspends
It seems that without verbose transactions, there is no way to get the number of confirmations of a tx nor the block hash or height it was confirmed in? |
Why can't the verbose JSON be reproduced from the information in the indices? At least the information available could be returned.. It seems that the HTTP API knows most if not all of the information in the verbose API. |
Added verbose support to blockchain.transaction.get.
It is necessary to set
txindex=1
in the .conf file of coind.Verbose support is required when used as a backend for AtomicDEX (https://atomicdex.io/).