Browse Source

lightning: do not require lock for broadcast tx, it is thread-safe

regtest_lnd
Janus 7 years ago
committed by SomberNight
parent
commit
2a83ae012f
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 27
      lib/lightning.py

27
lib/lightning.py

@ -197,12 +197,7 @@ def SendOutputs(json):
m.resultHash = "" m.resultHash = ""
return json_format.MessageToJson(m) return json_format.MessageToJson(m)
suc, has = NETWORK.broadcast(tx) publishTxThread(tx)
if not suc:
m.success = False
m.error = "electrum/lightning/SendOutputs: Could not broadcast: " + str(has)
m.resultHash = ""
return json_format.MessageToJson(m)
m.success = True m.success = True
m.error = "" m.error = ""
m.resultHash = tx.txid() m.resultHash = tx.txid()
@ -475,21 +470,21 @@ def signOutputRaw(tx, signDesc):
signDesc.output.value, signDesc.witnessScript, sigHashAll, pri2) signDesc.output.value, signDesc.witnessScript, sigHashAll, pri2)
return sig[:len(sig) - 1] return sig[:len(sig) - 1]
async def PublishTransaction(json): def publishTxThread(tx):
req = rpc_pb2.PublishTransactionRequest() global NETWORK
json_format.Parse(json, req) def target(tx, NETWORK):
global NETWORK, globLock
tx = transaction.Transaction(binascii.hexlify(req.tx).decode("utf-8"))
def target(tx, NETWORK, globLock):
globLock.acquire()
try: try:
res = NETWORK.broadcast(tx) res = NETWORK.broadcast(tx)
print("PUBLISH TRANSACTION IN SEPARATE THREAD PRODUCED", res) print("PUBLISH TRANSACTION IN SEPARATE THREAD PRODUCED", res)
except: except:
traceback.print_exc() traceback.print_exc()
finally: threading.Thread(target=target, args=(tx, NETWORK)).start()
globLock.release()
threading.Thread(target=target, args=(tx, NETWORK, globLock)).start() async def PublishTransaction(json):
req = rpc_pb2.PublishTransactionRequest()
json_format.Parse(json, req)
tx = transaction.Transaction(binascii.hexlify(req.tx).decode("utf-8"))
publishTxThread(tx)
m = rpc_pb2.PublishTransactionResponse() m = rpc_pb2.PublishTransactionResponse()
m.success = True m.success = True
m.error = "" m.error = ""

Loading…
Cancel
Save