This repository was archived by the owner on Apr 26, 2024. It is now read-only.
  
  
  - 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.1k
          Allow events to be created with no prev_events (MSC2716)
          #11243
        
      
          
     Merged
      
      
    
  
     Merged
                    Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      39efad1
              
                Allow events to be created with no prev_events
              
              
                MadLittleMods 66f0859
              
                Add changelog
              
              
                MadLittleMods 9f45d09
              
                Allow member state events without prev_events
              
              
                MadLittleMods e093481
              
                More clarification and specificity in errors/comments
              
              
                MadLittleMods 4bb5fd3
              
                Add tests for creating events with empty prev_events
              
              
                MadLittleMods f421a2d
              
                Fix lints
              
              
                MadLittleMods d10625e
              
                Update test description to be accurate
              
              
                MadLittleMods 2370dca
              
                Remove redundant length check
              
              
                MadLittleMods e2928b5
              
                No new room version necessary and allow no prev_events via allow_no_p…
              
              
                MadLittleMods 85364c5
              
                Remove extra verbose check
              
              
                MadLittleMods 0ed300e
              
                Only worry about having auth_events when allowing no prev_events
              
              
                MadLittleMods 93ca0f8
              
                Update changelog to describe intended usage
              
              
                MadLittleMods 9b9deff
              
                Merge branch 'develop' into madlittlemods/empty-prev-events
              
              
                MadLittleMods 8fada7e
              
                Fix lint
              
              
                MadLittleMods File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -15,12 +15,14 @@ | |
| from typing import Tuple | ||
|  | ||
| from synapse.api.constants import EventTypes | ||
| from synapse.api.room_versions import RoomVersions | ||
| from synapse.events import EventBase | ||
| from synapse.events.snapshot import EventContext | ||
| from synapse.rest import admin | ||
| from synapse.rest.client import login, room | ||
| from synapse.types import create_requester | ||
| from synapse.util.stringutils import random_string | ||
| from tests.test_utils.event_injection import create_event | ||
|  | ||
| from tests import unittest | ||
|  | ||
|  | @@ -156,6 +158,79 @@ def test_duplicated_txn_id_one_call(self): | |
| self.assertEqual(len(events), 2) | ||
| self.assertEqual(events[0].event_id, events[1].event_id) | ||
|  | ||
| def test_create_empty_prev_events_in_msc2716_room_version(self): | ||
| """Try to create an event without any prev_events (only auth_events). | ||
|  | ||
| This is currently only supported in the experimental MSC2716 room versions. | ||
|         
                  MadLittleMods marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| """ | ||
| room_id = self.helper.create_room_as( | ||
| self.user_id, | ||
| tok=self.access_token, | ||
| room_version=RoomVersions.MSC2716v4.identifier, | ||
| ) | ||
|  | ||
| # Create a member event we can use as an auth_event | ||
| memberEvent, memberEventContext = self.get_success( | ||
| create_event( | ||
| self.hs, | ||
| room_id=room_id, | ||
| type="m.room.member", | ||
| sender=self.requester.user.to_string(), | ||
| state_key=self.requester.user.to_string(), | ||
| content={"membership": "join"}, | ||
| ) | ||
| ) | ||
| self.get_success( | ||
| self.persist_event_storage.persist_event(memberEvent, memberEventContext) | ||
| ) | ||
|  | ||
| # Try to create the event with empty prev_events (only auth_events) | ||
| event, _ = self.get_success( | ||
| self.handler.create_event( | ||
| self.requester, | ||
| { | ||
| "type": EventTypes.Message, | ||
| "room_id": room_id, | ||
| "sender": self.requester.user.to_string(), | ||
| "content": {"msgtype": "m.text", "body": random_string(5)}, | ||
| }, | ||
| # Empty prev_events is the key thing we're testing here | ||
| prev_event_ids=[], | ||
| auth_event_ids=[memberEvent.event_id], | ||
| ) | ||
| ) | ||
| self.assertIsNotNone(event) | ||
|         
                  anoadragon453 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
