Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
ff284273
Commit
ff284273
authored
7 months ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
wip endpoint_gossip module
parent
35eb66d9
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
node/src/endpoint_gossip/mod.rs
+60
-0
60 additions, 0 deletions
node/src/endpoint_gossip/mod.rs
node/src/lib.rs
+1
-0
1 addition, 0 deletions
node/src/lib.rs
node/src/service.rs
+38
-27
38 additions, 27 deletions
node/src/service.rs
with
99 additions
and
27 deletions
node/src/endpoint_gossip/mod.rs
0 → 100644
+
60
−
0
View file @
ff284273
use
sc_chain_spec
::
ChainSpec
;
use
sc_network
::
types
::
ProtocolName
;
// endpoint gossip is a single protocol used to gossip different kinds of endpoints like
// - rpc endpoints
// - squid indexer endpoints
// ...
pub
(
crate
)
const
NAME
:
&
str
=
"/endpoint_gossip/1"
;
/// Name of the notifications protocol used by endpoint gossip.
// Prefix by fork id to avoid gossiping endpoints of wrong network
pub
fn
protocol_name
<
Hash
:
AsRef
<
[
u8
]
>>
(
genesis_hash
:
&
Hash
,
chain_spec
:
&
Box
<
dyn
ChainSpec
>
,
)
->
ProtocolName
{
let
genesis_hash
=
genesis_hash
.as_ref
();
let
chain_prefix
=
match
chain_spec
.fork_id
()
{
Some
(
fork_id
)
=>
format!
(
"/{}/{}"
,
array_bytes
::
bytes2hex
(
""
,
genesis_hash
),
fork_id
),
None
=>
format!
(
"/{}"
,
array_bytes
::
bytes2hex
(
""
,
genesis_hash
)),
};
format!
(
"{}{}"
,
chain_prefix
,
NAME
)
.into
()
}
/// Returns the configuration value to put in
/// [`sc_network::config::FullNetworkConfiguration`].
pub
fn
peers_set_config
<
B
:
BlockT
,
N
:
NetworkBackend
<
B
,
<
B
as
BlockT
>
::
Hash
>>
(
protocol_name
:
ProtocolName
,
metrics
:
sc_network
::
service
::
NotificationMetrics
,
peer_store_handle
:
Arc
<
dyn
sc_network
::
peer_store
::
PeerStoreProvider
>
,
)
->
(
N
::
NotificationProtocolConfig
,
Box
<
dyn
NotificationService
>
)
{
use
communication
::
grandpa_protocol_name
;
N
::
notification_config
(
protocol_name
,
vec!
[],
// Inspired by GRANDPA notifications which are ~256kiB
1024
*
1024
,
None
,
sc_network
::
config
::
SetConfig
{
in_peers
:
0
,
out_peers
:
0
,
reserved_nodes
:
Vec
::
new
(),
non_reserved_mode
:
sc_network
::
config
::
NonReservedPeerMode
::
Deny
,
},
metrics
,
peer_store_handle
,
)
}
// /// Create notification protocol configuration and an associated `NotificationService`
// /// for the protocol.
// fn notification_config(
// protocol_name: ProtocolName,
// fallback_names: Vec<ProtocolName>,
// max_notification_size: u64,
// handshake: Option<NotificationHandshake>,
// set_config: SetConfig,
// metrics: NotificationMetrics,
// peerstore_handle: Arc<dyn PeerStoreProvider>,
// ) -> (Self::NotificationProtocolConfig, Box<dyn NotificationService>);
This diff is collapsed.
Click to expand it.
node/src/lib.rs
+
1
−
0
View file @
ff284273
...
@@ -17,5 +17,6 @@
...
@@ -17,5 +17,6 @@
pub
mod
chain_spec
;
pub
mod
chain_spec
;
pub
mod
cli
;
pub
mod
cli
;
pub
mod
command
;
pub
mod
command
;
pub
mod
endpoint_gossip
;
pub
mod
rpc
;
pub
mod
rpc
;
pub
mod
service
;
pub
mod
service
;
This diff is collapsed.
Click to expand it.
node/src/service.rs
+
38
−
27
View file @
ff284273
...
@@ -325,15 +325,14 @@ where
...
@@ -325,15 +325,14 @@ where
other
:
(
block_import
,
babe_link
,
babe_worker_handle
,
grandpa_link
,
mut
telemetry
),
other
:
(
block_import
,
babe_link
,
babe_worker_handle
,
grandpa_link
,
mut
telemetry
),
}
=
new_partial
::
<
RuntimeApi
,
Executor
>
(
&
config
,
sealing
.is_manual_consensus
())
?
;
}
=
new_partial
::
<
RuntimeApi
,
Executor
>
(
&
config
,
sealing
.is_manual_consensus
())
?
;
let
grandpa_protocol_name
=
sc_consensus_grandpa
::
protocol_standard_
name
(
// genesis hash used in protocol
name
s
&
client
let
genesis_hash
=
client
.block_hash
(
0
)
.block_hash
(
0
)
.ok
()
.ok
()
.flatten
()
.flatten
()
.expect
(
"Genesis block exists; qed"
),
.expect
(
"Genesis block exists; qed"
);
&
config
.chain_spec
,
);
// shared network config
let
mut
net_config
=
sc_network
::
config
::
FullNetworkConfiguration
::
<
let
mut
net_config
=
sc_network
::
config
::
FullNetworkConfiguration
::
<
Block
,
Block
,
<
Block
as
sp_runtime
::
traits
::
Block
>
::
Hash
,
<
Block
as
sp_runtime
::
traits
::
Block
>
::
Hash
,
...
@@ -341,6 +340,10 @@ where
...
@@ -341,6 +340,10 @@ where
>
::
new
(
&
config
.network
,
config
.prometheus_registry
()
.cloned
());
>
::
new
(
&
config
.network
,
config
.prometheus_registry
()
.cloned
());
let
metrics
=
N
::
register_notification_metrics
(
config
.prometheus_registry
());
let
metrics
=
N
::
register_notification_metrics
(
config
.prometheus_registry
());
let
peer_store_handle
=
net_config
.peer_store_handle
();
let
peer_store_handle
=
net_config
.peer_store_handle
();
// grandpa network config
let
grandpa_protocol_name
=
sc_consensus_grandpa
::
protocol_standard_name
(
&
genesis_hash
,
&
config
.chain_spec
);
let
(
grandpa_protocol_config
,
grandpa_notification_service
)
=
let
(
grandpa_protocol_config
,
grandpa_notification_service
)
=
sc_consensus_grandpa
::
grandpa_peers_set_config
::
<
_
,
N
>
(
sc_consensus_grandpa
::
grandpa_peers_set_config
::
<
_
,
N
>
(
grandpa_protocol_name
.clone
(),
grandpa_protocol_name
.clone
(),
...
@@ -351,11 +354,19 @@ where
...
@@ -351,11 +354,19 @@ where
// endpoint gossip
// endpoint gossip
// only active for non-authority (to save workload)
// only active for non-authority (to save workload)
if
!
role
.is_authority
()
{
//
if !role.is_authority() {
// configure protocol
// configure protocol
let
(
endpoint_gossip_protocol_config
,
endpoint_gossip_notification_service
)
=
((),
());
let
endpoint_gossip_protocol_name
=
endpoint_gossip
::
protocol_name
(
&
genesis_hash
,
&
config
.chain_spec
);
let
(
endpoint_gossip_protocol_config
,
endpoint_gossip_notification_service
)
=
endpoint_gossip
::
peers_set_config
::
<
_
,
N
>
(
endpoint_gossip_protocol_name
.clone
(),
metrics
.clone
(),
peer_store_handle
,
);
net_config
.add_notification_protocol
(
endpoint_gossip_protocol_config
);
net_config
.add_notification_protocol
(
endpoint_gossip_protocol_config
);
let
endpoint_gossip_config
=
();
let
endpoint_gossip_config
=
();
let
endpoint_gossip_params
=
EndpointGossipParams
{
let
endpoint_gossip_params
=
EndpointGossipParams
{
config
:
endpoint_gossip_config
,
config
:
endpoint_gossip_config
,
network
,
network
,
...
@@ -369,7 +380,7 @@ where
...
@@ -369,7 +380,7 @@ where
None
,
None
,
run_gossip_worker
(
endpoint_gossip_params
)
?
,
run_gossip_worker
(
endpoint_gossip_params
)
?
,
);
);
}
//
}
let
warp_sync
=
Arc
::
new
(
sc_consensus_grandpa
::
warp_proof
::
NetworkProvider
::
new
(
let
warp_sync
=
Arc
::
new
(
sc_consensus_grandpa
::
warp_proof
::
NetworkProvider
::
new
(
backend
.clone
(),
backend
.clone
(),
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment