• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

replace by fee – Losing replaced transactions when watching the mempool

Moussa by Moussa
March 22, 2025
in Bitcoin
0
peer discovery – how to obtain the IP addresses of nodes for mining pools?
189
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


I am trying to capture all the replaced transactions. I have complied Bitcon Core with tracing enabled and listen to the mempool:replaced as suggested in this question.

This method works as expected and I can get the replaced transactions. However, in some cases (about 20% of all the transactions I capture) the tracepoint alerts me of the transaction being replaced, but then I am not capturing the replacement of that transaction.

I can think of two reasons why this is happening:

  1. It could be that some of the replacements do not enter my mempool. But if that is the case, how does the tracepoint knows that the transactions is being replaced? Also, it is weird that this would happen with so many transactions (20% as explained earlier).
  2. The second option is that the script that process the transaction is not considering some cases, which ends up in losing transactions. The script is a modified version of this example. I have modified it so I can capture the children of the replaced transactions as well. The data I gather with this script is later saved in a pkl file, which is why it has a shared list.

I don’t know why I am losing so many transactions, and I was wondering if someone could help see what I am doing wrong.

Here are the modified functions:

       def handle_replaced(_, data, size):
          # Establish a new RPC connection for this event
          rpc_connection_replaced = connection()
          event = bpf["replaced_events"].event(data)
          hash_replaced = bytes(event.replaced_hash)[::-1].hex()
          hash_new = bytes(event.replacement_hash)[::-1].hex()
          tx_time = get_timestamp()
          
          hex_tx = rpc_connection_replaced.getrawtransaction(hash_new)
          new_tx = rpc_connection_replaced.decoderawtransaction(hex_tx)
          new_tx['hex'] = hex_tx
          # Determine parent transactions that are still in the mempool and are not the transaction itself
          parents = set([x['txid'] for x in new_tx['vin'] if x['txid'] in mempool.keys() and x['txid'] != new_tx['txid']])
          # Retrieve the old transaction info from the mempool 
          old = mempool.get(hash_replaced, None)
          if old is not None:  # Some transactions may be missing initially
            mempool.pop(hash_replaced, None)
            # Share the replaced event details via list_shared queue
            list_shared.put((old, [new_tx, tx_time, parents]))
            # Find all child transactions that reference the new transaction as a parent
            childs = [i[0]['txid'] for i in mempool.values() if new_tx['txid'] in i[2]]
            
            # Recursive function to collect child transaction IDs
            def child(ll):
              if len(ll) == 0:
                return []
              new_childs = [i[0]['txid'] for i in mempool.values() if ll - i[2] != ll]
              return list(ll) + new_childs + child(set(new_childs))
            
            if len(childs) > 0:
              childs = child(set(childs))
              # Share the connection between the new transaction and the first child
              list_shared.put(([new_tx, tx_time, parents], mempool[childs[0]]))
              # Share connections between subsequent child transactions
              for i in range(len(childs)-1):
                list_shared.put((mempool[childs[i]], mempool[childs[i+1]]))

          # Add the new transaction to the mempool with its timestamp and parent set
          mempool[new_tx['txid']] = [new_tx, tx_time, parents]
          logger.info('-----------')
          logger.info('New RBF!')        
          
      def handle_added(_, data, size):
          rpc_connection_added = connection()
          event = bpf["added_events"].event(data)
          hash_new = bytes(event.hash)[::-1].hex()
          hex_tx = rpc_connection_added.getrawtransaction(hash_new)
          tx_raw = rpc_connection_added.decoderawtransaction(hex_tx)
          tx_raw['hex'] = hex_tx
          parents = set([x['txid'] for x in tx_raw['vin'] if x['txid'] in mempool.keys()])
          mempool[tx_raw['txid']] = [tx_raw, get_timestamp(), parents]
          
      def handle_removed(_, data, size):
        event = bpf["removed_events"].event(data)
        if event.reason != b'replaced':
            txid_rem = bytes(event.hash)[::-1].hex()
                    
            keys = mempool.keys()
            if txid_rem in keys:
              mempool.pop(txid_rem) 
              logger.info('-----------')
              logger.info(f'Removed. Reason:{event.reason}')



Source link

Related articles

Binance Says Fake Job Interview, Compromised AI Tools Led to $6.3 Billion Hack

Binance Hack Exposed Three ‘Entirely Avoidable’ Flaws, Says Coinex Founder

November 4, 2026
CFTC clears Equity Perps on US stocks under Reg 40.3

CFTC clears Equity Perps on US stocks under Reg 40.3

November 4, 2026
Share76Tweet47

Related Posts

Binance Says Fake Job Interview, Compromised AI Tools Led to $6.3 Billion Hack

Binance Hack Exposed Three ‘Entirely Avoidable’ Flaws, Says Coinex Founder

by Moussa
November 4, 2026
0

Key TakeawaysHaipo Yang listed 3 failures at Binance, from shared devices to a multi-signature setup in name only.Binance says 98%...

CFTC clears Equity Perps on US stocks under Reg 40.3

CFTC clears Equity Perps on US stocks under Reg 40.3

by Moussa
November 4, 2026
0

Perpetual futures tied to individual US stocks can trade on American regulated exchanges for the first time, under an announcement...

BTC USD Bounces Back to $78,500 After a Democratic Sweep of Congress: Are Traders Really Punishing the Republicans?

BTC USD Bounces Back to $78,500 After a Democratic Sweep of Congress: Are Traders Really Punishing the Republicans?

by Moussa
November 4, 2026
0

Bitcoin (BTC USD) climbed back to $78,500 on Wednesday, November 4, hours after dipping to $75,736, as Democrats won control...

US Midterm Elections Shake Markets: Could Bitcoin Be Ready for a Comeback?

US Midterm Elections Shake Markets: Could Bitcoin Be Ready for a Comeback?

by Moussa
November 4, 2026
0

Trusted Editorial content, reviewed by leading industry experts and seasoned editors. Ad Disclosure The 2026 US midterm elections have delivered...

Solana Microscope Offers Open-Source Monitoring for Complex On-Chain Operations

Solana Microscope Offers Open-Source Monitoring for Complex On-Chain Operations

by Moussa
November 4, 2026
0

TL;DR: The Solana Foundation has described Microscope, an open-source monitoring approach for teams managing on-chain programmes and infrastructure. An alert...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1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hc3MlM0QlMjJ0bnAtZmllbGQlMjB0bnAtcHJpdmFjeS1maWVsZCUyMiUzRSUzQ2xhYmVsJTNFJTNDaW5wdXQlMjB0eXBlJTNEJTIyY2hlY2tib3glMjIlMjBuYW1lJTNEJTIybnklMjIlMjByZXF1aXJlZCUyMGNsYXNzJTNEJTIydG5wLXByaXZhY3klMjIlM0UlQzIlQTBCeSUyMGNvbnRpbnVpbmclMkMlMjB5b3UlMjBhY2NlcHQlMjB0aGUlMjBwcml2YWN5JTIwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News