|  | ||
| def test_reject_empty_prev_events_and_auth_events_in_msc2716_room_version( | ||
| self, | ||
| ): | ||
| """Try to create an event without any prev_events (only auth_events). | ||
|         
                  MadLittleMods marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| This is currently only supported in the experimental MSC2716 room versions. | ||
|         
                  MadLittleMods marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| """ | ||
| room_id = self.helper.create_room_as( | ||
| self.user_id, | ||
| tok=self.access_token, | ||
| room_version=RoomVersions.MSC2716v4.identifier, | ||
| ) | ||
|  | ||
| # Try to create the event with empty prev_events and empty auth_events | ||
| self.get_failure( | ||
| self.handler.create_event( | ||
| self.requester, | ||
| { | ||
| "type": EventTypes.Message, | ||
| "room_id": room_id, | ||
| "sender": self.requester.user.to_string(), | ||
| "content": {"msgtype": "m.text", "body": random_string(5)}, | ||
| }, | ||
| prev_event_ids=[], | ||
| # The event should be rejected when there are no auth_events | ||
| auth_event_ids=[], | ||
| ), | ||
| AssertionError, | ||
| ) | ||
|  | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 All of the MSC2716 Complement tests cover this use case since we use it so much there. I've just added some integration tests for this. I didn't add tests for every case to be completely exhaustive but did make sure this extra functionality works and that we don't allow events with empty  
 | ||
|  | ||
| class ServerAclValidationTestCase(unittest.HomeserverTestCase): | ||
| servlets = [ | ||
|  | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The insertion event is connected to the state chain so the whole historical batch can share the same
state_group, see #10975. It also looks nice in the DAG semantically to be able to see the state that authed the batch.For the federation cases, it seems to work 🤔🤷.
auth_event_idsprobablyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that surprises me a bit. I was very much imagining that the federation code would ask for the state at the insertion event. I guess it probably works because we fetch the state at the start of the chain of state events? And we return the full state, so we then can accept all the state events we add? I don't think that is necessary to make the whole batch have the same state group.
Also, I wonder if that'll make the client UI show the state events when backpaginating, making it look like the state was changed at those points, when actually they were changed much further back?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can play around with it but that seems like something for another PR. It's pretty finicky to get right.
Doesn't seem to be a problem for the local origin homeserver with Element probably because they are marked as
outliers🤔I want to test this on a federated homeserver though.
I'm trying to setup a federated homeserver locally to see if it's a problem for remote federated servers. Currently working out the hostname/
server_nameproblem mapping to a port onlocalhost(tips welcome) and basing the config off of the demo script. I'm attempting to use/etc/hostsand a nginx reverse proxy to127.0.0.1:8448(non-tls) . Synapse is configured to betls: falseon8008and8448. This appears to work to getmy.matrix.hostandother.matrix.hostresolving but doesn't make Synapse happy enough to be able to successfully fetch the room list between each other.Might just end up creating a Complement test around making sure the state isn't visible between batches ⏩ but would be nice to double-check with real Element about how it looks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI you can start some preconfigured HSes that federate with each other by running
./demo/start.sh(and./demo/stop.sh)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the Complement test which tests multiple batches over federation to check for historical state and didn't see any problems between batches. But when the historical state chain is connected to the
insertionevent, it does show up before the creation event. Not sure how Element handles events before the creation event 🤷♀️(image is in scrollback order, oldest messages at the top)

/messages response
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #11487 to add a test to ensure the
state_groupsare shared.Things seem to work just fine if I disconnect the floating state chain from the
insertionevent so we can move forward with that in #11114 (comment) after this merges.Both the state chain and the
insertionevent chain can float with noprev_events. No issues with sharedstate_groups, accepting over federation, and the historical state does not show up at all in/messages