Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Move the OUI upgrade and field to master #397

Merged
merged 2 commits into from Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/blockchain.erl
Expand Up @@ -72,7 +72,8 @@
%% not run their code later.
-define(upgrades,
[{<<"gateway_v2">>, fun upgrade_gateways_v2/1},
{<<"hex_targets">>, fun bootstrap_hexes/1}]).
{<<"hex_targets">>, fun bootstrap_hexes/1},
{<<"gateway_oui">>, fun upgrade_gateways_oui/1}]).
%% NB: we need to keep this in sync with the filter in the fingerprints


Expand Down Expand Up @@ -220,6 +221,26 @@ bootstrap_hexes_(Ledger) ->
end, Hexes),
ok.

upgrade_gateways_oui(Ledger) ->
upgrade_gateways_oui_(Ledger),
Ledger1 = blockchain_ledger_v1:mode(delayed, Ledger),
Ledger2 = blockchain_ledger_v1:new_context(Ledger1),
upgrade_gateways_oui_(Ledger2),
blockchain_ledger_v1:commit_context(Ledger2).

upgrade_gateways_oui_(Ledger) ->
%% the initial load here will automatically convert these into
%% records with oui slots
Gateways = blockchain_ledger_v1:active_gateways(Ledger),
%% find all neighbors for everyone
maps:map(
fun(A, G) ->
%% since we're here
G1 = blockchain_ledger_gateway_v2:neighbors([], G),
blockchain_ledger_v1:update_gateway(G1, A, Ledger)
end, Gateways),
ok.

%%--------------------------------------------------------------------
%% @doc
%% @end
Expand Down
19 changes: 16 additions & 3 deletions src/ledger/v1/blockchain_ledger_gateway_v2.erl
Expand Up @@ -59,7 +59,8 @@
nonce = 0 :: non_neg_integer(),
version = 0 :: non_neg_integer(),
neighbors = [] :: [libp2p_crypto:pubkey_bin()],
witnesses = #{} :: witnesses()
witnesses = #{} :: witnesses(),
oui = undefined :: undefined | pos_integer()
}).

-type gateway() :: #gateway_v2{}.
Expand Down Expand Up @@ -436,8 +437,20 @@ deserialize(<<1, Bin/binary>>) ->
convert(V1);
deserialize(<<2, Bin/binary>>) ->
Gw = erlang:binary_to_term(Bin),
Neighbors = neighbors(Gw),
neighbors(lists:usort(Neighbors), Gw).
Gw1 =
case size(Gw) of
%% pre-oui upgrade
12 ->
L = tuple_to_list(Gw),
%% add an undefined OUI slot
L1 = lists:append(L, [undefined]),
G1 = list_to_tuple(L1),
neighbors([], G1);
13 ->
Gw
end,
Neighbors = neighbors(Gw1),
neighbors(lists:usort(Neighbors), Gw1).

%% OK to include here, v1 should now be immutable.
-record(gateway_v1, {
Expand Down