Test that we offer and re-xmit peer storage for our peers if they have a channel or are explicitly enabled
(node_factory, bitcoind)
| 4947 | |
| 4948 | |
| 4949 | def test_peer_storage(node_factory, bitcoind): |
| 4950 | """Test that we offer and re-xmit peer storage for our peers if they have a channel or are explicitly enabled""" |
| 4951 | l1, l2, l3 = node_factory.get_nodes(3, |
| 4952 | opts={'may_reconnect': True, |
| 4953 | 'dev-no-reconnect': None}) |
| 4954 | |
| 4955 | # Connect them, no peer storage yet anyway. |
| 4956 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 4957 | |
| 4958 | assert not l1.daemon.is_in_log(r'WIRE_PEER_STORAGE_RETRIEVAL') |
| 4959 | assert not l2.daemon.is_in_log(r'WIRE_PEER_STORAGE_RETRIEVAL') |
| 4960 | |
| 4961 | # And they won't store. |
| 4962 | assert l1.rpc.listdatastore(['chanbackup', 'peers', l2.info['id']]) == {'datastore': []} |
| 4963 | assert l2.rpc.listdatastore(['chanbackup', 'peers', l1.info['id']]) == {'datastore': []} |
| 4964 | |
| 4965 | # Reconnect, still no xmit. |
| 4966 | l1.rpc.disconnect(l2.info['id']) |
| 4967 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 4968 | |
| 4969 | # Give it time to make sure we *would* catch it if it happened. |
| 4970 | time.sleep(10) |
| 4971 | assert not l1.daemon.is_in_log(r'WIRE_PEER_STORAGE_RETRIEVAL') |
| 4972 | assert not l2.daemon.is_in_log(r'WIRE_PEER_STORAGE_RETRIEVAL') |
| 4973 | |
| 4974 | # But we can force it manually by creating an empty one. |
| 4975 | l1.rpc.datastore(['chanbackup', 'peers', l2.info['id']], hex='') |
| 4976 | assert l1.rpc.listdatastore(['chanbackup', 'peers', l2.info['id']])['datastore'][0]['hex'] == '' |
| 4977 | l1.restart() |
| 4978 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 4979 | |
| 4980 | # Note: l1 may or may not send peer_storage_retrieval: if it |
| 4981 | # receives storage fast enough, it will, otherwise not. |
| 4982 | wait_for(lambda: l1.rpc.listdatastore(['chanbackup', 'peers', l2.info['id']])['datastore'][0]['hex'] != '') |
| 4983 | |
| 4984 | # Next reconnect, l1 will send it back. |
| 4985 | l1.rpc.disconnect(l2.info['id']) |
| 4986 | l1.rpc.connect(l2.info['id'], 'localhost', l2.port) |
| 4987 | |
| 4988 | l1.daemon.wait_for_log(r'peer_out WIRE_PEER_STORAGE_RETRIEVAL') |
| 4989 | l2.daemon.wait_for_log(r'peer_in WIRE_PEER_STORAGE_RETRIEVAL') |
| 4990 | assert not l1.daemon.is_in_log(r'peer_in WIRE_PEER_STORAGE_RETRIEVAL') |
| 4991 | assert not l2.daemon.is_in_log(r'peer_out WIRE_PEER_STORAGE_RETRIEVAL') |
| 4992 | |
| 4993 | # It must be valid. |
| 4994 | l2.daemon.wait_for_log(r'Received peer_storage from peer') |
| 4995 | assert not l2.daemon.is_in_log(r'PeerStorageFailed') |
| 4996 | |
| 4997 | # l2 will only store if we have an ESTABLISHED channel. |
| 4998 | l1.openchannel(l2, confirm=False, wait_for_announce=False) |
| 4999 | assert l2.rpc.listdatastore(['chanbackup', 'peers', l1.info['id']]) == {'datastore': []} |
| 5000 | |
| 5001 | # But it will create an entry once it hits CHANNELD_NORMAL. |
| 5002 | bitcoind.generate_block(1, wait_for_mempool=1) |
| 5003 | wait_for(lambda: l2.rpc.listdatastore(['chanbackup', 'peers', l1.info['id']]) != {'datastore': []}) |
| 5004 | |
| 5005 | # Now it will store l1's backup when channels change. |
| 5006 | l1.openchannel(l3, wait_for_announce=False) |
nothing calls this directly
no test coverage detected