Estoy tratando de capturar todas las transacciones reemplazadas. He cumplido Bitcon Core con rastreo habilitado y escuche el mempool:changed
Como se sugiere en esto pregunta.
Este método funciona como se esperaba y puedo obtener las transacciones reemplazadas. Sin embargo, en algunos casos (alrededor del 20% de todas las transacciones que captura), el TraCepoint me alerta de la transacción que se reemplaza, pero no estoy capturando el reemplazo de esa transacción.
Puedo pensar en dos razones por las que esto está sucediendo:
- Podría ser que algunos de los reemplazos no ingresen a mi mempool. Pero si ese es el caso, ¿cómo sabe el tracePoint que las transacciones se están reemplazando? Además, es extraño que esto suceda con tantas transacciones (20% como se explicó anteriormente).
- La segunda opción es que el script que procesa la transacción no está considerando algunos casos, lo que termina en la pérdida de transacciones. El script es una versión modificada de esto ejemplo. Lo he modificado para poder capturar a los niños de las transacciones reemplazadas también. Los datos que reúno con este script se guarda más tarde en un archivo PKL, por lo que tiene una lista compartida.
No sé por qué estoy perdiendo tantas transacciones, y me preguntaba si alguien podría ayudar a ver qué estoy haciendo mal.
Aquí están las funciones modificadas:
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 mother or father transactions which can be nonetheless within the mempool and are usually not the transaction itself
mother and father = 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 data from the mempool
outdated = mempool.get(hash_replaced, None)
if outdated isn't None: # Some transactions could also be lacking initially
mempool.pop(hash_replaced, None)
# Share the changed occasion particulars through list_shared queue
list_shared.put((outdated, (new_tx, tx_time, mother and father)))
# Discover all baby transactions that reference the brand new transaction as a mother or father
childs = (i(0)('txid') for i in mempool.values() if new_tx('txid') in i(2))
# Recursive operate 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 checklist(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, mother and father), 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 mother or father set
mempool(new_tx('txid')) = (new_tx, tx_time, mother and father)
logger.data('-----------')
logger.data('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
mother and father = set((x('txid') for x in tx_raw('vin') if x('txid') in mempool.keys()))
mempool(tx_raw('txid')) = (tx_raw, get_timestamp(), mother and father)
def handle_removed(_, knowledge, measurement):
occasion = bpf("removed_events").occasion(knowledge)
if occasion.purpose != b'changed':
txid_rem = bytes(occasion.hash)(::-1).hex()
keys = mempool.keys()
if txid_rem in keys:
mempool.pop(txid_rem)
logger.data('-----------')
logger.data(f'Eliminated. Motive:{occasion.purpose}')
Estoy tratando de capturar todas las transacciones reemplazadas. He cumplido Bitcon Core con rastreo habilitado y escuche el mempool:changed
Como se sugiere en esto pregunta.
Este método funciona como se esperaba y puedo obtener las transacciones reemplazadas. Sin embargo, en algunos casos (alrededor del 20% de todas las transacciones que captura), el TraCepoint me alerta de la transacción que se reemplaza, pero no estoy capturando el reemplazo de esa transacción.
Puedo pensar en dos razones por las que esto está sucediendo:
- Podría ser que algunos de los reemplazos no ingresen a mi mempool. Pero si ese es el caso, ¿cómo sabe el tracePoint que las transacciones se están reemplazando? Además, es extraño que esto suceda con tantas transacciones (20% como se explicó anteriormente).
- La segunda opción es que el script que procesa la transacción no está considerando algunos casos, lo que termina en la pérdida de transacciones. El script es una versión modificada de esto ejemplo. Lo he modificado para poder capturar a los niños de las transacciones reemplazadas también. Los datos que reúno con este script se guarda más tarde en un archivo PKL, por lo que tiene una lista compartida.
No sé por qué estoy perdiendo tantas transacciones, y me preguntaba si alguien podría ayudar a ver qué estoy haciendo mal.
Aquí están las funciones modificadas:
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 mother or father transactions which can be nonetheless within the mempool and are usually not the transaction itself
mother and father = 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 data from the mempool
outdated = mempool.get(hash_replaced, None)
if outdated isn't None: # Some transactions could also be lacking initially
mempool.pop(hash_replaced, None)
# Share the changed occasion particulars through list_shared queue
list_shared.put((outdated, (new_tx, tx_time, mother and father)))
# Discover all baby transactions that reference the brand new transaction as a mother or father
childs = (i(0)('txid') for i in mempool.values() if new_tx('txid') in i(2))
# Recursive operate 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 checklist(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, mother and father), 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 mother or father set
mempool(new_tx('txid')) = (new_tx, tx_time, mother and father)
logger.data('-----------')
logger.data('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
mother and father = set((x('txid') for x in tx_raw('vin') if x('txid') in mempool.keys()))
mempool(tx_raw('txid')) = (tx_raw, get_timestamp(), mother and father)
def handle_removed(_, knowledge, measurement):
occasion = bpf("removed_events").occasion(knowledge)
if occasion.purpose != b'changed':
txid_rem = bytes(occasion.hash)(::-1).hex()
keys = mempool.keys()
if txid_rem in keys:
mempool.pop(txid_rem)
logger.data('-----------')
logger.data(f'Eliminated. Motive:{occasion.purpose}')