Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
effaaa0
Add `CodableAddrCache` (Encode/Decode) with TryFrom/From impl for Add…
Sajjon Jun 12, 2025
7c01369
Rename `CodableAddrcache`>`SerializableAddrCache`, eeplace Encode/Dec…
Sajjon Jun 12, 2025
b084774
Add conversion tests and Serde tests for AddrCache
Sajjon Jun 12, 2025
b3feb52
Implement AddrCache write to disk
Sajjon Jun 13, 2025
702a75d
Remove optional path to AddrCache on disk - replaced with a non optio…
Sajjon Jun 16, 2025
b385fe0
Add failing test for persistence of AddrCache
Sajjon Jun 16, 2025
11cbaca
fix persisted cache test
Sajjon Jun 16, 2025
93bdefb
Test removal of values of persisted AddrCache
Sajjon Jun 16, 2025
72473ec
Add test load from cache
Sajjon Jun 16, 2025
a5925bf
Add prdoc for PR 8839
Sajjon Jun 16, 2025
8375781
Update substrate/client/authority-discovery/src/worker/addr_cache.rs
Sajjon Jun 16, 2025
ac9fd07
ThrottlingAsyncFileWriter takes a `spawner: impl SpawnNamed` to spawn…
Sajjon Jun 17, 2025
c9cc635
Fix authority discovery tests
Sajjon Jun 17, 2025
e517c13
Make `MultiAddr` and `PeerId` in `substrate/client/network` be Serde …
Sajjon Jun 18, 2025
c09b352
Workder holds an optional path, and we conditionally persist the Addr…
Sajjon Jun 18, 2025
e6b86b5
Simplify persist interval. Persist on shutdown.
Sajjon Jun 19, 2025
ec432c3
Skip using tokio::fs, use sync write_to_file - fix issue with tests b…
Sajjon Jun 19, 2025
5c0816e
Try to fix prdoc
Sajjon Jun 19, 2025
7f109e4
Derive ParitalEq instead of manual impl
Sajjon Jun 19, 2025
65f9a40
Remove manual impl of Debug for AddrCache - remnant of the past
Sajjon Jun 19, 2025
b90964d
rename variable, incorrectly named _tempdir
Sajjon Jun 19, 2025
1071803
Remove superflous setting of file permissions
Sajjon Jun 19, 2025
a691024
remove obsolete doc
Sajjon Jun 19, 2025
99a5950
Switched from `Arc<dyn SpawnNamed>` to `Box<dyn SpawnNamed>`
Sajjon Jun 19, 2025
c2dcd07
PR reviews
Sajjon Jun 23, 2025
2624620
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jun 23, 2025
3f6df96
resolve tempdir drop issue
Sajjon Jun 23, 2025
aab3b35
remove unnessary Arcs
Sajjon Jun 23, 2025
6a47ca7
remove trivial test
Sajjon Jun 23, 2025
ab08ed1
remove comment
Sajjon Jun 23, 2025
0641e93
remove unneeded dependency
Sajjon Jun 23, 2025
7a5a237
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jun 23, 2025
186bd5c
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Jun 23, 2025
c4ff9d9
Fix PRDoc
Sajjon Jun 23, 2025
2b25207
Change PRDoc
Sajjon Jun 23, 2025
2253791
Try to fix PRDoc
Sajjon Jun 23, 2025
28219c1
Try to fix PRDoc validation
Sajjon Jun 23, 2025
61e7315
Fix PRDoc
Sajjon Jun 23, 2025
2f4e84e
update PRDoc
Sajjon Jun 24, 2025
63e2119
Update PRDoc
Sajjon Jun 24, 2025
a93e938
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jun 24, 2025
1fee004
Update PRDoc
Sajjon Jun 24, 2025
64539f1
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jun 27, 2025
2ce02e4
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jun 27, 2025
629943f
Storage optimized AddrCache
Sajjon Jun 27, 2025
f1f9354
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jun 30, 2025
eaf46e8
Faster AddrCache persisting by cloning outside of spawned task and se…
Sajjon Jun 30, 2025
23d52a2
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jun 30, 2025
11498e3
Sacrifice code quality for speed and memory optimiziation. Drop itert…
Sajjon Jun 30, 2025
fcf1fa0
Remove word 'error' in info log, trying to fix zombinenet test which …
Sajjon Jun 30, 2025
a26e4cd
empty commit to retrigger ci
alvicsam Jun 30, 2025
7cd7463
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jul 2, 2025
7794a4f
Merge branch 'master' into cyon/persist_peers_cache
Sajjon Jul 2, 2025
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
36 changes: 36 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,7 @@ serde = { version = "1.0.214", default-features = false }
serde-big-array = { version = "0.3.2" }
serde_derive = { version = "1.0.117" }
serde_json = { version = "1.0.132", default-features = false }
serde_with = { version = "3.12.0", default-features = false, features = ["hex", "macros"] }
serde_yaml = { version = "0.9" }
sha1 = { version = "0.10.6" }
sha2 = { version = "0.10.7", default-features = false }
Expand Down
3 changes: 3 additions & 0 deletions cumulus/client/relay-chain-minimal-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,22 @@ fn build_authority_discovery_service<Block: BlockT>(
_ => None,
}
});
let net_config_path = config.network.net_config_path.clone();
let (worker, service) = sc_authority_discovery::new_worker_and_service_with_config(
sc_authority_discovery::WorkerConfig {
publish_non_global_ips: auth_disc_publish_non_global_ips,
public_addresses: auth_disc_public_addresses,
// Require that authority discovery records are signed.
strict_record_validation: true,
persisted_cache_directory: net_config_path,
..Default::default()
},
client,
Arc::new(network.clone()),
Box::pin(dht_event_stream),
authority_discovery_role,
prometheus_registry,
task_manager.spawn_handle(),
);

