fixes transaction signing bug when tx had no change outputs

This commit is contained in:
Lex Berezhny 2021-03-01 10:18:47 -05:00
parent 48c64143e3
commit 0cec80f676
3 changed files with 7 additions and 9 deletions

View file

@ -2617,7 +2617,6 @@ class Daemon(metaclass=JSONRPCServerType):
)
txo = tx.outputs[0]
await txo.generate_channel_private_key()
tx._reset()
await tx.sign(funding_accounts)
@ -2774,7 +2773,6 @@ class Daemon(metaclass=JSONRPCServerType):
new_txo.private_key = old_txo.private_key
new_txo.script.generate()
tx._reset()
await tx.sign(funding_accounts)
@ -3345,7 +3343,6 @@ class Daemon(metaclass=JSONRPCServerType):
file_stream = await self.file_manager.create_stream(file_path)
claim.stream.source.sd_hash = file_stream.sd_hash
new_txo.script.generate()
tx._reset()
if channel:
new_txo.sign(channel)
@ -3565,7 +3562,6 @@ class Daemon(metaclass=JSONRPCServerType):
file_stream = await self.file_manager.create_stream(file_path)
new_txo.claim.stream.source.sd_hash = file_stream.sd_hash
new_txo.script.generate()
tx._reset()
stream_hash = file_stream.stream_hash
elif old_stream:
stream_hash = old_stream.stream_hash
@ -3960,9 +3956,6 @@ class Daemon(metaclass=JSONRPCServerType):
)
new_txo = tx.outputs[0]
new_txo.script.generate()
tx._reset()
if channel:
new_txo.sign(channel)
await tx.sign(funding_accounts)

View file

@ -850,6 +850,7 @@ class Transaction:
return hash_type
async def sign(self, funding_accounts: Iterable['Account']):
self._reset()
ledger, wallet = self.ensure_all_have_same_ledger_and_wallet(funding_accounts)
for i, txi in enumerate(self._inputs):
assert txi.script is not None

View file

@ -1976,10 +1976,14 @@ class SupportCommands(CommandTestCase):
self.assertTrue(txs[1]['support_info'][0]['is_tip'])
self.assertTrue(txs[1]['support_info'][0]['is_spent'])
async def test_signed_supports(self):
async def test_signed_supports_with_no_change_txo_regression(self):
# reproduces a bug where transactions did not get properly signed
# if there was no change and just a single output
# lbrycrd returned 'the transaction was rejected by network rules.'
channel_id = self.get_claim_id(await self.channel_create())
stream_id = self.get_claim_id(await self.stream_create())
tx = await self.support_create(stream_id, '0.3', channel_id=channel_id)
tx = await self.support_create(stream_id, '7.967598', channel_id=channel_id)
self.assertEqual(len(tx['outputs']), 1) # must be one to reproduce bug
self.assertTrue(tx['outputs'][0]['is_channel_signature_valid'])