Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 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
33 changes: 33 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 @@ -1272,6 +1272,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 = ["macros", "hex"]}
Comment thread
Sajjon marked this conversation as resolved.
Outdated
serde_yaml = { version = "0.9" }
sha1 = { version = "0.10.6" }
sha2 = { version = "0.10.7", default-features = false }
Expand Down
20 changes: 20 additions & 0 deletions prdoc/pr_8839.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
title: net/discovery: File persistence for AddrCache

doc:
- audience: [ Node Dev, Node Operator ]
description: |
Introduce file persistence for `AddrCache`. Upon authority-discovery worker
startup, the worker tries to read a persisted cache from file, if not found
or if deserialization would fail (it should not with this PR, but might
in future if we were to change the JSON format) an empty cache is used.

For every time the in-memory cache is changed, the file is persisted to file,
by serializing the AddrCache to JSON.

The writing to disc is done using a new helper `ThrottlingAsyncFileWriter`
which "throttles" consecutive writes and only uses the last one, plus writing
is done in a background thread, as to not block worker execution.

crates:
- name: sc-authority-discovery
bump: patch
5 changes: 5 additions & 0 deletions substrate/client/authority-discovery/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ 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 }
serde_json.workspace = true
serde_with.workspace = true
serde.workspace = true
sp-api = { workspace = true, default-features = true }
sp-authority-discovery = { workspace = true, default-features = true }
sp-blockchain = { workspace = true, default-features = true }
Expand All @@ -39,6 +42,8 @@ sp-runtime = { workspace = true, default-features = true }
thiserror = { workspace = true }

[dev-dependencies]
hex.workspace = true
tempfile.workspace = true
quickcheck = { workspace = true }
sp-tracing = { workspace = true, default-features = true }
substrate-test-runtime-client = { workspace = true }
Expand Down
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
8 changes: 6 additions & 2 deletions substrate/client/authority-discovery/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
use crate::{
error::{Error, Result},
interval::ExpIncInterval,
worker::addr_cache::create_addr_cache,
ServicetoWorkerMsg, WorkerConfig,
};

use std::{
collections::{HashMap, HashSet},
marker::PhantomData,
path::PathBuf,
sync::Arc,
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
};

use futures::{channel::mpsc, future, stream::Fuse, FutureExt, Stream, StreamExt};

use addr_cache::AddrCache;
use codec::{Decode, Encode};
use ip_network::IpNetwork;
use linked_hash_set::LinkedHashSet;
Expand Down Expand Up @@ -69,6 +70,7 @@ mod schema {
pub mod tests;

const LOG_TARGET: &str = "sub-authority-discovery";
const ADDR_CACHE_PERSISTENCE_PATH: &str = "authority_discovery_addr_cache.json";
Comment thread
Sajjon marked this conversation as resolved.
Outdated

/// Maximum number of addresses cached per authority. Additional addresses are discarded.
const MAX_ADDRESSES_PER_AUTHORITY: usize = 16;
Expand Down Expand Up @@ -261,7 +263,9 @@ where
let publish_if_changed_interval =
ExpIncInterval::new(config.keystore_refresh_interval, config.keystore_refresh_interval);

let addr_cache = AddrCache::new();
// Load contents of persisted cache from file, if it exists, and is valid. Create a new one
// otherwise, and install a callback to persist it on change.
let addr_cache = create_addr_cache(PathBuf::from(ADDR_CACHE_PERSISTENCE_PATH));
Comment thread
Sajjon marked this conversation as resolved.
Outdated

let metrics = match prometheus_registry {
Some(registry) => match Metrics::register(&registry) {
Expand Down
Loading
Loading