Update GMSL: use static Check functions (#3052)

Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/359 

A nice side effect is that we don't need to re-parse the events in some
cases.
This commit is contained in:
kegsay 2023-04-14 12:32:42 +01:00 committed by GitHub
parent 94e81cc3f3
commit ca63b414da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 31 deletions

View file

@ -641,31 +641,19 @@ func (t *missingStateReq) lookupMissingStateViaState(
if err != nil {
return nil, err
}
s := fclient.RespState{
// Check that the returned state is valid.
authEvents, stateEvents, err := gomatrixserverlib.CheckStateResponse(ctx, &fclient.RespState{
StateEvents: state.GetStateEvents(),
AuthEvents: state.GetAuthEvents(),
}
// Check that the returned state is valid.
authEvents, stateEvents, err := s.Check(ctx, roomVersion, t.keys, nil)
}, roomVersion, t.keys, nil)
if err != nil {
return nil, err
}
parsedState := &parsedRespState{
return &parsedRespState{
AuthEvents: authEvents,
StateEvents: stateEvents,
}
// Cache the results of this state lookup and deduplicate anything we already
// have in the cache, freeing up memory.
// We load these as trusted as we called state.Check before which loaded them as untrusted.
for i, evJSON := range s.AuthEvents {
ev, _ := gomatrixserverlib.NewEventFromTrustedJSON(evJSON, false, roomVersion)
parsedState.AuthEvents[i] = t.cacheAndReturn(ev)
}
for i, evJSON := range s.StateEvents {
ev, _ := gomatrixserverlib.NewEventFromTrustedJSON(evJSON, false, roomVersion)
parsedState.StateEvents[i] = t.cacheAndReturn(ev)
}
return parsedState, nil
}, nil
}
func (t *missingStateReq) lookupMissingStateViaStateIDs(ctx context.Context, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion) (