Friday, March 28, 2025
HomeBitcoinsubstitute by charge - Shedding changed transactions when watching the mempool

substitute by charge – Shedding changed transactions when watching the mempool

I’m making an attempt to seize all of the changed transactions. I’ve complied Bitcon Core with tracing enabled and take heed to the mempool:changed as prompt on this query.

This methodology works as anticipated and I can get the changed transactions. Nonetheless, in some instances (about 20% of all of the transactions I seize) the tracepoint alerts me of the transaction being changed, however then I’m not capturing the alternative of that transaction.

I can consider two the reason why that is occurring:

  1. It could possibly be that among the replacements don’t enter my mempool. But when that’s the case, how does the tracepoint is aware of that the transactions is being changed? Additionally, it’s bizarre that this could occur with so many transactions (20% as defined earlier).
  2. The second possibility is that the script that course of the transaction is just not contemplating some instances, which leads to shedding transactions. The script is a modified model of this instance. I’ve modified it so I can seize the kids of the changed transactions as properly. The information I collect with this script is later saved in a pkl file, which is why it has a shared record.

I do not know why I’m shedding so many transactions, and I used to be questioning if somebody may assist see what I’m doing incorrect.

Listed below are the modified features:

       def handle_replaced(_, knowledge, measurement):
          # Set up a brand new RPC connection for this occasion
          rpc_connection_replaced = connection()
          occasion = bpf["replaced_events"].occasion(knowledge)
          hash_replaced = bytes(occasion.replaced_hash)[::-1].hex()
          hash_new = bytes(occasion.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
          # Decide dad or mum transactions which can be nonetheless within the mempool and should not the transaction itself
          dad and mom = set([x['txid'] for x in new_tx['vin'] if x['txid'] in mempool.keys() and x['txid'] != new_tx['txid']])
          # Retrieve the outdated transaction information from the mempool 
          outdated = mempool.get(hash_replaced, None)
          if outdated is just not None:  # Some transactions could also be lacking initially
            mempool.pop(hash_replaced, None)
            # Share the changed occasion particulars by way of list_shared queue
            list_shared.put((outdated, [new_tx, tx_time, parents]))
            # Discover all baby transactions that reference the brand new transaction as a dad or mum
            childs = [i[0]['txid'] for i in mempool.values() if new_tx['txid'] in i[2]]
            
            # Recursive perform to gather baby transaction IDs
            def baby(ll):
              if len(ll) == 0:
                return []
              new_childs = [i[0]['txid'] for i in mempool.values() if ll - i[2] != ll]
              return record(ll) + new_childs + baby(set(new_childs))
            
            if len(childs) > 0:
              childs = baby(set(childs))
              # Share the connection between the brand new transaction and the primary baby
              list_shared.put(([new_tx, tx_time, parents], mempool[childs[0]]))
              # Share connections between subsequent baby transactions
              for i in vary(len(childs)-1):
                list_shared.put((mempool[childs[i]], mempool[childs[i+1]]))

          # Add the brand new transaction to the mempool with its timestamp and dad or mum set
          mempool[new_tx['txid']] = [new_tx, tx_time, parents]
          logger.information('-----------')
          logger.information('New RBF!')        
          
      def handle_added(_, knowledge, measurement):
          rpc_connection_added = connection()
          occasion = bpf["added_events"].occasion(knowledge)
          hash_new = bytes(occasion.hash)[::-1].hex()
          hex_tx = rpc_connection_added.getrawtransaction(hash_new)
          tx_raw = rpc_connection_added.decoderawtransaction(hex_tx)
          tx_raw['hex'] = hex_tx
          dad and mom = 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(_, knowledge, measurement):
        occasion = bpf["removed_events"].occasion(knowledge)
        if occasion.motive != b'changed':
            txid_rem = bytes(occasion.hash)[::-1].hex()
                    
            keys = mempool.keys()
            if txid_rem in keys:
              mempool.pop(txid_rem) 
              logger.information('-----------')
              logger.information(f'Eliminated. Motive:{occasion.motive}')

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments