Use the same helper for submitting state events on room creation and on state endpoint #1799
Open
eve
wants to merge 1 commit from
eve/ackduck:room_creation_events into main
pull from: eve/ackduck:room_creation_events
merge into: continuwuation:main
continuwuation:main
continuwuation:aranje/illegal-car-mods
continuwuation:renovate/https-github.com-actions-setup-node-7.x
continuwuation:renovate/rand_core-0.x
continuwuation:renovate/rust-zerover-patch-updates
continuwuation:renovate/rust-non-major
continuwuation:renovate/node-patch-updates
continuwuation:renovate/ruma-digest
continuwuation:renovate/cargo-bins-cargo-binstall-1.x
continuwuation:nex/meta/release-schedule
continuwuation:nex/feat/centralise-remote-memberships
continuwuation:nex/feat/pdu-versions
continuwuation:ginger/revert-direct-tls
continuwuation:nex/fix/federated-invite-revoke
continuwuation:nex/feat/admin-api
continuwuation:nex/fix/plunger
continuwuation:jade/perf/gme-rebased
continuwuation:nex/perf/get-missing-events2
continuwuation:nex/backport/v0.5.11
continuwuation:nex/backport/v0.5.10-backport
continuwuation:nex/feat/msc4491-invite-reasons-in-room-creation
continuwuation:nex/feat/deprecated-room-versions
continuwuation:release/v0.5.9
continuwuation:nex/feat/enable-debug-log-release-builds
continuwuation:nex/feat/room-purging
continuwuation:nex/feat/room-shutdown
continuwuation:ginger/ruma-upstreaming
continuwuation:jade/tls-backends
continuwuation:ginger/email-fixes
continuwuation:jade/changelog-labels
continuwuation:nex/fix/v12-publishing
continuwuation:jade/build-info
continuwuation:jade/purge-sync-tokens
continuwuation:ginger/terms-and-conditions
continuwuation:ginger/remove-sliding-sync-proxy
continuwuation:nex/fix/pusher-association
continuwuation:ginger/email-support
continuwuation:jade/community-guidelines
continuwuation:nex/fix/federation-format
continuwuation:jade/git-deps-updates
continuwuation:jade/changelog-check
continuwuation:jade/rust-1-92
continuwuation:ginger/password-reset
continuwuation:nex/experiment/push-gateway-logs
continuwuation:ginger/msc3575-obliteration
continuwuation:nex/feat/block-busted-rooms
continuwuation:nex/fix/informative-startup-errs
continuwuation:ginger/no-left-room-initial-sync
continuwuation:jade/docker-entrypoint
continuwuation:jade/dehydrated-devices
continuwuation:ginger/complement-fixes
continuwuation:nex/fix/stale-destination-cache
continuwuation:nex/experiment/sync-mutex
continuwuation:tcpipuk/docker-docs
continuwuation:jade/snafu
continuwuation:jade/rand-update
continuwuation:nex/stateres-refactor
continuwuation:ginger/779-in-troubleshooting
continuwuation:jade/liveit-guide
continuwuation:jade/http3
continuwuation:nex/feat/admin-hide-empty-rooms
continuwuation:ginger/oobe
continuwuation:nex/fix/debian-thingy
continuwuation:jade/ldap-admin-check
continuwuation:nex/fix/remote-restricted-joins
continuwuation:nex/feat/msc4406-sender-ignored
continuwuation:jade/deadlock-detection
continuwuation:jade/get-started
continuwuation:jade/docs-guide
continuwuation:ginger/fix-local-invites
continuwuation:nex/fix/tpi
continuwuation:nex/feat/room-deletion
continuwuation:nex/feat/msc4322-media-redaction
continuwuation:ginger/stitched-order
continuwuation:ginger/deps/update-rspress
continuwuation:jade/admin-announce-improvements
continuwuation:ginger/xtask-improvements
continuwuation:jade/improve-admin-config-display
continuwuation:nex/fix/better-stateres-error-logs
continuwuation:jade/sender-timeouts
continuwuation:nex/feat/custom-v12-room-ids
continuwuation:ginger/update-metadata
continuwuation:nex/feat/admin-force-logout
continuwuation:tom/max-perf-docs
continuwuation:nex/fix/invalid-appservice-reg
continuwuation:nex/feat/antispam
continuwuation:nex/feat/account-locking
continuwuation:jade/logging-cleanup
continuwuation:jade/remove-legacy-appservice-auth
continuwuation:nex/fix/key-query
continuwuation:jade/update-prek
continuwuation:nex/fix/room-summaries
continuwuation:ginger/restrict-admin-commands
continuwuation:ginger/enable-console-by-default
continuwuation:jade/tag-fixes
continuwuation:jade/otlp
continuwuation:nex/meta/pull-req-template
continuwuation:nex/fix/fed-invite-compliance
continuwuation:nex/feat/build-commit
continuwuation:nex/feat/join-logging
continuwuation:jade/mailmap-updates
continuwuation:jade/hack-ci-tmp
continuwuation:jade/v12-stable
continuwuation:jade/relations
continuwuation:ginger/database-refactor
continuwuation:jade/fix-ldap-uiaa
continuwuation:nex/fix/validation
continuwuation:ginger/nuke-invalid-msc4133-fields-in-migration
continuwuation:ginger/downgrade-artifact-actions
continuwuation:oddlid/reload-fix
continuwuation:jade/fix-assert
continuwuation:ginger/sync-v3-cleanup
continuwuation:ginger/remove-absolute-action-urls
continuwuation:jade/website
continuwuation:nex/fix/backoff
continuwuation:ginger/fix-mdbook-for-0.5
continuwuation:ginger/no-docker-on-prs
continuwuation:backport/v0.5.0-rc.8-1
continuwuation:nex/fed-improvements
continuwuation:jade/rust-1.90
continuwuation:jade/mirror-dockerhub
continuwuation:jade/clippy-fixes
continuwuation:jade/fix-support
continuwuation:jade/clean-images
continuwuation:jade/wal-compression-type
continuwuation:jade/flake-clone
continuwuation:ginger/upload-rpms-on-schedule
continuwuation:nex/fix/incoming-fetch
continuwuation:nex/fix/upgrade
continuwuation:tom/ci-fedora-rpm
continuwuation:jade/ci-release-fix
continuwuation:jade/rocksdb-10-5
continuwuation:ginger/fix-msc4133-migration
continuwuation:ginger/migrate-busted-tz
continuwuation:hydra/public
continuwuation:nex/feat/manual-extremities
continuwuation:nex/feat/async-media
continuwuation:nex/feat/fast-joins-hack-do-not-use-DO-NOT-USE
continuwuation:nex/feat/better-logging
continuwuation:trigger-ci-so-latest-isnt-on-illegal-car-mods
continuwuation:nex/feat/pins-backfill
continuwuation:jade/tuwunel-2025-06-old
continuwuation:jade/ai-slop-db-docs
continuwuation:nex/fix-create-auth
continuwuation:jade/version-stats
continuwuation:jade/read-receipts
continuwuation:jade/rust-toolchain-no-targets
continuwuation:jade/logging-features
continuwuation:jade/syncv5-typing
continuwuation:jade/msc2815
continuwuation:morguldir/see-eye
continuwuation:jade/css-small-screen
continuwuation:nex/wip-751
continuwuation:tuwunel-rebase
continuwuation:test
continuwuation:oddlid/rename-admin-room-bot
continuwuation:strawberry/nix-ci-stuff
continuwuation:strawberry/valgrind
continuwuation:phonemain
continuwuation:strawberry/morgs-snake-sync-jason-main
continuwuation:newer-media-endpoints
continuwuation:folly-coroutines-async-io
continuwuation:federation-retry-timer-port
continuwuation:bad-attempt-at-extracting-homeserver-signing-key
continuwuation:room-deletion-attempt-do-not-use
No reviewers
Labels
Clear labels
Abandoned
This pull request appears to be abandoned by its author.
Blocked
This pull request or issue is currently blocked from being merged/closed
Bug
Something isn't working as intended
Changelog
Added
Changelog entry added
Changelog
Missing
No changelog when one is needed
Changelog
None
Changelog is unnecesary for this change
Cherry-picking
Commits picked from other conduit projects
Database
This requires or includes changes to the database
Dependencies
Something dependency related
Dependencies/Renovate
Automatic dependency upgrades by Renovate
Difficulty
Easy
Low difficulty to implement - touches few parts of the codebase, low complexity
Difficulty
Hard
High difficulty to implement - touches many parts of the codebase, high complexity
Difficulty
Medium
Medium difficulty to implement - touches more parts of the codebase, higher complexity
Documentation
Improvements or additions to documentation
Enhancement
New feature or request
Good first issue
Good for newcomers
Help wanted
Additional eyes and keyboards are required for this one
Inherited
Issues that have been inhereted from the project pre-fork
Matrix/Administration
Features pertaining to homeserver administration
Matrix/Appservices
Features pertaining to the appservice API
Matrix/Auth
Features pertaining to authentication
Matrix/Client
Features pertaining to client-to-server interactions
Matrix/Core
Issues relating to core matrix functionality, such as state resolution and PDU formats
Matrix/E2EE
Issues related to end to end encryption
Matrix/Federation
Features pertaining to server-to-server interactions
Matrix/Hydra
Issues related to room version 12 and related changes (temporary label)
Matrix/MSC
Features pertaining to unstable matrix features
Matrix/Media
Features pertaining to media interactions
Matrix/T&S
Changes or issues related to trust & safety tooling
Merge
This PR is ready to be merged
Merge/Manual
This PR should be manually merged
Merge/Squash
This PR should be squashed when it is merged
Meta
Related to housekeeping, maintenance, or other repo-meta.
Meta/CI
Issues related to CI changes
Meta/Packaging
Packaging
Priority
Blocking
This issue is blocking the next release
Priority
High
This issue is very important
Priority
Low
This issue is of a rather low priority
Security
This item is related to general security
Status
Confirmed
This issue has enough information and is confirmed
Status
Duplicate
This issue or pull request already exists
Status
Invalid
This issue doesn't seem right
Status
Needs Investigation
This issue needs further investigation
Support
Questions or support requests
bob the builder
pdu logic rewrite starring nexus nicholson
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Dependencies
No dependencies set.
Reference
continuwuation/continuwuity!1799
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "eve/ackduck:room_creation_events"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
On room creation, A list of initial state events may be provided that should be submitted to the room after creation. These events should be treated as any other state event and submitted to the same checks.
With this change, state events submitted on room creation will be submitted through the same helper as those through the usual endpoint.
The submission helper is moved to the timeline service to make it available everywhere. This will be useful for implementing #903.
This pull request...
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
420d2173e0210b7e95b7210b7e95b76656a2b1136656a2b1139cea8d2080seems sensible, just some comments R.E. making some opportunistic style changes
@ -0,0 +20,4 @@#[implement(super::Service)]#[allow(clippy::too_many_arguments)]pub async fn send_state_event_for_key_helper(I think if you're attaching it to the service,
_helperisn't necessary.send_state_eventis shorter and probably more memorable imo@ -0,0 +56,4 @@}#[implement(super::Service)]async fn allowed_to_send_state_event(I think this should be called
assert_allowed_to_send_state_event, since its sole function is propagating an error if the change is forbidden@ -0,0 +63,4 @@state_key: &str,json: &mut Raw<AnyStateEventContent>,) -> Result {match event_type {Forgejo forgot to include this comment apparently but I think it'd be a good idea to split these match arms into their own functions to make this function less complex cognitively
Would that be better ? Yeah it's a big match statement, but it's very intuitive to understand what it does. I feel like splitting it into functions would just make it more difficult to read the code by adding more indirection to the code, without really making it more clear than it already is.
I disagree. I think maintaining the match arms but having them all point to functions is easier to follow, since there's clear(er) boundaries. This might just be my dyslexia influencing my preferences, but I find the match statement really hard to follow.
Something like this is what I (personally) prefer:
I would also argue the simple arms should go into their own functions for style consistency but that'd be overly pedantic of me
It's very easy to jump to function definitions, I don't think it makes it any more difficult.
I tend to flatten the code when moving it into a function out of a match arm, preferring to
return falseexplicitly whenever such a condition is encountered rather than nesting a bunch of statements. For example:pub(super) fn verify_policy_signature(via: &ServerName,ps_key: &Base64<Standard, Vec<u8>>,pdu_json: &CanonicalJsonObject,redaction_rules: &RedactionRules,) -> bool {#[cfg(debug_assertions)]{let pretty = serde_json::to_string(pdu_json).unwrap();trace!(data=%pretty, "Preparing to check policy server signature");};let Some(canonical_json) = redact(pdu_json.clone(), redaction_rules, None).ok().and_then(|r| to_canonical_object(r).ok())else {debug_warn!("Failed to redact event");return false;};let Some(signature) = extract_signature(pdu_json, via, POLICY_SERVER_KEY_ID_ED25519) else {debug!("No (valid) policy server signature present on event");return false;};trace!(%signature, "Verifying policy server signature");let Ok(canonical_str) = to_canonical_json_string_for_signing(&canonical_json) else {debug_warn!("Could not convert canonical json object into string");return false;};verify_canonical_json_bytes(&SigningKeyAlgorithm::Ed25519,ps_key.as_bytes(),signature.as_bytes(),canonical_str.as_bytes(),).inspect_err(|e| debug_error!("Policy server verification failed: {e}")).is_ok()}This means the "happy path" is always as leftmost as possible and is generally easier to read.
Again though, "easy to read/follow" is subjective, and it's entirely plausible this is just an issue exclusive to me. If you disagree let me know and I'm happy to mark this as resolved
Fair enough. I've split the match statement. You're right I do think it's more readable this way now that I look at it.
9cea8d20805e47223ab9Finally getting back to this, sorry been busy.
No worries!
5e47223ab9a73be5450dcan we get the clippy lints fixed ? looks good otherwise
a73be5450da72d318c1aa72d318c1aeea0a79300eea0a79300848da5be3bView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.