From 103c47f43bca07c9197e552084b0c6ab7fa66607 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Fri, 2 Aug 2019 16:16:57 -0700 Subject: [PATCH 01/11] refactor vars into ct, split them, add to dkg --- rebar.lock | 2 +- test/miner_blockchain_SUITE.erl | 52 ++++-------------------- test/miner_ct_utils.erl | 68 +++++++++++++++++++++++++++++++- test/miner_dkg_SUITE.erl | 6 ++- test/miner_libp2p_SUITE.erl | 1 + test/miner_payment_txn_SUITE.erl | 51 +++--------------------- test/miner_poc_SUITE.erl | 52 ++++-------------------- test/miner_reward_SUITE.erl | 52 ++++-------------------- test/miner_router_SUITE.erl | 50 +++++------------------ 9 files changed, 110 insertions(+), 224 deletions(-) diff --git a/rebar.lock b/rebar.lock index b6a7bc644..f364ba543 100644 --- a/rebar.lock +++ b/rebar.lock @@ -3,7 +3,7 @@ {<<"base32">>,{pkg,<<"base32">>,<<"0.1.0">>},3}, {<<"blockchain">>, {git,"git@github.com:helium/blockchain-core.git", - {ref,"b0bd97938ae06fe8915c207cc5352f6bbae1d5f6"}}, + {ref,"e42e28992f58e9b3ca02bbd1a734dcabd9f3a986"}}, 0}, {<<"clique">>, {git,"https://github.com/helium/clique.git", diff --git a/test/miner_blockchain_SUITE.erl b/test/miner_blockchain_SUITE.erl index 942a58bb9..6e82eba21 100644 --- a/test/miner_blockchain_SUITE.erl +++ b/test/miner_blockchain_SUITE.erl @@ -45,54 +45,16 @@ init_per_testcase(TestCase, Config0) -> Interval = proplists:get_value(election_interval, Config), BatchSize = proplists:get_value(batch_size, Config), Curve = proplists:get_value(dkg_curve, Config), - %% VarCommitInterval = proplists:get_value(var_commit_interval, Config), - #{secret := Priv, public := Pub} = + #{secret := Priv, public := Pub} = Keys = libp2p_crypto:generate_keys(ecc_compact), - Vars = #{?block_time => BlockTime, - ?election_interval => Interval, - ?election_restart_interval => 10, - ?num_consensus_members => NumConsensusMembers, - ?batch_size => BatchSize, - ?vars_commit_delay => 5, - ?var_gw_inactivity_threshold => 20, - ?block_version => v1, - ?dkg_curve => Curve, - garbage_value => totes_garb, - ?predicate_callback_mod => miner, - ?predicate_callback_fun => test_version, - ?predicate_threshold => 0.85, - ?monthly_reward => 50000 * 1000000, - ?securities_percent => 0.35, - ?dc_percent => 0, - ?poc_challengees_percent => 0.19 + 0.16, - ?poc_challengers_percent => 0.09 + 0.06, - ?poc_witnesses_percent => 0.02 + 0.03, - ?consensus_percent => 0.10, - ?election_selection_pct => 60, - ?election_replacement_factor => 4, - ?election_replacement_slope => 20, - ?min_score => 0.2, - ?alpha_decay => 0.007, - ?beta_decay => 0.0005, - ?max_staleness => 100000, - ?min_assert_h3_res => 12, - ?h3_neighbor_res => 12, - ?h3_max_grid_distance => 13, - ?h3_exclusion_ring_dist => 2, - ?poc_challenge_interval => 10 - }, - - BinPub = libp2p_crypto:pubkey_to_bin(Pub), - KeyProof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - - ct:pal("master key ~p~n priv ~p~n vars ~p~n keyproof ~p~n artifact ~p", - [BinPub, Priv, Vars, KeyProof, - term_to_binary(Vars, [{compressed, 9}])]), - - InitialVars = [ blockchain_txn_vars_v1:new(Vars, <<>>, 1, #{master_key => BinPub, - key_proof => KeyProof}) ], + InitialVars = miner_ct_utils:make_vars(Keys, #{garbage_value => totes_garb, + ?block_time => BlockTime, + ?election_interval => Interval, + ?num_consensus_members => NumConsensusMembers, + ?batch_size => BatchSize, + ?dkg_curve => Curve}), InitialPayment = [ blockchain_txn_coinbase_v1:new(Addr, 5000) || Addr <- Addresses], Locations = lists:foldl( diff --git a/test/miner_ct_utils.erl b/test/miner_ct_utils.erl index 740d0335f..736c0cdd9 100644 --- a/test/miner_ct_utils.erl +++ b/test/miner_ct_utils.erl @@ -1,5 +1,8 @@ -module(miner_ct_utils). +-include_lib("eunit/include/eunit.hrl"). +-include_lib("blockchain/include/blockchain_vars.hrl"). + -export([pmap/2, pmap/3, wait_until/1, wait_until/3, @@ -14,7 +17,8 @@ random_n/2, init_per_testcase/2, end_per_testcase/2, - get_balance/2 + get_balance/2, + make_vars/1, make_vars/2 ]). pmap(F, L) -> @@ -291,3 +295,65 @@ get_balance(Miner, Addr) -> Ledger = ct_rpc:call(Miner, blockchain, ledger, [Chain]), {ok, Entry} = ct_rpc:call(Miner, blockchain_ledger_v1, find_entry, [Addr, Ledger]), ct_rpc:call(Miner, blockchain_ledger_entry_v1, balance, [Entry]). + +make_vars(Keys) -> + make_vars(Keys, #{}). + +make_vars(Keys, Map) -> + Vars1 = #{?block_time => 1, + ?election_interval => 30, + ?election_restart_interval => 10, + ?num_consensus_members => 7, + ?batch_size => 2500, + ?vars_commit_delay => 5, + ?var_gw_inactivity_threshold => 20, + ?block_version => v1, + ?dkg_curve => 'SS512', + ?poc_path_limit => 7, + ?predicate_callback_mod => miner, + ?predicate_callback_fun => test_version, + ?predicate_threshold => 0.85, + ?monthly_reward => 50000 * 1000000, + ?securities_percent => 0.35, + ?dc_percent => 0, + ?poc_challengees_percent => 0.19 + 0.16, + ?poc_challengers_percent => 0.09 + 0.06, + ?poc_witnesses_percent => 0.02 + 0.03, + ?consensus_percent => 0.10, + ?election_selection_pct => 60, + ?election_replacement_factor => 4, + ?election_replacement_slope => 20, + ?min_score => 0.2, + ?alpha_decay => 0.007, + ?beta_decay => 0.0005, + ?max_staleness => 100000, + ?min_assert_h3_res => 12, + ?h3_neighbor_res => 12, + ?h3_max_grid_distance => 13, + ?h3_exclusion_ring_dist => 2, + ?poc_challenge_interval => 10 + }, + Vars = maps:merge(Vars1, Map), + + Size = maps:size(Vars), + VarKeys = maps:keys(Vars), + {One, Two} = lists:split(Size div 2, VarKeys), + MOne = maps:with(One, Vars), + MTwo = maps:with(Two, Vars), + ?assert(maps:size(MOne) =< 32), + ?assert(maps:size(MTwo) =< 32), + + #{secret := Priv, public := Pub} = Keys, + BinPub = libp2p_crypto:pubkey_to_bin(Pub), + + KeyProof1 = blockchain_txn_vars_v1:create_proof(Priv, MOne), + KeyProof2 = blockchain_txn_vars_v1:create_proof(Priv, MTwo), + + %% ct:pal("master key ~p~n priv ~p~n vars ~p~n keyproof ~p~n artifact ~p", + %% [BinPub, Priv, Vars, KeyProof, + %% term_to_binary(Vars, [{compressed, 9}])]), + + [ blockchain_txn_vars_v1:new(MOne, <<>>, 1, #{master_key => BinPub, + key_proof => KeyProof1}), + blockchain_txn_vars_v1:new(MTwo, <<>>, 2, #{master_key => BinPub, + key_proof => KeyProof2}) ]. diff --git a/test/miner_dkg_SUITE.erl b/test/miner_dkg_SUITE.erl index ab40e4e4f..e7146ab27 100644 --- a/test/miner_dkg_SUITE.erl +++ b/test/miner_dkg_SUITE.erl @@ -37,14 +37,18 @@ end_per_testcase(_TestCase, Config) -> initial_dkg_test(Config) -> Miners = proplists:get_value(miners, Config), Addresses = proplists:get_value(addresses, Config), + Keys = libp2p_crypto:generate_keys(ecc_compact), + + InitialVars = miner_ct_utils:make_vars(Keys, #{}), InitialPaymentTransactions = [blockchain_txn_coinbase_v1:new(Addr, 5000) || Addr <- Addresses], + InitialTransactions = InitialVars ++ InitialPaymentTransactions, N = proplists:get_value(num_consensus_members, Config), Curve = proplists:get_value(dkg_curve, Config), DKGResults = miner_ct_utils:pmap( fun(Miner) -> ct_rpc:call(Miner, miner_consensus_mgr, initial_dkg, - [InitialPaymentTransactions, Addresses, N, Curve], + [InitialTransactions, Addresses, N, Curve], timer:seconds(60)) end, Miners), ?assertEqual([ok], lists:usort(DKGResults)), diff --git a/test/miner_libp2p_SUITE.erl b/test/miner_libp2p_SUITE.erl index ac8b1854f..a1bfc0211 100644 --- a/test/miner_libp2p_SUITE.erl +++ b/test/miner_libp2p_SUITE.erl @@ -3,6 +3,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -include_lib("kernel/include/inet.hrl"). +-include_lib("blockchain/include/blockchain_vars.hrl"). -export([ init_per_suite/1 diff --git a/test/miner_payment_txn_SUITE.erl b/test/miner_payment_txn_SUITE.erl index e267651a5..6c29e105c 100644 --- a/test/miner_payment_txn_SUITE.erl +++ b/test/miner_payment_txn_SUITE.erl @@ -45,52 +45,13 @@ init_per_testcase(_TestCase, Config0) -> Curve = proplists:get_value(dkg_curve, Config), %% VarCommitInterval = proplists:get_value(var_commit_interval, Config), - #{secret := Priv, public := Pub} = - libp2p_crypto:generate_keys(ecc_compact), - - Vars = #{?block_time => BlockTime, - ?election_interval => Interval, - ?election_restart_interval => 10, - ?num_consensus_members => N, - ?batch_size => BatchSize, - ?vars_commit_delay => 2, - ?var_gw_inactivity_threshold => 20, - ?block_version => v1, - ?dkg_curve => Curve, - ?predicate_callback_mod => miner, - ?predicate_callback_fun => test_version, - ?predicate_threshold => 0.85, - ?monthly_reward => 0, - ?securities_percent => 0, - ?dc_percent => 0, - ?poc_challengees_percent => 0, - ?poc_challengers_percent => 0, - ?poc_witnesses_percent => 0, - ?consensus_percent => 0, - ?election_selection_pct => 60, - ?election_replacement_factor => 4, - ?election_replacement_slope => 20, - ?min_score => 0.2, - ?alpha_decay => 0.007, - ?beta_decay => 0.0005, - ?max_staleness => 100000, - ?min_assert_h3_res => 12, - ?h3_neighbor_res => 12, - ?h3_max_grid_distance => 13, - ?h3_exclusion_ring_dist => 2, - ?poc_challenge_interval => 30 - }, - - BinPub = libp2p_crypto:pubkey_to_bin(Pub), - KeyProof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - - ct:pal("master key ~p~n priv ~p~n vars ~p~n keyproof ~p~n artifact ~p", - [BinPub, Priv, Vars, KeyProof, - term_to_binary(Vars, [{compressed, 9}])]), - - InitialVars = [ blockchain_txn_vars_v1:new(Vars, <<>>, 1, #{master_key => BinPub, - key_proof => KeyProof}) ], + Keys = libp2p_crypto:generate_keys(ecc_compact), + InitialVars = miner_ct_utils:make_vars(Keys, #{?block_time => BlockTime, + ?election_interval => Interval, + ?num_consensus_members => N, + ?batch_size => BatchSize, + ?dkg_curve => Curve}), DKGResults = miner_ct_utils:pmap( fun(Miner) -> ct_rpc:call(Miner, miner_consensus_mgr, initial_dkg, diff --git a/test/miner_poc_SUITE.erl b/test/miner_poc_SUITE.erl index ed08c03a5..fd639a57e 100644 --- a/test/miner_poc_SUITE.erl +++ b/test/miner_poc_SUITE.erl @@ -47,51 +47,13 @@ dist(Config0) -> Curve = proplists:get_value(dkg_curve, Config), %% VarCommitInterval = proplists:get_value(var_commit_interval, Config), - #{secret := Priv, public := Pub} = - libp2p_crypto:generate_keys(ecc_compact), - - Vars = #{?block_time => BlockTime, - ?election_interval => Interval, - ?election_restart_interval => 10, - ?num_consensus_members => N, - ?batch_size => BatchSize, - ?vars_commit_delay => 2, - ?var_gw_inactivity_threshold => 20, - ?block_version => v1, - ?dkg_curve => Curve, - ?predicate_callback_mod => miner, - ?predicate_callback_fun => test_version, - ?predicate_threshold => 0.85, - ?monthly_reward => 50000 * 1000000, - ?securities_percent => 0.35, - ?dc_percent => 0, - ?poc_challengees_percent => 0.19 + 0.16, - ?poc_challengers_percent => 0.09 + 0.06, - ?poc_witnesses_percent => 0.02 + 0.03, - ?consensus_percent => 0.10, - ?election_selection_pct => 60, - ?election_replacement_factor => 4, - ?election_replacement_slope => 20, - ?min_score => 0.2, - ?alpha_decay => 0.007, - ?beta_decay => 0.0005, - ?max_staleness => 100000, - ?min_assert_h3_res => 12, - ?h3_neighbor_res => 12, - ?h3_max_grid_distance => 13, - ?h3_exclusion_ring_dist => 2, - ?poc_challenge_interval => 20 - }, - - BinPub = libp2p_crypto:pubkey_to_bin(Pub), - KeyProof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - - ct:pal("master key ~p~n priv ~p~n vars ~p~n keyproof ~p~n artifact ~p", - [BinPub, Priv, Vars, KeyProof, - term_to_binary(Vars, [{compressed, 9}])]), - - InitialVars = [ blockchain_txn_vars_v1:new(Vars, <<>>, 1, #{master_key => BinPub, - key_proof => KeyProof}) ], + Keys = libp2p_crypto:generate_keys(ecc_compact), + + InitialVars = miner_ct_utils:make_vars(Keys, #{?block_time => BlockTime, + ?election_interval => Interval, + ?num_consensus_members => N, + ?batch_size => BatchSize, + ?dkg_curve => Curve}), InitialPaymentTransactions = [blockchain_txn_coinbase_v1:new(Addr, 5000) || Addr <- Addresses], Locations = lists:foldl( diff --git a/test/miner_reward_SUITE.erl b/test/miner_reward_SUITE.erl index 4d39a864c..9693f640b 100644 --- a/test/miner_reward_SUITE.erl +++ b/test/miner_reward_SUITE.erl @@ -42,51 +42,13 @@ init_per_testcase(_TestCase, Config0) -> BatchSize = proplists:get_value(batch_size, Config), Curve = proplists:get_value(dkg_curve, Config), - #{secret := Priv, public := Pub} = - libp2p_crypto:generate_keys(ecc_compact), - - Vars = #{?block_time => BlockTime, - ?election_interval => Interval, - ?election_restart_interval => 5, - ?num_consensus_members => N, - ?batch_size => BatchSize, - ?vars_commit_delay => 2, - ?var_gw_inactivity_threshold => 20, - ?block_version => v1, - ?dkg_curve => Curve, - ?predicate_callback_mod => miner, - ?predicate_callback_fun => test_version, - ?predicate_threshold => 0.85, - ?monthly_reward => 50000 * 1000000, - ?securities_percent => 0.35, - ?dc_percent => 0, - ?poc_challengees_percent => 0.19 + 0.16, - ?poc_challengers_percent => 0.09 + 0.06, - ?poc_witnesses_percent => 0.02 + 0.03, - ?consensus_percent => 0.10, - ?election_selection_pct => 60, - ?election_replacement_factor => 4, - ?election_replacement_slope => 20, - ?min_score => 0.2, - ?alpha_decay => 0.007, - ?beta_decay => 0.0005, - ?max_staleness => 100000, - ?min_assert_h3_res => 12, - ?h3_neighbor_res => 12, - ?h3_max_grid_distance => 13, - ?h3_exclusion_ring_dist => 2, - ?poc_challenge_interval => 30 - }, - - BinPub = libp2p_crypto:pubkey_to_bin(Pub), - KeyProof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - - ct:pal("master key ~p~n priv ~p~n vars ~p~n keyproof ~p~n artifact ~p", - [BinPub, Priv, Vars, KeyProof, - term_to_binary(Vars, [{compressed, 9}])]), - - InitialVars = [ blockchain_txn_vars_v1:new(Vars, <<>>, 1, #{master_key => BinPub, - key_proof => KeyProof}) ], + Keys = libp2p_crypto:generate_keys(ecc_compact), + + InitialVars = miner_ct_utils:make_vars(Keys, #{?block_time => BlockTime, + ?election_interval => Interval, + ?num_consensus_members => N, + ?batch_size => BatchSize, + ?dkg_curve => Curve}), DKGResults = miner_ct_utils:pmap( fun(Miner) -> diff --git a/test/miner_router_SUITE.erl b/test/miner_router_SUITE.erl index 3bff52df1..9b0e7975a 100644 --- a/test/miner_router_SUITE.erl +++ b/test/miner_router_SUITE.erl @@ -4,6 +4,8 @@ -include_lib("eunit/include/eunit.hrl"). -include_lib("kernel/include/inet.hrl"). -include_lib("helium_proto/src/pb/helium_longfi_pb.hrl"). +-include_lib("blockchain/include/blockchain_vars.hrl"). + -export([ init_per_testcase/2, @@ -43,47 +45,13 @@ init_per_testcase(_TestCase, Config0) -> Curve = proplists:get_value(dkg_curve, Config), %% VarCommitInterval = proplists:get_value(var_commit_interval, Config), - #{secret := Priv, public := Pub} = - libp2p_crypto:generate_keys(ecc_compact), - - Vars = #{block_time => BlockTime, - election_interval => Interval, - election_restart_interval => 10, - num_consensus_members => N, - batch_size => BatchSize, - vars_commit_delay => 2, - block_version => v1, - dkg_curve => Curve, - predicate_callback_mod => miner, - predicate_callback_fun => test_version, - proposal_threshold => 0.85, - monthly_reward => 0, - securities_percent => 0, - dc_percent => 0, - poc_challengees_percent => 0, - poc_challengers_percent => 0, - poc_witnesses_percent => 0, - consensus_percent => 0, - election_selection_pct => 60, - election_replacement_factor => 4, - election_replacement_slope => 20, - min_score => 0.2, - h3_ring_size => 2, - h3_path_res => 8, - alpha_decay => 0.007, - beta_decay => 0.0005, - max_staleness => 100000 - }, - - BinPub = libp2p_crypto:pubkey_to_bin(Pub), - KeyProof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - - ct:pal("master key ~p~n priv ~p~n vars ~p~n keyproof ~p~n artifact ~p", - [BinPub, Priv, Vars, KeyProof, - term_to_binary(Vars, [{compressed, 9}])]), - - InitialVars = [ blockchain_txn_vars_v1:new(Vars, <<>>, 1, #{master_key => BinPub, - key_proof => KeyProof}) ], + Keys = libp2p_crypto:generate_keys(ecc_compact), + + InitialVars = miner_ct_utils:make_vars(Keys, #{?block_time => BlockTime, + ?election_interval => Interval, + ?num_consensus_members => N, + ?batch_size => BatchSize, + ?dkg_curve => Curve}), DKGResults = miner_ct_utils:pmap( fun(Miner) -> From f38cc2ca763f650d8a8fe38181b7874d3bf18362 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Fri, 2 Aug 2019 16:19:33 -0700 Subject: [PATCH 02/11] change nonces to work --- test/miner_blockchain_SUITE.erl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/miner_blockchain_SUITE.erl b/test/miner_blockchain_SUITE.erl index 6e82eba21..fb1f27554 100644 --- a/test/miner_blockchain_SUITE.erl +++ b/test/miner_blockchain_SUITE.erl @@ -296,7 +296,7 @@ group_change_test(Config) -> Proof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - Txn = blockchain_txn_vars_v1:new(Vars, Proof, 2, #{version_predicate => 2, + Txn = blockchain_txn_vars_v1:new(Vars, Proof, 3, #{version_predicate => 2, unsets => [garbage_value]}), %% wait for it to take effect @@ -399,7 +399,7 @@ master_key_test(Config) -> Vars = #{garbage_value => totes_goats_garb}, Proof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - ConsensusTxn = blockchain_txn_vars_v1:new(Vars, Proof, 2, #{}), + ConsensusTxn = blockchain_txn_vars_v1:new(Vars, Proof, 3, #{}), _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn]) || Miner <- Miners], @@ -425,7 +425,7 @@ master_key_test(Config) -> Proof2 = blockchain_txn_vars_v1:create_proof(Priv, Vars2), KeyProof2 = blockchain_txn_vars_v1:create_proof(Priv2, Vars2), KeyProof2Corrupted = <>, - ConsensusTxn2 = blockchain_txn_vars_v1:new(Vars2, Proof2, 3, #{master_key => BinPub2, + ConsensusTxn2 = blockchain_txn_vars_v1:new(Vars2, Proof2, 4, #{master_key => BinPub2, key_proof => KeyProof2Corrupted}), {ok, Start2} = ct_rpc:call(hd(Miners), blockchain, height, [Blockchain1]), @@ -448,7 +448,7 @@ master_key_test(Config) -> %% good master key - ConsensusTxn3 = blockchain_txn_vars_v1:new(Vars2, Proof2, 4, #{master_key => BinPub2, + ConsensusTxn3 = blockchain_txn_vars_v1:new(Vars2, Proof2, 5, #{master_key => BinPub2, key_proof => KeyProof2}), _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn3]) @@ -471,7 +471,7 @@ master_key_test(Config) -> Vars4 = #{garbage_value => goats_are_too_garb}, Proof4 = blockchain_txn_vars_v1:create_proof(Priv, Vars4), - ConsensusTxn4 = blockchain_txn_vars_v1:new(Vars4, Proof4, 5, #{}), + ConsensusTxn4 = blockchain_txn_vars_v1:new(Vars4, Proof4, 6, #{}), {ok, Start4} = ct_rpc:call(hd(Miners), blockchain, height, [Blockchain1]), _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn4]) @@ -495,7 +495,7 @@ master_key_test(Config) -> Vars5 = #{garbage_value => goats_always_win}, Proof5 = blockchain_txn_vars_v1:create_proof(Priv2, Vars5), - ConsensusTxn5 = blockchain_txn_vars_v1:new(Vars5, Proof5, 6, #{}), + ConsensusTxn5 = blockchain_txn_vars_v1:new(Vars5, Proof5, 7, #{}), _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn5]) || Miner <- Miners], From 77847d31e16ab9ea57bce160561458e59d8caf8a Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Fri, 2 Aug 2019 17:01:31 -0700 Subject: [PATCH 03/11] fix poc suite, hopefully --- rebar.lock | 4 ---- test/miner_poc_SUITE.erl | 11 +++++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rebar.lock b/rebar.lock index f364ba543..322001d70 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,10 +1,6 @@ {"1.1.0", [{<<"backoff">>,{pkg,<<"backoff">>,<<"1.1.6">>},2}, {<<"base32">>,{pkg,<<"base32">>,<<"0.1.0">>},3}, - {<<"blockchain">>, - {git,"git@github.com:helium/blockchain-core.git", - {ref,"e42e28992f58e9b3ca02bbd1a734dcabd9f3a986"}}, - 0}, {<<"clique">>, {git,"https://github.com/helium/clique.git", {ref,"49c51c6d70e702d4d43d97306a4a5cbc3adf1d9d"}}, diff --git a/test/miner_poc_SUITE.erl b/test/miner_poc_SUITE.erl index fd639a57e..61cf31f2f 100644 --- a/test/miner_poc_SUITE.erl +++ b/test/miner_poc_SUITE.erl @@ -53,7 +53,8 @@ dist(Config0) -> ?election_interval => Interval, ?num_consensus_members => N, ?batch_size => BatchSize, - ?dkg_curve => Curve}), + ?dkg_curve => Curve, + ?poc_challenge_interval => 20}), InitialPaymentTransactions = [blockchain_txn_coinbase_v1:new(Addr, 5000) || Addr <- Addresses], Locations = lists:foldl( @@ -128,7 +129,13 @@ dist(Config0) -> %% load the genesis block on all the nodes lists:foreach( fun(Miner) -> - ct_rpc:call(Miner, blockchain_worker, integrate_genesis_block, [GenesisBlock]) + case ct_rpc:call(Miner, miner_consensus_mgr, in_consensus, [], 5000) of + true -> + ok; + false -> + ct_rpc:call(Miner, blockchain_worker, + integrate_genesis_block, [GenesisBlock], 5000) + end end, Miners ), From 4e9fb1b4fadcd394eeef5fda1ed1afe32989a71e Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Fri, 2 Aug 2019 17:20:58 -0700 Subject: [PATCH 04/11] readd manipulated lockfile --- rebar.lock | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rebar.lock b/rebar.lock index 322001d70..f364ba543 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,6 +1,10 @@ {"1.1.0", [{<<"backoff">>,{pkg,<<"backoff">>,<<"1.1.6">>},2}, {<<"base32">>,{pkg,<<"base32">>,<<"0.1.0">>},3}, + {<<"blockchain">>, + {git,"git@github.com:helium/blockchain-core.git", + {ref,"e42e28992f58e9b3ca02bbd1a734dcabd9f3a986"}}, + 0}, {<<"clique">>, {git,"https://github.com/helium/clique.git", {ref,"49c51c6d70e702d4d43d97306a4a5cbc3adf1d9d"}}, From 77fbecb93166da0efc6b59b0e9ec05ba7c241972 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Fri, 2 Aug 2019 17:58:33 -0700 Subject: [PATCH 05/11] try to debug payment test --- test/miner_payment_txn_SUITE.erl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/miner_payment_txn_SUITE.erl b/test/miner_payment_txn_SUITE.erl index 6c29e105c..51b92ad21 100644 --- a/test/miner_payment_txn_SUITE.erl +++ b/test/miner_payment_txn_SUITE.erl @@ -40,7 +40,6 @@ init_per_testcase(_TestCase, Config0) -> N = proplists:get_value(num_consensus_members, Config), BlockTime = proplists:get_value(block_time, Config), - Interval = proplists:get_value(election_interval, Config), BatchSize = proplists:get_value(batch_size, Config), Curve = proplists:get_value(dkg_curve, Config), %% VarCommitInterval = proplists:get_value(var_commit_interval, Config), @@ -48,7 +47,8 @@ init_per_testcase(_TestCase, Config0) -> Keys = libp2p_crypto:generate_keys(ecc_compact), InitialVars = miner_ct_utils:make_vars(Keys, #{?block_time => BlockTime, - ?election_interval => Interval, + %% rule out rewards + ?election_interval => infinity, ?num_consensus_members => N, ?batch_size => BatchSize, ?dkg_curve => Curve}), @@ -173,7 +173,7 @@ single_payment_test(Config) -> Miners -- [Candidate] ) end, - 60, + 20, timer:seconds(1) ), @@ -195,13 +195,14 @@ single_payment_test(Config) -> PayerBalance3 = miner_ct_utils:get_balance(Miner, PayerAddr), PayeeBalance3 = miner_ct_utils:get_balance(Miner, PayeeAddr), + ct:pal("payer ~p payee ~p", [PayerBalance3, PayeeBalance3]), 3000 == PayerBalance3 + Fee andalso 7000 == PayeeBalance3 end, Miners ) end, - 60, + 20, timer:seconds(1) ), ct:comment("FinalPayerBalance: ~p, FinalPayeeBalance: ~p", [PayerBalance, PayeeBalance]), From be518a131df951368bb317cdfff3f365df40cb99 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Sun, 4 Aug 2019 19:31:48 -0700 Subject: [PATCH 06/11] fortify wait_util --- test/miner_ct_utils.erl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/miner_ct_utils.erl b/test/miner_ct_utils.erl index 736c0cdd9..6ab2e7642 100644 --- a/test/miner_ct_utils.erl +++ b/test/miner_ct_utils.erl @@ -48,7 +48,7 @@ wait_until(Fun) -> wait_until(Fun, 40, 100). wait_until(Fun, Retry, Delay) when Retry > 0 -> Res = Fun(), - case Res of + try Res of true -> ok; _ when Retry == 1 -> @@ -56,6 +56,9 @@ wait_until(Fun, Retry, Delay) when Retry > 0 -> _ -> timer:sleep(Delay), wait_until(Fun, Retry-1, Delay) + catch _:_ -> + timer:sleep(Delay), + wait_until(Fun, Retry-1, Delay) end. wait_until_offline(Node) -> From b13784d967ac749a7830deb1deedd0c3834cd062 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Mon, 5 Aug 2019 10:34:48 -0700 Subject: [PATCH 07/11] harden more checks --- test/miner_blockchain_SUITE.erl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/miner_blockchain_SUITE.erl b/test/miner_blockchain_SUITE.erl index fb1f27554..530f1c97d 100644 --- a/test/miner_blockchain_SUITE.erl +++ b/test/miner_blockchain_SUITE.erl @@ -317,11 +317,10 @@ group_change_test(Config) -> end, 40, timer:seconds(1)), %% make sure we still haven't executed it - CGroup1 = lists:filtermap( - fun(Miner) -> - true == ct_rpc:call(Miner, miner_consensus_mgr, in_consensus, []) - end, Miners), - ?assertEqual(4, length(CGroup1)), + C = ct_rpc:call(hd(Miners), blockchain_worker, blockchain, []), + L = ct_rpc:call(hd(Miners), blockchain, ledger, [C]), + {ok, Members} = ct_rpc:call(hd(Miners), blockchain_ledger_v1, consensus_members, [L]), + ?assertEqual(4, length(Members)), %% alter the "version" for all of them. lists:foreach( @@ -444,7 +443,7 @@ master_key_test(Config) -> {ok, totes_goats_garb} == ct_rpc:call(Miner, blockchain, config, [garbage_value, Ledger]) end, shuffle(Miners)) - end, 40, timer:seconds(1)), + end, 60, timer:seconds(1)), %% good master key From bbc4d8ef88ec3e7d0a3da51556c29c0d668d7319 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Mon, 5 Aug 2019 10:52:35 -0700 Subject: [PATCH 08/11] harden yet more checks --- rebar.lock | 4 ---- test/miner_blockchain_SUITE.erl | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/rebar.lock b/rebar.lock index f364ba543..322001d70 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,10 +1,6 @@ {"1.1.0", [{<<"backoff">>,{pkg,<<"backoff">>,<<"1.1.6">>},2}, {<<"base32">>,{pkg,<<"base32">>,<<"0.1.0">>},3}, - {<<"blockchain">>, - {git,"git@github.com:helium/blockchain-core.git", - {ref,"e42e28992f58e9b3ca02bbd1a734dcabd9f3a986"}}, - 0}, {<<"clique">>, {git,"https://github.com/helium/clique.git", {ref,"49c51c6d70e702d4d43d97306a4a5cbc3adf1d9d"}}, diff --git a/test/miner_blockchain_SUITE.erl b/test/miner_blockchain_SUITE.erl index 530f1c97d..1ef00aa3f 100644 --- a/test/miner_blockchain_SUITE.erl +++ b/test/miner_blockchain_SUITE.erl @@ -309,12 +309,12 @@ group_change_test(Config) -> ok = miner_ct_utils:wait_until( fun() -> true == lists:all(fun(Miner) -> - C = ct_rpc:call(Miner, blockchain_worker, blockchain, []), - {ok, Ht} = ct_rpc:call(Miner, blockchain, height, [C]), + C = ct_rpc:call(Miner, blockchain_worker, blockchain, [], 500), + {ok, Ht} = ct_rpc:call(Miner, blockchain, height, [C], 500), ct:pal("miner ~p height ~p", [Miner, Ht]), Ht > (Height + 20) end, shuffle(Miners)) - end, 40, timer:seconds(1)), + end, 80, timer:seconds(1)), %% make sure we still haven't executed it C = ct_rpc:call(hd(Miners), blockchain_worker, blockchain, []), From a8f268da3b583f1cfcc54b4c902844817941b541 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Mon, 5 Aug 2019 11:08:59 -0700 Subject: [PATCH 09/11] fix lock again --- rebar.lock | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/rebar.lock b/rebar.lock index 322001d70..f364ba543 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,6 +1,10 @@ {"1.1.0", [{<<"backoff">>,{pkg,<<"backoff">>,<<"1.1.6">>},2}, {<<"base32">>,{pkg,<<"base32">>,<<"0.1.0">>},3}, + {<<"blockchain">>, + {git,"git@github.com:helium/blockchain-core.git", + {ref,"e42e28992f58e9b3ca02bbd1a734dcabd9f3a986"}}, + 0}, {<<"clique">>, {git,"https://github.com/helium/clique.git", {ref,"49c51c6d70e702d4d43d97306a4a5cbc3adf1d9d"}}, From 003b2f9de7e99940734753121c02108a9aa2a21b Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Tue, 6 Aug 2019 13:24:42 -0700 Subject: [PATCH 10/11] support for v2 chain vars (#168) support for v2 chain vars + some test hardening --- rebar.lock | 2 +- src/cli/miner_cli_genesis.erl | 20 +-- test/miner_blockchain_SUITE.erl | 222 ++++++++++++++++++++++++++----- test/miner_ct_utils.erl | 52 ++++---- test/miner_payment_txn_SUITE.erl | 4 +- test/miner_reward_SUITE.erl | 44 +++--- 6 files changed, 260 insertions(+), 84 deletions(-) diff --git a/rebar.lock b/rebar.lock index f364ba543..ada5ace98 100644 --- a/rebar.lock +++ b/rebar.lock @@ -3,7 +3,7 @@ {<<"base32">>,{pkg,<<"base32">>,<<"0.1.0">>},3}, {<<"blockchain">>, {git,"git@github.com:helium/blockchain-core.git", - {ref,"e42e28992f58e9b3ca02bbd1a734dcabd9f3a986"}}, + {ref,"f6df5b5a143c9668b50150dc252f74f68bf6c497"}}, 0}, {<<"clique">>, {git,"https://github.com/helium/clique.git", diff --git a/src/cli/miner_cli_genesis.erl b/src/cli/miner_cli_genesis.erl index 96442070b..f50ce5783 100644 --- a/src/cli/miner_cli_genesis.erl +++ b/src/cli/miner_cli_genesis.erl @@ -97,8 +97,8 @@ create(OldGenesisFile, PubKeyB58, ProofB58, Addrs, N, Curve) -> BinPub = libp2p_crypto:b58_to_bin(PubKeyB58), Proof = base58:base58_to_binary(ProofB58), - VarTxn = blockchain_txn_vars_v1:new(make_vars(), <<>>, 1, #{master_key => BinPub, - key_proof => Proof}), + VarTxn = blockchain_txn_vars_v1:new(make_vars(), 1, #{master_key => BinPub}), + VarTxn1 = blockchain_txn_vars_v1:key_proof(VarTxn, Proof), OldSecurities = case proplists:get_value(securities, Config) of undefined -> []; @@ -132,7 +132,7 @@ create(OldGenesisFile, PubKeyB58, ProofB58, Addrs, N, Curve) -> OldGenesisTransactions = OldAccounts ++ OldGateways ++ OldSecurities ++ OldDCs, Addresses = [libp2p_crypto:p2p_to_pubkey_bin(Addr) || Addr <- string:split(Addrs, ",", all)], - miner_consensus_mgr:initial_dkg(OldGenesisTransactions ++ [VarTxn], Addresses, N, Curve), + miner_consensus_mgr:initial_dkg(OldGenesisTransactions ++ [VarTxn1], Addresses, N, Curve), [clique_status:text("ok")]; {error, Reason} -> [clique_status:text(io_lib:format("~p", [Reason]))] @@ -170,8 +170,8 @@ forge(PubKeyB58, ProofB58, Addrs, N, Curve) -> BinPub = libp2p_crypto:b58_to_bin(PubKeyB58), Proof = base58:base58_to_binary(ProofB58), - VarTxn = blockchain_txn_vars_v1:new(make_vars(), <<>>, 1, #{master_key => BinPub, - key_proof => Proof}), + VarTxn = blockchain_txn_vars_v1:new(make_vars(), 1, #{master_key => BinPub}), + VarTxn1 = blockchain_txn_vars_v1:key_proof(VarTxn, Proof), Addresses = [libp2p_crypto:p2p_to_pubkey_bin(Addr) || Addr <- string:split(Addrs, ",", all)], InitialPaymentTransactions = [ blockchain_txn_coinbase_v1:new(Addr, 500000000) || Addr <- Addresses], @@ -182,7 +182,7 @@ forge(PubKeyB58, ProofB58, Addrs, N, Curve) -> %% NOTE: This is mostly for locally testing run.sh so we have nodes added as gateways in the genesis block InitialGatewayTransactions = [blockchain_txn_gen_gateway_v1:new(Addr, Addr, 16#8c283475d4e89ff, 0) || Addr <- Addresses ], - miner_consensus_mgr:initial_dkg([VarTxn] ++ + miner_consensus_mgr:initial_dkg([VarTxn1] ++ InitialPaymentTransactions ++ InitialGatewayTransactions ++ InitialSecurityTransactions ++ @@ -296,9 +296,13 @@ genesis_proof(["genesis", "proof", PrivKeyB58], [], []) -> PrivKeyBin = base58:base58_to_binary(PrivKeyB58), #{secret := Priv, public := Pub} = libp2p_crypto:keys_from_bin(PrivKeyBin), Vars = make_vars(), - KeyProof = blockchain_txn_vars_v1:create_proof(Priv, Vars), + + BinPub = libp2p_crypto:pubkey_to_bin(Pub), + Txn = blockchain_txn_vars_v1:new(Vars, 1, #{master_key => BinPub}), + Proof = blockchain_txn_vars_v1:create_proof(Priv, Txn), + [clique_status:text(io_lib:format("Proof:~n~s~nPubKey:~n~s", - [base58:binary_to_base58(KeyProof), + [base58:binary_to_base58(Proof), libp2p_crypto:pubkey_to_b58(Pub)]))]; genesis_proof(_, [], []) -> usage. diff --git a/test/miner_blockchain_SUITE.erl b/test/miner_blockchain_SUITE.erl index 1ef00aa3f..d7c86b36d 100644 --- a/test/miner_blockchain_SUITE.erl +++ b/test/miner_blockchain_SUITE.erl @@ -26,7 +26,8 @@ all() -> [ growth_test, election_test, group_change_test, - master_key_test + master_key_test, + version_change_test ]. init_per_suite(Config) -> @@ -49,12 +50,28 @@ init_per_testcase(TestCase, Config0) -> #{secret := Priv, public := Pub} = Keys = libp2p_crypto:generate_keys(ecc_compact), - InitialVars = miner_ct_utils:make_vars(Keys, #{garbage_value => totes_garb, - ?block_time => BlockTime, - ?election_interval => Interval, - ?num_consensus_members => NumConsensusMembers, - ?batch_size => BatchSize, - ?dkg_curve => Curve}), + Extras = + case TestCase of + _ -> + #{} + end, + + Vars = #{garbage_value => totes_garb, + ?block_time => BlockTime, + ?election_interval => Interval, + ?num_consensus_members => NumConsensusMembers, + ?batch_size => BatchSize, + ?dkg_curve => Curve}, + FinalVars = maps:merge(Vars, Extras), + ct:pal("final vars ~p", [FinalVars]), + + InitialVars = + case TestCase of + version_change_test -> + miner_ct_utils:make_vars(Keys, FinalVars, legacy); + _ -> + miner_ct_utils:make_vars(Keys, FinalVars) + end, InitialPayment = [ blockchain_txn_coinbase_v1:new(Addr, 5000) || Addr <- Addresses], Locations = lists:foldl( @@ -294,13 +311,14 @@ group_change_test(Config) -> {Priv, _Pub} = proplists:get_value(master_key, Config), - Proof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - Txn = blockchain_txn_vars_v1:new(Vars, Proof, 3, #{version_predicate => 2, - unsets => [garbage_value]}), + Txn = blockchain_txn_vars_v1:new(Vars, 2, #{version_predicate => 2, + unsets => [garbage_value]}), + Proof = blockchain_txn_vars_v1:create_proof(Priv, Txn), + Txn1 = blockchain_txn_vars_v1:proof(Txn, Proof), %% wait for it to take effect - _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn]) + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn1]) || Miner <- Miners], HChain = ct_rpc:call(hd(Miners), blockchain_worker, blockchain, []), @@ -397,10 +415,11 @@ master_key_test(Config) -> {Priv, _Pub} = proplists:get_value(master_key, Config), Vars = #{garbage_value => totes_goats_garb}, - Proof = blockchain_txn_vars_v1:create_proof(Priv, Vars), - ConsensusTxn = blockchain_txn_vars_v1:new(Vars, Proof, 3, #{}), + Txn1_0 = blockchain_txn_vars_v1:new(Vars, 2), + Proof = blockchain_txn_vars_v1:create_proof(Priv, Txn1_0), + Txn1_1 = blockchain_txn_vars_v1:proof(Txn1_0, Proof), - _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn]) + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn1_1]) || Miner <- Miners], ok = miner_ct_utils:wait_until( @@ -421,14 +440,16 @@ master_key_test(Config) -> BinPub2 = libp2p_crypto:pubkey_to_bin(Pub2), Vars2 = #{garbage_value => goats_are_not_garb}, - Proof2 = blockchain_txn_vars_v1:create_proof(Priv, Vars2), - KeyProof2 = blockchain_txn_vars_v1:create_proof(Priv2, Vars2), - KeyProof2Corrupted = <>, - ConsensusTxn2 = blockchain_txn_vars_v1:new(Vars2, Proof2, 4, #{master_key => BinPub2, - key_proof => KeyProof2Corrupted}), + Txn2_0 = blockchain_txn_vars_v1:new(Vars2, 3, #{master_key => BinPub2}), + Proof2 = blockchain_txn_vars_v1:create_proof(Priv, Txn2_0), + KeyProof2 = blockchain_txn_vars_v1:create_proof(Priv2, Txn2_0), + KeyProof2Corrupted = <>, + Txn2_1 = blockchain_txn_vars_v1:proof(Txn2_0, Proof2), + Txn2_2c = blockchain_txn_vars_v1:key_proof(Txn2_1, KeyProof2Corrupted), + {ok, Start2} = ct_rpc:call(hd(Miners), blockchain, height, [Blockchain1]), - _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn2]) + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn2_2c]) || Miner <- Miners], ok = miner_ct_utils:wait_until( @@ -447,10 +468,8 @@ master_key_test(Config) -> %% good master key - ConsensusTxn3 = blockchain_txn_vars_v1:new(Vars2, Proof2, 5, #{master_key => BinPub2, - key_proof => KeyProof2}), - - _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn3]) + Txn2_2 = blockchain_txn_vars_v1:key_proof(Txn2_1, KeyProof2), + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn2_2]) || Miner <- Miners], ok = miner_ct_utils:wait_until( @@ -469,11 +488,13 @@ master_key_test(Config) -> %% make sure old master key is no longer working Vars4 = #{garbage_value => goats_are_too_garb}, - Proof4 = blockchain_txn_vars_v1:create_proof(Priv, Vars4), - ConsensusTxn4 = blockchain_txn_vars_v1:new(Vars4, Proof4, 6, #{}), + Txn4_0 = blockchain_txn_vars_v1:new(Vars4, 4), + Proof4 = blockchain_txn_vars_v1:create_proof(Priv, Txn4_0), + Txn4_1 = blockchain_txn_vars_v1:proof(Txn4_0, Proof4), + {ok, Start4} = ct_rpc:call(hd(Miners), blockchain, height, [Blockchain1]), - _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn4]) + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn4_1]) || Miner <- Miners], ok = miner_ct_utils:wait_until( @@ -488,15 +509,16 @@ master_key_test(Config) -> {ok, goats_are_not_garb} == ct_rpc:call(Miner, blockchain, config, [garbage_value, Ledger]) end, shuffle(Miners)) - end, 40, timer:seconds(1)), + end, 80, timer:seconds(1)), %% double check that new master key works Vars5 = #{garbage_value => goats_always_win}, - Proof5 = blockchain_txn_vars_v1:create_proof(Priv2, Vars5), - ConsensusTxn5 = blockchain_txn_vars_v1:new(Vars5, Proof5, 7, #{}), + Txn5_0 = blockchain_txn_vars_v1:new(Vars5, 4), + Proof5 = blockchain_txn_vars_v1:create_proof(Priv2, Txn5_0), + Txn5_1 = blockchain_txn_vars_v1:proof(Txn5_0, Proof5), - _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [ConsensusTxn5]) + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn5_1]) || Miner <- Miners], ok = miner_ct_utils:wait_until( @@ -513,3 +535,141 @@ master_key_test(Config) -> ok. + + + +version_change_test(Config) -> + %% get all the miners + Miners = proplists:get_value(miners, Config), + + %% check consensus miners + ConsensusMiners = lists:filtermap(fun(Miner) -> + true == ct_rpc:call(Miner, miner_consensus_mgr, in_consensus, []) + end, Miners), + + %% check non consensus miners + NonConsensusMiners = lists:filtermap(fun(Miner) -> + false == ct_rpc:call(Miner, miner_consensus_mgr, in_consensus, []) + end, Miners), + + ?assertNotEqual([], ConsensusMiners), + %% get the first consensus miner + FirstConsensusMiner = hd(ConsensusMiners), + + ?assertEqual(7, length(ConsensusMiners)), + + Blockchain = ct_rpc:call(FirstConsensusMiner, blockchain_worker, blockchain, []), + + %% get the genesis block from first consensus miner + {ok, GenesisBlock} = ct_rpc:call(FirstConsensusMiner, blockchain, genesis_block, [Blockchain]), + + %% check genesis load results for non consensus miners + _GenesisLoadResults = miner_ct_utils:pmap(fun(M) -> + ct_rpc:call(M, blockchain_worker, integrate_genesis_block, [GenesisBlock]) + end, NonConsensusMiners), + + %% make sure that elections are rolling + ok = miner_ct_utils:wait_until(fun() -> + true == lists:all(fun(Miner) -> + Epoch = ct_rpc:call(Miner, miner, election_epoch, []), + ct:pal("miner ~p Epoch ~p", [Miner, Epoch]), + Epoch > 1 + end, shuffle(Miners)) + end, 30, timer:seconds(1)), + + + %% baseline: old-style chain vars are working + + Blockchain1 = ct_rpc:call(hd(Miners), blockchain_worker, blockchain, []), + {Priv, _Pub} = proplists:get_value(master_key, Config), + + Vars = #{garbage_value => totes_goats_garb}, + Proof = blockchain_txn_vars_v1:legacy_create_proof(Priv, Vars), + Txn1_0 = blockchain_txn_vars_v1:new(Vars, 2), + Txn1_1 = blockchain_txn_vars_v1:proof(Txn1_0, Proof), + + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn1_1]) + || Miner <- Miners], + + ok = miner_ct_utils:wait_until( + fun() -> + lists:all( + fun(Miner) -> + C = ct_rpc:call(Miner, blockchain_worker, blockchain, []), + Ledger = ct_rpc:call(Miner, blockchain, ledger, [C]), + {ok, totes_goats_garb} == ct_rpc:call(Miner, blockchain, config, [garbage_value, Ledger]) + end, shuffle(Miners)) + end, 40, timer:seconds(1)), + + %% switch chain version + + Vars2 = #{?chain_vars_version => 2}, + Proof2 = blockchain_txn_vars_v1:legacy_create_proof(Priv, Vars2), + Txn2_0 = blockchain_txn_vars_v1:new(Vars2, 3), + Txn2_1 = blockchain_txn_vars_v1:proof(Txn2_0, Proof2), + + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn2_1]) + || Miner <- Miners], + + %% make sure that it has taken effect + ok = miner_ct_utils:wait_until( + fun() -> + lists:all( + fun(Miner) -> + C = ct_rpc:call(Miner, blockchain_worker, blockchain, []), + Ledger = ct_rpc:call(Miner, blockchain, ledger, [C]), + {ok, 2} == + ct_rpc:call(Miner, blockchain, config, [?chain_vars_version, + Ledger]) + end, shuffle(Miners)) + end, 60, timer:seconds(1)), + + %% try a new-style txn change + + Vars3 = #{garbage_value => goats_are_not_garb}, + Txn3_0 = blockchain_txn_vars_v1:new(Vars3, 4), + Proof3 = blockchain_txn_vars_v1:create_proof(Priv, Txn3_0), + Txn3_1 = blockchain_txn_vars_v1:proof(Txn3_0, Proof3), + + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn3_1]) + || Miner <- Miners], + + ok = miner_ct_utils:wait_until( + fun() -> + lists:all( + fun(Miner) -> + C = ct_rpc:call(Miner, blockchain_worker, blockchain, []), + Ledger = ct_rpc:call(Miner, blockchain, ledger, [C]), + Val = ct_rpc:call(Miner, blockchain, config, [garbage_value, Ledger]), + ct:pal("val ~p", [Val]), + {ok, goats_are_not_garb} == Val + end, shuffle(Miners)) + end, 40, timer:seconds(1)), + + + %% make sure old style is now closed off. + + Vars4 = #{garbage_value => goats_are_too_garb}, + Txn4_0 = blockchain_txn_vars_v1:new(Vars4, 5), + Proof4 = blockchain_txn_vars_v1:legacy_create_proof(Priv, Vars4), + Txn4_1 = blockchain_txn_vars_v1:proof(Txn4_0, Proof4), + + {ok, Start4} = ct_rpc:call(hd(Miners), blockchain, height, [Blockchain1]), + + _ = [ok = ct_rpc:call(Miner, blockchain_worker, submit_txn, [Txn4_1]) + || Miner <- Miners], + + ok = miner_ct_utils:wait_until( + fun() -> + lists:all( + fun(Miner) -> + C = ct_rpc:call(Miner, blockchain_worker, blockchain, []), + Ledger = ct_rpc:call(Miner, blockchain, ledger, [C]), + {ok, Ht} = ct_rpc:call(Miner, blockchain, height, [C]), + ct:pal("miner ~p height ~p", [Miner, Ht]), + Ht > (Start4 + 15) andalso + {ok, goats_are_not_garb} == + ct_rpc:call(Miner, blockchain, config, [garbage_value, Ledger]) + end, shuffle(Miners)) + end, 40, timer:seconds(1)), + ok. diff --git a/test/miner_ct_utils.erl b/test/miner_ct_utils.erl index 6ab2e7642..238e5f5c2 100644 --- a/test/miner_ct_utils.erl +++ b/test/miner_ct_utils.erl @@ -18,7 +18,7 @@ init_per_testcase/2, end_per_testcase/2, get_balance/2, - make_vars/1, make_vars/2 + make_vars/1, make_vars/2, make_vars/3 ]). pmap(F, L) -> @@ -303,7 +303,11 @@ make_vars(Keys) -> make_vars(Keys, #{}). make_vars(Keys, Map) -> - Vars1 = #{?block_time => 1, + make_vars(Keys, Map, modern). + +make_vars(Keys, Map, Mode) -> + Vars1 = #{?chain_vars_version => 2, + ?block_time => 1, ?election_interval => 30, ?election_restart_interval => 10, ?num_consensus_members => 7, @@ -312,7 +316,6 @@ make_vars(Keys, Map) -> ?var_gw_inactivity_threshold => 20, ?block_version => v1, ?dkg_curve => 'SS512', - ?poc_path_limit => 7, ?predicate_callback_mod => miner, ?predicate_callback_fun => test_version, ?predicate_threshold => 0.85, @@ -334,29 +337,30 @@ make_vars(Keys, Map) -> ?h3_neighbor_res => 12, ?h3_max_grid_distance => 13, ?h3_exclusion_ring_dist => 2, - ?poc_challenge_interval => 10 + ?poc_challenge_interval => 10%% , + %% ?poc_path_limit => 7 }, - Vars = maps:merge(Vars1, Map), - - Size = maps:size(Vars), - VarKeys = maps:keys(Vars), - {One, Two} = lists:split(Size div 2, VarKeys), - MOne = maps:with(One, Vars), - MTwo = maps:with(Two, Vars), - ?assert(maps:size(MOne) =< 32), - ?assert(maps:size(MTwo) =< 32), #{secret := Priv, public := Pub} = Keys, BinPub = libp2p_crypto:pubkey_to_bin(Pub), - KeyProof1 = blockchain_txn_vars_v1:create_proof(Priv, MOne), - KeyProof2 = blockchain_txn_vars_v1:create_proof(Priv, MTwo), - - %% ct:pal("master key ~p~n priv ~p~n vars ~p~n keyproof ~p~n artifact ~p", - %% [BinPub, Priv, Vars, KeyProof, - %% term_to_binary(Vars, [{compressed, 9}])]), - - [ blockchain_txn_vars_v1:new(MOne, <<>>, 1, #{master_key => BinPub, - key_proof => KeyProof1}), - blockchain_txn_vars_v1:new(MTwo, <<>>, 2, #{master_key => BinPub, - key_proof => KeyProof2}) ]. + Vars = maps:merge(Vars1, Map), + case Mode of + modern -> + Txn = blockchain_txn_vars_v1:new(Vars, 1, #{master_key => BinPub}), + Proof = blockchain_txn_vars_v1:create_proof(Priv, Txn), + [blockchain_txn_vars_v1:key_proof(Txn, Proof)]; + %% in legacy mode, we have to do without some stuff + %% because everything will break if there are too many vars + legacy -> + %% ideally figure out a few more that are safe to + %% remove or bring back the splitting code + LegVars = maps:without([poc_path_limit, ?chain_vars_version, ?block_version], + Vars), + Proof = blockchain_txn_vars_v1:legacy_create_proof(Priv, LegVars), + Txn = blockchain_txn_vars_v1:new(LegVars, 1, #{master_key => BinPub, + key_proof => Proof}), + + [Txn] + + end. diff --git a/test/miner_payment_txn_SUITE.erl b/test/miner_payment_txn_SUITE.erl index 51b92ad21..c84f9c33f 100644 --- a/test/miner_payment_txn_SUITE.erl +++ b/test/miner_payment_txn_SUITE.erl @@ -181,8 +181,8 @@ single_payment_test(Config) -> PayerBalance2 = miner_ct_utils:get_balance(Payer, PayerAddr), PayeeBalance2 = miner_ct_utils:get_balance(Payee, PayeeAddr), - 4000 = PayerBalance2 + Fee, - 6000 = PayeeBalance2, + ?assertEqual(4000, PayerBalance2 + Fee), + ?assertEqual(6000, PayeeBalance2), ct_rpc:call(Candidate, sys, resume, [Group]), diff --git a/test/miner_reward_SUITE.erl b/test/miner_reward_SUITE.erl index 9693f640b..c52006d66 100644 --- a/test/miner_reward_SUITE.erl +++ b/test/miner_reward_SUITE.erl @@ -38,7 +38,7 @@ init_per_testcase(_TestCase, Config0) -> N = proplists:get_value(num_consensus_members, Config), BlockTime = proplists:get_value(block_time, Config), - Interval = 3, + Interval = 5, BatchSize = proplists:get_value(batch_size, Config), Curve = proplists:get_value(dkg_curve, Config), @@ -137,7 +137,7 @@ basic_test(Config) -> fun(Miner) -> C = ct_rpc:call(Miner, blockchain_worker, blockchain, []), {ok, Height} = ct_rpc:call(Miner, blockchain, height, [C]), - Height >= CurrentHeight + 6 + Height >= CurrentHeight + 10 end, Miners ) @@ -149,19 +149,27 @@ basic_test(Config) -> %% Check that the election txn is in the same block as the rewards txn ok = lists:foreach(fun(Miner) -> Chain0 = ct_rpc:call(Miner, blockchain_worker, blockchain, []), - {ok, ElectionRewardBlock} = ct_rpc:call(Miner, blockchain, get_block, [6, Chain0]), - Txns = ct_rpc:call(Miner, blockchain_block, transactions, [ElectionRewardBlock]), - ?assertEqual(length(Txns), 2), - [First, Second] = Txns, - ?assertEqual(blockchain_txn:type(Second), blockchain_txn_consensus_group_v1), - ?assertEqual(blockchain_txn:type(First), blockchain_txn_rewards_v1), - Rewards = blockchain_txn_rewards_v1:rewards(First), - ?assertEqual(length(Rewards), length(ConsensusMiners)), - lists:foreach(fun(R) -> - ?assertEqual(blockchain_txn_reward_v1:type(R), consensus), - ?assertEqual(blockchain_txn_reward_v1:amount(R), 83) - end, - Rewards) + lists:any( + fun(H) -> + try + {ok, ElectionRewardBlock} = ct_rpc:call(Miner, blockchain, get_block, [H, Chain0]), + Txns = ct_rpc:call(Miner, blockchain_block, transactions, [ElectionRewardBlock]), + ?assertEqual(length(Txns), 2), + [First, Second] = Txns, + ?assertEqual(blockchain_txn:type(Second), blockchain_txn_consensus_group_v1), + ?assertEqual(blockchain_txn:type(First), blockchain_txn_rewards_v1), + Rewards = blockchain_txn_rewards_v1:rewards(First), + ?assertEqual(length(Rewards), length(ConsensusMiners)), + lists:foreach(fun(R) -> + ?assertEqual(blockchain_txn_reward_v1:type(R), consensus), + ?assertEqual(blockchain_txn_reward_v1:amount(R), 83) + end, + Rewards), + true + catch _:_ -> + false + end + end, lists:seq(4, 10)) end, Miners), @@ -175,15 +183,15 @@ basic_test(Config) -> lists:member(Miner, ConsensusMiners), lists:member(Miner, NonConsensusMiners)} of {true, _, true, _} -> - ?assertEqual(4083, Bal); + ?assertEqual(4138, Bal); {true, _, _, true} -> ?assertEqual(4000, Bal); {_, true, true, _} -> - ?assertEqual(6083, Bal); + ?assertEqual(6138, Bal); {_, true, _, true} -> ?assertEqual(6000, Bal); {_, _, true, _} -> - ?assertEqual(5083, Bal); + ?assertEqual(5138, Bal); _ -> ?assertEqual(5000, Bal) end From 9a0266e1eea3794e79565dbb1af00b6ad7a24b25 Mon Sep 17 00:00:00 2001 From: Evan Vigil-McClanahan Date: Tue, 6 Aug 2019 14:00:05 -0700 Subject: [PATCH 11/11] bump core with rescue blocks --- rebar.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebar.lock b/rebar.lock index ada5ace98..ea28f1333 100644 --- a/rebar.lock +++ b/rebar.lock @@ -3,7 +3,7 @@ {<<"base32">>,{pkg,<<"base32">>,<<"0.1.0">>},3}, {<<"blockchain">>, {git,"git@github.com:helium/blockchain-core.git", - {ref,"f6df5b5a143c9668b50150dc252f74f68bf6c497"}}, + {ref,"898acb718cbec21be43982143c4925d3edf4ff76"}}, 0}, {<<"clique">>, {git,"https://github.com/helium/clique.git",