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

remove sync tid lookups #384

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{<<"base32">>,{pkg,<<"base32">>,<<"0.1.0">>},3},
{<<"blockchain">>,
{git,"https://github.com/helium/blockchain-core.git",
{ref,"ee956f969e609915947f9253067ab53de3ecf7d2"}},
{ref,"22b606c63e6a0ab36646b5c8917a7c836bbc34fd"}},
0},
{<<"clique">>,
{git,"https://github.com/helium/clique.git",
Expand Down Expand Up @@ -95,7 +95,7 @@
1},
{<<"libp2p">>,
{git,"https://github.com/helium/erlang-libp2p.git",
{ref,"f3bc0338caa72696cff8dc17e775222feae120a7"}},
{ref,"a4add6c6117eb7de4d8a0136bcb48088fa4431ac"}},
1},
{<<"libp2p_crypto">>,{pkg,<<"libp2p_crypto">>,<<"1.0.1">>},2},
{<<"longfi">>,
Expand Down
15 changes: 8 additions & 7 deletions src/miner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ block_age() ->
%%--------------------------------------------------------------------
-spec p2p_status() -> [{Check::string(), Result::string()}].
p2p_status() ->
Swarm = blockchain_swarm:swarm(),
SwarmTID = blockchain_swarm:tid(),
CheckSessions = fun() ->
case (catch length(libp2p_swarm:sessions(Swarm)) > 5) of
case (catch length(libp2p_swarm:sessions(SwarmTID)) > 5) of
true -> "yes";
_ -> "no"
end
Expand All @@ -120,15 +120,15 @@ p2p_status() ->
case (catch lists:any(fun(Addr) ->
libp2p_relay:is_p2p_circuit(Addr) orelse
libp2p_transport_tcp:is_public(Addr)
end, libp2p_swarm:listen_addrs(Swarm))) of
end, libp2p_swarm:listen_addrs(SwarmTID))) of
true -> "yes";
_ -> "no"
end
end,
CheckNatType = fun() ->
try
case libp2p_peerbook:get(libp2p_swarm:peerbook(Swarm),
libp2p_swarm:pubkey_bin(Swarm)) of
case libp2p_peerbook:get(libp2p_swarm:peerbook(SwarmTID),
libp2p_swarm:pubkey_bin(SwarmTID)) of
{ok, Peer} -> atom_to_list(libp2p_peer:nat_type(Peer));
{error, _} -> "unknown"
end
Expand Down Expand Up @@ -277,10 +277,11 @@ signed_block(Signatures, BinBlock) ->
ok ->
lager:info("sending the gossiped block to other workers"),
Swarm = blockchain_swarm:swarm(),
SwarmTID = blockchain_swarm:tid(),
libp2p_group_gossip:send(
libp2p_swarm:gossip_group(Swarm),
libp2p_swarm:gossip_group(SwarmTID),
?GOSSIP_PROTOCOL,
blockchain_gossip_handler:gossip_data(Swarm, Block)
blockchain_gossip_handler:gossip_data(SwarmTID, Block)
),
{Signatories, _} = lists:unzip(blockchain_block:signatures(Block)),
{ok, ConsensusAddrs} = blockchain_ledger_v1:consensus_members(blockchain:ledger(Chain)),
Expand Down
20 changes: 10 additions & 10 deletions src/miner_consensus_mgr.erl
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ handle_call({genesis_block_done, BinaryGenesisBlock, Signatures, Members, PrivKe
[]],
[{create, true}]],
Name = consensus_group_name(1, 0, Members),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:swarm(), Name,
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:tid(), Name,
libp2p_group_relcast, GroupArg),
lager:info("started initial hbbft group: ~p~n", [Group]),
%% NOTE: I *think* this is the only place to store the chain reference in the miner state
Expand Down Expand Up @@ -262,7 +262,7 @@ handle_call({election_done, _Artifact, Signatures, Members, PrivKey, Height, Del
[{create, true}]],
%% while this won't reflect the actual height, it has to be deterministic
Name = consensus_group_name(max(0, Height), Delay, Members),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:swarm(),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:tid(),
Name,
libp2p_group_relcast, GroupArg),

Expand Down Expand Up @@ -301,7 +301,7 @@ handle_call({rescue_done, _Artifact, _Signatures, Members, PrivKey, _Height, _De
[{create, true}]], % gets filled later
%% while this won't reflect the actual height, it has to be deterministic
Name = consensus_group_name(max(0, Height), 0, Members),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:swarm(),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:tid(),
Name,
libp2p_group_relcast, GroupArg),
Ref = erlang:monitor(process, Group),
Expand Down Expand Up @@ -584,7 +584,7 @@ handle_info(timeout, State) ->
Chain]],
%% while this won't reflect the actual height, it has to be deterministic
lager:info("restoring consensus group ~p", [Name]),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:swarm(),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:tid(),
Name,
libp2p_group_relcast, GroupArg),
Round = blockchain_block:hbbft_round(HeadBlock),
Expand All @@ -595,7 +595,7 @@ handle_info(timeout, State) ->
State#state{active_group = Group, ag_monitor = Ref};
{error, cannot_start} ->
lager:info("didn't restore consensus group, missing"),
ok = libp2p_swarm:remove_group(blockchain_swarm:swarm(), Name),
ok = libp2p_swarm:remove_group(blockchain_swarm:tid(), Name),
case BlockHeight < (ElectionHeight+ElectionDelay+10) of
true ->
restore_dkg(ElectionHeight, ElectionDelay, BlockHeight, Round, State);
Expand All @@ -604,7 +604,7 @@ handle_info(timeout, State) ->
end;
{error, Reason} ->
lager:info("didn't restore consensus group: ~p", [Reason]),
ok = libp2p_swarm:remove_group(blockchain_swarm:swarm(), Name),
ok = libp2p_swarm:remove_group(blockchain_swarm:tid(), Name),
State
end;
false ->
Expand Down Expand Up @@ -662,7 +662,7 @@ handle_info({'DOWN', OldRef, process, _GroupPid, _Reason},
undefined,
Chain]],
lager:info("restoring down consensus group ~p", [Name]),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:swarm(),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:tid(),
Name,
libp2p_group_relcast, GroupArg),
Round = blockchain_block:hbbft_round(Block),
Expand Down Expand Up @@ -778,7 +778,7 @@ restore_dkg(Height, Delay, CurrHeight, Round, State) ->
[{create, true}]],
%% while this won't reflect the actual height, it has to be deterministic
Name = consensus_group_name(max(0, Height), Delay, Members),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:swarm(),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:tid(),
Name,
libp2p_group_relcast, GroupArg),

