Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: response checking from RequestManager for blobs #6755

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions beacon_chain/spec/helpers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# Uncategorized helper functions from the spec

import
std/sequtils,
agnxsh marked this conversation as resolved.
Show resolved Hide resolved
# Status libraries
stew/[byteutils, endians2, objects],
nimcrypto/sha2,
Expand Down
33 changes: 23 additions & 10 deletions beacon_chain/sync/request_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import
"."/sync_protocol, "."/sync_manager,
../gossip_processing/block_processor

from std/algorithm import binarySearch
from ../beacon_clock import GetBeaconTimeFn
export block_quarantine, sync_manager

Expand Down Expand Up @@ -102,21 +103,33 @@ proc checkResponse(roots: openArray[Eth2Digest],
checks.del(res)
true

func cmpSidecarIdentifier(x: BlobIdentifier | DataColumnIdentifier,
y: ref BlobSidecar | ref DataColumnSidecar): int =
cmp(x.index, y.index)

proc checkResponse(idList: seq[BlobIdentifier],
blobs: openArray[ref BlobSidecar]): bool =
if len(blobs) > len(idList):
if blobs.len > idList.len:
return false
for blob in blobs:
let block_root = hash_tree_root(blob.signed_block_header.message)
var found = false
for id in idList:
if id.block_root == block_root and id.index == blob.index:
found = true
break
if not found:
var i = 0
while i < blobs.len:
let
block_root = hash_tree_root(blobs[i].signed_block_header.message)
id = idList[i]

# Check if the blob response is a subset
if binarySearch(idList, blobs[i], cmpSidecarIdentifier) == -1:
i = if i != blobs.len - 1: i + 2 else: i + 1
agnxsh marked this conversation as resolved.
Show resolved Hide resolved
continue

# Verify block_root and index match
if id.block_root != block_root or id.index != blobs[i].index:
return false
blob[].verify_blob_sidecar_inclusion_proof().isOkOr:

# Verify inclusion proof
blobs[i][].verify_blob_sidecar_inclusion_proof().isOkOr:
return false
inc i
true

proc requestBlocksByRoot(rman: RequestManager, items: seq[Eth2Digest]) {.async: (raises: [CancelledError]).} =
Expand Down
Loading