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

Set network coordinates from BeaconChain #927

Merged
merged 34 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dcc4bac
Add the node origin of the slot in the summary cache
samuelmanzanera Mar 2, 2023
53997c7
Aggregate stats with weighed logistic regression
samuelmanzanera Mar 2, 2023
00f3193
Add fetch remote network stats
samuelmanzanera Mar 6, 2023
afd5e6b
Integrate network patches in the beacon summary
samuelmanzanera Mar 7, 2023
ce11a16
Integrate network patches in summary aggregate
samuelmanzanera Mar 8, 2023
cf5d7fb
Integrate network patch in the p2p summary dump
samuelmanzanera Mar 8, 2023
875cf0f
Sort list for weight application
samuelmanzanera Mar 20, 2023
d3f8d51
Clean summary cache in the next 1st beacon slot
samuelmanzanera Mar 20, 2023
da77d0e
Optimize network stats fetching
samuelmanzanera Mar 20, 2023
9c8fb4a
Better cleaning of the previous summary slots
samuelmanzanera Mar 22, 2023
1effd0a
Merge branch 'develop' into compute_beacon_latency_matrix
samuelmanzanera Mar 22, 2023
cad65ff
lint
samuelmanzanera Mar 23, 2023
427d02a
Add code_change
samuelmanzanera Mar 23, 2023
d99eaf4
Fix summary patch serialization when starts by 0
samuelmanzanera Mar 27, 2023
766e6de
Fix beacon chain test
samuelmanzanera Mar 27, 2023
9223052
Merge branch 'develop' into compute_beacon_latency_matrix
samuelmanzanera Mar 27, 2023
3d65a77
Fallback code_change
samuelmanzanera Mar 27, 2023
d4bd190
Aggregate mutliple stats
samuelmanzanera Mar 31, 2023
3d03d86
Add stats collector to cache the parallel requests
samuelmanzanera Mar 31, 2023
368c148
Simplify the network patch serialization
samuelmanzanera Mar 31, 2023
df06bfc
Fix encoding/decoding of network patch digit
samuelmanzanera Apr 3, 2023
ecc8ae7
Resolve missing beacon network stats
samuelmanzanera Apr 3, 2023
99b9bf3
Reduce debug trace
samuelmanzanera Apr 3, 2023
5d807a3
Lint
samuelmanzanera Apr 3, 2023
f2e9a72
Create slot event only for authorized nodes
samuelmanzanera Apr 3, 2023
42410d4
Lint
samuelmanzanera Apr 5, 2023
de87ded
Use median in aggregation of conflicting patches
samuelmanzanera Apr 5, 2023
c6be90a
Fix P2P edge case on bootstrap
samuelmanzanera Apr 5, 2023
826c9d2
Fix serialize nb of subsets
samuelmanzanera Apr 7, 2023
98ae846
Set before? flag to true for all beacon election
Neylix Apr 7, 2023
7532120
Fix Credo
Neylix Apr 7, 2023
40cc48a
Merge branch 'develop' into compute_beacon_latency_matrix
Neylix Apr 7, 2023
8f91d8a
Fix format
Neylix Apr 7, 2023
0c6b2db
Add PubSub register in code change
Neylix Apr 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions lib/archethic/beacon_chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ defmodule Archethic.BeaconChain do
alias __MODULE__.Slot.Validation, as: SlotValidation
alias __MODULE__.SlotTimer
alias __MODULE__.Subset
alias __MODULE__.NetworkCoordinates
alias __MODULE__.Subset.P2PSampling
alias __MODULE__.Subset.SummaryCache
alias __MODULE__.Summary
Expand All @@ -28,6 +29,7 @@ defmodule Archethic.BeaconChain do
alias Archethic.P2P.Message.BeaconSummaryList
alias Archethic.P2P.Message.NotFound
alias Archethic.P2P.Message.TransactionSummaryList

alias Archethic.TaskSupervisor

alias Archethic.TransactionChain.TransactionSummary
Expand Down Expand Up @@ -110,8 +112,8 @@ defmodule Archethic.BeaconChain do
@doc """
Load a slot in summary cache
"""
@spec load_slot(Slot.t()) :: :ok | :error
def load_slot(slot = %Slot{subset: subset, slot_time: slot_time}) do
@spec load_slot(Slot.t(), Crypto.key()) :: :ok | :error
def load_slot(slot = %Slot{subset: subset, slot_time: slot_time}, node_public_key) do
if slot_time == SlotTimer.previous_slot(DateTime.utc_now()) do
Task.Supervisor.start_child(TaskSupervisor, fn ->
case validate_slot(slot) do
Expand All @@ -120,7 +122,7 @@ defmodule Archethic.BeaconChain do
beacon_subset: Base.encode16(subset)
)

SummaryCache.add_slot(subset, slot)
SummaryCache.add_slot(subset, slot, node_public_key)

{:error, reason} ->
Logger.error("Invalid beacon slot - #{inspect(reason)}")
Expand Down Expand Up @@ -195,6 +197,10 @@ defmodule Archethic.BeaconChain do
@spec get_summary_slots(binary()) :: list(TransactionSummary.t())
def get_summary_slots(subset) when is_binary(subset) do
SummaryCache.stream_current_slots(subset)
|> Stream.map(fn
{slot, _} -> slot
slot -> slot
end)
|> Stream.flat_map(fn %Slot{transaction_attestations: transaction_attestations} ->
transaction_summaries =
transaction_attestations
Expand Down Expand Up @@ -252,7 +258,12 @@ defmodule Archethic.BeaconChain do
if unsubscribe?, do: Update.unsubscribe()

Enum.map(list_subsets(), fn subset ->
nodes = Election.beacon_storage_nodes(subset, date, P2P.authorized_and_available_nodes())
nodes =
Election.beacon_storage_nodes(
subset,
date,
P2P.authorized_and_available_nodes(date, true)
)

nodes =
Enum.reject(nodes, fn node -> node.first_public_key == Crypto.first_node_public_key() end)
Expand Down Expand Up @@ -324,10 +335,10 @@ defmodule Archethic.BeaconChain do
@spec list_transactions_summaries_from_current_slot(DateTime.t()) ::
list(TransactionSummary.t())
def list_transactions_summaries_from_current_slot(date = %DateTime{} \\ DateTime.utc_now()) do
authorized_nodes = P2P.authorized_and_available_nodes()

next_summary_date = next_summary_date(DateTime.truncate(date, :millisecond))

authorized_nodes = P2P.authorized_and_available_nodes(next_summary_date, true)

# get the subsets to request per node
list_subsets()
|> Enum.map(fn subset ->
Expand Down Expand Up @@ -472,4 +483,12 @@ defmodule Archethic.BeaconChain do
e
end
end

@doc """
Retrieve the network stats for a given subset from the cached slots
"""
@spec get_network_stats(binary()) :: %{Crypto.key() => Slot.net_stats()}
def get_network_stats(subset) when is_binary(subset) do
NetworkCoordinates.aggregate_network_stats(subset)
end
end
Loading