@@ -990,9 +990,6 @@ async def test_new_transaction_and_mempool(
990990 await full_node_1 .new_transaction (new_transaction , fake_peer )
991991 await time_out_assert (10 , new_transaction_requested , True , incoming_queue , new_transaction )
992992
993- respond_transaction_2 = fnp .RespondTransaction (spend_bundle )
994- await full_node_1 .respond_transaction (respond_transaction_2 , peer )
995-
996993 blocks = bt .get_consecutive_blocks (
997994 1 ,
998995 block_list_input = blocks ,
@@ -1039,9 +1036,8 @@ async def test_new_transaction_and_mempool(
10391036 ]
10401037 spend_bundle = WalletSpendBundle .aggregate (spend_bundles )
10411038 assert estimate_fees (spend_bundle ) == fee
1042- respond_transaction = wallet_protocol .SendTransaction (spend_bundle )
10431039
1044- await full_node_1 .send_transaction (respond_transaction , fake_peer )
1040+ await full_node_1 .send_transaction (SendTransaction ( spend_bundle ) , fake_peer )
10451041
10461042 request = fnp .RequestTransaction (spend_bundle .get_hash ())
10471043 req = await full_node_1 .request_transaction (request )
@@ -1168,9 +1164,8 @@ async def test_request_respond_transaction(
11681164 coin = find_reward_coin (blocks [- 1 ], wallet_ph )
11691165 spend_bundle = wallet_a .generate_signed_transaction (uint64 (100 ), receiver_puzzlehash , coin )
11701166 assert spend_bundle is not None
1171- respond_transaction = fnp .RespondTransaction (spend_bundle )
1172- res = await full_node_1 .respond_transaction (respond_transaction , peer )
1173- assert res is None
1167+ res = await full_node_1 .send_transaction (SendTransaction (spend_bundle ), peer )
1168+ assert res is not None
11741169
11751170 # Check broadcast
11761171 await time_out_assert (10 , time_out_messages (incoming_queue , "new_transaction" ))
@@ -1182,7 +1177,7 @@ async def test_request_respond_transaction(
11821177
11831178
11841179@pytest .mark .anyio
1185- async def test_respond_transaction_fail (
1180+ async def test_send_transaction_fail (
11861181 wallet_nodes : tuple [
11871182 FullNodeSimulator , FullNodeSimulator , ChiaServer , ChiaServer , WalletTool , WalletTool , BlockTools
11881183 ],
@@ -1223,9 +1218,11 @@ async def test_respond_transaction_fail(
12231218 spend_bundle = wallet_a .generate_signed_transaction (uint64 (100_000_000_000_000 ), receiver_puzzlehash , coin )
12241219
12251220 assert spend_bundle is not None
1226- respond_transaction = fnp .RespondTransaction (spend_bundle )
1227- msg = await full_node_1 .respond_transaction (respond_transaction , peer )
1228- assert msg is None
1221+ response_msg = await full_node_1 .send_transaction (SendTransaction (spend_bundle ), peer )
1222+ assert response_msg is not None
1223+ assert TransactionAck .from_bytes (response_msg .data ) == TransactionAck (
1224+ txid = spend_bundle .name (), status = uint8 (MempoolInclusionStatus .FAILED ), error = "MINTING_COIN"
1225+ )
12291226
12301227 await asyncio .sleep (1 )
12311228 assert incoming_queue .qsize () == 0
@@ -3778,3 +3775,40 @@ async def test_register_for_coin_updates(
37783775 assert {cs .coin .name () for cs in response_data .coin_states } == set (first_coin )
37793776 for coin_id in remaining_coins :
37803777 assert coin_id not in response_data .coin_ids
3778+
3779+
3780+ @pytest .mark .anyio
3781+ @pytest .mark .limit_consensus_modes (allowed = [ConsensusMode .HARD_FORK_2_0 ], reason = "irrelevant" )
3782+ async def test_respond_transaction (
3783+ one_node_one_block : tuple [FullNodeSimulator , ChiaServer , BlockTools ], self_hostname : str
3784+ ) -> None :
3785+ _ , server , _ = one_node_one_block
3786+ sb = SpendBundle ([], G2Element ())
3787+ msg = make_msg (ProtocolMessageTypes .respond_transaction , bytes (fnp .RespondTransaction (sb )))
3788+ # A peer with no allowance should get banned
3789+ wsc , peer_id = await add_dummy_connection_wsc (server , self_hostname , 42 )
3790+ await time_out_assert (5 , lambda : peer_id in server .all_connections )
3791+ conn = server .all_connections [peer_id ]
3792+ conn .peer_info = PeerInfo ("1.3.3.7" , conn .peer_info .port )
3793+ assert conn .respond_transaction_allowance == 0
3794+ await wsc .send_message (msg )
3795+ await time_out_assert (5 , lambda : wsc .closed )
3796+ await time_out_assert (5 , lambda : "1.3.3.7" in server .banned_peers )
3797+ # A peer with allowance x can send x messages without being banned
3798+ wsc2 , peer_id2 = await add_dummy_connection_wsc (server , self_hostname , 42 )
3799+ await time_out_assert (5 , lambda : peer_id2 in server .all_connections )
3800+ conn2 = server .all_connections [peer_id2 ]
3801+ conn2 .peer_info = PeerInfo ("1.2.3.4" , conn2 .peer_info .port )
3802+ conn2 .respond_transaction_allowance = 2
3803+ await wsc2 .send_message (msg )
3804+ await asyncio .sleep (1 )
3805+ assert wsc2 .closed is False
3806+ assert "1.2.3.4" not in server .banned_peers
3807+ await wsc2 .send_message (msg )
3808+ await asyncio .sleep (1 )
3809+ assert wsc2 .closed is False
3810+ assert "1.2.3.4" not in server .banned_peers
3811+ # Now the x+1 message gets it banned
3812+ await wsc2 .send_message (msg )
3813+ await time_out_assert (5 , lambda : wsc2 .closed )
3814+ await time_out_assert (5 , lambda : "1.2.3.4" in server .banned_peers )
0 commit comments