Skip to content

Commit 0561869

Browse files
committed
Optimize peak post processing by using transaction IDs instead of NewPeakItem elements.
1 parent 8539ae8 commit 0561869

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

chia/full_node/full_node.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
from chia.full_node.hint_management import get_hints_and_subscription_coin_ids
5959
from chia.full_node.hint_store import HintStore
6060
from chia.full_node.mempool import MempoolRemoveInfo
61-
from chia.full_node.mempool_manager import MempoolManager, NewPeakItem
61+
from chia.full_node.mempool_manager import MempoolManager
6262
from chia.full_node.subscriptions import PeerSubscriptions, peers_for_spend_bundle
6363
from chia.full_node.sync_store import Peak, SyncStore
6464
from chia.full_node.tx_processing_queue import TransactionQueue, TransactionQueueEntry
@@ -99,7 +99,8 @@
9999
# This is the result of calling peak_post_processing, which is then fed into peak_post_processing_2
100100
@dataclasses.dataclass
101101
class PeakPostProcessingResult:
102-
mempool_peak_result: list[NewPeakItem] # The new items from calling MempoolManager.new_peak
102+
# The added transactions IDs from calling MempoolManager.new_peak
103+
mempool_peak_added_tx_ids: list[bytes32]
103104
mempool_removals: list[MempoolRemoveInfo] # The removed mempool items from calling MempoolManager.new_peak
104105
fns_peak_result: FullNodeStorePeakResult # The result of calling FullNodeStore.new_peak
105106
hints: list[tuple[bytes32, bytes]] # The hints added to the DB
@@ -321,7 +322,8 @@ async def manage(self) -> AsyncIterator[None]:
321322
)
322323
async with self.blockchain.priority_mutex.acquire(priority=BlockchainMutexPriority.high):
323324
pending_tx = await self.mempool_manager.new_peak(self.blockchain.get_tx_peak(), None)
324-
assert len(pending_tx.items) == 0 # no pending transactions when starting up
325+
# No pending transactions when starting up
326+
assert len(pending_tx.transaction_ids) == 0
325327

326328
full_peak: Optional[FullBlock] = await self.blockchain.get_full_peak()
327329
assert full_peak is not None
@@ -1939,7 +1941,7 @@ async def peak_post_processing(
19391941
mempool_new_peak_result = await self.mempool_manager.new_peak(self.blockchain.get_tx_peak(), spent_coins)
19401942

19411943
return PeakPostProcessingResult(
1942-
mempool_new_peak_result.items,
1944+
mempool_new_peak_result.transaction_ids,
19431945
mempool_new_peak_result.removals,
19441946
fns_peak_result,
19451947
hints_to_add,
@@ -1961,9 +1963,9 @@ async def peak_post_processing_2(
19611963
record = state_change_summary.peak
19621964
for signage_point in ppp_result.signage_points:
19631965
await self.signage_point_post_processing(*signage_point)
1964-
for new_peak_item in ppp_result.mempool_peak_result:
1965-
self.log.debug(f"Added transaction to mempool: {new_peak_item.transaction_id}")
1966-
mempool_item = self.mempool_manager.get_mempool_item(new_peak_item.transaction_id)
1966+
for transaction_id in ppp_result.mempool_peak_added_tx_ids:
1967+
self.log.debug(f"Added transaction to mempool: {transaction_id}")
1968+
mempool_item = self.mempool_manager.get_mempool_item(transaction_id)
19671969
assert mempool_item is not None
19681970
await self.broadcast_added_tx(mempool_item)
19691971

chia/full_node/mempool_manager.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,10 @@ class SpendBundleAddInfo:
134134

135135
@dataclass
136136
class NewPeakInfo:
137-
items: list[NewPeakItem]
137+
transaction_ids: list[bytes32]
138138
removals: list[MempoolRemoveInfo]
139139

140140

141-
@dataclass
142-
class NewPeakItem:
143-
transaction_id: bytes32
144-
spend_bundle: SpendBundle
145-
conds: SpendBundleConditions
146-
147-
148141
# For block overhead cost calculation
149142
QUOTE_BYTES = 2
150143
QUOTE_EXECUTION_COST = 20
@@ -991,7 +984,7 @@ async def local_get_coin_records(names: Collection[bytes32]) -> list[CoinRecord]
991984
lineage_cache.get_unspent_lineage_info,
992985
)
993986
if info.status == MempoolInclusionStatus.SUCCESS:
994-
txs_added.append(NewPeakItem(item.spend_bundle_name, item.spend_bundle, item.conds))
987+
txs_added.append(item.spend_bundle_name)
995988
mempool_item_removals.extend(info.removals)
996989
log.info(
997990
f"Size of mempool: {self.mempool.size()} spends, "

0 commit comments

Comments
 (0)