-
Notifications
You must be signed in to change notification settings - Fork 230
feat: always import inlined data in tx headers if missing #864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hlolli
wants to merge
1
commit into
ArweaveTeam:master
Choose a base branch
from
hlolli:always-import-inlined-tx-data
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1964,21 +1964,28 @@ handle_post_tx(Req, Peer, TX) -> | |
| end. | ||
|
|
||
| handle_post_tx_accepted(Req, TX, Peer) -> | ||
| %% Exclude successful requests with valid transactions from the | ||
| %% IP-based throttling, to avoid connectivity issues at the times | ||
| %% of excessive transaction volumes. | ||
| {A, B, C, D, _} = Peer, | ||
| ar_blacklist_middleware:decrement_ip_addr({A, B, C, D}, Req), | ||
| BodyReadTime = ar_http_req:body_read_time(Req), | ||
| ar_peers:rate_gossiped_data(Peer, tx, | ||
| erlang:convert_time_unit(BodyReadTime, native, microsecond), | ||
| byte_size(term_to_binary(TX))), | ||
| ar_events:send(tx, {new, TX, {pushed, Peer}}), | ||
| TXID = TX#tx.id, | ||
| Ref = erlang:get(tx_id_ref), | ||
| ar_ignore_registry:remove_ref(TXID, Ref), | ||
| ar_ignore_registry:add_temporary(TXID, 10 * 60 * 1000), | ||
| ok. | ||
| %% Exclude successful requests with valid transactions from the | ||
| %% IP-based throttling, to avoid connectivity issues at the times | ||
| %% of excessive transaction volumes. | ||
| {A, B, C, D, _} = Peer, | ||
| ar_blacklist_middleware:decrement_ip_addr({A, B, C, D}, Req), | ||
| BodyReadTime = ar_http_req:body_read_time(Req), | ||
| ar_peers:rate_gossiped_data(Peer, tx, | ||
| erlang:convert_time_unit(BodyReadTime, native, microsecond), | ||
| byte_size(term_to_binary(TX))), | ||
| ar_events:send(tx, {new, TX, {pushed, Peer}}), | ||
| TXID = TX#tx.id, | ||
| Ref = erlang:get(tx_id_ref), | ||
| ar_ignore_registry:remove_ref(TXID, Ref), | ||
| ar_ignore_registry:add_temporary(TXID, 10 * 60 * 1000), | ||
| % Mark as processed with data if this is a format 2 tx with data | ||
| case TX#tx.format == 2 andalso byte_size(TX#tx.data) > 0 of | ||
| true -> | ||
| ar_ignore_registry:add_with_data(TXID); | ||
| false -> | ||
| ok | ||
| end, | ||
| ok. | ||
|
|
||
| handle_post_tx_verification_response() -> | ||
| {error_response, {400, #{}, <<"Transaction verification failed.">>}}. | ||
|
|
@@ -2994,15 +3001,24 @@ post_tx_parse_id(check_header, {Req, Pid, Encoding}) -> | |
| end | ||
| end; | ||
| post_tx_parse_id(check_ignore_list, {TXID, Req, Pid, Encoding}) -> | ||
| case ar_mempool:is_known_tx(TXID) of | ||
| true -> | ||
| {error, tx_already_processed, TXID, Req}; | ||
| false -> | ||
| Ref = make_ref(), | ||
| erlang:put(tx_id_ref, Ref), | ||
| ar_ignore_registry:add_ref(TXID, Ref, 5000), | ||
| post_tx_parse_id(read_body, {TXID, Req, Pid, Encoding}) | ||
| end; | ||
| case ar_mempool:is_known_tx(TXID) of | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks the mechanism where we process every tx only once and thus makes the network amplify spam. We would need to do something like a two-tier ignore registry where a tx with data is accepted if it is not yet recorded in the second tier. |
||
| true -> | ||
| % Check if this is a format 2 tx with data that we haven't processed with data yet | ||
| case should_accept_tx_with_data(TXID, Req) of | ||
| true -> | ||
| Ref = make_ref(), | ||
| erlang:put(tx_id_ref, Ref), | ||
| ar_ignore_registry:add_ref(TXID, Ref, 5000), | ||
| post_tx_parse_id(read_body, {TXID, Req, Pid, Encoding}); | ||
| false -> | ||
| {error, tx_already_processed, TXID, Req} | ||
| end; | ||
| false -> | ||
| Ref = make_ref(), | ||
| erlang:put(tx_id_ref, Ref), | ||
| ar_ignore_registry:add_ref(TXID, Ref, 5000), | ||
| post_tx_parse_id(read_body, {TXID, Req, Pid, Encoding}) | ||
| end; | ||
| post_tx_parse_id(read_body, {TXID, Req, Pid, Encoding}) -> | ||
| case read_complete_body(Req, Pid) of | ||
| {ok, Body, Req2} -> | ||
|
|
@@ -3017,6 +3033,25 @@ post_tx_parse_id(read_body, {TXID, Req, Pid, Encoding}) -> | |
| {error, timeout} -> | ||
| {error, timeout} | ||
| end; | ||
| post_tx_parse_id(check_ignore_list, {TXID, Req, Pid, Encoding}) -> | ||
| case ar_mempool:is_known_tx(TXID) of | ||
| true -> | ||
| % Check if this is a format 2 tx with data that we haven't processed with data yet | ||
| case should_accept_tx_with_data(TXID, Req) of | ||
| true -> | ||
| Ref = make_ref(), | ||
| erlang:put(tx_id_ref, Ref), | ||
| ar_ignore_registry:add_ref(TXID, Ref, 5000), | ||
| post_tx_parse_id(read_body, {TXID, Req, Pid, Encoding}); | ||
| false -> | ||
| {error, tx_already_processed, TXID, Req} | ||
| end; | ||
| false -> | ||
| Ref = make_ref(), | ||
| erlang:put(tx_id_ref, Ref), | ||
| ar_ignore_registry:add_ref(TXID, Ref, 5000), | ||
| post_tx_parse_id(read_body, {TXID, Req, Pid, Encoding}) | ||
| end; | ||
| post_tx_parse_id(parse_json, {TXID, Req, Body}) -> | ||
| Ref = erlang:get(tx_id_ref), | ||
| case catch ar_serialize:json_struct_to_tx(Body) of | ||
|
|
@@ -3105,6 +3140,26 @@ post_tx_parse_id(verify_id_match, {MaybeTXID, Req, TX}) -> | |
| end | ||
| end. | ||
|
|
||
| should_accept_tx_with_data(TXID, Req) -> | ||
| % Only accept if we haven't already processed this tx with data | ||
| case ar_ignore_registry:permanent_member_with_data(TXID) of | ||
| true -> | ||
| false; % Already processed with data | ||
| false -> | ||
| % Check if this request has a content-length indicating data | ||
| case cowboy_req:header(<<"content-length">>, Req, <<"0">>) of | ||
| <<"0">> -> | ||
| false; % No data in request | ||
| ContentLength -> | ||
| try | ||
| Size = binary_to_integer(ContentLength), | ||
| % Only accept if there's substantial data (> base tx size) | ||
| Size > 1000 % Rough estimate for tx with meaningful data | ||
| catch | ||
| _:_ -> false | ||
| end | ||
| end | ||
| end. | ||
| handle_post_vdf(Req, Pid) -> | ||
| Peer = ar_http_util:arweave_peer(Req), | ||
| case ets:member(ar_peers, {vdf_server_peer, Peer}) of | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small thing: arweave codebase uses
tabsfor indenting