Skip to content

Commit

Permalink
Send bin_values in the CONF message
Browse files Browse the repository at this point in the history
  • Loading branch information
Vagabond committed May 5, 2018
1 parent 7dd93d1 commit 62889f0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/hbbft_bba.erl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ aux(Data = #bba_data{n=N, f=F}, Id, V) ->
%% only send conf after n-f aux messages
case maps:is_key(Id, NewData#bba_data.conf_witness) of
false ->
{NewData#bba_data{conf_sent=true}, {send, [{multicast, {conf, NewData#bba_data.round, V}}]}};
{NewData#bba_data{conf_sent=true}, {send, [{multicast, {conf, NewData#bba_data.round, NewData#bba_data.bin_values}}]}};
true ->
%% conf was already sent
{NewData, ok}
Expand Down Expand Up @@ -280,14 +280,14 @@ deserialize(#bba_serialized_data{state=State,
-spec threshold(pos_integer(), non_neg_integer(), bba_data(), aux | conf) -> boolean().
threshold(N, F, Data, Msg) ->
case Msg of
aux -> check(N, F, Data#bba_data.bin_values, Data#bba_data.aux_witness);
conf -> check(N, F, Data#bba_data.bin_values, Data#bba_data.conf_witness)
aux -> check(N, F, Data#bba_data.bin_values, Data#bba_data.aux_witness, fun has/2);
conf -> check(N, F, Data#bba_data.bin_values, Data#bba_data.conf_witness, fun subset/2)
end.

-spec check(pos_integer(), non_neg_integer(), 0 | 1 | 2 | 3, #{non_neg_integer() => 0 | 1}) -> boolean().
check(N, F, ToCheck, Map) ->
-spec check(pos_integer(), non_neg_integer(), 0 | 1 | 2 | 3, #{non_neg_integer() => 0 | 1}, fun((0|1|2|3, 0|1|2|3) -> boolean())) -> boolean().
check(N, F, ToCheck, Map, Fun) ->
maps:fold(fun(_, V, Acc) ->
case has(V, ToCheck) of
case Fun(V, ToCheck) of
true ->
Acc + 1;
false -> Acc
Expand All @@ -302,6 +302,10 @@ add(X, Y) ->
has(X, Y) ->
((1 bsl X) band Y) /= 0.

%% is X a subset of Y?
subset(X, Y) ->
(X band Y) == X.

%% count elements of set
count(2#0) -> 0;
count(2#1) -> 1;
Expand Down

0 comments on commit 62889f0

Please sign in to comment.