From a71e9543fe6ee5ed47e47172ad859ff0cfc07827 Mon Sep 17 00:00:00 2001 From: Scott Lystig Fritchie Date: Tue, 18 Aug 2015 22:35:57 +0900 Subject: [PATCH] WIP: refactoring inner handling, but ... (more) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are a couple of weird things in the snippet below (AP mode): 22:32:58.209 b uses inner: [{epoch,136},{author,c},{mode,ap_mode},{witnesses,[]},{upi,[b,c]},{repair,[]},{down,[a]},{flap,undefined},{d,[d_foo1,{ps,[{a,b}]},{nodes_up,[b,c]}]},{d2,[]}] (outer flap epoch 136: {flap_i,{{{epk,115},{1439,904777,11627}},28},[a,{a,problem_with,b},{b,problem_with,a}],[{a,{{{epk,126},{1439,904777,149865}},16}},{b,{{{epk,115},{1439,904777,11627}},28}},{c,{{{epk,121},{1439,904777,134392}},15}}]}) (my flap {{epk,115},{1439,904777,11627}} 29 [{a,{{{epk,126},{1439,904777,149865}},28}},{b,{{{epk,115},{1439,904777,11627}},29}},{c,{{{epk,121},{1439,904777,134392}},26}}]) 22:32:58.224 c uses inner: [{epoch,136},{author,c},{mode,ap_mode},{witnesses,[]},{upi,[b,c]},{repair,[]},{down,[a]},{flap,undefined},{d,[d_foo1,{ps,[{a,b}]},{nodes_up,[b,c]}]},{d2,[]}] (outer flap epoch 136: {flap_i,{{{epk,115},{1439,904777,11627}},28},[a,{a,problem_with,b},{b,problem_with,a}],[{a,{{{epk,126},{1439,904777,149865}},16}},{b,{{{epk,115},{1439,904777,11627}},28}},{c,{{{epk,121},{1439,904777,134392}},15}}]}) (my flap {{epk,121},{1439,904777,134392}} 28 [{a,{{{epk,126},{1439,904777,149865}},28}},{b,{{{epk,115},{1439,904777,11627}},28}},{c,{{{epk,121},{1439,904777,134392}},28}}]) CONFIRM by epoch inner 136 <<103,64,252,...>> at [b,c] [] Priv1 [{a,{{132,<<"Cï|ÿzKX:Á"...>>},[a],[c],[b],[],false}}, {b,{{127,<<185,139,3,2,96,189,...>>},[b,c],[],[a],[],false}}, {c,{{133,<<145,71,223,6,177,...>>},[b,c],[a],[],[],false}}] agree false Pubs: [{a,136},{b,136},{c,136}] DoIt, 1. Both the "uses inner" messages and also the "CONFIRM by epoch inner 136" show that B & C are using the same inner projection. However, the 'Priv1' output shows b & c on different epochs, 127 & 133. Weird. 2. I've added an infinite loop, probably in this commit. :-( --- src/machi_chain_manager1.erl | 158 ++++++++++++++++++----------------- 1 file changed, 83 insertions(+), 75 deletions(-) diff --git a/src/machi_chain_manager1.erl b/src/machi_chain_manager1.erl index 37017e0..a20781d 100644 --- a/src/machi_chain_manager1.erl +++ b/src/machi_chain_manager1.erl @@ -1299,83 +1299,90 @@ a30_make_inner_projection(P_current, P_newprop3, P_latest, Up, down=P_i2#projection_v1.all_members -- [MyName]} end, - FinalInnerEpoch = - case inner_projection_exists(P_current) of - false -> - FinalCreation = P_newprop3#projection_v1.creation_time, - AllFlapCounts_epk = - [Epk || {{Epk,_FlTime}, _FlCount} <- - get_all_flap_counts(P_newprop3)], - case AllFlapCounts_epk of - [] -> - P_newprop3#projection_v1.epoch_number; - [_|_] -> - lists:max(AllFlapCounts_epk) - end; + #projection_v1{epoch_number=Epoch_p_inner, + upi=UPI_p_inner, + repairing=Repairing_p_inner} = P_inner, + LatestHasCompatibleInner = + case inner_projection_exists(P_latest) of true -> - P_oldinner = inner_projection_or_self(P_current), - if P_oldinner#projection_v1.upi == - P_inner#projection_v1.upi - andalso - P_oldinner#projection_v1.repairing == - P_inner#projection_v1.repairing - andalso - P_oldinner#projection_v1.down == - P_inner#projection_v1.down -> - FinalCreation = P_oldinner#projection_v1.creation_time, - P_oldinner#projection_v1.epoch_number; - true -> - FinalCreation = P_newprop3#projection_v1.creation_time, - P_oldinner#projection_v1.epoch_number + 1 - end + P_latest_i = inner_projection_or_self(P_latest), + #projection_v1{epoch_number=Epoch_latest_i, + upi=UPI_latest_i, + repairing=Repairing_latest_i} = P_latest_i, + ?REACT({a30, ?LINE, [{epoch_latest_i, Epoch_latest_i}, + {upi_latest_i, UPI_latest_i}, + {repairing_latest_i}]}), + %io:format(user, "INNER: ~p line ~p ~p\n", [{epoch_latest_i, Epoch_latest_i}, {epoch_final_inner, FinalInnerEpoch}, {upi_latest_i, UPI_latest_i}, {repairing_latest_i}]), + if %% TODO yo delete? Epoch_latest_i > FinalInnerEpoch + %% TODO yo delete? andalso + UPI_p_inner == UPI_latest_i + andalso + Repairing_p_inner == Repairing_latest_i -> + %% Use latest's inner projection instead! + ?REACT({a30, ?LINE, []}), + %io:format(user, "INNER: ~p line ~p\n", [MyName, ?LINE]), + machi_projection:update_checksum( + P_inner#projection_v1{inner=P_latest_i}); + true -> + ?REACT({a30, ?LINE, []}), + false + end; + false -> + ?REACT({a30, ?LINE, []}), + false end, - - %% TODO: When we implement the real chain repair function, we - %% need to keep in mind that an inner projection with - %% up nodes > 1, repair is required there! In the - %% current simulator, repair is not simulated and - %% finished (and then growing the UPI list). Fix. - P_inner2 = machi_projection:update_checksum( - P_inner#projection_v1{epoch_number=FinalInnerEpoch, - creation_time=FinalCreation}), - ?REACT({a30, ?LINE, [{inner_summary, - machi_projection:make_summary(P_inner2)}]}), - %% Put it all together. - P_newprop4 = machi_projection:update_checksum( - P_newprop3#projection_v1{inner=P_inner2}), - #projection_v1{epoch_number=Epoch_i4, - upi=UPI_i4, - repairing=Repairing_i4} = P_newprop4, - case inner_projection_exists(P_latest) of - true -> - P_latest_i = inner_projection_or_self(P_latest), - #projection_v1{epoch_number=Epoch_latest_i, - upi=UPI_latest_i, - repairing=Repairing_latest_i} = P_latest_i, - ?REACT({a30, ?LINE, [{epoch_latest_i, Epoch_latest_i}, - {epoch_final_inner, FinalInnerEpoch}, - {upi_latest_i, UPI_latest_i}, - {repairing_latest_i}]}), -%io:format(user, "INNER: ~p line ~p ~p\n", [{epoch_latest_i, Epoch_latest_i}, {epoch_final_inner, FinalInnerEpoch}, {upi_latest_i, UPI_latest_i}, {repairing_latest_i}]), - if Epoch_latest_i > FinalInnerEpoch - andalso - UPI_i4 == UPI_latest_i - andalso - Repairing_i4 == Repairing_latest_i -> - %% Use latest's inner projection instead! - ?REACT({a30, ?LINE, []}), -%io:format(user, "INNER: ~p line ~p\n", [MyName, ?LINE]), - P_newprop5 = machi_projection:update_checksum( - P_newprop4#projection_v1{inner=P_latest_i}), - {P_newprop5, S_i}; - true -> - ?REACT({a30, ?LINE, []}), -%io:format(user, "INNER: ~p line ~p\n", [MyName, ?LINE]), - {P_newprop4, S_i} - end; - false -> - ?REACT({a30, ?LINE, []}), -%io:format(user, "INNER: ~p line ~p\n", [MyName, ?LINE]), + if LatestHasCompatibleInner /= false -> + {LatestHasCompatibleInner, S_i}; + true -> + FinalInnerEpoch = + case inner_projection_exists(P_current) of + false -> + ?REACT({a30xyzxyz, ?LINE, [P_newprop3#projection_v1.epoch_number]}), + FinalCreation = P_newprop3#projection_v1.creation_time, + P_newprop3#projection_v1.epoch_number; + %% AllFlapCounts_epk = + %% [Epk || {{Epk,_FlTime}, _FlCount} <- + %% get_all_flap_counts(P_newprop3)], + %% case AllFlapCounts_epk of + %% [] -> + %% ?REACT({a30xyzxyz, ?LINE, [P_newprop3#projection_v1.epoch_number]}), + %% P_newprop3#projection_v1.epoch_number; + %% [_|_] -> + %% ?REACT({a30xyzxyz, ?LINE, [AllFlapCounts_epk]}), + %% lists:max(AllFlapCounts_epk) + %% end; + true -> + P_oldinner = inner_projection_or_self(P_current), + if P_oldinner#projection_v1.upi == + P_inner#projection_v1.upi + andalso + P_oldinner#projection_v1.repairing == + P_inner#projection_v1.repairing + andalso + P_oldinner#projection_v1.down == + P_inner#projection_v1.down -> + ?REACT({a30xyzxyz, ?LINE, [P_oldinner#projection_v1.epoch_number]}), + FinalCreation = P_oldinner#projection_v1.creation_time, + P_oldinner#projection_v1.epoch_number; + true -> + ?REACT({a30xyzxyz, ?LINE, [P_oldinner#projection_v1.epoch_number + 1]}), + FinalCreation = P_newprop3#projection_v1.creation_time, + P_oldinner#projection_v1.epoch_number + 1 + end + end, + %% TODO: When we implement the real chain repair function, we + %% need to keep in mind that an inner projection with + %% up nodes > 1, repair is required there! In the + %% current simulator, repair is not simulated and + %% finished (and then growing the UPI list). Fix. + P_inner2 = machi_projection:update_checksum( + P_inner#projection_v1{epoch_number=FinalInnerEpoch, + creation_time=FinalCreation}), + ?REACT({a30, ?LINE, [{inner_summary, + machi_projection:make_summary(P_inner2)}]}), + %% Put it all together. + P_newprop4 = machi_projection:update_checksum( + P_newprop3#projection_v1{inner=P_inner2}), {P_newprop4, S_i} end. @@ -1527,6 +1534,7 @@ react_to_env_A50(P_latest, FinalProps, #ch_mgr{proj=P_current}=S) -> ?REACT({a50, ?LINE, [{current_epoch, P_current#projection_v1.epoch_number}, {latest_epoch, P_latest#projection_v1.epoch_number}, {final_props, FinalProps}]}), + %% if S#ch_mgr.name == b; S#ch_mgr.name == c -> io:format(user, "A50: ~p: ~p\n", [S#ch_mgr.name, get(react)]); true -> ok end, {{no_change, FinalProps, P_current#projection_v1.epoch_number}, S}. react_to_env_B10(Retries, P_newprop, P_latest, LatestUnanimousP,