From 5ee3f509cd9791bc666182c78fe14530c21fc283 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Tue, 3 Jan 2023 18:01:29 -0800 Subject: [PATCH] Handle the fact that encode_list can truncate the proposed list Because encode_list can truncate proposals over 1mb, the local "decrypted" entry for our own proposal needs to account for truncation. To achieve this we simply use decode_list on the encoded list and recover the transactions we actually encoded instead of using the raw list we selected. --- src/hbbft.erl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/hbbft.erl b/src/hbbft.erl index 097d204..20363a4 100644 --- a/src/hbbft.erl +++ b/src/hbbft.erl @@ -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) @@ -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) -> @@ -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) @@ -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 ->