task_manager.spawn_handle().spawn(
Expand Down
3 changes: 3 additions & 0 deletions polkadot/node/service/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ where
);
}

let network_config = config.network.clone();
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
config,
backend: backend.clone(),
Expand Down Expand Up @@ -568,13 +569,15 @@ where
public_addresses: auth_disc_public_addresses,
// Require that authority discovery records are signed.
strict_record_validation: true,
persisted_cache_directory: network_config.net_config_path,
..Default::default()
},
client.clone(),
Arc::new(network.clone()),
Box::pin(dht_event_stream),
authority_discovery_role,
prometheus_registry.clone(),
task_manager.spawn_handle(),
);

task_manager.spawn_handle().spawn(
Expand Down
23 changes: 23 additions & 0 deletions prdoc/pr_8839.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
title: "net/discovery: File persistence for AddrCache"
doc:
- audience: Node Dev
description: |-
Persisting the AddrCache periodically (every 10 minutes) and on worker
shutdown. Read AddrCache from file upon launch of worker.

AddrCache is saved as authority_discovery_addr_cache.json in the
folder configured by net_config_path of NetworkConfiguration.

This reduces the time it takes for a node to reconnect to peers after
restart.
crates:
- name: sc-authority-discovery
bump: major
- name: sc-network-types
bump: minor
- name: cumulus-relay-chain-minimal-node
bump: patch
- name: polkadot-service
bump: patch
- name: staging-node-cli
bump: patch
3 changes: 3 additions & 0 deletions substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ pub fn new_full_base<N: NetworkBackend<Block, <Block as BlockT>::Hash>>(
task_manager.spawn_handle().spawn("mixnet", None, mixnet);
}

let net_config_path = config.network.net_config_path.clone();
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
config,
backend: backend.clone(),
Expand Down Expand Up @@ -659,13 +660,15 @@ pub fn new_full_base<N: NetworkBackend<Block, <Block as BlockT>::Hash>>(
sc_authority_discovery::WorkerConfig {
publish_non_global_ips: auth_disc_publish_non_global_ips,
public_addresses: auth_disc_public_addresses,
persisted_cache_directory: net_config_path,
..Default::default()
},
client.clone(),
Arc::new(network.clone()),
Box::pin(dht_event_stream),
authority_discovery_role,
prometheus_registry.clone(),
task_manager.spawn_handle(),
);

task_manager.spawn_handle().spawn(
Expand Down
6 changes: 6 additions & 0 deletions substrate/client/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ rand = { workspace = true, default-features = true }
sc-client-api = { workspace = true, default-features = true }
sc-network = { workspace = true, default-features = true }
sc-network-types = { workspace = true, default-features = true }
sc-service.workspace = true
serde.workspace = true
serde_json.workspace = true
sp-api = { workspace = true, default-features = true }
sp-authority-discovery = { workspace = true, default-features = true }
sp-blockchain = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-keystore = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
thiserror = { workspace = true }
tokio.workspace = true

[dev-dependencies]
hex.workspace = true
quickcheck = { workspace = true }
sp-tracing = { workspace = true, default-features = true }
substrate-test-runtime-client = { workspace = true }
tempfile.workspace = true

[build-dependencies]
prost-build = { workspace = true }
3 changes: 3 additions & 0 deletions substrate/client/authority-discovery/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub enum Error {
#[error("Failed to encode or decode scale payload.")]
EncodingDecodingScale(#[from] codec::Error),

#[error("Failed to encode or decode AddrCache.")]
EncodingDecodingAddrCache(String),

#[error("Failed to parse a libp2p multi address.")]
ParsingMultiaddress(#[from] sc_network::multiaddr::ParseError),

Expand Down
25 changes: 21 additions & 4 deletions substrate/client/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub use crate::{
worker::{AuthorityDiscovery, NetworkProvider, Role, Worker},
};

use std::{collections::HashSet, sync::Arc, time::Duration};
use std::{collections::HashSet, path::PathBuf, sync::Arc, time::Duration};

use futures::{
channel::{mpsc, oneshot},
Expand All @@ -44,8 +44,8 @@ use sc_network::{event::DhtEvent, Multiaddr};
use sc_network_types::PeerId;
use sp_authority_discovery::AuthorityId;
use sp_blockchain::HeaderBackend;
use sp_core::traits::SpawnNamed;
use sp_runtime::traits::Block as BlockT;

mod error;
mod interval;
mod service;
Expand Down Expand Up @@ -88,6 +88,11 @@ pub struct WorkerConfig {
///
/// Defaults to `false` to provide compatibility with old versions
pub strict_record_validation: bool,

/// The directory of where the persisted AddrCache file is located,
/// optional since NetworkConfiguration's `net_config_path` field
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we make sure that there is always a default path so we always are able to persist ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sandreim read the section about net_config_path in PR description. In practice the path seems to always be set. So should always be using persistence.

@lexnv what do you say? Any way to default to a valid path..?

/// is optional. If None, we won't persist the AddrCache at all.
pub persisted_cache_directory: Option<PathBuf>,
}

impl Default for WorkerConfig {
Expand All @@ -110,6 +115,7 @@ impl Default for WorkerConfig {
publish_non_global_ips: true,
public_addresses: Vec::new(),
strict_record_validation: false,
persisted_cache_directory: None,
}
}
}
Expand All @@ -123,6 +129,7 @@ pub fn new_worker_and_service<Client, Block, DhtEventStream>(
dht_event_rx: DhtEventStream,
role: Role,
prometheus_registry: Option<prometheus_endpoint::Registry>,
spawner: impl SpawnNamed + 'static,
) -> (Worker<Client, Block, DhtEventStream>, Service)
where
Block: BlockT + Unpin + 'static,
Expand All @@ -136,6 +143,7 @@ where
dht_event_rx,
role,
prometheus_registry,
spawner,
)
}

Expand All @@ -149,6 +157,7 @@ pub fn new_worker_and_service_with_config<Client, Block, DhtEventStream>(
dht_event_rx: DhtEventStream,
role: Role,
prometheus_registry: Option<prometheus_endpoint::Registry>,
spawner: impl SpawnNamed + 'static,
) -> (Worker<Client, Block, DhtEventStream>, Service)
where
Block: BlockT + Unpin + 'static,
Expand All @@ -157,8 +166,16 @@ where
{
let (to_worker, from_service) = mpsc::channel(0);

let worker =
Worker::new(from_service, client, network, dht_event_rx, role, prometheus_registry, config);
let worker = Worker::new(
from_service,
client,
network,
dht_event_rx,
role,
prometheus_registry,
config,
spawner,
);
let service = Service::new(to_worker);

(worker, service)
Expand Down
Loading