Trying to patch Core ZMQ "rawtx" topic to only publish unconfirmed transactions: How? [combined summary]



Individual post summaries: Click here to read the original discussion on the bitcoin-dev mailing list

Published on: 2021-11-29T14:13:37+00:00


Summary:

In an email thread on the bitcoin-dev mailing list, a discussion is being held regarding an issue with the ZeroMQ topic "rawtx." This topic emits a raw transaction when it appears on the mempool, but it also emits the same transaction once it has been confirmed. This causes problems with software that de-duplicates arrays, as the same transaction is received twice. The proposed solution is to configure Core to only publish unconfirmed transactions. However, this cannot be done through configuration or command-line options and requires editing the source code directly.A draft pull request has been opened by 0xB10C to add a rawmempooltx publisher. This PR includes a new function called NotifyMempoolTransaction() in zmq/zmqnotificationinterface.cpp, which notifies the CZMQNotificationInterface about TransactionAddedToMempool. The function calls the publisher with the rawmempooltx topic. The author of the PR mentions that a mempool transaction publisher with both the raw transaction and transaction fee would also be useful, but changes to the chain notifications in interfaces/chain.h would be necessary for this.Meanwhile, on the Bitcointalk forum, a user named Ali Sherief reports experiencing the issue with the "rawtx" topic emitting confirmed transactions. Ali attempts to instruct Core to only publish unconfirmed transactions but discovers that it requires editing the source code directly. They are uncertain which function in src/zmq/zmqnotificationinterface.cpp needs to be patched for their own build. They mention two possibilities: CZMQNotificationInterface::TransactionRemovedFromMempool or void CZMQNotificationInterface::BlockDisconnected, both of which call the NotifyTransaction() method that fires a message on the "rawtx" channel.The author refers to Jonas Schnelli's suggestion from several years ago to add an `if (!pblock)` check. However, they note that the function he was referencing no longer exists and are unsure if the pblock check is still applicable in the present day to determine the block a transaction is inside.To resolve the issue, Prayank suggests a solution to Ali. The solution involves saving zmqpubsequence=tcp://127.0.0.1:28332 in the bitcoin.conf file, running bitcoind, and executing a Python script provided at https://pastebin.com/raw/tNp2x5y3. Prayank shares screenshots of the script execution, showing the status of accepted, connected (block), and removal transactions. Prayank recommends modifying the script to handle transaction duplication since transactions could be printed twice. Alternatively, they suggest using debug=mempool and reading debug.log for changes without polling.Overall, the discussion revolves around the issue with the ZeroMQ topic "rawtx" emitting confirmed transactions and the need to patch the source code to only publish unconfirmed transactions. Suggestions have been made through a pull request and on the Bitcointalk forum, but the exact function to be patched and the applicability of Jonas Schnelli's suggestion are still under consideration. Additionally, Prayank offers a solution involving configuration changes and a Python script to manage transaction duplication.


Updated on: 2023-08-02T05:10:04.251556+00:00