Skip to content

Commit

Permalink
fix: block 2.9 syncing server-side
Browse files Browse the repository at this point in the history
Also allow us to disable blocking in tests
  • Loading branch information
JamesPiechota committed Jan 7, 2025
1 parent 39e9948 commit 3a67413
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions apps/arweave/include/ar_data_sync.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@
-define(STORE_CHUNK_QUEUE_FLUSH_TIME_THRESHOLD, 2_000). % 2 seconds.
-endif.

%% By default we prevent syncing replica 2.9 chunks since they are too expensive to unpack.
-ifndef(BLOCK_2_9_SYNCING).
-define(BLOCK_2_9_SYNCING, true).
-endif.

%% @doc The state of the server managing data synchronization.
-record(sync_data_state, {
%% The last entries of the block index.
Expand Down
8 changes: 1 addition & 7 deletions apps/arweave/src/ar_data_sync.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2810,19 +2810,13 @@ pick_missing_blocks([{H, WeaveSize, _} | CurrentBI], BlockTXPairs) ->
_ ->
{WeaveSize, lists:reverse(After)}
end.

-ifdef(AR_TEST).
should_unpack(_) ->
true.
-else.
should_unpack({replica_2_9, Addr}) ->
should_unpack({replica_2_9, Addr}) when ?BLOCK_2_9_SYNCING ->
%% Unpacking another peer's replica 2.9 chunk is expensive, so don't do it.
%% Note: peers running the reference client won't share replica 2.9 chunks
%% anyways, so this check is just a backup.
{false, got_replica_2_9_chunk_from_peer, [{mining_addr, ar_util:encode(Addr)}]};
should_unpack(_) ->
true.
-endif.

process_invalid_fetched_chunk(Peer, Byte, State) ->
%% Not necessarily a malicious peer, it might happen
Expand Down
4 changes: 3 additions & 1 deletion apps/arweave/src/ar_http_iface_middleware.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2010,11 +2010,13 @@ handle_get_chunk(OffsetBinary, Req, Encoding) ->
{{true, RequestedPacking}, _StoreID} ->
ok = ar_semaphore:acquire(get_chunk, infinity),
{RequestedPacking, ok};
{true, {replica_2_9, _}, _StoreID} ->
{{true, {replica_2_9, _}}, _StoreID} when ?BLOCK_2_9_SYNCING ->
%% Don't serve replica 2.9 chunks as they are expensive to
%% unpack.
{none, {reply, {404, #{}, <<>>, Req}}};
{{true, Packing}, _StoreID} when RequestedPacking == any ->
?LOG_INFO([{event, get_chunk3}, {requested_packing, ar_serialize:encode_packing(Packing, false)},
{store_id, _StoreID}, {offset, Offset}]),
ok = ar_semaphore:acquire(get_chunk, infinity),
{Packing, ok};
{{true, _}, _StoreID} ->
Expand Down

0 comments on commit 3a67413

Please sign in to comment.