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

Commit

Permalink
Merge pull request #397 from helium/pevm/port-oui-to-master
Browse files Browse the repository at this point in the history
Move the OUI upgrade and field to master
  • Loading branch information
evanmcc authored Apr 1, 2020
2 parents ec2cc73 + c826f01 commit 7f8731b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
23 changes: 22 additions & 1 deletion src/blockchain.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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 @@ -221,6 +222,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
Original file line number Diff line number Diff line change
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

0 comments on commit 7f8731b

Please sign in to comment.