from diskjumble.slab
where disk_id = %(disk_id)s
),
- joined as (
+ with_hashes as (
select
entity_id, entity.length, entity_blocks,
slab_plus.disk_blocks, crypt_key,
hashes,
+ elh.block_range as elh_range,
entity_blocks * elh.block_range as check_erange
from
public.entityv2_leaf_hashes elh
left outer join public.entity using (entity_id)
),
filtered as (
- select * from joined where not isempty(check_erange)
+ select *, generate_series(lower(check_erange), upper(check_erange) - 1) as piece_num
+ from (select * from with_hashes where not isempty(check_erange))
),
exploded as (
select
- entity_id,
- length,
- generate_series(lower(check_erange), upper(check_erange) - 1) as piece_num,
- (
- generate_series(lower(check_erange), upper(check_erange) - 1)
- - lower(entity_blocks) + lower(disk_blocks)
- ) as block,
+ entity_id, length, piece_num,
+ piece_num - lower(entity_blocks) + lower(disk_blocks) as block,
substring(
hashes,
- generate_series(lower(check_erange), upper(check_erange) - 1)::integer * 32 + 1,
+ (piece_num - lower(elh_range))::integer * 32 + 1,
32
) as hash,
crypt_key
else:
hasher = hashlib.sha256()
entity_off = run.piece_num * BLOCK_SIZE
+ assert len(run.hash) == hasher.digest_size, "incorrect validation hash length"
try:
for range_ in run.block_ranges: