Skip to content

Commit 9a0dcd5

Browse files
committed
Improve requesting transactions advertised via NewTransaction.
1 parent 7a426e5 commit 9a0dcd5

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

chia/_tests/core/full_node/test_full_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ async def test_request_respond_transaction(
11691169
spend_bundle = wallet_a.generate_signed_transaction(uint64(100), receiver_puzzlehash, coin)
11701170
assert spend_bundle is not None
11711171
respond_transaction = fnp.RespondTransaction(spend_bundle)
1172-
peer.expected_mempool_responses += 1
1172+
peer.expected_mempool_responses = 1
11731173
res = await full_node_1.respond_transaction(respond_transaction, peer)
11741174
assert res is None
11751175

@@ -1225,7 +1225,7 @@ async def test_respond_transaction_fail(
12251225

12261226
assert spend_bundle is not None
12271227
respond_transaction = fnp.RespondTransaction(spend_bundle)
1228-
peer.expected_mempool_responses += 1
1228+
peer.expected_mempool_responses = 1
12291229
msg = await full_node_1.respond_transaction(respond_transaction, peer)
12301230
assert msg is None
12311231

chia/_tests/core/mempool/test_mempool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ async def test_basic_mempool_manager(
465465
spend_bundle = generate_test_spend_bundle(wallet_a, coin)
466466
assert spend_bundle is not None
467467
tx: full_node_protocol.RespondTransaction = full_node_protocol.RespondTransaction(spend_bundle)
468-
peer.expected_mempool_responses += 1
468+
peer.expected_mempool_responses = 1
469469
await full_node_1.respond_transaction(tx, peer, test=True)
470470

471471
await time_out_assert(

chia/_tests/wallet/simple_sync/test_simple_sync_protocol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ async def test_subscribe_for_hint(simulator_and_wallet: OldSimulatorsAndWallets,
506506
await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)
507507

508508
tx = wt.generate_signed_transaction(uint64(10), wt.get_new_puzzlehash(), coin_spent, condition_dic=condition_dict)
509-
fake_wallet_peer.expected_mempool_responses += 1
509+
fake_wallet_peer.expected_mempool_responses = 1
510510
await full_node_api.respond_transaction(RespondTransaction(tx), fake_wallet_peer)
511511

512512
await full_node_api.process_spend_bundles(bundles=[tx])
@@ -558,7 +558,7 @@ async def test_subscribe_for_puzzle_hash_coin_hint_duplicates(
558558
ConditionOpcode.CREATE_COIN: [ConditionWithArgs(ConditionOpcode.CREATE_COIN, [ph, int_to_bytes(1), ph])]
559559
},
560560
)
561-
wallet_connection.expected_mempool_responses += 1
561+
wallet_connection.expected_mempool_responses = 1
562562
await full_node_api.respond_transaction(RespondTransaction(tx), wallet_connection)
563563
await full_node_api.process_spend_bundles(bundles=[tx])
564564
# Query the coin states and make sure it doesn't contain duplicated entries
@@ -617,7 +617,7 @@ async def test_subscribe_for_hint_long_sync(
617617
await full_node_api.wait_for_wallet_synced(wallet_node=wallet_node, timeout=20)
618618

619619
tx = wt.generate_signed_transaction(uint64(10), wt.get_new_puzzlehash(), coin_spent, condition_dic=condition_dict)
620-
fake_wallet_peer.expected_mempool_responses += 1
620+
fake_wallet_peer.expected_mempool_responses = 1
621621
await full_node_api.respond_transaction(RespondTransaction(tx), fake_wallet_peer)
622622

623623
await full_node_api.process_spend_bundles(bundles=[tx])

chia/full_node/full_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ async def on_connect(self, connection: WSChiaConnection) -> None:
949949
except Exception:
950950
old_peer = True
951951
if old_peer:
952-
connection.expected_mempool_responses += 100
952+
connection.expected_mempool_responses = 100
953953

954954
peak_full: FullBlock | None = await self.blockchain.get_full_peak()
955955

chia/full_node/full_node_api.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,32 @@ async def tx_request_and_timeout(full_node: FullNode, transaction_id: bytes32, t
110110
if peer_id not in full_node.server.all_connections:
111111
continue
112112
random_peer = full_node.server.all_connections[peer_id]
113-
request_tx = full_node_protocol.RequestTransaction(transaction_id)
114-
msg = make_msg(ProtocolMessageTypes.request_transaction, request_tx)
115-
await random_peer.send_message(msg)
116-
await asyncio.sleep(5)
117-
if full_node.mempool_manager.seen(transaction_id):
118-
break
113+
try:
114+
response = await random_peer.call_api(
115+
FullNodeAPI.request_transaction, full_node_protocol.RequestTransaction(transaction_id), timeout=5
116+
)
117+
except Exception:
118+
continue
119+
if not isinstance(response, full_node_protocol.RespondTransaction):
120+
continue
121+
entry = TransactionQueueEntry(
122+
transaction=response.transaction,
123+
transaction_bytes=bytes(response.transaction),
124+
spend_name=response.transaction.name(),
125+
peer=random_peer,
126+
test=False,
127+
peers_with_tx=peers_with_tx,
128+
)
129+
# Try to put the transaction in this peer's queue, but if it's full
130+
# then try another peer's queue. `TransactionQueue` has an internal
131+
# queue for each peer.
132+
for pid in [random_peer.peer_node_id, *peers_with_tx]:
133+
try:
134+
full_node.transaction_queue.put(entry, pid)
135+
break
136+
except TransactionQueueFull:
137+
continue
138+
break
119139
except asyncio.CancelledError:
120140
pass
121141
finally:

0 commit comments

Comments
 (0)