• 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

Illinois Delays Crypto Tax Six Months Pending Court Approval

Illinois Delays Crypto Tax Six Months Pending Court Approval

October 6, 2026
BTC To $132k In 2027 & MSTR Price Outlook

BTC To $132k In 2027 & MSTR Price Outlook

October 6, 2026
Share76Tweet47

Related Posts

Illinois Delays Crypto Tax Six Months Pending Court Approval

Illinois Delays Crypto Tax Six Months Pending Court Approval

by Moussa
October 6, 2026
0

Join Our Telegram channel to stay up to date on breaking news coverage Illinois has agreed to push the start...

BTC To $132k In 2027 & MSTR Price Outlook

BTC To $132k In 2027 & MSTR Price Outlook

by Moussa
October 6, 2026
0

Institutions are no longer debating whether to own Bitcoin. Now the question is how. TD Cowen Managing Director Lance Vitanza...

Ripple Targets Turkey’s $200 Billion Crypto Market Amid Lira Pressure

Ripple Targets Turkey’s $200 Billion Crypto Market Amid Lira Pressure

by Moussa
October 6, 2026
0

Key TakeawaysTurkey recorded nearly $200 billion in annual transactions, according to Chainalysis.Garanti BBVA’s digital asset service is available to its...

CFTC Approval “Opens Many Doors” For Bitcoin

CFTC Approval “Opens Many Doors” For Bitcoin

by Moussa
October 6, 2026
0

The SEC’s proposed custody rules could make it easier for investment advisors to help clients own Bitcoin directly. Coinbase’s Ryan...

Brazil Calls Its Own Betting Laws Unconstitutional as Shutdown Begins

Brazil Calls Its Own Betting Laws Unconstitutional as Shutdown Begins

by Moussa
October 5, 2026
0

Key TakeawaysBrazil’s government lawyers asked the Supreme Court on Oct. 2 to void its 2018 and 2023 betting laws.Licensed betting...

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/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSUzQ2RpdiUyMGNsYXNzJTNEJTIydG5wJTIwd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Y2tib3glMjIlMjBuYW1lJTNEJTIybnklMjIlMjByZXF1aXJlZCUyMGNsYXNzJTNEJTIydG5wLXByaXZhY3klMjIlM0UlQzIlQTBCeSUyMGNvbnRpbnVpbmclMkMlMjB5b3UlMjBhY2NlcHQlMjB0aGUlMjBwcml2YWN5JTIwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News