Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Refactor event building into EventBuilder #4481

Merged
merged 8 commits into from
Jan 29, 2019
Merged

Conversation

erikjohnston
Copy link
Member

This is so that everything is done in one place, making it easier to change the event format based on room version.

The crux of what's happening here is that the EventBuilder is now meant to be independent of the format version, allowing the rest of the code to build up events without worrying about different versions. This is done by making it an attr class with well defined fields that are of interest when building an event (mainly type/state_key/content/etc), and only adding the rest of the fields when we finally build the event (which handles things like adding prev events, signing and hashing it, using the right format etc)

Hopefully the commits are relatively stand alone.

@erikjohnston erikjohnston requested a review from a team January 25, 2019 17:53
@codecov-io
Copy link

codecov-io commented Jan 25, 2019

Codecov Report

Merging #4481 into develop will increase coverage by 6.89%.
The diff coverage is 96.8%.

@@             Coverage Diff             @@
##           develop    #4481      +/-   ##
===========================================
+ Coverage    67.87%   74.76%   +6.89%     
===========================================
  Files          336      336              
  Lines        34163    34198      +35     
  Branches      5556     5564       +8     
===========================================
+ Hits         23188    25568    +2380     
+ Misses        9362     7054    -2308     
+ Partials      1613     1576      -37

synapse/crypto/event_signing.py Outdated Show resolved Hide resolved
synapse/events/builder.py Outdated Show resolved Hide resolved
synapse/events/builder.py Outdated Show resolved Hide resolved
synapse/handlers/message.py Show resolved Hide resolved
synapse/events/builder.py Show resolved Hide resolved
synapse/events/builder.py Show resolved Hide resolved
@erikjohnston
Copy link
Member Author

Now based on #4493 and #4494

This is so that everything is done in one place, making it easier to
change the event format based on room version
`.user_id` is proxed to `.sender` in FrozenEvent, so this has no
functional change
@erikjohnston erikjohnston requested a review from a team January 29, 2019 11:24
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

generally seems plausible. a few questions.

synapse/events/builder.py Outdated Show resolved Hide resolved
synapse/handlers/message.py Show resolved Hide resolved
synapse/handlers/message.py Outdated Show resolved Hide resolved
Deferred[FrozenEvent]
"""

state_ids = yield self._state.get_current_state_ids(
Copy link
Member

Choose a reason for hiding this comment

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

Slightly concerned that we used to do context.get_prev_state_ids, which might return something different to this?

Copy link
Member Author

Choose a reason for hiding this comment

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

In practice, they're exactly the same, compute_event_context just resolves the state across the prev_events to get prev_state_ids. From a protocol perspective, auth_events should be based on the state at the event.

We could make compute_event_context work with an EventBuilder, but I was slightly shying away from doing so in the interests of not changing too much. We could probably do so though

@erikjohnston erikjohnston requested a review from a team January 29, 2019 12:16
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm I think...

@erikjohnston erikjohnston merged commit b8d75ef into develop Jan 29, 2019
@erikjohnston erikjohnston deleted the erikj/event_builder branch March 5, 2019 13:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants