Skip to content

statement-store: source-aware local topic set in ExplicitAffinity#12308

Open
AndreiEres wants to merge 5 commits into
feature/statement-store-dhtfrom
andrei/explicit-affinity-local-topic-set
Open

statement-store: source-aware local topic set in ExplicitAffinity#12308
AndreiEres wants to merge 5 commits into
feature/statement-store-dhtfrom
andrei/explicit-affinity-local-topic-set

Conversation

@AndreiEres

@AndreiEres AndreiEres commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Part of #11934: a source-aware local topic set in ExplicitAffinity. Replaces the stub add_topics/remove_topics with a per-topic, per-source reference-count map; a topic stays present until its last source drops. Dead code behind v2dht_enabled (off).

// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Explicit topic affinity for the v2 DHT gossip path.
//!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This hunk is for AI, not humans.

/// tracks how many holders of that category want the topic.
#[allow(dead_code)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) enum AffinitySource {

@P1sar P1sar Jun 9, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why there is no DHT based affinity?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IIUC, it's not a responsibility of this module. I beleive we can't add topic based on DHT affinity as we don't determine the topics for that, we compute the distance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

well yes, but then would be still nice to have a list of topics that we store in general for future peers steering, and the fastest way is basically add every topic that we observe and DHT affinate to to some list as well. so why it can't be this list?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Created an issues to think about it while doing peer stearing

//! drops. Expose `topics()` to read the current set. Source-keying can't be retrofitted cheaply,
//! so it comes first; the enum is the extension point for future sources; `topics()` also feeds
//! the peers-topology module (#11933).
//! 4. [x] **Configured source.** Read topics from CLI at construction and `add_topics(Configured,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this marked as done ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Was done in the different PR already :-)

pub(crate) fn add_topics(&mut self, source: AffinitySource, topics: &[Topic]) {
log::trace!(target: LOG_TARGET, "explicit_affinity: add_topics {} from {source:?}", topics.len());
for &topic in topics {
*self.local.entry(topic).or_default().entry(source).or_insert(0) += 1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe follow the same as in func remove_topics?

let count = self.local.entry(topic).or_default().entry(source).or_insert(0);
*count = count.saturating_add(1);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

}

#[test]
fn add_then_remove_same_source() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This test looks redundant with the final remove/assert steps in the two refcount tests below. Could we drop it and keep only the tests that cover distinct invariants

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep

@AndreiEres AndreiEres enabled auto-merge (squash) June 9, 2026 15:06
@AndreiEres AndreiEres force-pushed the andrei/explicit-affinity-local-topic-set branch from fb39d1d to 7bd9815 Compare June 9, 2026 15:20
@AndreiEres AndreiEres disabled auto-merge June 10, 2026 07:04
@AndreiEres AndreiEres enabled auto-merge (squash) June 10, 2026 08:35
@paritytech-workflow-stopper

Copy link
Copy Markdown

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/27263889836
Failed job name: check-runtime-compatibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants