Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt test_create_bundle_from_mempool_on_max_cost #17479

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion chia/full_node/mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def __init__(
multiprocessing_context: Optional[BaseContext] = None,
*,
single_threaded: bool = False,
max_tx_clvm_cost: Optional[uint64] = None,
):
self.constants: ConsensusConstants = consensus_constants

Expand All @@ -194,7 +195,9 @@ def __init__(

BLOCK_SIZE_LIMIT_FACTOR = 0.6
self.max_block_clvm_cost = uint64(self.constants.MAX_BLOCK_COST_CLVM * BLOCK_SIZE_LIMIT_FACTOR)
self.max_tx_clvm_cost = uint64(self.constants.MAX_BLOCK_COST_CLVM // 2)
self.max_tx_clvm_cost = (
max_tx_clvm_cost if max_tx_clvm_cost is not None else uint64(self.constants.MAX_BLOCK_COST_CLVM // 2)
)
self.mempool_max_total_cost = int(self.constants.MAX_BLOCK_COST_CLVM * self.constants.MEMPOOL_BLOCK_BUFFER)

# Transactions that were unable to enter mempool, used for retry. (they were invalid)
Expand Down
27 changes: 19 additions & 8 deletions tests/core/mempool/test_mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,21 @@ async def instantiate_mempool_manager(
block_height: uint32 = TEST_HEIGHT,
block_timestamp: uint64 = TEST_TIMESTAMP,
constants: ConsensusConstants = DEFAULT_CONSTANTS,
max_tx_clvm_cost: Optional[uint64] = None,
) -> MempoolManager:
mempool_manager = MempoolManager(get_coin_records, constants)
mempool_manager = MempoolManager(get_coin_records, constants, max_tx_clvm_cost=max_tx_clvm_cost)
test_block_record = create_test_block_record(height=block_height, timestamp=block_timestamp)
await mempool_manager.new_peak(test_block_record, None)
invariant_check_mempool(mempool_manager.mempool)
return mempool_manager


async def setup_mempool_with_coins(
*, coin_amounts: List[int], max_block_clvm_cost: Optional[int] = None
*,
coin_amounts: List[int],
max_block_clvm_cost: Optional[int] = None,
max_tx_clvm_cost: Optional[uint64] = None,
mempool_block_buffer: Optional[int] = None,
) -> Tuple[MempoolManager, List[Coin]]:
coins = []
test_coin_records = {}
Expand All @@ -159,11 +164,14 @@ async def get_coin_records(coin_ids: Collection[bytes32]) -> List[CoinRecord]:
ret.append(r)
return ret

constants = DEFAULT_CONSTANTS
if max_block_clvm_cost is not None:
constants = dataclasses.replace(DEFAULT_CONSTANTS, MAX_BLOCK_COST_CLVM=max_block_clvm_cost)
else:
constants = DEFAULT_CONSTANTS
mempool_manager = await instantiate_mempool_manager(get_coin_records, constants=constants)
constants = dataclasses.replace(constants, MAX_BLOCK_COST_CLVM=max_block_clvm_cost)
if mempool_block_buffer is not None:
constants = dataclasses.replace(constants, MEMPOOL_BLOCK_BUFFER=mempool_block_buffer)
mempool_manager = await instantiate_mempool_manager(
get_coin_records, constants=constants, max_tx_clvm_cost=max_tx_clvm_cost
)
return (mempool_manager, coins)


Expand Down Expand Up @@ -1022,15 +1030,18 @@ async def get_unspent_lineage_info_for_puzzle_hash(_: bytes32) -> Optional[Unspe
async def make_and_send_big_cost_sb(coin: Coin) -> None:
conditions = []
g1 = G1Element()
for _ in range(120):
for _ in range(144):
conditions.append([ConditionOpcode.AGG_SIG_UNSAFE, g1, IDENTITY_PUZZLE_HASH])
conditions.append([ConditionOpcode.CREATE_COIN, IDENTITY_PUZZLE_HASH, coin.amount - 10_000_000])
# Create a spend bundle with a big enough cost that gets it close to the limit
_, _, res = await generate_and_add_spendbundle(mempool_manager, conditions, coin)
assert res[1] == MempoolInclusionStatus.SUCCESS

mempool_manager, coins = await setup_mempool_with_coins(
coin_amounts=list(range(1_000_000_000, 1_000_000_030)), max_block_clvm_cost=550_000_000
coin_amounts=list(range(1_000_000_000, 1_000_000_030)),
max_block_clvm_cost=550_000_000,
max_tx_clvm_cost=uint64(550_000_000),
mempool_block_buffer=20,
)
# Create the spend bundles with a big enough cost that they get close to the limit
for i in range(num_skipped_items):
Expand Down
Loading