Merge bitcoin/bitcoin#30552: test: fix constructor of msg_tx

ec5e294e4b830766dcc4a80add0613d3705c1794 test: fix constructor of msg_tx (Martin Zumsande)

Pull request description:

  In python, if the default value is a mutable object (here: a class) it is shared over all instances, so that one instance being changed would affect others to be changed as well.
  This was the source of #30543, and possibly various other intermittent bugs in the functional tests, see
  https://github.com/bitcoin/bitcoin/issues/29621#issuecomment-1999298224.

  Fixes #30543
  Fixes #29621
  Fixes #25128

ACKs for top commit:
  sipa:
    utACK ec5e294e4b830766dcc4a80add0613d3705c1794. I believe some linters even warn about doing this.
  maflcko:
    ACK ec5e294e4b830766dcc4a80add0613d3705c1794
  vasild:
    ACK ec5e294e4b830766dcc4a80add0613d3705c1794 ❤️
  theStack:
    ACK ec5e294e4b830766dcc4a80add0613d3705c1794

Tree-SHA512: a6204fb1a326de3f9aa965f345fd658f6a4dcf78731db25cc905ff6eb8d4eeb65d14cc316305eebd89387aec8748c57c3a4f4ca62408f8e5ee53f535b88b1411
This commit is contained in:
merge-script 2024-07-31 12:01:33 +01:00 committed by pasta
parent df3c2392ca
commit e4e5605ef8
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -1724,7 +1724,10 @@ class msg_tx:
__slots__ = ("tx",)
msgtype = b"tx"
def __init__(self, tx=CTransaction()):
def __init__(self, tx=None):
if tx is None:
self.tx = CTransaction()
else:
self.tx = tx
def deserialize(self, f):