diff --git a/apps/arweave/include/ar_data_sync.hrl b/apps/arweave/include/ar_data_sync.hrl index d92f7ec7d..7a911a109 100644 --- a/apps/arweave/include/ar_data_sync.hrl +++ b/apps/arweave/include/ar_data_sync.hrl @@ -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. diff --git a/apps/arweave/src/ar_data_sync.erl b/apps/arweave/src/ar_data_sync.erl index 2a2217a88..4b8aa3269 100644 --- a/apps/arweave/src/ar_data_sync.erl +++ b/apps/arweave/src/ar_data_sync.erl @@ -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 diff --git a/apps/arweave/src/ar_http_iface_middleware.erl b/apps/arweave/src/ar_http_iface_middleware.erl index 09573269a..0fafa6c7b 100644 --- a/apps/arweave/src/ar_http_iface_middleware.erl +++ b/apps/arweave/src/ar_http_iface_middleware.erl @@ -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} ->