mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 00:24:37 +03:00
Improved mempool validation and test (#8652)
This commit is contained in:
parent
9179353dda
commit
7fdd0b2fd7
@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import dataclasses
|
||||
import time
|
||||
import traceback
|
||||
from secrets import token_bytes
|
||||
from typing import Callable, Dict, List, Optional, Tuple, Set
|
||||
|
||||
@ -724,6 +725,7 @@ class FullNodeAPI:
|
||||
curr_l_tb.header_hash
|
||||
)
|
||||
except Exception as e:
|
||||
self.log.error(f"Traceback: {traceback.format_exc()}")
|
||||
self.full_node.log.error(f"Error making spend bundle {e} peak: {peak}")
|
||||
mempool_bundle = None
|
||||
if mempool_bundle is not None:
|
||||
|
@ -255,6 +255,8 @@ class MempoolManager:
|
||||
return None, MempoolInclusionStatus.FAILED, Err(npc_result.error)
|
||||
# build removal list
|
||||
removal_names: List[bytes32] = [npc.coin_name for npc in npc_list]
|
||||
if set(removal_names) != set([s.name() for s in new_spend.removals()]):
|
||||
return None, MempoolInclusionStatus.FAILED, Err.INVALID_SPEND_BUNDLE
|
||||
|
||||
additions = additions_for_npc(npc_list)
|
||||
|
||||
|
@ -152,6 +152,7 @@ class Err(Enum):
|
||||
INVALID_FEE_TOO_CLOSE_TO_ZERO = 123
|
||||
COIN_AMOUNT_NEGATIVE = 124
|
||||
INTERNAL_PROTOCOL_ERROR = 125
|
||||
INVALID_SPEND_BUNDLE = 126
|
||||
|
||||
|
||||
class ValidationError(Exception):
|
||||
|
@ -14,6 +14,7 @@ from chia.protocols import full_node_protocol
|
||||
from chia.simulator.simulator_protocol import FarmNewBlockProtocol
|
||||
from chia.types.announcement import Announcement
|
||||
from chia.types.blockchain_format.coin import Coin
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.types.coin_spend import CoinSpend
|
||||
from chia.types.condition_opcodes import ConditionOpcode
|
||||
from chia.types.condition_with_args import ConditionWithArgs
|
||||
@ -30,6 +31,7 @@ from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions
|
||||
from chia.full_node.pending_tx_cache import PendingTxCache
|
||||
from blspy import G2Element
|
||||
|
||||
from chia.util.recursive_replace import recursive_replace
|
||||
from tests.connection_utils import connect_and_get_peer
|
||||
from tests.core.node_height import node_height_at_least
|
||||
from tests.setup_nodes import bt, setup_simulators_and_wallets
|
||||
@ -2179,3 +2181,26 @@ class TestMaliciousGenerators:
|
||||
assert len(npc_result.npc_list[0].conditions[0][1]) == 6094
|
||||
assert run_time < 1
|
||||
print(f"run time:{run_time}")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_invalid_coin_spend_coin(self, two_nodes):
|
||||
reward_ph = WALLET_A.get_new_puzzlehash()
|
||||
blocks = bt.get_consecutive_blocks(
|
||||
5,
|
||||
guarantee_transaction_block=True,
|
||||
farmer_reward_puzzle_hash=reward_ph,
|
||||
pool_reward_puzzle_hash=reward_ph,
|
||||
)
|
||||
full_node_1, full_node_2, server_1, server_2 = two_nodes
|
||||
|
||||
for block in blocks:
|
||||
await full_node_1.full_node.respond_block(full_node_protocol.RespondBlock(block))
|
||||
|
||||
await time_out_assert(60, node_height_at_least, True, full_node_2, blocks[-1].height)
|
||||
|
||||
spend_bundle = generate_test_spend_bundle(list(blocks[-1].get_included_reward_coins())[0])
|
||||
coin_spend_0 = recursive_replace(spend_bundle.coin_spends[0], "coin.puzzle_hash", bytes32([1] * 32))
|
||||
new_bundle = recursive_replace(spend_bundle, "coin_spends", [coin_spend_0] + spend_bundle.coin_spends[1:])
|
||||
assert spend_bundle is not None
|
||||
res = await full_node_1.full_node.respond_transaction(new_bundle, new_bundle.name())
|
||||
assert res == (MempoolInclusionStatus.FAILED, Err.INVALID_SPEND_BUNDLE)
|
||||
|
Loading…
Reference in New Issue
Block a user