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

Commit

Permalink
include attestation in witnesses and receipts
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Mar 11, 2022
1 parent fcc35a3 commit 1a07ed7
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,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, "andymck/poc-grpc"}}},
{helium_proto, {git, "https://github.com/helium/proto.git", {branch, "andymck/poc-grpc-report-attestation"}}},
{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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
0},
{<<"helium_proto">>,
{git,"https://github.com/helium/proto.git",
{ref,"f743a80e534bdc78805e3c5438cb466bec3c0b6f"}},
{ref,"9643884f68c7553f73a5b2de4b8c9ce10874e100"}},
0},
{<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},2},
{<<"inert">>,{pkg,<<"inert">>,<<"1.0.4">>},2},
Expand Down
30 changes: 27 additions & 3 deletions src/transactions/v1/blockchain_poc_receipt_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
-include("blockchain_caps.hrl").
-include("blockchain_vars.hrl").
-include("blockchain_utils.hrl").
-include_lib("helium_proto/include/blockchain_poc_core_v1_pb.hrl").
-include_lib("helium_proto/include/blockchain_txn_poc_receipts_v1_pb.hrl").

-export([
new/5, new/7, new/9,
new/5, new/7, new/9, new/10,
gateway/1,
timestamp/1,
signal/1,
Expand All @@ -36,7 +37,7 @@
-include_lib("eunit/include/eunit.hrl").
-endif.

-type origin() :: p2p | radio | integer() | undefined.
-type origin() :: grpc | p2p | radio | integer() | undefined.
-type poc_receipt() :: #blockchain_poc_receipt_v1_pb{}.
-type poc_receipts() :: [poc_receipt()].

Expand Down Expand Up @@ -98,7 +99,30 @@ new(Address, Timestamp, Signal, Data, Origin, SNR, Frequency, Channel, DataRate)
datarate=DataRate,
signature = <<>>
}.

-spec new(Address :: libp2p_crypto:pubkey_bin(),
Timestamp :: non_neg_integer(),
Signal :: integer(),
Data :: binary(),
Origin :: origin(),
SNR :: float(),
Frequency :: float(),
Channel :: non_neg_integer(),
DataRate :: binary(),
Attestation :: #attestation_pb{}) -> poc_receipt().
new(Address, Timestamp, Signal, Data, Origin, SNR, Frequency, Channel, DataRate, Attestation) ->
#blockchain_poc_receipt_v1_pb{
gateway=Address,
timestamp=Timestamp,
signal=Signal,
data=Data,
origin=Origin,
snr=SNR,
frequency=Frequency,
channel=Channel,
datarate=DataRate,
signature = <<>>,
attestation = Attestation
}.
-spec gateway(Receipt :: poc_receipt()) -> libp2p_crypto:pubkey_bin().
gateway(Receipt) ->
Receipt#blockchain_poc_receipt_v1_pb.gateway.
Expand Down
26 changes: 25 additions & 1 deletion src/transactions/v1/blockchain_poc_witness_v1.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
-include("blockchain_caps.hrl").
-include("blockchain_json.hrl").
-include("blockchain_utils.hrl").
-include_lib("helium_proto/include/blockchain_poc_core_v1_pb.hrl").
-include_lib("helium_proto/include/blockchain_txn_poc_receipts_v1_pb.hrl").

-export([
new/4, new/6, new/8,
new/4, new/6, new/8, new/9,
gateway/1,
timestamp/1,
signal/1,
Expand Down Expand Up @@ -88,6 +89,29 @@ new(Gateway, Timestamp, Signal, PacketHash, SNR, Frequency, Channel, DataRate) -
signature = <<>>
}.

-spec new(Gateway :: libp2p_crypto:pubkey_bin(),
Timestamp :: non_neg_integer(),
Signal :: integer(),
PacketHash :: binary(),
SNR :: float(),
Frequency :: float(),
Channel :: non_neg_integer(),
DataRate :: binary(),
Attestation :: #attestation_pb{}) -> poc_witness().
new(Gateway, Timestamp, Signal, PacketHash, SNR, Frequency, Channel, DataRate, Attestation) ->
#blockchain_poc_witness_v1_pb{
gateway=Gateway,
timestamp=Timestamp,
signal=Signal,
packet_hash=PacketHash,
snr=SNR,
frequency=Frequency,
channel=Channel,
datarate=DataRate,
signature = <<>>,
attestation = Attestation
}.

-spec gateway(Witness :: poc_witness()) -> libp2p_crypto:pubkey_bin().
gateway(Witness) ->
Witness#blockchain_poc_witness_v1_pb.gateway.
Expand Down
12 changes: 6 additions & 6 deletions src/transactions/v2/blockchain_txn_poc_receipts_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ assign_alpha_beta(HasContinued, Receipt, Witnesses) ->
%% path broke, receipt, no witnesses
%% likely the next hop broke the path
case blockchain_poc_receipt_v1:origin(Receipt) of
p2p ->
grpc ->
%% you really did nothing here other than be online
{{0, 0}, false};
radio ->
Expand Down Expand Up @@ -481,7 +481,7 @@ allocate_alpha_beta(HasContinued, Element, Receipt, Witnesses, Ledger) ->
{false, Receipt, []} when Receipt /= undefined ->
%% path broke, receipt, no witnesses
case blockchain_poc_receipt_v1:origin(Receipt) of
p2p ->
grpc ->
%% you really did nothing here other than be online
{{0, 0}, false};
radio ->
Expand Down Expand Up @@ -818,7 +818,7 @@ validate(_POCVersion, Txn, Path, LayerData, LayerHashes, OldLedger) ->
IsFirst = Elem == hd(?MODULE:path(Txn)),
Receipt = blockchain_poc_path_element_v1:receipt(Elem),
ExpectedOrigin = case IsFirst of
true -> p2p;
true -> grpc;
false -> radio
end,
%% check the receipt
Expand Down Expand Up @@ -1466,7 +1466,7 @@ delta_test() ->
OnionKeyHash = <<"onion_key_hash">>,
BlockHash = <<"blockhash">>,

Receipt = blockchain_poc_receipt_v1:new(<<"r">>, 10, 10, <<"data">>, p2p, 1.2, 915.2, 2, <<"dr">>),
Receipt = blockchain_poc_receipt_v1:new(<<"r">>, 10, 10, <<"data">>, grpc, 1.2, 915.2, 2, <<"dr">>),

W1 = blockchain_poc_witness_v1:new(<<"w1">>, 10, 10, <<"ph">>, 1.2, 915.2, 2, <<"dr">>),
W2 = blockchain_poc_witness_v1:new(<<"w2">>, 10, 10, <<"ph">>, 1.2, 915.2, 2, <<"dr">>),
Expand Down Expand Up @@ -1504,7 +1504,7 @@ duplicate_delta_test() ->
<<"baz">>,
[{blockchain_poc_path_element_v1_pb,<<"first">>,
{blockchain_poc_receipt_v1_pb,<<"a">>,
1559953989978238892,0,<<"§Úi½">>,p2p,
1559953989978238892,0,<<"§Úi½">>,grpc,
<<"b">>, 10.1, 912.4},
[]},
{blockchain_poc_path_element_v1_pb,<<"second">>,
Expand Down Expand Up @@ -1546,7 +1546,7 @@ to_json_test() ->
OnionKeyHash = <<"onion_key_hash">>,
BlockHash = <<"blockhash">>,

Receipt = blockchain_poc_receipt_v1:new(<<"r">>, 10, 10, <<"data">>, p2p, 1.2, 915.2, 2, <<"dr">>),
Receipt = blockchain_poc_receipt_v1:new(<<"r">>, 10, 10, <<"data">>, grpc, 1.2, 915.2, 2, <<"dr">>),

W1 = blockchain_poc_witness_v1:new(<<"w1">>, 10, 10, <<"ph">>, 1.2, 915.2, 2, <<"dr">>),
W2 = blockchain_poc_witness_v1:new(<<"w2">>, 10, 10, <<"ph">>, 1.2, 915.2, 2, <<"dr">>),
Expand Down
3 changes: 2 additions & 1 deletion src/transactions/v2/blockchain_txn_rewards_v2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,8 @@ poc_challengees_rewards_(#{poc_version := Version}=Vars,
maps:put(Challengee, I+1, Acc0)
end,
poc_challengees_rewards_(Vars, Path, StaticPath, Txn, Chain, Ledger, false, VarMap, Acc1);
p2p ->
X when X == p2p;
X == grpc ->
%% if there are legitimate witnesses or the path continues
%% the challengee did their job
Acc1 = case
Expand Down

0 comments on commit 1a07ed7

Please sign in to comment.