mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-02 18:25:21 +00:00
lightning: do not require lock for broadcast tx, it is thread-safe
This commit is contained in:
parent
c90bbf8d27
commit
fba9072c15
1 changed files with 11 additions and 16 deletions
|
@ -197,12 +197,7 @@ def SendOutputs(json):
|
|||
m.resultHash = ""
|
||||
return json_format.MessageToJson(m)
|
||||
|
||||
suc, has = NETWORK.broadcast(tx)
|
||||
if not suc:
|
||||
m.success = False
|
||||
m.error = "electrum/lightning/SendOutputs: Could not broadcast: " + str(has)
|
||||
m.resultHash = ""
|
||||
return json_format.MessageToJson(m)
|
||||
publishTxThread(tx)
|
||||
m.success = True
|
||||
m.error = ""
|
||||
m.resultHash = tx.txid()
|
||||
|
@ -475,21 +470,21 @@ def signOutputRaw(tx, signDesc):
|
|||
signDesc.output.value, signDesc.witnessScript, sigHashAll, pri2)
|
||||
return sig[:len(sig) - 1]
|
||||
|
||||
async def PublishTransaction(json):
|
||||
req = rpc_pb2.PublishTransactionRequest()
|
||||
json_format.Parse(json, req)
|
||||
global NETWORK, globLock
|
||||
tx = transaction.Transaction(binascii.hexlify(req.tx).decode("utf-8"))
|
||||
def target(tx, NETWORK, globLock):
|
||||
globLock.acquire()
|
||||
def publishTxThread(tx):
|
||||
global NETWORK
|
||||
def target(tx, NETWORK):
|
||||
try:
|
||||
res = NETWORK.broadcast(tx)
|
||||
print("PUBLISH TRANSACTION IN SEPARATE THREAD PRODUCED", res)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
finally:
|
||||
globLock.release()
|
||||
threading.Thread(target=target, args=(tx, NETWORK, globLock)).start()
|
||||
threading.Thread(target=target, args=(tx, NETWORK)).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.success = True
|
||||
m.error = ""
|
||||
|
|
Loading…
Add table
Reference in a new issue