Skip to content

Commit 27bfa7e

Browse files
authored
reject transactions from the mempool, that take too long to validate (#19611)
1 parent e53cb26 commit 27bfa7e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

chia/full_node/mempool_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ async def validate_spend_bundle(
588588
Optional[MempoolItem]: the item to add (to mempool or pending pool)
589589
list[bytes32]: conflicting mempool items to remove, if no Err
590590
"""
591-
start_time = time.time()
591+
start_time = time.monotonic()
592592
if self.peak is None:
593593
return Err.MEMPOOL_NOT_INITIALIZED, None, []
594594

@@ -778,14 +778,18 @@ async def validate_spend_bundle(
778778
if not can_replace(conflicts, removal_names, potential):
779779
return Err.MEMPOOL_CONFLICT, potential, []
780780

781-
duration = time.time() - start_time
781+
duration = time.monotonic() - start_time
782782

783783
log.log(
784784
logging.DEBUG if duration < 2 else logging.WARNING,
785785
f"add_spendbundle {spend_name} took {duration:0.2f} seconds. "
786786
f"Cost: {cost} ({round(100.0 * cost / self.constants.MAX_BLOCK_COST_CLVM, 3)}% of max block cost)",
787787
)
788788

789+
if duration > 2:
790+
log.warning("validating spend took too long, rejecting")
791+
return Err.INVALID_SPEND_BUNDLE, None, []
792+
789793
return None, potential, [item.name for item in conflicts]
790794

791795
def get_spendbundle(self, bundle_hash: bytes32) -> Optional[SpendBundle]:

0 commit comments

Comments
 (0)