Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Add packet hash to state channel rejection #1035

Merged
merged 2 commits into from Oct 7, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rebar.config
Expand Up @@ -39,7 +39,7 @@
{erlang_stats, ".*", {git, "https://github.com/helium/erlang-stats.git", {branch, "master"}}},
{e2qc, ".*", {git, "https://github.com/helium/e2qc", {branch, "master"}}},
{vincenty, ".*", {git, "https://github.com/helium/vincenty", {branch, "master"}}},
{helium_proto, {git, "https://github.com/helium/proto.git", {branch, "master"}}},
{helium_proto, {git, "https://github.com/helium/proto.git", {branch, "madninja/rejection_packet_hash"}}},
madninja marked this conversation as resolved.
Show resolved Hide resolved
{merkerl, ".*", {git, "https://github.com/helium/merkerl.git", {branch, "master"}}},
{xxhash, {git, "https://github.com/pierreis/erlang-xxhash", {branch, "master"}}},
{exor_filter, ".*", {git, "https://github.com/mpope9/exor_filter", {branch, "master"}}},
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Expand Up @@ -66,7 +66,7 @@
0},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"3a1f0a304cdb01e70b61c34e8e64955b38652253"}},
{ref,"aaa1bcc1009e11654358a97078c42ac21d75e18f"}},
0},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},2},
{<<"inert">>,{pkg,<<"inert">>,<<"1.0.2">>},2},
Expand Down
3 changes: 2 additions & 1 deletion src/state_channel/blockchain_state_channel_common.erl
Expand Up @@ -338,7 +338,8 @@ handle_offer(Offer, Time, HandlerState) ->
end;
reject ->
%% we were able to reject out of hand
Rejection = blockchain_state_channel_rejection_v1:new(),
PacketHash = blockchain_state_channel_offer_v1:packet_hash(Offer),
Rejection = blockchain_state_channel_rejection_v1:new(PacketHash),
Msg = maybe_encode_msg(MaybeEncodeMsg, Rejection),
{ok, HandlerState, Msg}
end.
Expand Down
11 changes: 6 additions & 5 deletions src/state_channel/blockchain_state_channels_worker.erl
Expand Up @@ -218,7 +218,7 @@ offer(
DCAmount = blockchain_state_channel_v1:amount(SC),
case (TotalDCs + NumDCs) > DCAmount andalso PreventOverSpend of
true ->
ok = send_offer_rejection(HandlerPid),
ok = send_offer_rejection(HandlerPid, Offer),
lager:warning(
"dropping this packet because it will overspend DC ~p, (cost: ~p, total_dcs: ~p)",
[DCAmount, NumDCs, TotalDCs]
Expand All @@ -241,7 +241,7 @@ offer(
"dropping this packet because: ~p ~p",
[_Reason, lager:pr(SC, blockchain_state_channel_v1)]
),
ok = send_offer_rejection(HandlerPid),
ok = send_offer_rejection(HandlerPid, Offer),
{noreply, State0};
{ok, PurchaseSC} ->
lager:debug("purchasing offer from ~p ~p", [HotspotName, PurchaseSC]),
Expand Down Expand Up @@ -333,9 +333,10 @@ maybe_update_streams(HotspotID, Handler, #state{handlers=Handlers0}=State) ->
end,
State#state{handlers=Handlers1}.

-spec send_offer_rejection(HandlerPid :: pid()) -> ok.
send_offer_rejection(HandlerPid) ->
RejectionMsg = blockchain_state_channel_rejection_v1:new(),
-spec send_offer_rejection(HandlerPid :: pid(), Offer :: blockchain_state_channel_offer_v1:offer()) -> ok.
send_offer_rejection(HandlerPid, Offer) ->
PacketHash = blockchain_state_channel_offer_v1:packet_hash(Offer),
RejectionMsg = blockchain_state_channel_rejection_v1:new(PacketHash),
ok = blockchain_state_channel_common:send_rejection(HandlerPid, RejectionMsg).

-spec try_update_summary(
Expand Down
Expand Up @@ -6,7 +6,7 @@
-module(blockchain_state_channel_rejection_v1).

-export([
new/0,
new/1,
encode/1, decode/1
]).

Expand All @@ -20,9 +20,9 @@
-type rejection() :: #blockchain_state_channel_rejection_v1_pb{}.
-export_type([rejection/0]).

-spec new() -> rejection().
new() ->
#blockchain_state_channel_rejection_v1_pb{}.
-spec new(PacketHash :: binary()) -> rejection().
new(PacketHash) ->
#blockchain_state_channel_rejection_v1_pb{ packet_hash = PacketHash}.

-spec encode(rejection()) -> binary().
encode(#blockchain_state_channel_rejection_v1_pb{}=Rejection) ->
Expand Down