diff --git a/beacon_chain/sync/sync_protocol.nim b/beacon_chain/sync/sync_protocol.nim index f9693f7bc..77ae5c2e7 100644 --- a/beacon_chain/sync/sync_protocol.nim +++ b/beacon_chain/sync/sync_protocol.nim @@ -479,26 +479,28 @@ p2pProtocol BeaconSync(version = 1, for i in startIndex..endIndex: for j in 0..= dag.cfg.BELLATRIX_FORK_EPOCH and - not dag.head.executionValid: - continue + if ColumnIndex(j) in reqColumns: + if dag.db.getDataColumnSidecarSZ(blockIds[i].root, ColumnIndex(j), bytes): + if blockIds[i].slot.epoch >= dag.cfg.BELLATRIX_FORK_EPOCH and + not dag.head.executionValid: + continue + let uncompressedLen = uncompressedLenFramed(bytes).valueOr: + warn "Cannot read data column sidecar size, database, corrupt", + bytes = bytes.len(), blck = shortLog(blockIds[i]) + continue + peer.awaitQuota(dataColumnResponseCost, "data_column_sidecars_by_range/1") + peer.network.awaitQuota(dataColumnResponseCost, "data_column_sidecars_by_range/1") + await response.writeBytesSZ( + uncompressedLen, bytes, + peer.network.forkDigestAtEpoch(blockIds[i].slot.epoch).data) + inc found + var cols: seq[ColumnIndex] + cols.add(j) + debug "Responded to DataColumnSidecar range request", + peer, blck = shortLog(blockIds[i]), columns = cols + else: + break - let uncompressedLen = uncompressedLenFramed(bytes).valueOr: - warn "Cannot read data column sidecar size, database, corrupt", - bytes = bytes.len(), blck = shortLog(blockIds[i]) - continue - - peer.awaitQuota(dataColumnResponseCost, "data_column_sidecars_by_range/1") - peer.network.awaitQuota(dataColumnResponseCost, "data_column_sidecars_by_range/1") - - await response.writeBytesSZ( - uncompressedLen, bytes, - peer.network.forkDigestAtEpoch(blockIds[i].slot.epoch).data) - inc found - - debug "Responded to DataColumnSidecar range request", - peer, blck = shortLog(blockIds[i]) else: break