Skip to content

Commit 1e7ba5c

Browse files
committed
use monotonic clock in rate limiter
1 parent 52cd108 commit 1e7ba5c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

chia-blockchain-gui

Submodule chia-blockchain-gui updated 456 files

chia/server/rate_limits.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import dataclasses
44
import logging
5-
import time
65
from collections import Counter
6+
from time import monotonic
77
from typing import Optional
88

99
from chia.protocols.outbound_message import Message
@@ -35,7 +35,7 @@ def __init__(self, incoming: bool, reset_seconds: int = 60, percentage_of_limit:
3535
"""
3636
self.incoming = incoming
3737
self.reset_seconds = reset_seconds
38-
self.current_minute = int(time.time() // reset_seconds)
38+
self.current_minute = int(monotonic() // reset_seconds)
3939
self.message_counts = Counter()
4040
self.message_cumulative_sizes = Counter()
4141
self.percentage_of_limit = percentage_of_limit
@@ -51,7 +51,7 @@ def process_msg_and_check(
5151
hit and the message is good to be sent or received.
5252
"""
5353

54-
current_minute = int(time.time() // self.reset_seconds)
54+
current_minute = int(monotonic() // self.reset_seconds)
5555
if current_minute != self.current_minute:
5656
self.current_minute = current_minute
5757
self.message_counts = Counter()

0 commit comments

Comments
 (0)