Skip to content

Commit

Permalink
fixup! feat: Introduce tool to verify a storage module
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesPiechota committed Nov 7, 2024
1 parent 452f854 commit 811b9c5
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions apps/arweave/src/ar_verify_chunks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ verify_chunks({End, _Start}, _Intervals, #state{cursor = Cursor} = State) when C
verify_chunks({IntervalEnd, IntervalStart}, Intervals, State) ->
#state{cursor = Cursor, store_id = StoreID} = State,
Cursor2 = max(IntervalStart, Cursor),
ChunkData = ar_data_sync:get_chunk_by_byte({chunks_index, StoreID}, Cursor2+1),
ChunkData = ar_data_sync:get_chunk_by_byte({chunks_index, StoreID}, Cursor2),
State2 = verify_chunk(ChunkData, Intervals, State#state{ cursor = Cursor2 }),
verify_chunks({IntervalEnd, IntervalStart}, Intervals, State2).

Expand All @@ -119,11 +119,12 @@ verify_chunk({ok, _Key, MetaData}, Intervals, State) ->
_TXRelativeOffset, ChunkSize} = MetaData,
{ChunkStorageInterval, _DataSyncInterval} = Intervals,

State2 = verify_chunk_storage(AbsoluteOffset, ChunkSize, ChunkStorageInterval, State),
PaddedOffset = ar_data_sync:get_chunk_padded_offset(AbsoluteOffset),
State2 = verify_chunk_storage(PaddedOffset, ChunkSize, ChunkStorageInterval, State),

State3 = verify_proof(MetaData, State2),

PaddedOffset = ar_data_sync:get_chunk_padded_offset(AbsoluteOffset),

State3#state{ cursor = PaddedOffset }.

verify_proof(MetaData, State) ->
Expand All @@ -144,14 +145,14 @@ verify_proof(MetaData, State) ->
read_data_path_error, AbsoluteOffset, ChunkSize, [{reason, Error}], State)
end.

verify_chunk_storage(Offset, _ChunkSize, {End, Start}, State)
when Offset - ?DATA_CHUNK_SIZE >= Start andalso Offset =< End ->
verify_chunk_storage(PaddedOffset, _ChunkSize, {End, Start}, State)
when PaddedOffset - ?DATA_CHUNK_SIZE >= Start andalso PaddedOffset =< End ->
State;
verify_chunk_storage(Offset, ChunkSize, _Interval, State) ->
verify_chunk_storage(PaddedOffset, ChunkSize, _Interval, State) ->
#state{ packing = Packing } = State,
case ar_data_sync:should_store_in_chunk_storage(Offset, ChunkSize, Packing) of
case ar_data_sync:should_store_in_chunk_storage(PaddedOffset, ChunkSize, Packing) of
true ->
invalidate_chunk(chunk_storage_gap, Offset, ChunkSize, State);
invalidate_chunk(chunk_storage_gap, PaddedOffset, ChunkSize, State);
false ->
State
end.
Expand Down

0 comments on commit 811b9c5

Please sign in to comment.