Skip to content

Commit

Permalink
Merge pull request #79 from helium/adt/account-for-truncated-proposals
Browse files Browse the repository at this point in the history
Handle the fact that encode_list can truncate the proposed list
  • Loading branch information
Vagabond authored Jan 4, 2023
2 parents 16a75ba + 5ee3f50 commit d6d5115
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/hbbft.erl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,12 @@ start_on_demand(
{M, F, A} -> erlang:apply(M, F, A)
end,
true = is_binary(Stamp),
EncX = encrypt(KeyShare, encode_list([Stamp|Proposed])),
Encoded = encode_list([Stamp|Proposed]),
EncX = encrypt(KeyShare, Encoded),
%% encode_list can truncate large proposals, so determine what we actually proposed
%% so we can track it locally
[Stamp | ActuallyProposed ] = decode_list(Encoded, []),

%% time to kick off a round
{NewACSState, {send, ACSResponse}} = hbbft_acs:input(Data#hbbft_data.acs, EncX),
%% add this to acs set in data and send out the ACS response(s)
Expand All @@ -213,7 +218,7 @@ start_on_demand(
acs = NewACSState,
acs_init = true,
stamps = lists:keystore(J, 1, Stamps, {J, Stamp}),
decrypted = maps:put(J, Proposed, Decrypted)
decrypted = maps:put(J, ActuallyProposed, Decrypted)
},
{send, hbbft_utils:wrap({acs, Data#hbbft_data.round}, ACSResponse)}};
start_on_demand(Data) ->
Expand Down Expand Up @@ -670,7 +675,11 @@ maybe_start_acs(
{M, F, A} -> erlang:apply(M, F, A)
end,
true = is_binary(Stamp),
EncX = encrypt(KeyShare, encode_list([Stamp|Proposed])),
Encoded = encode_list([Stamp|Proposed]),
EncX = encrypt(KeyShare, Encoded),
%% encode_list can truncate large proposals, so determine what we actually proposed
%% so we can track it locally
[Stamp | ActuallyProposed ] = decode_list(Encoded, []),
%% time to kick off a round
{NewACSState, {send, ACSResponse}} = hbbft_acs:input(Data#hbbft_data.acs, EncX),
%% add this to acs set in data and send out the ACS response(s)
Expand All @@ -681,7 +690,7 @@ maybe_start_acs(
acs = NewACSState,
acs_init = true,
stamps = lists:keystore(J, 1, Stamps, {J, Stamp}),
decrypted = maps:put(J, Proposed, Decrypted)
decrypted = maps:put(J, ActuallyProposed, Decrypted)
},
{send, hbbft_utils:wrap({acs, Data#hbbft_data.round}, ACSResponse)}};
false ->
Expand Down

0 comments on commit d6d5115

Please sign in to comment.