From 5443e795523e1c47e41a073410bb56f130a6a078 Mon Sep 17 00:00:00 2001 From: Andrew McKenzie Date: Mon, 4 Jul 2022 17:08:08 +0100 Subject: [PATCH] include attestation in witness and receipt reports --- rebar.config | 4 +- rebar.lock | 8 +- src/miner_util.erl | 25 +++- src/poc/miner_onion_server_light.erl | 47 ++++--- src/poc/miner_poc_grpc_client_statem.erl | 158 ++++++++++++----------- 5 files changed, 136 insertions(+), 106 deletions(-) diff --git a/rebar.config b/rebar.config index 773da4c7a..586ecf69e 100644 --- a/rebar.config +++ b/rebar.config @@ -10,9 +10,9 @@ {deps, [ {blockchain, {git, "https://github.com/helium/blockchain-core.git", - {branch, "master"}}}, + {branch, "andymck/poc-grpc-v2-report-attestation"}}}, {sibyl, {git, "https://github.com/helium/sibyl.git", - {branch, "master"}}}, + {branch, "andymck/poc-grpc-v2-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 671c69fa9..de1c9dc00 100644 --- a/rebar.lock +++ b/rebar.lock @@ -8,7 +8,7 @@ {<<"base64url">>,{pkg,<<"base64url">>,<<"1.0.1">>},1}, {<<"blockchain">>, {git,"https://github.com/helium/blockchain-core.git", - {ref,"2418468a75bbed961ac2ff244694de859cbb0756"}}, + {ref,"02558491319997e7e13120de0f5c49a9a3f67597"}}, 0}, {<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2}, {<<"chatterbox">>, @@ -110,7 +110,7 @@ 0}, {<<"helium_proto">>, {git,"https://github.com/helium/proto.git", - {ref,"d1694d5ddb3801f70461921a33407b04d9df66f3"}}, + {ref,"068e4fc448ffbec1807936e84467af61d67f5d9c"}}, 1}, {<<"hpack">>,{pkg,<<"hpack_erl">>,<<"0.2.3">>},3}, {<<"http2_client">>, @@ -147,6 +147,10 @@ {git,"https://github.com/helium/longfi-erlang", {ref,"08669ccdd7847b584cbcbcb5cf756ed253581a13"}}, 0}, + {<<"lorawan">>, + {git,"https://github.com/helium/erlang-lorawan.git", + {ref,"49925a083347e91e74daee3516a2105e82ef6c07"}}, + 1}, {<<"merkerl">>, {git,"https://github.com/helium/merkerl.git", {ref,"26ddcaf7f3c2c76eebf6f9258822f923ce69cb75"}}, diff --git a/src/miner_util.erl b/src/miner_util.erl index 8b4195fb4..4e26cec86 100644 --- a/src/miner_util.erl +++ b/src/miner_util.erl @@ -18,16 +18,23 @@ 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("blockchain/include/blockchain_vars.hrl"). -include_lib("blockchain/include/blockchain.hrl"). +-include_lib("helium_proto/include/blockchain_poc_core_v1_pb.hrl"). %% 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"). +-type attestation() :: #attestation_pb{}. +-export_type([attestation/0]). + %%----------------------------------------------------------------------------- %% @doc Count the number of occurrences of each element in the list. %% @end @@ -285,3 +292,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 295c83ef6..816ebae71 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_p2p/2, decrypt_radio/7, - retry_decrypt/11, - send_receipt/11, + send_receipt/12, send_witness/9, region_params_update/3, region_params/0 @@ -73,16 +72,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_p2p(binary(), miner_util:attestation()) -> ok. +decrypt_p2p(Onion, Attestation) -> + gen_server:cast(?MODULE, {decrypt_p2p, 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()], integer()) -> ok. region_params_update(Region, RegionParams, Gain) -> gen_server:cast(?MODULE, {region_params_update, Region, RegionParams, Gain}). @@ -101,8 +97,9 @@ region_params() -> Channel :: non_neg_integer(), DataRate :: list(), 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)}]), @@ -114,7 +111,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) @@ -184,16 +181,16 @@ handle_cast({region_params_update, Region, RegionParams, Gain}, State) -> region = Region, region_params = RegionParams, gain = Gain}}; -handle_cast({decrypt_p2p, _Payload}, #state{region_params = undefined} = State) -> +handle_cast({decrypt_p2p, _Payload, _Attestation}, #state{region_params = undefined} = State) -> lager:warning("dropping p2p 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(p2p, 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", []), @@ -203,13 +200,11 @@ 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), + %% NOTE: attestation is defaulted to undefined for radio + %% attestation is only applicable to receipts and we never + %% get a receipt over the radio + %% it always comes in over p2p ( rather grpc but we are reusing the p2p function here ) + NewState = decrypt(radio, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channel, DataRate, undefined, State), {noreply, NewState}; handle_cast(_Msg, State) -> {noreply, State}. @@ -221,7 +216,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:debug("attempting decrypt of type ~p for onion key hash ~p", [Type, OnionKeyHash]), @@ -264,7 +261,7 @@ decrypt(Type, IV, OnionCompactKey, Tag, CipherText, RSSI, SNR, Frequency, Channe TxPower = tx_power(Region), erlang:spawn(fun() -> miner_lora_light:send_poc(Packet, immediate, ChannelSelectorFun, Spreading, TxPower) end), erlang:spawn(fun() -> ?MODULE:send_receipt(Data, OnionCompactKey, Type, os:system_time(nanosecond), - RSSI, SNR, Frequency, Channel, DataRate, TxPower, State) end); + RSSI, SNR, Frequency, Channel, DataRate, TxPower, Attestation, State) end); _ -> case blockchain_region_params_v1:get_spreading(RegionParams, erlang:byte_size(Packet)) of {error, Why} -> @@ -286,14 +283,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, DR, EffectiveTxPower, State); + RSSI, SNR, Frequency, Channel, DR, 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, DR, CorrectedPower + AssertedGain, State); + RSSI, SNR, Frequency, Channel, DR, 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_statem.erl b/src/poc/miner_poc_grpc_client_statem.erl index 955e5b075..c279f5f45 100644 --- a/src/poc/miner_poc_grpc_client_statem.erl +++ b/src/poc/miner_poc_grpc_client_statem.erl @@ -6,8 +6,10 @@ -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"). +-include_lib("helium_proto/include/blockchain_poc_core_v1_pb.hrl"). -include_lib("blockchain/include/blockchain_utils.hrl"). %% ------------------------------------------------------------------ @@ -101,7 +103,9 @@ connected/3 ]). --type unary_result() :: {error, any(), map()} | {error, any()} | {ok, any(), map()} | {ok, map()}. +-type unary_result() :: {error, any(), miner_util:attestation()} | + {error, any()} | {ok, any(), miner_util:attestation()} | + {ok, miner_util:attestation()}. %% ------------------------------------------------------------------ %% API Definitions %% ------------------------------------------------------------------ @@ -397,15 +401,22 @@ connected( "send_report ~p with onionkeyhash ~p: ~p", [ReportType, OnionKeyHash, Report] ), - ok = send_report( - ReportType, - Report, - OnionKeyHash, - SelfPubKeyBin, - SelfSigFun, - Connection, - RetryAttempts - ), + %% 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, @@ -465,13 +476,13 @@ find_validator() -> end, Req = build_validators_req(1), case send_grpc_unary_req(SeedValIP, SeedValGRPCPort, Req, 'validators') of - {ok, #gateway_validators_resp_v1_pb{result = []}, _ReqDetails} -> + {ok, #gateway_validators_resp_v1_pb{result = []}, _Attestation} -> %% no routes, retry in a bit lager:warning("failed to find any validator routing from seed validator ~p", [ SeedValIP ]), {error, no_validators}; - {ok, #gateway_validators_resp_v1_pb{result = Routing}, _ReqDetails} -> + {ok, #gateway_validators_resp_v1_pb{result = Routing}, _Attestation} -> %% resp will contain the payload 'gateway_validators_resp_v1_pb' [ #routing_address_pb{ @@ -487,9 +498,12 @@ find_validator() -> } = uri_string:parse(binary_to_list(DurableValURI)), {ok, DurableValIP, DurableValGRPCPort, DurableValP2PAddr}; - {error, _} = Error -> - lager:warning("request to validator failed: ~p", [Error]), - {error, Error} + {error, Reason, _Attestation} -> + lager:warning("request to validator failed: ~p", [Reason]), + {error, Reason}; + {error, Reason} -> + lager:warning("request to validator failed: ~p", [Reason]), + {error, Reason} end; _ -> lager:warning("failed to find seed validators", []), @@ -586,64 +600,55 @@ connect_stream_region_params_update(Connection, SelfPubKeyBin, SelfSigFun) -> OnionKeyHash::binary(), SelfPubKeyBin::libp2p_crypto:pubkey_bin(), SigFun::function(), - Connection::grpc_client_custom:connection(), + IP::string(), + Port::pos_integer(), + Attestation::miner_util:attestation(), RetryAttempts::non_neg_integer() ) -> ok. -send_report(_ReportType, _Report, _OnionKeyHash, _SelfPubKeyBin, _SigFun, _Connection, 0) -> +send_report(_ReportType, _Report, _OnionKeyHash, _SelfPubKeyBin, _SigFun, _ChallengerIP, _ChallengerPort, _Attestation, 0) -> lager:warning("failed to submit report. OnionKeyHash: ~p, Report: ~p", [_OnionKeyHash, _Report]), ok; send_report( - receipt = ReportType, Report, OnionKeyHash, _SelfPubKeyBin, SigFun, Connection, RetryAttempts + 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 - ), + 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); + msg = {ReportType, SignedReceipt}}, + case send_grpc_unary_req(ChallengerIP, ChallengerPort, Req, 'send_report') of + {ok, _Attestation} -> + ok; + _Error -> + lager:debug("send_grpc_unary_req(~p, ~p, ~p, 'send_report') failed with: ~p", + [ChallengerIP,ChallengerPort,Req,_Error]), + retry_report({send_report, ReportType, Report, OnionKeyHash, SelfPubKeyBin, SigFun, ChallengerIP, ChallengerPort, Attestation, RetryAttempts - 1}) + end; send_report( - witness = ReportType, Report, OnionKeyHash, _SelfPubKeyBin, SigFun, Connection, RetryAttempts + 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 - ), + 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). - --spec do_send_report( - Req :: #gateway_poc_report_req_v1_pb{}, - ReportType :: receipt | witness, - Report :: #blockchain_poc_receipt_v1_pb{} | #blockchain_poc_witness_v1_pb{}, - OnionKeyHash ::binary(), - Connection :: grpc_client_custom:connection(), - RetryAttempts :: 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; - _Error -> - lager:debug("send_grpc_unary_req(~p, ~p, ~p, 'send_report') failed with: ~p", - [IP,Port,Req,_Error]), - retry_report({send_report, ReportType, Report, OnionKeyHash, RetryAttempts - 1}) - end; - {error, _Reason} -> - lager:debug("get_uri_for_challenger(~p, ~p) failed with reason: ~p", - [OnionKeyHash, Connection, _Reason]), - retry_report({send_report, ReportType, Report, OnionKeyHash, RetryAttempts - 1}) - end, - ok. + msg = {ReportType, SignedWitness}}, + case send_grpc_unary_req(ChallengerIP, ChallengerPort, Req, 'send_report') of + {ok, _Attestation} -> + ok; + _Error -> + lager:debug("send_grpc_unary_req(~p, ~p, ~p, 'send_report') failed with: ~p", + [ChallengerIP,ChallengerPort,Req,_Error]), + retry_report({send_report, ReportType, Report0, OnionKeyHash, SelfPubKeyBin, SigFun, ChallengerIP, ChallengerPort, Attestation, RetryAttempts - 1}) + end. retry_report(Msg) -> RetryDelay = application:get_env(miner, poc_send_report_retry_delay, ?DEFAULT_GRPC_SEND_REPORT_RETRY_DELAY), @@ -675,7 +680,7 @@ fetch_config(UpdatedKeys, ValIP, ValGRPCPort) -> || #blockchain_var_v1_pb{} = Var <- Vars ], ok; - {error, Reason, _Details} -> + {error, Reason, _Attestation} -> {error, Reason}; {error, Reason} -> {error, Reason} @@ -790,26 +795,25 @@ process_unary_response( {ok, #{ http_status := 200, result := #gateway_resp_v1_pb{ - msg = {success_resp, _Payload}, height = Height, signature = Sig - } + msg = {success_resp, _Payload}} = Res }} ) -> - {ok, #{height => Height, signature => Sig}}; + {ok, miner_util:get_attestation(Res)}; process_unary_response( {ok, #{ http_status := 200, - result := #gateway_resp_v1_pb{msg = {error_resp, Details}, height = Height, signature = Sig} + result := #gateway_resp_v1_pb{msg = {error_resp, Details}} = Res }} ) -> #gateway_error_resp_pb{error = ErrorReason} = Details, - {error, ErrorReason, #{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}, height = Height, signature = Sig} + result := #gateway_resp_v1_pb{msg = {_RespType, Payload}} = Res }} ) -> - {ok, Payload, #{height => Height, signature => Sig}}; + {ok, Payload, miner_util:get_attestation(Res)}; process_unary_response({error, _}) -> lager:warning("grpc client error response", []), {error, req_failed}. @@ -821,11 +825,11 @@ process_unary_response({error, _}) -> 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}, Attestation} -> #routing_address_pb{uri = URI, pub_key = _PubKey} = URIData, #{host := IP, port := Port} = uri_string:parse(binary_to_list(URI)), - {ok, {IP, Port}}; - {error, Reason, _Details} -> + {ok, {IP, Port, Attestation}}; + {error, Reason, _Attestation} -> {error, Reason}; {error, Reason} -> {error, Reason} @@ -921,11 +925,11 @@ check_if_target( ), lager:info("check target result for key ~p: ~p, Retry: ~p", [OnionKeyHash, TargetRes, IsRetry]), case TargetRes of - {ok, Result, _Details} -> + {ok, Result, Attestation} -> %% we got an expected response, purge req from queued cache should it exist _ = delete_cached_check_target_req(OnionKeyHash), - handle_check_target_resp(Result); - {error, <<"queued_poc">>, _Details = #{height := ValRespHeight}} -> + handle_check_target_resp(Result, Attestation); + {error, <<"queued_poc">>, #attestation_pb{height = ValRespHeight} = _Attestation} -> %% seems the POC key exists but the POC itself may not yet be initialised %% this can happen if the challenging validator is behind our %% notifying validator @@ -942,7 +946,7 @@ check_if_target( %% eh shouldnt hit here but ok ok end; - {error, _Reason, _Details} -> + {error, _Reason, _Attestation} -> %% we got a non queued response, purge req from queued cache should it exist %% these are valid errors, which should not be retried, like mismatched block hash _ = delete_cached_check_target_req(OnionKeyHash), @@ -1000,13 +1004,15 @@ send_check_target_req( ), send_grpc_unary_req(TargetIP, Port, Req, 'check_challenge_target'). --spec handle_check_target_resp(#gateway_poc_check_challenge_target_resp_v1_pb{}) -> ok. +-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 + #gateway_poc_check_challenge_target_resp_v1_pb{target = true, onion = Onion} = _ChallengeResp, + Attestation ) -> - ok = miner_onion_server_light:decrypt_p2p(Onion); + ok = miner_onion_server_light:decrypt_p2p(Onion, Attestation); handle_check_target_resp( - #gateway_poc_check_challenge_target_resp_v1_pb{target = false} = _ChallengeResp + #gateway_poc_check_challenge_target_resp_v1_pb{target = false} = _ChallengeResp, + _Attestation ) -> ok.