Skip to content

Commit b8b8195

Browse files
feat: less agressive fast updates reporting
1 parent 55fbaa3 commit b8b8195

File tree

2 files changed

+46
-9
lines changed

2 files changed

+46
-9
lines changed

observer/observer.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,26 @@ def calculate_update_from_tx(config: Configuration, w: AsyncWeb3, tx: TxData):
151151
return signing_policy_address, address, signed_array
152152

153153

154+
async def get_block_production(w: AsyncWeb3) -> float:
155+
latest_block = await w.eth.get_block("latest")
156+
assert "timestamp" in latest_block
157+
assert "number" in latest_block
158+
to_compare = min(1_000_000, int(latest_block["number"]) - 1)
159+
comparison_block = await w.eth.get_block(int(latest_block["number"]) - to_compare)
160+
assert "timestamp" in comparison_block
161+
time_delta = latest_block["timestamp"] - comparison_block["timestamp"]
162+
block_production = time_delta / to_compare
163+
return block_production
164+
165+
166+
def calculate_maximum_exponent(block_production: float, config: Configuration) -> int:
167+
blocks_in_epoch = int(
168+
config.epoch.reward_epoch_factory.duration() / block_production
169+
)
170+
max_exponent = blocks_in_epoch // 100
171+
return max_exponent
172+
173+
154174
async def find_voter_registration_blocks(
155175
w: AsyncWeb3,
156176
current_block_id: int,
@@ -340,6 +360,9 @@ async def observer_loop(config: Configuration) -> None:
340360
)
341361
spb = SigningPolicy.builder().for_epoch(reward_epoch.next)
342362

363+
block_production = await get_block_production(w)
364+
maximum_exponent = calculate_maximum_exponent(block_production, config)
365+
343366
# print("Signing policy created for reward epoch", current_rid)
344367
# print("Reward Epoch object created", reward_epoch_info)
345368
# print("Current Reward Epoch status", reward_epoch_info.status(config))
@@ -666,13 +689,17 @@ async def observer_loop(config: Configuration) -> None:
666689
messages.extend(event_messages)
667690
entity = signing_policy.entity_mapper.by_identity_address[tia]
668691

669-
# perform all minimal condition checks here and reset node connections
692+
# perform all minimal condition checks here
670693
if int(time.time() - last_minimal_conditions_check) > 60:
671694
min_cond_messages: list[Message] = []
672695

673696
min_cond_messages.extend(
674697
minimal_conditions.calculate_ftso_block_latency_feeds(
675-
entity, signing_policy, fum.last_update_block, block
698+
maximum_exponent,
699+
entity,
700+
signing_policy,
701+
fum.last_update_block,
702+
block,
676703
)
677704
)
678705
min_cond_messages.extend(

observer/validation/minimal_conditions.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def calculate_ftso_anchor_feeds(
9292

9393
def calculate_ftso_block_latency_feeds(
9494
self,
95+
max_exponent: int,
9596
entity: Entity,
9697
sp: SigningPolicy,
9798
last_update: int,
@@ -108,22 +109,31 @@ def calculate_ftso_block_latency_feeds(
108109

109110
per_block = MinimalConditionsConfig.fast_updates_updates_per_block
110111
n_blocks = current_block - last_update
111-
probability_bips = int(
112-
10_000 * (1 - per_block * weight / total_weight) ** (n_blocks)
112+
if n_blocks >= max_exponent:
113+
n_blocks = max_exponent
114+
probability_ppb = int(
115+
1_000_000_000 * (1 - per_block * weight / total_weight) ** (n_blocks)
113116
)
114-
115-
if probability_bips > 100:
117+
if n_blocks < max_exponent:
118+
if probability_ppb <= 100:
119+
level = MessageLevel.CRITICAL
120+
messages.append(
121+
mb.build(
122+
level,
123+
f"didn't submit a fast update in {n_blocks} blocks",
124+
)
125+
)
116126
return messages
117127

118128
level = MessageLevel.WARNING
119-
if probability_bips <= 10:
129+
if probability_ppb <= 100:
120130
level = MessageLevel.CRITICAL
121131

122132
messages.append(
123133
mb.build(
124134
level,
125-
f"didn't submit fast update in {n_blocks} "
126-
f"(false positive probability: {probability_bips / 100:.2f})%",
135+
f"didn't submit a fast update in {n_blocks} blocks "
136+
f"(false positive probability: {probability_ppb / 10_000_000:.5f})%",
127137
)
128138
)
129139

0 commit comments

Comments
 (0)