simplify the mempool filter to only pass in the spend_bundle name (#14665)

simplify the mempool filter to only pass in the spend_bundle name. That's the only thing we use
This commit is contained in:
Arvid Norberg 2023-02-27 19:57:32 +01:00 committed by GitHub
parent 3943b3ee8b
commit e195d268fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 12 deletions

View File

@ -219,7 +219,7 @@ class SpendSim:
async def farm_block(
self,
puzzle_hash: bytes32 = bytes32(b"0" * 32),
item_inclusion_filter: Optional[Callable[[MempoolManager, MempoolItem], bool]] = None,
item_inclusion_filter: Optional[Callable[[bytes32], bool]] = None,
) -> Tuple[List[Coin], List[Coin]]:
# Fees get calculated
fees = uint64(0)

View File

@ -170,7 +170,7 @@ class MempoolManager:
self.pool.shutdown(wait=True)
def process_mempool_items(
self, item_inclusion_filter: Callable[[MempoolManager, MempoolItem], bool]
self, item_inclusion_filter: Callable[[bytes32], bool]
) -> Tuple[List[SpendBundle], uint64, List[Coin], List[Coin]]:
cost_sum = 0 # Checks that total cost does not exceed block maximum
fee_sum = 0 # Checks that total fees don't exceed 64 bits
@ -178,7 +178,7 @@ class MempoolManager:
removals: List[Coin] = []
additions: List[Coin] = []
for item in self.mempool.spends_by_feerate():
if not item_inclusion_filter(self, item):
if not item_inclusion_filter(item.name):
continue
log.info(f"Cumulative cost: {cost_sum}, fee per cost: {item.fee / item.cost}")
if item.cost + cost_sum > self.max_block_clvm_cost or item.fee + fee_sum > self.constants.MAX_COIN_AMOUNT:
@ -193,7 +193,7 @@ class MempoolManager:
def create_bundle_from_mempool(
self,
last_tb_header_hash: bytes32,
item_inclusion_filter: Optional[Callable[[MempoolManager, MempoolItem], bool]] = None,
item_inclusion_filter: Optional[Callable[[bytes32], bool]] = None,
) -> Optional[Tuple[SpendBundle, List[Coin], List[Coin]]]:
"""
Returns aggregated spendbundle that can be used for creating new block,
@ -204,7 +204,7 @@ class MempoolManager:
if item_inclusion_filter is None:
def always(mm: MempoolManager, mi: MempoolItem) -> bool:
def always(bundle_name: bytes32) -> bool:
return True
item_inclusion_filter = always

View File

@ -11,11 +11,9 @@ from chia.clvm.spend_sim import SimClient, SpendSim, sim_and_client
from chia.consensus.constants import ConsensusConstants
from chia.consensus.default_constants import DEFAULT_CONSTANTS
from chia.full_node.bitcoin_fee_estimator import BitcoinFeeEstimator
from chia.full_node.mempool_manager import MempoolManager
from chia.types.blockchain_format.program import Program
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_spend import CoinSpend
from chia.types.mempool_item import MempoolItem
from chia.types.spend_bundle import SpendBundle
log = logging.getLogger(__name__)
@ -32,7 +30,7 @@ NEW_DEFAULT_CONSTANTS: ConsensusConstants = DEFAULT_CONSTANTS.replace(
async def farm(
sim: SpendSim,
puzzle_hash: bytes32,
item_inclusion_filter: Optional[Callable[[MempoolManager, MempoolItem], bool]] = None,
item_inclusion_filter: Optional[Callable[[bytes32], bool]] = None,
) -> Tuple[List[Coin], List[Coin], List[Coin]]:
additions, removals = await sim.farm_block(puzzle_hash) # , item_inclusion_filter)
height = sim.get_height()
@ -91,10 +89,10 @@ async def test_mempool_inclusion_filter_basic() -> None:
mempool_item = sim.mempool_manager.get_mempool_item(spend_bundle.name())
assert mempool_item
def include_none(mm: MempoolManager, mi: MempoolItem) -> bool:
def include_none(bundle_name: bytes32) -> bool:
return False
def include_all(mm: MempoolManager, mi: MempoolItem) -> bool:
def include_all(bundle_name: bytes32) -> bool:
return True
additions, removals = await sim.farm_block(the_puzzle_hash, item_inclusion_filter=include_none)
@ -123,9 +121,9 @@ async def test_mempoolitem_height_added(db_version: int) -> None:
assert mempool_item
heights = {sim.get_height(): mempool_item.height_added_to_mempool}
def ignore_spend(mm: MempoolManager, mi: MempoolItem) -> bool:
def ignore_spend(bundle_name: bytes32) -> bool:
assert mempool_item
return mi.name != mempool_item.name
return bundle_name != mempool_item.name
additions, removals = await sim.farm_block(the_puzzle_hash, item_inclusion_filter=ignore_spend)
removal_ids = [c.name() for c in removals]