From 0cec80f676c6f451770f0fd6d95a5bfaceae8ed9 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Mon, 1 Mar 2021 10:18:47 -0500 Subject: [PATCH] fixes transaction signing bug when tx had no change outputs --- lbry/extras/daemon/daemon.py | 7 ------- lbry/wallet/transaction.py | 1 + tests/integration/blockchain/test_claim_commands.py | 8 ++++++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lbry/extras/daemon/daemon.py b/lbry/extras/daemon/daemon.py index 7319710c3..a465e4802 100644 --- a/lbry/extras/daemon/daemon.py +++ b/lbry/extras/daemon/daemon.py @@ -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) diff --git a/lbry/wallet/transaction.py b/lbry/wallet/transaction.py index c05d7bc12..9856d274a 100644 --- a/lbry/wallet/transaction.py +++ b/lbry/wallet/transaction.py @@ -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 diff --git a/tests/integration/blockchain/test_claim_commands.py b/tests/integration/blockchain/test_claim_commands.py index ce9859de6..679dd85b8 100644 --- a/tests/integration/blockchain/test_claim_commands.py +++ b/tests/integration/blockchain/test_claim_commands.py @@ -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'])