File tree 2 files changed +12
-8
lines changed
2 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,9 @@ def __init__(
130
130
self ._task .clock = self .__CLOCK
131
131
self ._task .interval = self ._IDLE_INTERVAL
132
132
133
+ # busy interval
134
+ self ._busy_interval = None
135
+
133
136
super ().__init__ ()
134
137
135
138
self .add_listener (_Machine .LogObserver ())
@@ -173,12 +176,15 @@ def _enter_idle_mode(self):
173
176
@_transition_to_busy .before
174
177
def _enter_busy_mode (self ):
175
178
"""About to enter busy work mode (speed up interval)"""
176
- average_block_time = _get_average_blocktime (
177
- w3 = self .w3 , sample_size = self ._BLOCK_SAMPLE_SIZE
178
- )
179
- self ._task .interval = max (
180
- round (average_block_time * self ._BLOCK_INTERVAL ), self ._MIN_INTERVAL
181
- )
179
+ if self ._busy_interval is None :
180
+ average_block_time = _get_average_blocktime (
181
+ w3 = self .w3 , sample_size = self ._BLOCK_SAMPLE_SIZE
182
+ )
183
+ self ._busy_interval = max (
184
+ round (average_block_time * self ._BLOCK_INTERVAL ), self ._MIN_INTERVAL
185
+ )
186
+
187
+ self ._task .interval = self ._busy_interval
182
188
self .log .info (f"[working] cycle interval is now { self ._task .interval } seconds" )
183
189
184
190
@_BUSY .enter
Original file line number Diff line number Diff line change 1
1
import contextlib
2
2
from typing import Callable , Optional
3
3
4
- from cytoolz import memoize
5
4
from eth_utils import ValidationError
6
5
from twisted .internet import reactor
7
6
from web3 import Web3
18
17
from atxm .tx import AsyncTx , PendingTx , TxHash
19
18
20
19
21
- @memoize
22
20
def _get_average_blocktime (w3 : Web3 , sample_size : int ) -> float :
23
21
"""Returns the average block time in seconds."""
24
22
latest_block = w3 .eth .get_block ("latest" )
You can’t perform that action at this time.
0 commit comments