Skip to content

Commit

Permalink
CHIA-1362 Deduct block overhead from the mempool's maximum block clvm…
Browse files Browse the repository at this point in the history
… cost limit (#18574)

Deduct block overhead from the mempool's maximum block clvm cost limit.
  • Loading branch information
AmineKhaldi committed Sep 23, 2024
1 parent 1e8c999 commit 19dd1e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 6 additions & 4 deletions chia/_tests/core/mempool/test_mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from chia.full_node.mempool_check_conditions import get_name_puzzle_conditions, mempool_check_time_locks
from chia.full_node.mempool_manager import (
MEMPOOL_MIN_FEE_INCREASE,
QUOTE_BYTES,
QUOTE_EXECUTION_COST,
MempoolManager,
TimelockConditions,
can_replace,
Expand Down Expand Up @@ -1943,8 +1945,8 @@ async def get_coin_records(coin_ids: Collection[bytes32]) -> List[CoinRecord]:


TEST_FILL_RATE_ITEM_COST = 144_720_020
QUOTE_BYTE_COST = 2 * DEFAULT_CONSTANTS.COST_PER_BYTE
QUOTE_EXECUTION_COST = 20
TEST_COST_PER_BYTE = 12_000
TEST_BLOCK_OVERHEAD = QUOTE_BYTES * TEST_COST_PER_BYTE + QUOTE_EXECUTION_COST


@pytest.mark.anyio
Expand All @@ -1962,8 +1964,8 @@ async def get_coin_records(coin_ids: Collection[bytes32]) -> List[CoinRecord]:
# 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.
# 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),
# does not include the block overhead.
(TEST_FILL_RATE_ITEM_COST * 2 - 1, 1, TEST_FILL_RATE_ITEM_COST + TEST_BLOCK_OVERHEAD),
],
)
async def test_fill_rate_block_validation(
Expand Down
11 changes: 10 additions & 1 deletion chia/full_node/mempool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ class NewPeakItem:
conds: SpendBundleConditions


# For block overhead cost calculation
QUOTE_BYTES = 2
QUOTE_EXECUTION_COST = 20


class MempoolManager:
pool: Executor
constants: ConsensusConstants
Expand Down Expand Up @@ -158,7 +163,11 @@ def __init__(
self.nonzero_fee_minimum_fpc = 5

BLOCK_SIZE_LIMIT_FACTOR = 0.7
self.max_block_clvm_cost = uint64(self.constants.MAX_BLOCK_COST_CLVM * BLOCK_SIZE_LIMIT_FACTOR)
# We need to deduct the block overhead, which consists of the wrapping
# quote opcode's bytes cost as well as its execution cost.
BLOCK_OVERHEAD = QUOTE_BYTES * self.constants.COST_PER_BYTE + QUOTE_EXECUTION_COST

self.max_block_clvm_cost = uint64(self.constants.MAX_BLOCK_COST_CLVM * BLOCK_SIZE_LIMIT_FACTOR - BLOCK_OVERHEAD)
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)
)
Expand Down

0 comments on commit 19dd1e0

Please sign in to comment.