Skip to content

Commit

Permalink
Adapt to fixing get_conditions_from_spendbundle's return value to inc…
Browse files Browse the repository at this point in the history
…lude the cost of the whole spend.
  • Loading branch information
AmineKhaldi committed Sep 4, 2024
1 parent c53d78b commit 3e35acc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions chia/_tests/core/full_node/test_full_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,8 +935,8 @@ async def test_new_transaction_and_mempool(self, wallet_nodes, self_hostname, se
# these numbers reflect the capacity of the mempool. In these
# tests MEMPOOL_BLOCK_BUFFER is 1. The other factors are COST_PER_BYTE
# and MAX_BLOCK_COST_CLVM
assert included_tx == 27
assert not_included_tx == 6
assert included_tx == 23
assert not_included_tx == 10
assert seen_bigger_transaction_has_high_fee

# Mempool is full
Expand Down
18 changes: 11 additions & 7 deletions chia/_tests/core/mempool/test_mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ async def test_duplicate_output() -> None:
async def test_block_cost_exceeds_max() -> None:
mempool_manager = await instantiate_mempool_manager(zero_calls_get_coin_records)
conditions = []
for i in range(3800):
for i in range(2400):
conditions.append([ConditionOpcode.CREATE_COIN, IDENTITY_PUZZLE_HASH, i])
sb = spend_bundle_from_conditions(conditions)
with pytest.raises(ValidationError, match="BLOCK_COST_EXCEEDS_MAX"):
Expand Down Expand Up @@ -581,7 +581,7 @@ async def test_same_sb_twice_with_eligible_coin() -> None:
sb = SpendBundle.aggregate([sb1, sb2])
sb_name = sb.name()
result = await add_spendbundle(mempool_manager, sb, sb_name)
expected_cost = uint64(6_600_088)
expected_cost = uint64(10_236_088)
assert result == (expected_cost, MempoolInclusionStatus.SUCCESS, None)
assert mempool_manager.get_spendbundle(sb_name) == sb
result = await add_spendbundle(mempool_manager, sb, sb_name)
Expand Down Expand Up @@ -614,7 +614,7 @@ async def test_sb_twice_with_eligible_coin_and_different_spends_order() -> None:
assert mempool_manager.get_spendbundle(sb_name) is None
assert mempool_manager.get_spendbundle(reordered_sb_name) is None
result = await add_spendbundle(mempool_manager, sb, sb_name)
expected_cost = uint64(7_800_132)
expected_cost = uint64(13_056_132)
assert result == (expected_cost, MempoolInclusionStatus.SUCCESS, None)
assert mempool_manager.get_spendbundle(sb_name) == sb
assert mempool_manager.get_spendbundle(reordered_sb_name) is None
Expand Down Expand Up @@ -1053,7 +1053,7 @@ async def make_and_send_big_cost_sb(coin: Coin) -> None:
g1 = sk.get_g1()
sig = AugSchemeMPL.sign(sk, IDENTITY_PUZZLE_HASH, g1)
aggsig = G2Element()
for _ in range(318):
for _ in range(169):
conditions.append([ConditionOpcode.AGG_SIG_UNSAFE, g1, IDENTITY_PUZZLE_HASH])
aggsig += sig
conditions.append([ConditionOpcode.CREATE_COIN, IDENTITY_PUZZLE_HASH, coin.amount - 10_000_000])
Expand Down Expand Up @@ -1942,7 +1942,9 @@ async def get_coin_records(coin_ids: Collection[bytes32]) -> List[CoinRecord]:
assert e.code == expected


TEST_FILL_RATE_ITEM_COST = 144_744_040
TEST_FILL_RATE_ITEM_COST = 144_720_020
QUOTE_BYTE_COST = 2 * DEFAULT_CONSTANTS.COST_PER_BYTE
QUOTE_EXECUTION_COST = 20


@pytest.mark.anyio
Expand All @@ -1956,10 +1958,12 @@ async def get_coin_records(coin_ids: Collection[bytes32]) -> List[CoinRecord]:
# because of the spend bundle aggregation that creates the block
# bundle, in addition to a small block compression effect that we
# can't completely avoid.
(TEST_FILL_RATE_ITEM_COST * 2, 2, TEST_FILL_RATE_ITEM_COST * 2 - 156_020),
(TEST_FILL_RATE_ITEM_COST * 2, 2, TEST_FILL_RATE_ITEM_COST * 2 - 107_980),
# Here we set the block cost limit to twice the test items' cost - 1,
# so we expect only one of the two test items to get included in the block.
(TEST_FILL_RATE_ITEM_COST * 2 - 1, 1, TEST_FILL_RATE_ITEM_COST),
# NOTE: The cost difference here is because get_conditions_from_spendbundle
# does not include the overhead to make a block (quote byte cost + quote runtime cost).
(TEST_FILL_RATE_ITEM_COST * 2 - 1, 1, TEST_FILL_RATE_ITEM_COST + QUOTE_BYTE_COST + QUOTE_EXECUTION_COST),
],
)
async def test_fill_rate_block_validation(
Expand Down
1 change: 1 addition & 0 deletions chia/clvm/spend_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ async def farm_block(
get_unspent_lineage_info_for_puzzle_hash=self.coin_store.get_unspent_lineage_info_for_puzzle_hash,
item_inclusion_filter=item_inclusion_filter,
)

if result is not None:
bundle, additions = result
generator_bundle = bundle
Expand Down
4 changes: 1 addition & 3 deletions chia/full_node/mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ async def pre_validate_spendbundle(
if ret.error is not None:
raise ValidationError(Err(ret.error), "pre_validate_spendbundle failed")
assert ret.conds is not None
# TODO: this cost padding is temporary, until we update the mempool's
# block creation logic to take the block overhead into account
return ret.conds.replace(cost=ret.conds.cost + 10000000)
return ret.conds.replace(cost=ret.conds.cost)

async def add_spend_bundle(
self,
Expand Down

0 comments on commit 3e35acc

Please sign in to comment.