Skip to content

Commit

Permalink
make batchsize a param for hbbft_worker
Browse files Browse the repository at this point in the history
  • Loading branch information
vihu committed May 2, 2018
1 parent eb7d52b commit 6a7d3b6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion test/hbbft_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ end_per_testcase(_, _) ->
simple_test(_Config) ->
N=5,
F=(N div 3),
BatchSize = 20,
dealer:start_link(N, F+1, 'SS512'),
{ok, PubKey, PrivateKeys} = dealer:deal(),
gen_server:stop(dealer),
Workers = [ element(2, hbbft_worker:start_link(N, F, I, tpke_privkey:serialize(SK))) || {I, SK} <- enumerate(PrivateKeys) ],
Workers = [ element(2, hbbft_worker:start_link(N, F, I, tpke_privkey:serialize(SK), BatchSize)) || {I, SK} <- enumerate(PrivateKeys) ],
Msgs = [ crypto:strong_rand_bytes(128) || _ <- lists:seq(1, N*20)],
%% feed the badgers some msgs
lists:foreach(fun(Msg) ->
Expand Down
6 changes: 4 additions & 2 deletions test/hbbft_distributed_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ simple_test(Config) ->
%% master starts the dealer
N = length(Nodes),
F = (N div 3),
BatchSize = 20,
dealer:start_link(N, F+1, 'SS512'),
{ok, PubKey, PrivateKeys} = dealer:deal(),
gen_server:stop(dealer),
Expand All @@ -70,7 +71,7 @@ simple_test(Config) ->
end, Nodes),

%% start a hbbft_worker on each node
Workers = [{Node, rpc:call(Node, hbbft_worker, start_link, [N, F, I, tpke_privkey:serialize(SK)])} || {I, {Node, SK}} <- enumerate(NodesSKs)],
Workers = [{Node, rpc:call(Node, hbbft_worker, start_link, [N, F, I, tpke_privkey:serialize(SK), BatchSize])} || {I, {Node, SK}} <- enumerate(NodesSKs)],
ok = global:sync(),

[ link(W) || {_, {ok, W}} <- Workers ],
Expand Down Expand Up @@ -137,6 +138,7 @@ serialization_test(Config) ->
%% master starts the dealer
N = length(Nodes),
F = (N div 3),
BatchSize = 20,
dealer:start_link(N, F+1, 'SS512'),
{ok, PubKey, PrivateKeys} = dealer:deal(),
gen_server:stop(dealer),
Expand All @@ -151,7 +153,7 @@ serialization_test(Config) ->
end, Nodes),

%% start a hbbft_worker on each node
Workers = [{Node, rpc:call(Node, hbbft_worker, start_link, [N, F, I, tpke_privkey:serialize(SK)])} || {I, {Node, SK}} <- enumerate(NodesSKs)],
Workers = [{Node, rpc:call(Node, hbbft_worker, start_link, [N, F, I, tpke_privkey:serialize(SK), BatchSize])} || {I, {Node, SK}} <- enumerate(NodesSKs)],
ok = global:sync(),

[ link(W) || {_, {ok, W}} <- Workers ],
Expand Down
10 changes: 5 additions & 5 deletions test/hbbft_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-include_lib("../src/hbbft.hrl").
-behaviour(gen_server).

-export([start_link/4, submit_transaction/2, get_blocks/1]).
-export([start_link/5, submit_transaction/2, get_blocks/1]).
-export([verify_chain/2, block_transactions/1]).

-export([init/1, handle_call/3, handle_cast/2, handle_info/2]).
Expand All @@ -24,8 +24,8 @@
ssk :: tpke_privkey:privkey_serialized()
}).

start_link(N, F, ID, SK) ->
gen_server:start_link({global, name(ID)}, ?MODULE, [N, F, ID, SK], []).
start_link(N, F, ID, SK, BatchSize) ->
gen_server:start_link({global, name(ID)}, ?MODULE, [N, F, ID, SK, BatchSize], []).

submit_transaction(Msg, Pid) ->
gen_server:call(Pid, {submit_txn, Msg}, infinity).
Expand Down Expand Up @@ -90,11 +90,11 @@ verify_block_fit([A, B | _], PubKey) ->
block_transactions(Block) ->
Block#block.transactions.

init([N, F, ID, SK]) ->
init([N, F, ID, SK, BatchSize]) ->
%% deserialize the secret key once
DSK = tpke_privkey:deserialize(SK),
%% init hbbft
HBBFT = hbbft:init(DSK, N, F, ID, 20),
HBBFT = hbbft:init(DSK, N, F, ID, BatchSize),
%% store the serialized state and serialized SK
{ok, #state{hbbft=HBBFT, blocks=[], id=ID, n=N, sk=DSK, ssk=SK}}.

Expand Down

0 comments on commit 6a7d3b6

Please sign in to comment.