Skip to content

Commit 9935848

Browse files
committed
Probabalistically check pow during skeleton sync
1 parent 889cac9 commit 9935848

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

trinity/sync/common/headers.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ async def _fetch_full_skeleton(self) -> None:
158158
pairs = tuple(zip(parents, children))
159159
try:
160160
validate_pair_coros = [
161-
self._chain.coro_validate_chain(parent, (child, ))
161+
self.wait(self._chain.coro_validate_chain(parent, (child, )))
162162
for parent, child in pairs
163163
]
164164
await asyncio.gather(*validate_pair_coros, loop=self.get_event_loop())
@@ -208,7 +208,11 @@ async def _get_final_headers(self, peer: TChainPeer, previous_tail_header: Block
208208
if len(final_headers) == 0:
209209
break
210210

211-
await self._chain.coro_validate_chain(previous_tail_header, final_headers)
211+
await self.wait(self._chain.coro_validate_chain(
212+
previous_tail_header,
213+
final_headers,
214+
SEAL_CHECK_RANDOM_SAMPLE_RATE,
215+
))
212216
await self.wait(self._fetched_headers.put(final_headers))
213217
previous_tail_header = final_headers[-1]
214218

@@ -292,7 +296,11 @@ async def _find_launch_headers(self, peer: TChainPeer) -> Tuple[BlockHeader, ...
292296
) from exc
293297

294298
# validate new headers against the parent in the database
295-
await self.wait(self._chain.coro_validate_chain(launch_parent, new_headers))
299+
await self.wait(self._chain.coro_validate_chain(
300+
launch_parent,
301+
new_headers,
302+
SEAL_CHECK_RANDOM_SAMPLE_RATE,
303+
))
296304
return new_headers
297305

298306
async def _fill_in_gap(
@@ -344,7 +352,11 @@ async def _fill_in_gap(
344352
# validate the filled headers
345353
filled_gap_children = tuple(concatv(gap_headers, pairs[gap_index + 1]))
346354
try:
347-
await self._chain.coro_validate_chain(gap_parent, filled_gap_children)
355+
await self.wait(self._chain.coro_validate_chain(
356+
gap_parent,
357+
filled_gap_children,
358+
SEAL_CHECK_RANDOM_SAMPLE_RATE,
359+
))
348360
except ValidationError:
349361
self.logger.warning(
350362
"%s returned an invalid gap for index %s, with pairs %s, filler %s",
@@ -651,11 +663,11 @@ async def _fetch_segment(
651663
return tuple()
652664
else:
653665
try:
654-
await self._chain.coro_validate_chain(
666+
await self.wait(self._chain.coro_validate_chain(
655667
parent_header,
656668
headers,
657669
SEAL_CHECK_RANDOM_SAMPLE_RATE,
658-
)
670+
))
659671
except ValidationError as e:
660672
self.logger.warning("Received invalid headers from %s, disconnecting: %s", peer, e)
661673
await peer.disconnect(DisconnectReason.subprotocol_error)
@@ -821,7 +833,11 @@ async def _full_skeleton_sync(self, skeleton_syncer: SkeletonSyncer[TChainPeer])
821833
raise ValidationError(f"Header skeleton gap of {gap_length} > {MAX_HEADERS_FETCH}")
822834
elif gap_length == 0:
823835
# no need to fill in when there is no gap, just verify against previous header
824-
await self._chain.coro_validate_chain(previous_segment[-1], segment)
836+
await self.wait(self._chain.coro_validate_chain(
837+
previous_segment[-1],
838+
segment,
839+
SEAL_CHECK_RANDOM_SAMPLE_RATE,
840+
))
825841
elif gap_length < 0:
826842
raise ValidationError(
827843
f"Invalid headers: {gap_length} gap from {previous_segment} to {segment}"

0 commit comments

Comments
 (0)