Skip to content

Port Event.signatures field to Rust#19706

Merged
erikjohnston merged 7 commits into
developfrom
erikj/port_signatures_field
May 6, 2026
Merged

Port Event.signatures field to Rust#19706
erikjohnston merged 7 commits into
developfrom
erikj/port_signatures_field

Conversation

@erikjohnston
Copy link
Copy Markdown
Member

This is another stepping stone in porting the event class fully to Rust.

The new Signatures class is relatively simple, as we actually don't interact with it that much in the code. It does not implement Mapping or MutableMapping as that takes quite a lot of effort that we don't need, even though it would be more ergonomic.

Comment thread rust/Cargo.toml

[features]
extension-module = ["pyo3/extension-module"]
default = ["extension-module"]
Copy link
Copy Markdown
Member Author

@erikjohnston erikjohnston Apr 17, 2026

Choose a reason for hiding this comment

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

Using this feature means that cargo test doesn't work when interacting with pyo3 types. This is a known issue, and so PyO3 have moved to having maturin and setuptools_rust set the equivalent env var.

This should be a no-op change.

c.f. PyO3/pyo3#5202

@erikjohnston erikjohnston force-pushed the erikj/port_signatures_field branch from 8f525d6 to e5648a0 Compare April 17, 2026 10:57
@erikjohnston erikjohnston force-pushed the erikj/port_signatures_field branch from e5648a0 to 5b57b4e Compare April 17, 2026 12:08
@erikjohnston erikjohnston marked this pull request as ready for review April 17, 2026 13:23
@erikjohnston erikjohnston requested a review from a team as a code owner April 17, 2026 13:23
@anoadragon453 anoadragon453 requested a review from Copilot May 1, 2026 11:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Ports the Event.signatures structure from a Python dict to a Rust-backed Signatures PyO3 class, as part of the incremental Rust migration of the event model.

Changes:

  • Introduces a new Rust Signatures PyO3 class with helpers like get_signature(), update(), and as_dict().
  • Updates Python call sites to use the new API (get_signature, in, update, as_dict) instead of direct nested-dict access patterns.
  • Wraps event signatures in EventBase and ensures JSON materialization uses as_dict().

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/handlers/test_federation.py Updates test to avoid direct item assignment on signatures, using update() instead.
synapse/synapse_rust/events.pyi Adds type stub for the new Signatures class.
synapse/storage/databases/main/events_bg_updates.py Switches old-key signature lookup to get_signature().
synapse/handlers/room_policy.py Uses update() for applying policy server signatures and moves request creation into try.
synapse/handlers/message.py Converts remote invite signatures via as_dict() before updating local event signatures.
synapse/events/init.py Wraps incoming signatures in Signatures and serializes via as_dict() in get_dict().
synapse/event_auth.py Uses __contains__ (in) rather than .get(...) on signatures.
synapse/crypto/keyring.py Updates signature existence checks and key-id extraction to use in + __getitem__.
synapse/crypto/event_signing.py Uses get_signature() for determining whether an event needs re-signing.
rust/src/events/signatures.rs Adds the Rust implementation of the Signatures PyO3 class (plus unit tests).
rust/src/events/mod.rs Registers the new Signatures class in the Rust → Python module.
rust/Cargo.toml Enables serde rc feature (for Arc serialization support).
changelog.d/19706.misc Adds a changelog entry for the port.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread synapse/synapse_rust/events.pyi
Comment thread rust/src/events/signatures.rs
Comment thread rust/src/events/signatures.rs
Comment thread synapse/synapse_rust/events.pyi
Comment thread synapse/synapse_rust/events.pyi Outdated
Copy link
Copy Markdown
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

A few minor points, but looks good on the whole 🦀

Comment thread rust/src/events/signatures.rs
Comment thread rust/src/events/signatures.rs Outdated
Comment thread rust/src/events/signatures.rs
@erikjohnston erikjohnston requested a review from anoadragon453 May 1, 2026 13:21
Copy link
Copy Markdown
Member

@anoadragon453 anoadragon453 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@erikjohnston erikjohnston merged commit 3e6bf10 into develop May 6, 2026
46 checks passed
@erikjohnston erikjohnston deleted the erikj/port_signatures_field branch May 6, 2026 10:38
erikjohnston added a commit that referenced this pull request May 6, 2026
Similar to #19706, let's port the `unsigned` field into a Rust class.

This does change things a bit in that we now define exactly what
unsigned fields that are allowed to be added to an event, and what
actually gets persisted. This should be a noop though, as we carefully
filter out what unsigned fields we allow in from federation, for example

As a side effect of this cleanup, I think this fixes handling
`unsigned.age` on events received over federation.
event.signatures.setdefault(policy_server.server_name, {}).update(
signature.get(policy_server.server_name, {})
)
event.signatures.update(signature)
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.

Is this just casually re-introducing the bug that the preceding 12-line comment warns about?

Copy link
Copy Markdown
Contributor

@MadLittleMods MadLittleMods May 21, 2026

Choose a reason for hiding this comment

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

Tracked by #19796 and being fixed in #19797

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants