Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
dialyzer related tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Apr 6, 2022
1 parent b01fc1c commit 7d55b23
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/poc/grpc_client_custom.erl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
trailers := metadata()}}.

-type error_response() ::
{error, #{error_type := error_type(),
{error, #{error_type => error_type(),
http_status => integer(),
grpc_status => integer(),
status_message => binary(),
Expand Down
36 changes: 18 additions & 18 deletions src/poc/grpc_client_stream_custom.erl
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,30 @@
%% gen_server behaviors
-export([code_change/3, handle_call/3, handle_cast/2, handle_info/2, init/1, terminate/2]).

%%-type stream() ::
%% #{stream_id := integer(),
%% package := string(),
%% service := string(),
%% rpc := string(),
%% queue := queue:queue(),
%% response_pending := boolean(),
%% state := idle | open | half_closed_local | half_closed_remote | closed,
%% encoder := module(),
%% connection := grpc_client_custom:connection(),
%% headers_sent := boolean(),
%% metadata := grpc_client_custom:metadata(),
%% compression := grpc_client_custom:compression_method(),
%% buffer := binary(),
%% handler_callback := undefined,
%% handler_state := undefined,
%% type := unary | streaming | undefined}.
-type stream() ::
#{stream_id := integer(),
package := string(),
service := string(),
rpc := string(),
queue := queue:queue(),
response_pending := boolean(),
state := idle | open | half_closed_local | half_closed_remote | closed,
encoder := module(),
connection := grpc_client_custom:connection(),
headers_sent := boolean(),
metadata := grpc_client_custom:metadata(),
compression := grpc_client_custom:compression_method(),
buffer := binary(),
handler_callback := undefined,
handler_state := undefined,
type := unary | streaming | undefined}.

-spec new(Connection::grpc_client_custom:connection(),
Service::atom(),
Rpc::atom(),
Encoder::module(),
Options::list(),
HandlerMod::atom() ) -> {ok, Pid::pid()} | {error, Reason::term()}.
HandlerMod::module() ) -> {ok, Pid::pid()} | {error, Reason::term()}.
new(Connection, Service, Rpc, Encoder, Options, HandlerMod) ->
gen_server:start_link(?MODULE,
{Connection, Service, Rpc, Encoder, Options, HandlerMod}, []).
Expand Down
3 changes: 1 addition & 2 deletions src/poc/miner_poc_grpc_client_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ connect(PeerP2P) ->
connect(PeerP2P, PeerIP, GRPCPort) ->
try
lager:debug("connecting over grpc to peer ~p via IP ~p and port ~p", [PeerP2P, PeerIP, GRPCPort]),
{ok, Connection} = grpc_client_custom:connect(tcp, PeerIP, GRPCPort),
{ok, Connection}
grpc_client_custom:connect(tcp, PeerIP, GRPCPort)
catch _Error:_Reason:_Stack ->
lager:warning("*** failed to connect over grpc to peer ~p. Reason ~p Stack ~p", [PeerP2P, _Reason, _Stack]),
{error, failed_to_connect_to_grpc_peer}
Expand Down
42 changes: 24 additions & 18 deletions src/poc/miner_poc_grpc_client_statem.erl
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
-module(miner_poc_grpc_client_statem).
-behavior(gen_statem).

%%-dialyzer({nowarn_function, process_unary_response/1}).
%%-dialyzer({nowarn_function, handle_info/2}).
%%-dialyzer({nowarn_function, build_config_req/1}).
%% tmp disable no match warning from dialyzer
%%-dialyzer(no_match).

-include("src/grpc/autogen/client/gateway_miner_client_pb.hrl").
-include_lib("public_key/include/public_key.hrl").
Expand Down Expand Up @@ -59,14 +57,19 @@

%% delay between validator reconnects attempts
-define(VALIDATOR_RECONNECT_DELAY, 5000).
-ifdef(TEST).
%% delay between active check retries
%% these checks determine where to proceed with
%% grpc requests...
-define(ACTIVE_CHECK_DELAY, 1000).
%% interval in seconds at which queued check target reqs are processed
-define(CHECK_TARGET_REQ_DELAY, 5000).
-else.
-define(ACTIVE_CHECK_DELAY, 30000).
-define(CHECK_TARGET_REQ_DELAY, 60000).
-endif.
%% delay between stream reconnects attempts
-define(STREAM_RECONNECT_DELAY, 5000).
%% interval in seconds at which queued check target reqs are processed
-define(CHECK_TARGET_REQ_DELAY, 60000).
%% ets table name for check target reqs cache
-define(CHECK_TARGET_REQS, check_target_reqs).
-type data() :: #data{}.
Expand Down Expand Up @@ -202,7 +205,9 @@ setup(info, find_validator, Data) ->
val_grpc_port = ValPort,
val_p2p_addr = ValP2P
},
[{next_event, info, connect_validator}]}
[{next_event, info, connect_validator}]};
_ ->
{repeat_state, Data}
end;
setup(
info,
Expand Down Expand Up @@ -427,9 +432,9 @@ find_validator() ->
} =
uri_string:parse(binary_to_list(DurableValURI)),
{ok, DurableValIP, DurableValGRPCPort, DurableValP2PAddr};
{error, Reason} = _Error ->
lager:warning("request to validator failed: ~p", [_Error]),
{error, Reason}
{error, _} = Error ->
lager:warning("request to validator failed: ~p", [Error]),
{error, Error}
end;
_ ->
lager:warning("failed to find seed validators", []),
Expand Down Expand Up @@ -827,11 +832,11 @@ delete_cached_check_target_req(Key) ->

-spec check_if_target(
URI :: string(),
PubKeyBin :: libp2p_crypto:pubkey_bin(),
PubKeyBin :: binary(),
OnionKeyHash :: binary(),
BlockHash :: binary(),
NotificationHeight :: pos_integer(),
ChallengerSig :: function(),
NotificationHeight :: non_neg_integer(),
ChallengerSig :: binary(),
IsRetry :: boolean()
) -> ok.
check_if_target(
Expand Down Expand Up @@ -886,14 +891,15 @@ check_if_target(
ok
end
end,
spawn(F).
spawn(F),
ok.

-spec send_check_target_req(
ChallengerURI :: string(),
ChallengerPubKeyBin :: libp2p_crypto:pubkey_bin(),
ChallengerPubKeyBin :: binary(),
OnionKeyHash :: binary(),
BlockHash :: binary(),
NotificationHeight :: pos_integer(),
NotificationHeight :: non_neg_integer(),
ChallengerSig :: binary()
) -> unary_result().
send_check_target_req(
Expand All @@ -908,7 +914,7 @@ send_check_target_req(
{ok, _, SelfSigFun, _} = blockchain_swarm:keys(),
%% split the URI into its IP and port parts
#{host := IP, port := Port, scheme := _Scheme} =
uri_string:parse(binary_to_list(ChallengerURI)),
uri_string:parse(ChallengerURI),
TargetIP = maybe_override_ip(IP),
%% build the request
Req = build_check_target_req(
Expand Down Expand Up @@ -949,7 +955,7 @@ do_handle_streamed_msg(
onion_key_hash = OnionKeyHash
} = ChallengeNotification,
_ = check_if_target(
URI, PubKeyBin, OnionKeyHash, BlockHash, NotificationHeight, ChallengerSig, false
binary_to_list(URI), PubKeyBin, OnionKeyHash, BlockHash, NotificationHeight, ChallengerSig, false
),
State;
do_handle_streamed_msg(
Expand Down

0 comments on commit 7d55b23

Please sign in to comment.