From 5f13ca3a3eb9a144baa06ba346fc39e0921f9e0f Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 6 Oct 2022 08:30:24 -0700 Subject: [PATCH 1/4] Fix poc_mgr record upgrades again --- src/poc/miner_poc_mgr.erl | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/poc/miner_poc_mgr.erl b/src/poc/miner_poc_mgr.erl index 372ac3e9a..5f777320f 100644 --- a/src/poc/miner_poc_mgr.erl +++ b/src/poc/miner_poc_mgr.erl @@ -69,7 +69,7 @@ target :: libp2p_crypto:pubkey_bin(), onion :: binary() | undefined, secret :: binary() | undefined, - responses = #{}, + responses = #{} :: #{binary() => [{binary(), blockchain_poc_witness_v1:witness()}] | blockchain_poc_receipt_v1:poc_receipt()}, challengees = [] :: [libp2p_crypto:pubkey_bin()], packet_hashes = [] :: [{libp2p_crypto:pubkey_bin(), binary()}], start_height :: non_neg_integer() @@ -932,11 +932,14 @@ update_addr_hash(Bloom, Element) -> end. upgrade_responses(#local_poc{responses=Responses}=POC) -> - NewResponses = maps:map(fun(_Key, Value) when element(1, Value) == blockchain_poc_receipt_v1_pb -> - blockchain_poc_receipt_v1:maybe_upgrade(Value); - (_Key, Value) when element(1, Value) == blockchain_poc_witness_v1_pb -> - blockchain_poc_witness_v1:maybe_upgrade(Value) - end, Responses), + NewResponses = maps:map(fun(_Key, Value) when is_list(Value) -> + %% witnesses are stored in a key/value list + lists:map(fun({Key, Witness}) -> + {Key, blockchain_poc_witness_v1:maybe_upgrade(Witness)} + end, Value); + (_Key, Value) when element(1, Value) == blockchain_poc_receipt_v1_pb -> + blockchain_poc_receipt_v1:maybe_upgrade(Value) + end, Responses), POC#local_poc{responses=NewResponses}. %% ------------------------------------------------------------------ @@ -989,28 +992,25 @@ delete_local_poc_keys(OnionKeyHash, DB, CF) -> -ifdef(TEST). upgrade_responses_test() -> - Responses = #{<<"a">> => {blockchain_poc_receipt_v1_pb,<<"r">>,10,10,<<"data">>,p2p,<<>>, + Responses = #{<<"challengee">> => {blockchain_poc_receipt_v1_pb,<<"r">>,10,10,<<"data">>,p2p,<<>>, 1.2,915.2,2,<<"dr">>,<<>>,0}, - <<"b">> => {blockchain_poc_witness_v1_pb,<<"w1">>,10,10,<<"ph">>,<<>>,1.2, - 915.2,2,<<"dr">>}, - <<"c">> => {blockchain_poc_witness_v1_pb,<<"w2">>,10,10,<<"ph">>,<<>>,1.2, + <<"packethash">> => [{<<"2">>, {blockchain_poc_witness_v1_pb,<<"w1">>,10,10,<<"ph">>,<<>>,1.2, 915.2,2,<<"dr">>}}, + %% the following should not need upgrading + {<<"3">>, {blockchain_poc_witness_v1_pb,<<"w2">>,10,10,<<"ph">>,<<>>,1.2, + 915.2,2,<<"dr">>, 1.0}}]}, Upgraded = upgrade_responses(#local_poc{responses=Responses}), - lists:all(fun(E) when element(1, E) == blockchain_poc_receipt_v1_pb -> - blockchain_poc_receipt_v1:print(E), - true; - (E) when element(1, E) == blockchain_poc_witness_v1_pb -> + lists:all(fun(E) when element(1, E) == blockchain_poc_witness_v1_pb -> blockchain_poc_witness_v1:print(E), true - end, maps:values(Upgraded#local_poc.responses)), + end, element(2, lists:unzip(lists:flatten(maps:get(<<"packethash">>, Upgraded#local_poc.responses))))), + blockchain_poc_receipt_v1:print(maps:get(<<"challengee">>, Upgraded#local_poc.responses)), - ?assertError(function_clause, lists:all(fun(E) when element(1, E) == blockchain_poc_receipt_v1_pb -> - blockchain_poc_receipt_v1:print(E), - true; - (E) when element(1, E) == blockchain_poc_witness_v1_pb -> + ?assertError(function_clause, lists:all(fun(E) when element(1, E) == blockchain_poc_witness_v1_pb -> blockchain_poc_witness_v1:print(E), true - end, maps:values(Responses))), + end, element(2, lists:unzip(lists:flatten(maps:get(<<"packethash">>, Responses)))))), + ?assertError(function_clause, blockchain_poc_receipt_v1:print(maps:get(<<"challengee">>, Responses))), ok. -endif. From 25a7ddd7bf6a5c106b81d7650a343f32dec41e65 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 6 Oct 2022 09:14:50 -0700 Subject: [PATCH 2/4] Update src/poc/miner_poc_mgr.erl Co-authored-by: andymck --- src/poc/miner_poc_mgr.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poc/miner_poc_mgr.erl b/src/poc/miner_poc_mgr.erl index 5f777320f..6077abc75 100644 --- a/src/poc/miner_poc_mgr.erl +++ b/src/poc/miner_poc_mgr.erl @@ -69,7 +69,7 @@ target :: libp2p_crypto:pubkey_bin(), onion :: binary() | undefined, secret :: binary() | undefined, - responses = #{} :: #{binary() => [{binary(), blockchain_poc_witness_v1:witness()}] | blockchain_poc_receipt_v1:poc_receipt()}, + responses = #{} :: #{binary() => [{binary(), blockchain_poc_witness_v1:witness()}] | {binary(), blockchain_poc_receipt_v1:poc_receipt()}}, challengees = [] :: [libp2p_crypto:pubkey_bin()], packet_hashes = [] :: [{libp2p_crypto:pubkey_bin(), binary()}], start_height :: non_neg_integer() From e018f1c9b86a27197fd813e4c451010b29c560ac Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 6 Oct 2022 09:15:01 -0700 Subject: [PATCH 3/4] Update src/poc/miner_poc_mgr.erl Co-authored-by: andymck --- src/poc/miner_poc_mgr.erl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/poc/miner_poc_mgr.erl b/src/poc/miner_poc_mgr.erl index 6077abc75..74360be5b 100644 --- a/src/poc/miner_poc_mgr.erl +++ b/src/poc/miner_poc_mgr.erl @@ -937,7 +937,8 @@ upgrade_responses(#local_poc{responses=Responses}=POC) -> lists:map(fun({Key, Witness}) -> {Key, blockchain_poc_witness_v1:maybe_upgrade(Witness)} end, Value); - (_Key, Value) when element(1, Value) == blockchain_poc_receipt_v1_pb -> + (_Key, {Peer, Value}) when element(1, Value) == blockchain_poc_receipt_v1_pb -> + {Peer, blockchain_poc_receipt_v1:maybe_upgrade(Value)} blockchain_poc_receipt_v1:maybe_upgrade(Value) end, Responses), POC#local_poc{responses=NewResponses}. From 6425a6c0c4ecd2f49fd679508a934d23b017c985 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 6 Oct 2022 09:22:51 -0700 Subject: [PATCH 4/4] Fix --- src/poc/miner_poc_mgr.erl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/poc/miner_poc_mgr.erl b/src/poc/miner_poc_mgr.erl index 74360be5b..5dc89c1fa 100644 --- a/src/poc/miner_poc_mgr.erl +++ b/src/poc/miner_poc_mgr.erl @@ -939,7 +939,6 @@ upgrade_responses(#local_poc{responses=Responses}=POC) -> end, Value); (_Key, {Peer, Value}) when element(1, Value) == blockchain_poc_receipt_v1_pb -> {Peer, blockchain_poc_receipt_v1:maybe_upgrade(Value)} - blockchain_poc_receipt_v1:maybe_upgrade(Value) end, Responses), POC#local_poc{responses=NewResponses}. @@ -993,8 +992,8 @@ delete_local_poc_keys(OnionKeyHash, DB, CF) -> -ifdef(TEST). upgrade_responses_test() -> - Responses = #{<<"challengee">> => {blockchain_poc_receipt_v1_pb,<<"r">>,10,10,<<"data">>,p2p,<<>>, - 1.2,915.2,2,<<"dr">>,<<>>,0}, + Responses = #{<<"challengee">> => {<<"peer">>, {blockchain_poc_receipt_v1_pb,<<"r">>,10,10,<<"data">>,p2p,<<>>, + 1.2,915.2,2,<<"dr">>,<<>>,0}}, <<"packethash">> => [{<<"2">>, {blockchain_poc_witness_v1_pb,<<"w1">>,10,10,<<"ph">>,<<>>,1.2, 915.2,2,<<"dr">>}}, %% the following should not need upgrading @@ -1005,13 +1004,13 @@ upgrade_responses_test() -> blockchain_poc_witness_v1:print(E), true end, element(2, lists:unzip(lists:flatten(maps:get(<<"packethash">>, Upgraded#local_poc.responses))))), - blockchain_poc_receipt_v1:print(maps:get(<<"challengee">>, Upgraded#local_poc.responses)), + blockchain_poc_receipt_v1:print(element(2, maps:get(<<"challengee">>, Upgraded#local_poc.responses))), ?assertError(function_clause, lists:all(fun(E) when element(1, E) == blockchain_poc_witness_v1_pb -> blockchain_poc_witness_v1:print(E), true end, element(2, lists:unzip(lists:flatten(maps:get(<<"packethash">>, Responses)))))), - ?assertError(function_clause, blockchain_poc_receipt_v1:print(maps:get(<<"challengee">>, Responses))), + ?assertError(function_clause, blockchain_poc_receipt_v1:print(element(2, maps:get(<<"challengee">>, Responses)))), ok. -endif.