Expand Down Expand Up @@ -864,7 +864,7 @@ do_dkg(Addrs, Artifact, Sign, Done, N, Curve, Create,
Delay],
[{create, Create}]],

{ok, DKGGroup} = libp2p_swarm:add_group(blockchain_swarm:swarm(),
{ok, DKGGroup} = libp2p_swarm:add_group(blockchain_swarm:tid(),
DKGGroupName,
libp2p_group_relcast,
GroupArg),
Expand Down Expand Up @@ -900,7 +900,7 @@ start_hbbft(DKG, Height, Delay, Chain, Retries) ->
[{create, true}]],
%% while this won't reflect the actual height, it has to be deterministic
Name = consensus_group_name(max(0, Height), Delay, Members),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:swarm(),
{ok, Group} = libp2p_swarm:add_group(blockchain_swarm:tid(),
Name,
libp2p_group_relcast, GroupArg),

Expand Down
4 changes: 2 additions & 2 deletions src/miner_hbbft_sidecar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ handle_call({set_group, Group}, _From, #state{group = OldGroup} = State) ->
{P1, P2} when is_pid(P1) andalso is_pid(P2) ->
ok;
{undefined, P} when is_pid(P) ->
ok = libp2p_swarm:add_stream_handler(blockchain_swarm:swarm(), ?TX_PROTOCOL,
ok = libp2p_swarm:add_stream_handler(blockchain_swarm:tid(), ?TX_PROTOCOL,
{libp2p_framed_stream, server,
[blockchain_txn_handler, self(),
fun(T) -> miner_hbbft_sidecar:submit(T) end]});
{P, undefined} when is_pid(P) ->
libp2p_swarm:remove_stream_handler(blockchain_swarm:swarm(), ?TX_PROTOCOL)
libp2p_swarm:remove_stream_handler(blockchain_swarm:tid(), ?TX_PROTOCOL)
end,
{reply, ok, State#state{group = Group}};
handle_call({submit, _}, _From, #state{chain = undefined} = State) ->
Expand Down
9 changes: 4 additions & 5 deletions src/poc/miner_onion.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ dial_framed_stream(Swarm, Address, Args) ->
%% @doc
%% @end
%%--------------------------------------------------------------------
-spec add_stream_handler(pid()) -> ok.
add_stream_handler(Swarm) ->
TID = libp2p_swarm:tid(Swarm),
-spec add_stream_handler(pid() | ets:tab()) -> ok.
add_stream_handler(SwarmTID) ->
libp2p_swarm:add_stream_handler(
TID,
SwarmTID,
?ONION_VERSION,
{libp2p_framed_stream, server, [miner_onion_handler, self(), TID]}
{libp2p_framed_stream, server, [miner_onion_handler, self(), SwarmTID]}
).
9 changes: 4 additions & 5 deletions src/poc/miner_poc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ dial_framed_stream(Swarm, Address, Args) ->
%% @doc
%% @end
%%--------------------------------------------------------------------
-spec add_stream_handler(pid()) -> ok.
add_stream_handler(Swarm) ->
TID = libp2p_swarm:tid(Swarm),
-spec add_stream_handler(pid() | ets:tab()) -> ok.
add_stream_handler(SwarmTID) ->
libp2p_swarm:add_stream_handler(
TID,
SwarmTID,
?POC_VERSION,
{libp2p_framed_stream, server, [miner_poc_handler, self(), TID]}
{libp2p_framed_stream, server, [miner_poc_handler, self(), SwarmTID]}
).
4 changes: 2 additions & 2 deletions src/poc/miner_poc_statem.erl
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ witness(Data) ->
%% ------------------------------------------------------------------
init(Args) ->
ok = blockchain_event:add_handler(self()),
ok = miner_poc:add_stream_handler(blockchain_swarm:swarm()),
ok = miner_onion:add_stream_handler(blockchain_swarm:swarm()),
ok = miner_poc:add_stream_handler(blockchain_swarm:tid()),
ok = miner_onion:add_stream_handler(blockchain_swarm:tid()),
Address = blockchain_swarm:pubkey_bin(),
Blockchain = blockchain_worker:blockchain(),
BaseDir = maps:get(base_dir, Args, undefined),
Expand Down