Repository: Bitmessage/PyBitmessage

Issue:
Fix backward compatibility in pickle_deserialize_old_knownnodes()
Hello!

#1662 is caused by changed package structure.

Here I've set up a minimal upgrade from v0.6.3 to reproduce the bug. Using v0.6.2 would be difficult, because it has no command line args.


Discussion:
I'm going to squash e2673fb with d8099fd when you check the failure.
I was testing PR and faces this issue on logs.
![image](https://user-images.githubusercontent.com/33522186/94989560-6a7f6f80-0593-11eb-8171-74071139148a.png)


> I was testing PR and faces this issue on logs.
> ![image](https://user-images.githubusercontent.com/33522186/94989560-6a7f6f80-0593-11eb-8171-74071139148a.png)

It is #1661, the bug is present in current v0.6.
can you rebase this on top of #1683 when ready?

Resolving patch:
diff --git a/src/network/knownnodes.py b/src/network/knownnodes.py
--- a/src/network/knownnodes.py
+++ b/src/network/knownnodes.py
@@ -17,6 +17,8 @@
 from bmconfigparser import BMConfigParser
 from network.node import Peer
 
+state.Peer = Peer
+
 knownNodesLock = threading.RLock()
 """Thread lock for knownnodes modification"""
 knownNodes = {stream: {} for stream in range(1, 4)}


Test patch:
diff --git a/src/tests/core.py b/src/tests/core.py
--- a/src/tests/core.py
+++ b/src/tests/core.py
@@ -7,6 +7,7 @@
 import pickle  # nosec
 import Queue
 import random  # nosec
+import shutil
 import string
 import sys
 import time
@@ -231,7 +232,8 @@ def test_version(self):
         msg = protocol.assembleVersionMessage('127.0.0.1', 8444, [1])
         decoded = self._decode_msg(msg, "IQQiiQlsLv")
         peer, _, ua, streams = self._decode_msg(msg, "IQQiiQlsLv")[4:]
-        self.assertEqual(peer, Node(3, '127.0.0.1', 8444))
+        self.assertEqual(
+            peer, Node(11 if state.dandelion else 3, '127.0.0.1', 8444))
         self.assertEqual(ua, '/PyBitmessage:' + softwareVersion + '/')
         self.assertEqual(streams, [1])
         # with multiple streams
@@ -259,6 +261,19 @@ def test_insert_method_msgid(self):
             '''select typeof(msgid) from sent where ackdata=?''', result)
         self.assertEqual(column_type[0][0] if column_type else '', 'text')
 
+    def test_old_knownnodes_pickle(self):
+        """Testing old(v.0.6.2) version knownnodes.dat file"""
+        try:
+            old_source_file = os.path.join(
+                os.path.abspath(os.path.dirname(__file__)), 'test_pattern', 'knownnodes.dat')
+            new_destination_file = os.path.join(state.appdata, 'knownnodes.dat')
+            shutil.copyfile(old_source_file, new_destination_file)
+            knownnodes.readKnownNodes()
+        except AttributeError as e:
+            self.fail('Failed to load knownnodes: %s' % e)
+        finally:
+            cleanup(files=('knownnodes.dat',))
+
 
 def run():
     """Starts all tests defined in this module"""
diff --git a/src/tests/test_pattern/knownnodes.dat b/src/tests/test_pattern/knownnodes.dat
new file mode 100644
--- /dev/null
+++ b/src/tests/test_pattern/knownnodes.dat
@@ -0,0 +1,104 @@
+(dp0
+I1
+(dp1
+ccopy_reg
+_reconstructor
+p2
+(cstate
+Peer
+p3
+c__builtin__
+tuple
+p4
+(S'85.180.139.241'
+p5
+I8444
+tp6
+tp7
+Rp8
+I1608398841
+sg2
+(g3
+g4
+(S'158.222.211.81'
+p9
+I8080
+tp10
+tp11
+Rp12
+I1608398841
+sg2
+(g3
+g4
+(S'178.62.12.187'
+p13
+I8448
+tp14
+tp15
+Rp16
+I1608398841
+sg2
+(g3
+g4
+(S'109.147.204.113'
+p17
+I1195
+tp18
+tp19
+Rp20
+I1608398841
+sg2
+(g3
+g4
+(S'5.45.99.75'
+p21
+I8444
+tp22
+tp23
+Rp24
+I1608398841
+sg2
+(g3
+g4
+(S'178.11.46.221'
+p25
+I8444
+tp26
+tp27
+Rp28
+I1608398841
+sg2
+(g3
+g4
+(S'95.165.168.168'
+p29
+I8444
+tp30
+tp31
+Rp32
+I1608398841
+sg2
+(g3
+g4
+(S'24.188.198.204'
+p33
+I8111
+tp34
+tp35
+Rp36
+I1608398841
+sg2
+(g3
+g4
+(S'75.167.159.54'
+p37
+I8444
+tp38
+tp39
+Rp40
+I1608398841
+ssI2
+(dp41
+sI3
+(dp42
+s.
\ No newline at end of file