Update Tendermint to 0.20.0

parent 70cf673f
Pipeline #23720972 canceled with stages
......@@ -15,7 +15,7 @@ PROJECT_DESCRIPTION = A simple cryptocurrency using Tendermint
PROJECT_VERSION = 0.1.0
DEPS = abci_server dynarec erlsha2 gb_merkle_trees jiffy libsodium nist_beacon
dep_abci_server = git https://github.com/KrzysiekJ/abci_server.git v0.5.0
dep_abci_server = git https://github.com/KrzysiekJ/abci_server.git 2f38de3b21dfb463ec33f54f6c08b7ce63c27f56
dep_dynarec = git https://github.com/dieswaytoofast/dynarec.git 1f477
dep_erlsha2 = git https://github.com/vinoski/erlsha2 e3434b33cfeea02609bbf877954d856d895b9e1d
dep_gb_merkle_trees = git https://github.com/KrzysiekJ/gb_merkle_trees.git 1687f8be1187cf0964e63012b175b286af69c21a
......
......@@ -58,8 +58,9 @@ terminate(_Reason, _State, _Data) ->
ok.
uninitialized({call, From}, #'RequestInitChain'{app_state_bytes=AppStateJSON}, none) ->
Data = binary_to_term(base64:decode(jiffy:decode(AppStateJSON))),
{next_state, gossiping, Data, {reply, From, #'ResponseInitChain'{}}};
Data = #data{validators=Validators} = binary_to_term(base64:decode(jiffy:decode(AppStateJSON))),
TendermintValidators = [#'Validator'{pub_key=#'PubKey'{data=PK, type="ed25519"}, power=Power} || {PK, <<Power, _/binary>>} <- gb_merkle_trees:to_orddict(Validators)],
{next_state, gossiping, Data, {reply, From, #'ResponseInitChain'{validators=TendermintValidators}}};
uninitialized({call, From}, #'RequestInfo'{}, _) ->
Reply = #'ResponseInfo'{last_block_height=0, last_block_app_hash= <<>>},
{keep_state_and_data, {reply, From, Reply}}.
......@@ -70,7 +71,7 @@ gossiping(internal, dump_data, Data) ->
gossiping(
{call, From},
#'RequestBeginBlock'{
absent_validators=AbsentValidatorsIndices,
validators=SigningValidators,
header=#'Header'{time=NewTimestamp}},
Data=
#data{
......@@ -87,16 +88,20 @@ gossiping(
_ ->
OldLastEpochEnd
end,
ValidatorsList = gb_merkle_trees:to_orddict(Validators),
NewValidators =
lists:foldl(
fun (I, Acc) ->
{PK, <<Power, Absencies:3/unit:8, VoteBin/binary>>} = lists:nth(I + 1, ValidatorsList),
NewAbsencies = Absencies + 1,
gb_merkle_trees:enter(PK, <<Power, NewAbsencies:3/unit:8, VoteBin/binary>>, Acc)
fun (#'SigningValidator'{signed_last_block=Signed, validator=#'Validator'{pub_key=#'PubKey'{data=PK}}}, Acc) ->
case Signed of
true ->
Acc;
false ->
<<Power, Absencies:3/unit:8, VoteBin/binary>> = gb_merkle_trees:lookup(PK, Validators),
NewAbsencies = Absencies + 1,
gb_merkle_trees:enter(PK, <<Power, NewAbsencies:3/unit:8, VoteBin/binary>>, Acc)
end
end,
Validators,
AbsentValidatorsIndices),
SigningValidators),
NewData =
Data#data{
validators=NewValidators,
......@@ -205,12 +210,11 @@ calculate_diffs(New, Old) ->
[],
Tree)
end,
%% pub_key in Tendermint is prefixed with type byte (1 for Ed25519).
DeletedEntries = [#'Validator'{pub_key= <<1, PK/binary>>, power=0} || PK <- KeysFun(Old) -- KeysFun(New)],
DeletedEntries = [#'Validator'{pub_key=#'PubKey'{data=PK, type="ed25519"}, power=0} || PK <- KeysFun(Old) -- KeysFun(New)],
NewEntries =
[begin
<<VP, _/binary>> = Value,
#'Validator'{pub_key= <<1, PK/binary>>, power=VP}
#'Validator'{pub_key=#'PubKey'{data=PK, type="ed25519"}, power=VP}
end || {PK, Value} <- gb_merkle_trees:to_orddict(New) -- gb_merkle_trees:to_orddict(Old)],
NewEntries ++ DeletedEntries.
......
......@@ -17,10 +17,6 @@
-compile({parse_transform, dynarec}).
-spec uniqify_list(list(any())) -> list(any()).
uniqify_list(L) ->
sets:to_list(sets:from_list(L)).
-spec end_block(data()) -> data().
end_block(Data) ->
{keep_state, NewData, {reply, "from", #'ResponseEndBlock'{}}} =
......@@ -30,7 +26,7 @@ end_block(Data) ->
-spec apply_diffs(list(#'Validator'{}), gb_merkle_trees:tree()) -> gb_merkle_trees:tree().
apply_diffs([], Validators) ->
Validators;
apply_diffs([#'Validator'{power=VP, pub_key= <<1, PubKey/binary>>}|Diffs], Validators) ->
apply_diffs([#'Validator'{power=VP, pub_key=#'PubKey'{data=PubKey, type="ed25519"}}|Diffs], Validators) ->
NewValidators =
case VP of
0 ->
......@@ -46,17 +42,25 @@ apply_diffs([#'Validator'{power=VP, pub_key= <<1, PubKey/binary>>}|Diffs], Valid
gb_merkle_trees:enter(PubKey, <<VP, RestBin/binary>>, Validators)
end,
apply_diffs(Diffs, NewValidators).
-spec data_to_app_state_bytes(data()) -> binary().
data_to_app_state_bytes(Data) ->
iolist_to_binary(io_lib:format("\"~s\"", [base64:encode(term_to_binary(Data))])).
prop_init_chain_sets_data() ->
prop_init_chain_sets_data_and_responds_with_validators() ->
?FORALL(
Data,
Data=#data{validators=Validators},
data(),
{next_state, gossiping, Data, {reply, foo, #'ResponseInitChain'{}}} =:=
ercoin_abci:uninitialized(
{call, foo},
#'RequestInitChain'{
app_state_bytes=iolist_to_binary(io_lib:format("\"~s\"", [base64:encode(term_to_binary(Data))]))},
none)).
begin
{next_state, gossiping, ResponseData, {reply, foo, #'ResponseInitChain'{validators=ResponseValidators}}} =
ercoin_abci:uninitialized(
{call, foo},
#'RequestInitChain'{
app_state_bytes=data_to_app_state_bytes(Data)},
none),
ResponseData =:= Data andalso
ResponseValidators =:= [#'Validator'{power=Power, pub_key=#'PubKey'{data=PK, type="ed25519"}} || {PK, <<Power, _/binary>>} <- gb_merkle_trees:to_orddict(Validators)]
end).
prop_validators_at_end_block() ->
?FORALL(
......@@ -310,28 +314,34 @@ prop_commit_responds_with_app_hash() ->
prop_begin_block_increments_absencies() ->
?FORALL(
{Data=#data{validators=Validators}, AbsentValidators, Header},
{Data=#data{validators=Validators}, SigningValidators, Header},
?LET(
Data=#data{validators=Validators},
data(),
{Data,
?LET(
AbsentValidatorsNonUnique,
list(elements(lists:seq(0, gb_merkle_trees:size(Validators) - 1))),
uniqify_list(AbsentValidatorsNonUnique)),
header(Data)}),
?LET(
{SignedList, Header},
{vector(gb_merkle_trees:size(Validators), bool()), header(Data)},
{Data,
[#'SigningValidator'{
signed_last_block=Signed,
validator=#'Validator'{pub_key=#'PubKey'{data=PK}, power=Power}}
|| {{PK, <<Power, _/binary>>}, Signed} <- lists:zip(gb_merkle_trees:to_orddict(Validators), SignedList)],
Header})),
begin
{next_state, committing, #data{validators=ResponseValidators}, {reply, "from", #'ResponseBeginBlock'{}}} =
ercoin_abci:gossiping({call, "from"}, #'RequestBeginBlock'{absent_validators=AbsentValidators, header=Header}, Data),
ValidatorsList = gb_merkle_trees:to_orddict(Validators),
ResponseValidatorsList = gb_merkle_trees:to_orddict(ResponseValidators),
ercoin_abci:gossiping({call, "from"}, #'RequestBeginBlock'{validators=SigningValidators, header=Header}, Data),
lists:all(
fun (I) ->
{_, <<_, Absencies:3/unit:8, _/binary>>} = lists:nth(I + 1, ValidatorsList),
{_, <<_, ResponseAbsencies:3/unit:8, _/binary>>} = lists:nth(I + 1, ResponseValidatorsList),
ResponseAbsencies =:= Absencies + 1
fun (#'SigningValidator'{signed_last_block=Signed, validator=#'Validator'{pub_key=#'PubKey'{data=PK}}}) ->
<<_, Absencies:3/unit:8, _/binary>> = gb_merkle_trees:lookup(PK, Validators),
<<_, ResponseAbsencies:3/unit:8, _/binary>> = gb_merkle_trees:lookup(PK, ResponseValidators),
case Signed of
true ->
ResponseAbsencies =:= Absencies;
false ->
ResponseAbsencies =:= Absencies + 1
end
end,
AbsentValidators)
SigningValidators)
end).
prop_begin_block_updates_timestamps() ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment