Skip to content

Commit e58a375

Browse files
Fix wrong message after syncing, fix test suite
1 parent da9ab82 commit e58a375

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

btclib_node/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def finish_sync(node):
2222
if node.status == NodeStatus.BlockSynced:
2323
return
2424
node.status = NodeStatus.BlockSynced
25-
# node.p2p_manager.sendall(Filterclear())
25+
# start new connections with tx relay enabled
26+
node.p2p_manager.stop_all()
2627

2728

2829
# TODO: support for failed updates

btclib_node/rpc/callbacks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ def ping(node, conn, _):
142142

143143

144144
def stop(node, conn, _):
145-
node.stop()
146145
return "Btclib node stopping"
147146

148147

btclib_node/rpc/connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ async def async_send(self, response):
6969
def send(self, response):
7070
asyncio.run_coroutine_threadsafe(self.async_send(response), self.loop)
7171

72+
# Use with care
73+
def send_and_wait(self, response):
74+
future = asyncio.run_coroutine_threadsafe(self.async_send(response), self.loop)
75+
try:
76+
future.result(timeout=2)
77+
except TimeoutError:
78+
pass
79+
7280
def __repr__(self):
7381
try:
7482
out = f"Connection to {self.client.getpeername()[0]}:{self.client.getpeername()[1]}"

btclib_node/rpc/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def handle_rpc(node):
6666
node.logger.exception("Exception occurred")
6767
response.append(error_msg(-32603))
6868

69-
conn.send(response)
69+
if request.get("method") == "stop":
70+
conn.send_and_wait(response)
71+
node.stop()
72+
else:
73+
conn.send(response)
7074
node.logger.debug("Finished rpc\n")
7175
# node.rpc_manager.connections.pop(conn_id)

tests/functional/p2p/test_tx.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,26 @@ def test_send_tx(tmp_path):
3838

3939
wait_until(lambda: node1.p2p_manager.is_alive())
4040
wait_until(lambda: node2.p2p_manager.is_alive())
41+
42+
# Add one block
43+
block = generate_random_chain(1, RegTest().genesis.hash)[0]
44+
for node in (node1, node2):
45+
block_index = node.chainstate.block_index
46+
node.chainstate.block_index.add_headers([block.header])
47+
node.status = NodeStatus.HeaderSynced
48+
node.block_db.add_block(block)
49+
block_info = block_index.get_block_info(block.header.hash)
50+
block_info.downloaded = True
51+
block_index.insert_block_info(block_info)
52+
wait_until(lambda: len(block_index.active_chain) == 2)
53+
4154
node2.p2p_manager.connect(local_addr(node1.p2p_port))
4255
wait_until(lambda: len(node1.p2p_manager.connections))
4356
connection = node1.p2p_manager.connections[0]
4457
wait_until(lambda: connection.status == P2pConnStatus.Connected)
4558
connection = node2.p2p_manager.connections[0]
4659
wait_until(lambda: connection.status == P2pConnStatus.Connected)
4760

48-
# Add one block
49-
block = generate_random_chain(1, RegTest().genesis.hash)[0]
50-
block_index = node1.chainstate.block_index
51-
node1.chainstate.block_index.add_headers([block.header])
52-
node1.status = NodeStatus.HeaderSynced
53-
node1.block_db.add_block(block)
54-
block_info = block_index.get_block_info(block.header.hash)
55-
block_info.downloaded = True
56-
block_index.insert_block_info(block_info)
57-
wait_until(lambda: len(block_index.active_chain) == 2)
58-
5961
tx = generate_random_transaction(block.transactions[0].id)
6062

6163
assert node1.mempool.size == 0

0 commit comments

Comments
 (0)