Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the h3dex to find gateways in the selected hex for poc notifications #58

Merged
merged 4 commits into from Jun 7, 2022
Merged
Changes from 1 commit
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
12 changes: 4 additions & 8 deletions src/sibyl_poc_mgr.erl
Expand Up @@ -150,22 +150,18 @@ handle_poc_event(
],
{noreply, State#state{}}.

run_poc_targetting(ChallengerAddr, Key, Ledger, BlockHash, Vars) ->
run_poc_targetting(ChallengerAddr, Key, Ledger, BlockHash, _Vars) ->
Entropy = <<Key/binary, BlockHash/binary>>,
ZoneRandState = blockchain_utils:rand_state(Entropy),
TargetMod = blockchain_utils:target_v_to_mod(blockchain:config(?poc_targeting_version, Ledger)),
case TargetMod:target_zone(ZoneRandState, Ledger) of
{error, _} ->
lager:debug("*** failed to find a target zone", []),
noop;
{ok, {HexList, Hex, HexRandState}} ->
{ok, {_HexList, Hex, _HexRandState}} ->
%% get all GWs in this zone
{ok, ZoneGWs} = TargetMod:gateways_for_zone(
ChallengerAddr,
Ledger,
Vars,
HexList,
[{Hex, HexRandState}]
ZoneGWs = lists:flatten(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see where you are going with this...the list here though will contain active and inactive GWs. As the inactive GWs wont likely have a streaming connection that is prob fine. Even if they do have a streaming connection but have not yet been reactivated via the HBs, it should still be fine as should they check with the challenger they will just get the usual not target response

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, we will be potentially sending a lot of additional notifications....via gateways for zone, we would be dropping hundreds of notifications over this...at most in the old way we would have 20 notifications per hex, now we will have many hundreds for the more populated hexes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd pub-sub on the h3 index, can we switch to doing that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah thats perfectly doable, the sub takes place in helium_stream_poc_impl:subscribe_to_events/1 whilst the pub takes place in sibyl_poc_mgr:run_poc_targetting/5. I can make that change later if you dont get to it

Going to reiterate the price for this is that end up sending potentially hundreds of extra notifications which themselves will result in same amount of additional API calls to durable validators and then all the same to the challenger

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but don't we need to do this anyway? only the challenger knows what the entropy to pick the challengee is, we need to notify everyone in the hex?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at this I see why my PR was so confusing/hard to incorporate.

seems to me like we could make it a lot cheaper by doing cheap checks first. That said, here the cost isn't that bad, we're mostly concerned about expensive thing happening at validation time, so if we don't need to do this there, it's probably OK even if it's expensive. I might misunderstand, though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but don't we need to do this anyway? only the challenger knows what the entropy to pick the challengee is, we need to notify everyone in the hex?

Previously the target would have been selected from the filtered subset of 20 ( 20 being the max value, actuality much less). Only that same subset would have been notified here, whereas with this change we will be notifying all hotspots in the hex.

Maybe its worth it too take the hit here and reduce the critical path of the validations or maybe there is another option that reduces the cost on both sides...

maps:values(blockchain_ledger_v1:lookup_gateways_from_hex(Hex, Ledger))
),
lager:debug("*** found gateways for target zone: ~p", [ZoneGWs]),
%% create the notification
Expand Down