From ee841f0880aab9d832f186f1e11dbc6023b5fab4 Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Fri, 11 Mar 2022 14:02:26 +0000 Subject: [PATCH] include attestation in witness and receipt reports --- Makefile | 3 +- rebar.config | 4 +- rebar.lock | 6 +- src/miner_util.erl | 25 +++++- src/poc/miner_onion_server_light.erl | 47 +++++------- src/poc/miner_poc_grpc_client_handler.erl | 17 ++-- src/poc/miner_poc_grpc_client_statem.erl | 94 +++++++++++++---------- test/miner_poc_grpc_SUITE.erl | 2 - 8 files changed, 114 insertions(+), 84 deletions(-) diff --git a/Makefile b/Makefile index 984838c79..14ce550c4 100755 --- a/Makefile +++ b/Makefile @@ -21,6 +21,7 @@ deps: compile: REBAR_CONFIG="config/grpc_client_gen_local.config" $(REBAR) grpc gen + REBAR_CONFIG="config/grpc_client_gen.config" $(REBAR) grpc gen $(MAKE) external_svcs $(REBAR) compile @@ -72,7 +73,7 @@ devrelease: grpc: @echo "generating miner grpc services" REBAR_CONFIG="config/grpc_client_gen_local.config" $(REBAR) grpc gen - REBAR_CONFIG="config/grpc_client_gen.config" $(REBAR) grpc gen + REBAR_CONFIG="config/grpc_client_gen.config" $(REBAR) grpc gen $(GRPC_SERVICE_DIR): @echo "miner grpc service directory $(directory) does not exist" diff --git a/rebar.config b/rebar.config index f5bdf6680..e94d69238 100644 --- a/rebar.config +++ b/rebar.config @@ -10,9 +10,9 @@ {deps, [ {blockchain, {git, "https://github.com/helium/blockchain-core.git", - {branch, "andymck/poc-grpc-v2"}}}, + {branch, "andymck/poc-grpc-v2-report-attestation"}}}, {sibyl, {git, "https://github.com/helium/sibyl.git", - {branch, "andymck/poc-grpc"}}}, + {branch, "andymck/poc-grpc-report-attestation"}}}, {hbbft, {git, "https://github.com/helium/erlang-hbbft.git", {branch, "master"}}}, {dkg, {git, "https://github.com/helium/erlang-dkg.git", {branch, "master"}}}, diff --git a/rebar.lock b/rebar.lock index 0cca22f06..88b50e01b 100644 --- a/rebar.lock +++ b/rebar.lock @@ -5,7 +5,7 @@ {<<"base64url">>,{pkg,<<"base64url">>,<<"1.0.1">>},1}, {<<"blockchain">>, {git,"https://github.com/helium/blockchain-core.git", - {ref,"fcc35a3de11b083cbe6a527a4e614d07dc2d2f9d"}}, + {ref,"1a07ed7ba57bf48f73405f18f8f2060cb1d2162d"}}, 0}, {<<"chatterbox">>, {git,"https://github.com/andymck/chatterbox", @@ -105,7 +105,7 @@ 0}, {<<"helium_proto">>, {git,"https://github.com/helium/proto.git", - {ref,"f743a80e534bdc78805e3c5438cb466bec3c0b6f"}}, + {ref,"9643884f68c7553f73a5b2de4b8c9ce10874e100"}}, 1}, {<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},3}, {<<"http2_client">>, @@ -170,7 +170,7 @@ 3}, {<<"sibyl">>, {git,"https://github.com/helium/sibyl.git", - {ref,"9c68561f1e9689ce3d0bc02c40f3af548b2a51e4"}}, + {ref,"e3a594e7e7054d0ec7c335a11438e1797260b63f"}}, 0}, {<<"sidejob">>,{pkg,<<"sidejob">>,<<"2.1.0">>},2}, {<<"small_ints">>,{pkg,<<"small_ints">>,<<"0.1.0">>},4}, diff --git a/src/miner_util.erl b/src/miner_util.erl index 2e204efdc..a6ca01dc4 100644 --- a/src/miner_util.erl +++ b/src/miner_util.erl @@ -18,12 +18,19 @@ true_predicate/1, has_valid_local_capability/2, hbbft_perf/0, - mk_rescue_block/3 + mk_rescue_block/3, + get_attestation/1 ]). +-include("src/grpc/autogen/client/gateway_miner_client_pb.hrl"). +-include_lib("helium_proto/include/blockchain_poc_core_v1_pb.hrl"). -include_lib("blockchain/include/blockchain_vars.hrl"). -include_lib("blockchain/include/blockchain.hrl"). + +-type attestation() :: #attestation_pb{}. +-export_type([attestation/0]). + %% get the firmware release data from a hotspot -define(LSB_FILE, "/etc/lsb_release"). -define(RELEASE_CMD, "cat " ++ ?LSB_FILE ++ " | grep RELEASE | cut -d'=' -f2"). @@ -270,3 +277,19 @@ mk_rescue_block(Vars, Addrs, KeyStr) -> RescueSig = RescueSigFun(EncodedBlock), blockchain_block_v1:set_signatures(RescueBlock, [], RescueSig). + +-spec get_attestation(#gateway_resp_v1_pb{}) -> attestation(). +get_attestation(Msg) -> + #gateway_resp_v1_pb{ + address = AttAddress, + height = AttHeight, + block_time = AttBlockTime, + block_age = AttBlockAge, + signature = AttSig} = Msg, + #attestation_pb{ + height = AttHeight, + block_time = AttBlockTime, + block_age = AttBlockAge, + address = AttAddress, + signature = AttSig + }. diff --git a/src/poc/miner_onion_server_light.erl b/src/poc/miner_onion_server_light.erl index 6861d4f90..634fdc962 100644 --- a/src/poc/miner_onion_server_light.erl +++ b/src/poc/miner_onion_server_light.erl @@ -17,10 +17,9 @@ %% ------------------------------------------------------------------ -export([ start_link/1, - decrypt_p2p/1, + decrypt_grpc/2, decrypt_radio/7, - retry_decrypt/11, - send_receipt/11, + send_receipt/12, send_witness/9, region_params_update/2, region_params/0 @@ -72,16 +71,13 @@ start_link(Args) -> gen_server:start_link({local, ?MODULE}, ?MODULE, Args, []). --spec decrypt_p2p(binary()) -> ok. -decrypt_p2p(Onion) -> - gen_server:cast(?MODULE, {decrypt_p2p, Onion}). +-spec decrypt_grpc(binary(), miner_util:attestation()) -> ok. +decrypt_grpc(Onion, Attestation) -> + gen_server:cast(?MODULE, {decrypt_grpc, Onion, Attestation}). decrypt_radio(Packet, RSSI, SNR, Timestamp, Freq, Channel, Spreading) -> gen_server:cast(?MODULE, {decrypt_radio, Packet, RSSI, SNR, Timestamp, Freq, Channel, Spreading}). -retry_decrypt(Type, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, DataRate, Stream) -> - gen_server:cast(?MODULE, {retry_decrypt, Type, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, DataRate, Stream}). - -spec region_params_update(atom(), [blockchain_region_param_v1:region_param_v1()]) -> ok. region_params_update(Region, RegionParams) -> gen_server:cast(?MODULE, {region_params_update, Region, RegionParams}). @@ -92,7 +88,7 @@ region_params() -> -spec send_receipt(Data :: binary(), OnionCompactKey :: libp2p_crypto:pubkey_bin(), - Type :: radio | p2p, + Type :: radio | p2p | grpc, Time :: pos_integer(), RSSI :: integer(), SNR :: float(), @@ -100,8 +96,9 @@ region_params() -> Channel :: non_neg_integer(), DataRate :: binary(), Power :: non_neg_integer(), + Attestation :: miner_util:attestation(), State :: state()) -> ok | {error, any()}. -send_receipt(Data, OnionCompactKey, Type, Time, RSSI, SNR, Frequency, Channel, DataRate, Power, _State) -> +send_receipt(Data, OnionCompactKey, Type, Time, RSSI, SNR, Frequency, Channel, DataRate, Power, Attestation, _State) -> case miner_lora_light:location_ok() of true -> lager:md([{poc_id, blockchain_utils:poc_id(OnionCompactKey)}]), @@ -113,7 +110,7 @@ send_receipt(Data, OnionCompactKey, Type, Time, RSSI, SNR, Frequency, Channel, D 2 -> blockchain_poc_receipt_v1:new(Address, Time, RSSI, Data, Type, SNR, Frequency, Channel, DataRate); V when V >= 3 -> - R0 = blockchain_poc_receipt_v1:new(Address, Time, RSSI, Data, Type, SNR, Frequency, Channel, DataRate), + R0 = blockchain_poc_receipt_v1:new(Address, Time, RSSI, Data, Type, SNR, Frequency, Channel, DataRate, Attestation), blockchain_poc_receipt_v1:tx_power(R0, Power); _ -> blockchain_poc_receipt_v1:new(Address, Time, RSSI, Data, Type) @@ -181,16 +178,16 @@ handle_call(_Msg, _From, State) -> handle_cast({region_params_update, Region, RegionParams}, State) -> lager:info("updating region params. Region: ~p, Params: ~p", [Region, RegionParams]), {noreply, State#state{region = Region, region_params = RegionParams}}; -handle_cast({decrypt_p2p, _Payload}, #state{region_params = undefined} = State) -> - lager:warning("dropping p2p challenge packet as no region params data", []), +handle_cast({decrypt_grpc, _Payload, _Attestation}, #state{region_params = undefined} = State) -> + lager:warning("dropping grpc challenge packet as no region params data", []), {noreply, State}; -handle_cast({decrypt_p2p, <>}, State) -> + CipherText/binary>>, Attestation}, State) -> %%TODO - rssi, freq, snr, channel and datarate were originally undefined %% but this breaks the in use PB encoder, so defaulted to values below - NewState = decrypt(p2p, IV, OnionCompactKey, Tag, CipherText, 0, 0.0, 0.0, 0, [12], State), + NewState = decrypt(grpc, IV, OnionCompactKey, Tag, CipherText, 0, 0.0, 0.0, 0, [12], Attestation, State), {noreply, NewState}; handle_cast({decrypt_radio, _Payload}, #state{region_params = undefined} = State) -> lager:warning("dropping radio challenge packet as no region params data", []), @@ -200,13 +197,7 @@ handle_cast({decrypt_radio, <>, RSSI, SNR, _Timestamp, Frequency, Channel, DataRate}, State) -> - NewState = decrypt(radio, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, DataRate, State), - {noreply, NewState}; -handle_cast({retry_decrypt, Type, _IV, _OnionCompactKey, _Tag, _CipherText, _RSSI, _SNR, _Frequency, _Channel, _DataRate}, #state{region_params = undefined} = State) -> - lager:warning("dropping retry ~p challenge packet as no region params data", [Type]), - {noreply, State}; -handle_cast({retry_decrypt, Type, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, DataRate}, State) -> - NewState = decrypt(Type, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, DataRate, State), + NewState = decrypt(radio, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, DataRate, undefined, State), {noreply, NewState}; handle_cast(_Msg, State) -> {noreply, State}. @@ -218,7 +209,9 @@ handle_info(_Msg, State) -> %% ------------------------------------------------------------------ %% Internal Function Definitions %% ------------------------------------------------------------------ -decrypt(Type, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, DataRate, #state{ecdh_fun=ECDHFun, region_params = RegionParams, region = Region}=State) -> +decrypt(Type, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, + DataRate, Attestation, + #state{ecdh_fun=ECDHFun, region_params = RegionParams, region = Region} = State) -> POCID = blockchain_utils:poc_id(OnionCompactKey), OnionKeyHash = crypto:hash(sha256, OnionCompactKey), lager:info("attempting decrypt of type ~p for onion key hash ~p", [Type, OnionKeyHash]), @@ -283,14 +276,14 @@ decrypt(Type, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channe ok -> lager:info("sending receipt with observed power: ~p with radio power ~p", [EffectiveTxPower, TxPower]), ?MODULE:send_receipt(Data, OnionCompactKey, Type, os:system_time(nanosecond), - RSSI, SNR, Frequency, Channel, DataRate, EffectiveTxPower, State); + RSSI, SNR, Frequency, Channel, DataRate, EffectiveTxPower, Attestation, State); {warning, {tx_power_corrected, CorrectedPower}} -> %% Corrected power never takes into account antenna gain config in pkt forwarder so we %% always add it back here lager:warning("tx_power_corrected! original_power: ~p, corrected_power: ~p, with gain ~p; sending receipt with power ~p", [TxPower, CorrectedPower, AssertedGain, CorrectedPower + AssertedGain]), ?MODULE:send_receipt(Data, OnionCompactKey, Type, os:system_time(nanosecond), - RSSI, SNR, Frequency, Channel, DataRate, CorrectedPower + AssertedGain, State); + RSSI, SNR, Frequency, Channel, DataRate, CorrectedPower + AssertedGain, Attestation, State); {warning, {unknown, Other}} -> %% This should not happen lager:warning("What is this? ~p", [Other]), diff --git a/src/poc/miner_poc_grpc_client_handler.erl b/src/poc/miner_poc_grpc_client_handler.erl index 7bc17360e..f80c59099 100644 --- a/src/poc/miner_poc_grpc_client_handler.erl +++ b/src/poc/miner_poc_grpc_client_handler.erl @@ -4,6 +4,7 @@ -module(miner_poc_grpc_client_handler). -include("src/grpc/autogen/client/gateway_miner_client_pb.hrl"). +-include_lib("helium_proto/include/blockchain_poc_core_v1_pb.hrl"). %% ------------------------------------------------------------------ %% Stream Exports @@ -128,8 +129,8 @@ handle_msg({data, #gateway_resp_v1_pb{msg = {poc_challenge_resp, ChallengeNotifi TargetRes = miner_poc_grpc_client_statem:check_target(binary_to_list(URI), PubKeyBin, OnionKeyHash, BlockHash, NotificationHeight, ChallengerSig), lager:info("check target result for key ~p: ~p",[OnionKeyHash, TargetRes]), case TargetRes of - {ok, Result, _Details} -> - handle_check_target_resp(Result); + {ok, Result, Attestation} -> + handle_check_target_resp(Result, Attestation); {error, <<"queued_poc">>} -> erlang:send_after(5000, Self, {retry_check_target, 1, Msg}); {error, _Reason, _Details} -> @@ -165,8 +166,8 @@ handle_info({retry_check_target, Attempt, Msg}, StreamState) when Attempt =< 3 TargetRes = miner_poc_grpc_client_statem:check_target(binary_to_list(URI), PubKeyBin, OnionKeyHash, BlockHash, NotificationHeight, ChallengerSig), lager:info("check target result retry ~p for key ~p: ~p",[Attempt, OnionKeyHash, TargetRes]), case TargetRes of - {ok, Result, _Details} -> - handle_check_target_resp(Result); + {ok, Result, Attestation} -> + handle_check_target_resp(Result, Attestation); {error, <<"queued_poc">>} -> erlang:send_after(5000, Self, {retry_check_target, Attempt +1, Msg}); {error, _Reason, _Details} -> @@ -184,10 +185,10 @@ handle_info(_Msg, StreamState) -> %% ------------------------------------------------------------------ %% Internal functions %% ------------------------------------------------------------------ --spec handle_check_target_resp(#gateway_poc_check_challenge_target_resp_v1_pb{})-> ok. -handle_check_target_resp(#gateway_poc_check_challenge_target_resp_v1_pb{target = true, onion = Onion} = _ChallengeResp) -> - ok = miner_onion_server_light:decrypt_p2p(Onion); -handle_check_target_resp(#gateway_poc_check_challenge_target_resp_v1_pb{target = false} = _ChallengeResp) -> +-spec handle_check_target_resp(#gateway_poc_check_challenge_target_resp_v1_pb{}, miner_util:attestation())-> ok. +handle_check_target_resp(#gateway_poc_check_challenge_target_resp_v1_pb{target = true, onion = Onion} = _ChallengeResp, Attestation) -> + ok = miner_onion_server_light:decrypt_grpc(Onion, Attestation); +handle_check_target_resp(#gateway_poc_check_challenge_target_resp_v1_pb{target = false} = _ChallengeResp, _Attestation) -> ok. -ifdef(TEST). diff --git a/src/poc/miner_poc_grpc_client_statem.erl b/src/poc/miner_poc_grpc_client_statem.erl index f82355b09..3b8736b5b 100644 --- a/src/poc/miner_poc_grpc_client_statem.erl +++ b/src/poc/miner_poc_grpc_client_statem.erl @@ -9,7 +9,6 @@ -include("src/grpc/autogen/client/gateway_miner_client_pb.hrl"). -include_lib("public_key/include/public_key.hrl"). -include_lib("helium_proto/include/blockchain_txn_vars_v1_pb.hrl"). - %% ------------------------------------------------------------------ %% API Function Exports %% ------------------------------------------------------------------ @@ -220,10 +219,17 @@ setup(_EventType, _Msg, Data) -> connected(enter, _OldState, Data)-> {keep_state, Data}; -connected(cast, {send_report, ReportType, Report, OnionKeyHash, RetryAttempts}, #data{connection = Connection, self_sig_fun = SelfSigFun, self_pub_key_bin = SelfPubKeyBin} = Data) -> - lager:info("send_report ~p with onionkeyhash ~p: ~p", [ReportType, OnionKeyHash, Report]), - ok = send_report(ReportType, Report, OnionKeyHash, SelfPubKeyBin, SelfSigFun, Connection, RetryAttempts), +connected(cast, {send_report, ReportType, Report, OnionKeyHash, RetryAttempts}, + #data{connection = Connection, self_sig_fun = SelfSigFun, self_pub_key_bin = SelfPubKeyBin} = Data) -> + %% ask our durable val for grpc connection details of the challenger + case get_uri_for_challenger(OnionKeyHash, Connection) of + {ok, {IP, Port, Attestation}} -> + send_report(ReportType, Report, OnionKeyHash, SelfPubKeyBin, SelfSigFun, IP, Port, Attestation, RetryAttempts); + {error, _Reason} -> + ?MODULE:send_report(ReportType, Report, OnionKeyHash, RetryAttempts - 1) + end, {keep_state, Data}; + connected(cast, {update_config, Keys}, #data{val_public_ip = ValIP, val_grpc_port = ValPort} = Data) -> lager:info("update_config for keys ~p", [Keys]), _ = fetch_config(Keys, ValIP, ValPort), @@ -323,40 +329,49 @@ connect_stream_region_params_update(Connection, SelfPubKeyBin, SelfSigFun) -> Res end. --spec send_report(witness | receipt, any(), binary(), libp2p_crypto:pubkey_bin(), function(), grpc_client_custom:connection(), non_neg_integer()) -> ok. -send_report(_ReportType, _Report, _OnionKeyHash, _SelfPubKeyBin, _SigFun, _Connection, 0) -> - ok; -send_report(receipt = ReportType, Report, OnionKeyHash, _SelfPubKeyBin, SigFun, Connection, RetryAttempts) -> - EncodedReceipt = gateway_miner_client_pb:encode_msg(Report#blockchain_poc_receipt_v1_pb{signature = <<>>}, blockchain_poc_receipt_v1_pb), +-spec send_report(witness | receipt, any(), binary(), libp2p_crypto:pubkey_bin(), + function(), string(), pos_integer(), miner_util:attestation(), non_neg_integer()) -> ok. +send_report(receipt = ReportType, Report, OnionKeyHash, _SelfPubKeyBin, SigFun, + ChallengerIP, ChallengerPort, _Attestation, RetryAttempts) -> + %% a receipt will already contain attestation data, so dont use the data provided here + EncodedReceipt = gateway_miner_client_pb:encode_msg( + Report#blockchain_poc_receipt_v1_pb{signature = <<>>}, blockchain_poc_receipt_v1_pb), SignedReceipt = Report#blockchain_poc_receipt_v1_pb{signature = SigFun(EncodedReceipt)}, + lager:info("send_report ~p with onionkeyhash ~p: ~p", [ReportType, OnionKeyHash, SignedReceipt]), Req = #gateway_poc_report_req_v1_pb{ onion_key_hash = OnionKeyHash, msg = {ReportType, SignedReceipt}}, - do_send_report(Req, ReportType, Report, OnionKeyHash, Connection, RetryAttempts); -send_report(witness = ReportType, Report, OnionKeyHash, _SelfPubKeyBin, SigFun, Connection, RetryAttempts) -> - EncodedWitness = gateway_miner_client_pb:encode_msg(Report#blockchain_poc_witness_v1_pb{signature = <<>>}, blockchain_poc_witness_v1_pb), + do_send_report(Req, ChallengerIP, ChallengerPort, RetryAttempts); +send_report(witness = ReportType, Report0, OnionKeyHash, _SelfPubKeyBin, SigFun, + ChallengerIP, ChallengerPort, Attestation, RetryAttempts) -> + %% a witness report will not have any attestation data at this point + %% so include the data provided here ( received from request to get challenger ) + Report = Report0#blockchain_poc_witness_v1_pb{attestation = Attestation}, + EncodedWitness = gateway_miner_client_pb:encode_msg( + Report#blockchain_poc_witness_v1_pb{ + signature = <<>>}, blockchain_poc_witness_v1_pb), SignedWitness = Report#blockchain_poc_witness_v1_pb{signature = SigFun(EncodedWitness)}, + lager:info("send_report ~p with onionkeyhash ~p: ~p", [ReportType, OnionKeyHash, SignedWitness]), Req = #gateway_poc_report_req_v1_pb{ onion_key_hash = OnionKeyHash, msg = {ReportType, SignedWitness}}, - do_send_report(Req, ReportType, Report, OnionKeyHash, Connection, RetryAttempts). + do_send_report(Req, ChallengerIP, ChallengerPort, RetryAttempts). --spec do_send_report(binary(), witness | receipt, any(), binary(), grpc_client_custom:connection(), non_neg_integer()) -> ok. -do_send_report(Req, ReportType, Report, OnionKeyHash, Connection, RetryAttempts) -> - %% ask validator for public uri of the challenger of this POC - case get_uri_for_challenger(OnionKeyHash, Connection) of - {ok, {IP, Port}} -> - %% send the report to our challenger - case send_grpc_unary_req(IP, Port, Req, 'send_report') of - {ok, _} -> - ok; - _ -> - ?MODULE:send_report(ReportType, Report, OnionKeyHash, RetryAttempts - 1) - end; - {error, _Reason} -> - ?MODULE:send_report(ReportType, Report, OnionKeyHash, RetryAttempts - 1) - end, - ok. +-spec do_send_report(binary(), string(), pos_integer(), non_neg_integer()) -> ok. +do_send_report(_Req, _ChallengerIP, _ChallengerPort, 0) -> + ok; +do_send_report(Req, ChallengerIP, ChallengerPort, RetryAttempts) -> + case send_grpc_unary_req(ChallengerIP, ChallengerPort, Req, 'send_report') of + {ok, _Attestation} -> + ok; + _ -> + spawn( + fun()-> + timer:sleep(5000), + do_send_report(Req, ChallengerIP, ChallengerPort, RetryAttempts - 1) + end), + ok + end. -spec fetch_config([string()], string(), pos_integer()) -> {error, any()} | ok. fetch_config(UpdatedKeys, ValIP, ValGRPCPort) -> @@ -406,7 +421,7 @@ send_grpc_unary_req(Connection, Req, RPC) -> {error, req_failed} end. --spec send_grpc_unary_req(string(), non_neg_integer(), any(), atom()) -> {error, any(), map()} | {error, any()} | {ok, any(), map()} | {ok, map()}. +-spec send_grpc_unary_req(string(), non_neg_integer(), any(), atom()) -> {error, any(), miner_util:attestation()} | {error, any()} | {ok, any(), miner_util:attestation()} | {ok, miner_util:attestation()}. send_grpc_unary_req(PeerIP, GRPCPort, Req, RPC)-> try lager:info("Send unary request via new connection to ip ~p: ~p", [PeerIP, Req]), @@ -459,15 +474,14 @@ build_config_req(Keys) -> build_poc_challenger_req(OnionKeyHash) -> #gateway_poc_key_routing_data_req_v1_pb{ key = OnionKeyHash}. -%% TODO: return a better and consistent response -%%-spec process_unary_response(grpc_client_custom:unary_response()) -> {error, any(), map()} | {error, any()} | {ok, any(), map()} | {ok, map()}. -process_unary_response({ok, #{http_status := 200, result := #gateway_resp_v1_pb{msg = {success_resp, _Payload}, height = Height, signature = Sig}}}) -> - {ok, #{height => Height, signature => Sig}}; -process_unary_response({ok, #{http_status := 200, result := #gateway_resp_v1_pb{msg = {error_resp, Details}, height = Height, signature = Sig}}}) -> +%%-spec process_unary_response(grpc_client_custom:unary_response()) -> {error, any(), miner_util:attestation()} | {error, any()} | {ok, any(), miner_util:attestation()} | {ok, miner_util:attestation()}. +process_unary_response({ok, #{http_status := 200, result := #gateway_resp_v1_pb{msg = {success_resp, _Payload}} = Res}}) -> + {ok, miner_util:get_attestation(Res)}; +process_unary_response({ok, #{http_status := 200, result := #gateway_resp_v1_pb{msg = {error_resp, Details}} = Res}}) -> #gateway_error_resp_pb{error = ErrorReason} = Details, - {error, ErrorReason, #{height => Height, signature => Sig}}; -process_unary_response({ok, #{http_status := 200, result := #gateway_resp_v1_pb{msg = {_RespType, Payload}, height = Height, signature = Sig}}}) -> - {ok, Payload, #{height => Height, signature => Sig}}; + {error, ErrorReason, miner_util:get_attestation(Res)}; +process_unary_response({ok, #{http_status := 200, result := #gateway_resp_v1_pb{msg = {_RespType, Payload}} = Res}}) -> + {ok, Payload, miner_util:get_attestation(Res)}; process_unary_response({error, ClientError = #{error_type := 'client'}}) -> lager:warning("grpc error response ~p", [ClientError]), {error, grpc_client_error}; @@ -520,10 +534,10 @@ handle_down_event(_CurState, {'DOWN', Ref, process, _, Reason} = Event, Data = # get_uri_for_challenger(OnionKeyHash, Connection)-> Req = build_poc_challenger_req(OnionKeyHash), case send_grpc_unary_req(Connection, Req, 'poc_key_to_public_uri') of - {ok, #gateway_public_routing_data_resp_v1_pb{public_uri = URIData}, _Req2Details} -> + {ok, #gateway_public_routing_data_resp_v1_pb{public_uri = URIData}, AttData} -> #routing_address_pb{uri = URI, pub_key = _PubKey} = URIData, #{host := IP, port := Port} = uri_string:parse(binary_to_list(URI)), - {ok, {IP, Port}}; + {ok, {IP, Port, AttData}}; {error, Reason, _Details} -> {error, Reason}; {error, Reason} -> diff --git a/test/miner_poc_grpc_SUITE.erl b/test/miner_poc_grpc_SUITE.erl index 8414f683c..1442ec6f1 100644 --- a/test/miner_poc_grpc_SUITE.erl +++ b/test/miner_poc_grpc_SUITE.erl @@ -147,8 +147,6 @@ exec_dist_test(_TestCase, Config, VarMap, Status) -> %% Check that the receipts are growing case maps:get(?poc_version, VarMap, 11) of V when V >= 10 -> - %% There are no paths in v11 or v10 for that matter, so we'll consolidate - %% the checks for both poc-v10 and poc-v11 here true = miner_ct_utils:wait_until( fun() -> %% Check if we have some receipts